make-java

An attempt to build java project using Makefiles
git clone git@getsh.org:make-java.git
Log | Files | Refs | README | LICENSE

commit 52ddce1682ef459e250a50d12508455235c69ca0
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date:   Sat, 13 Apr 2024 14:45:51 +0000

Brave New World

Diffstat:
A.gitignore | 1+
ACOPYING | 6++++++
AMakefile.sample | 18++++++++++++++++++
AREADME | 4++++
Aconfig.mk | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 112 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +out/ diff --git a/COPYING b/COPYING @@ -0,0 +1,6 @@ +nb is in the public domain. + +To the extent possible under law, Bharatvaj Hemanth <bharatvaj@getsh.org> +has waived all copyright and related or neighboring rights to this work. + +http://creativecommons.org/publicdomain/zero/1.0/ diff --git a/Makefile.sample b/Makefile.sample @@ -0,0 +1,18 @@ +.PHONY: build deps test deploy setup + +VERSION = 0.1.0 +SRC ?= $(wildcard src/*.scala) +DEST ?= .bin +MAIN ?= Main +PROGRAM := myjavaproject + +DEPS += com/android/org.osgi/osgi.core\:3.2.0 + +.DEFAULT_GOAL := all + +include config.mk + +all: $(BIN_DIR)/$(PROGRAM).jar + +clean: + $(RMDIR) $(BIN_DIR)/ diff --git a/README b/README @@ -0,0 +1,4 @@ +make-java +========= + +An attempt to build maven projects using plain GNUmakefile diff --git a/config.mk b/config.mk @@ -0,0 +1,83 @@ +JAVAC ?= javac +SCALAC ?= scalac +JAR ?= jar + +JAVA ?= java +SCALA ?= scala + +TARGET_MAIN = myjavaprogram.Main + +# Repos +MAVEN = https://repo1.maven.org/maven2 + +JVM_TARGET_VESRION ?= 1.8 +LIB_DIR ?= out/lib +BIN_DIR ?= out/bin + +ifeq ($(OS),Windows_NT) + RM = del /s /q + # TODO check whether it's working + RMDIR = rmdir /s /q + MKDIR = mkdir +else + RM = rm -rf + RMDIR = rm -rf + MKDIR = mkdir -p +endif +DOWNLOAD = curl -fLs +FINAL_PROGRAM = $(PROGRAM)-$(VERSION) + +empty:= +space := $(empty) $(empty) +$(space) := $(space) + +LIBS = $(wildcard $(LIB_DIR)/*.jar) + +JARFILES := $(foreach DEP, $(DEPS), \ + $(subst :,-,$(notdir $(DEP).jar)) \ +) + +pkgver = $(lastword $(subst :,$(space), $(1))) + +pkgname = $(firstword $(subst :, $(space), $(1))) + +maven_url = $(MAVEN)/$(call pkgname, $(1))/$(call pkgver, $(1))/$(notdir $(call pkgname, $(1)))-$(call pkgver, $(1)).jar + +jarfile = $(notdir $(subst :,-, $(1))).jar + +$(LIB_DIR)/%: setup + $(info > Downloading '$*' into $(LIB_DIR)/) + @$(DOWNLOAD) $(call maven_url, $*) --output "$(LIB_DIR)/$(call jarfile, $*)" + +CLASSPATH := $(subst $(space),:,$(wildcard $(LIB_DIR)/*.jar)) + +deps: $(foreach DEP, $(DEPS), $(LIB_DIR)/$(DEP)) + +%.class: %.scala + $(SCALAC) $< -sourcepath $(SRC) -classpath $(CLASSPATH) -target:jvm-$(JVM_TARGET_VESRION) + +DEPLOY_BIN = $(BIN_DIR)/$(FINAL_PROGRAM) +$(DEPLOY_BIN).jar: $(BIN_DIR)/$(PROGRAM).jar + $(info > Building '$(DEPLOY_BIN)') + # $(MKDIR) $(BIN_DIR)/classes + # $(foreach JARFILES, $(wildcard $(LIB_DIR)/*.jar), \ + # cd $(BIN_DIR)/classes; $(JAR) xvf $(realpath $(JARFILES)) \ + # ) + echo "$(SCALA) -classpath "$(CLASSPATH):$(FINAL_PROGRAM).jar" $(TARGET_MAIN) $$*" > $(DEPLOY_BIN) + cd $(BIN_DIR)/classes; $(JAR) xvf $(realpath $(BIN_DIR)/$(PROGRAM)).jar + cd $(BIN_DIR)/classes && $(JAR) cvf $(realpath $(DEPLOY_BIN)).jar * + chmod +x $(DEPLOY_BIN) + + +$(BIN_DIR)/$(PROGRAM).jar: $(SRC) + @make setup + $(info > Building '$(BIN_DIR)/$(PROGRAM)') + @$(SCALAC) -classpath "${CLASSPATH}" $^ -d $@ -target:jvm-$(JVM_TARGET_VESRION) + @echo "$(SCALA) -classpath "$(CLASSPATH):$(PROGRAM).jar" $(TARGET_MAIN) $$*" > $(BIN_DIR)/$(PROGRAM) + @chmod +x $(BIN_DIR)/$(PROGRAM) + +deploy: $(BIN_DIR)/$(PROGRAM)-$(VERSION).jar + +setup: + @$(MKDIR) $(BIN_DIR) + @$(MKDIR) $(LIB_DIR)