make-java

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

config.mk (2204B)


      1 JAVAC ?= javac
      2 SCALAC ?= scalac
      3 JAR ?= jar
      4 
      5 JAVA ?= java
      6 SCALA ?= scala
      7 
      8 TARGET_MAIN = myjavaprogram.Main
      9 
     10 # Repos
     11 MAVEN = https://repo1.maven.org/maven2
     12 
     13 JVM_TARGET_VESRION ?= 1.8
     14 LIB_DIR ?= out/lib
     15 BIN_DIR ?= out/bin
     16 
     17 ifeq ($(OS),Windows_NT)
     18 	RM = del /s /q
     19 	# TODO check whether it's working
     20 	RMDIR = rmdir /s /q
     21 	MKDIR = mkdir
     22 else
     23 	RM = rm -rf
     24 	RMDIR = rm -rf
     25 	MKDIR = mkdir -p
     26 endif
     27 DOWNLOAD = curl -fLs
     28 FINAL_PROGRAM = $(PROGRAM)-$(VERSION)
     29 
     30 empty:=
     31 space := $(empty) $(empty)
     32 $(space) := $(space)
     33 
     34 LIBS = $(wildcard $(LIB_DIR)/*.jar)
     35 
     36 JARFILES := $(foreach DEP, $(DEPS), \
     37 	   $(subst :,-,$(notdir $(DEP).jar)) \
     38 )
     39 
     40 pkgver = $(lastword $(subst :,$(space), $(1)))
     41 
     42 pkgname = $(firstword $(subst :, $(space), $(1)))
     43 
     44 maven_url = $(MAVEN)/$(call pkgname, $(1))/$(call pkgver, $(1))/$(notdir $(call pkgname, $(1)))-$(call pkgver, $(1)).jar
     45 
     46 jarfile = $(notdir $(subst :,-, $(1))).jar
     47 
     48 $(LIB_DIR)/%: setup
     49 	$(info > Downloading '$*' into $(LIB_DIR)/)
     50 	@$(DOWNLOAD) $(call maven_url, $*) --output "$(LIB_DIR)/$(call jarfile, $*)"
     51 
     52 CLASSPATH := $(subst $(space),:,$(wildcard $(LIB_DIR)/*.jar))
     53 
     54 deps: $(foreach DEP, $(DEPS), $(LIB_DIR)/$(DEP))
     55 
     56 %.class: %.scala
     57 	$(SCALAC) $< -sourcepath $(SRC) -classpath $(CLASSPATH) -target:jvm-$(JVM_TARGET_VESRION)
     58 
     59 DEPLOY_BIN = $(BIN_DIR)/$(FINAL_PROGRAM)
     60 $(DEPLOY_BIN).jar: $(BIN_DIR)/$(PROGRAM).jar
     61 	$(info > Building '$(DEPLOY_BIN)')
     62 	# $(MKDIR) $(BIN_DIR)/classes
     63 	# $(foreach JARFILES, $(wildcard $(LIB_DIR)/*.jar), \
     64 	# 	cd $(BIN_DIR)/classes; $(JAR) xvf $(realpath $(JARFILES)) \
     65 	# )
     66 	echo "$(SCALA) -classpath "$(CLASSPATH):$(FINAL_PROGRAM).jar" $(TARGET_MAIN) $$*" > $(DEPLOY_BIN)
     67 	cd $(BIN_DIR)/classes; $(JAR) xvf $(realpath $(BIN_DIR)/$(PROGRAM)).jar
     68 	cd $(BIN_DIR)/classes && $(JAR) cvf $(realpath $(DEPLOY_BIN)).jar *
     69 	chmod +x $(DEPLOY_BIN)
     70 
     71 
     72 $(BIN_DIR)/$(PROGRAM).jar: $(SRC)
     73 	@make setup
     74 	$(info > Building '$(BIN_DIR)/$(PROGRAM)')
     75 	@$(SCALAC) -classpath "${CLASSPATH}" $^ -d $@ -target:jvm-$(JVM_TARGET_VESRION)
     76 	@echo "$(SCALA) -classpath "$(CLASSPATH):$(PROGRAM).jar" $(TARGET_MAIN) $$*" > $(BIN_DIR)/$(PROGRAM)
     77 	@chmod +x $(BIN_DIR)/$(PROGRAM)
     78 
     79 deploy: $(BIN_DIR)/$(PROGRAM)-$(VERSION).jar
     80 
     81 setup:
     82 	@$(MKDIR) $(BIN_DIR)
     83 	@$(MKDIR) $(LIB_DIR)