make-quoter

Log | Files | Refs | README

config.mk (6134B)


      1 JAVAC ?= javac
      2 SCALAC ?= scalac
      3 KOTLINC ?= kotlinc
      4 JAR ?= jar
      5 
      6 JAVA ?= java
      7 SCALA ?= scala
      8 SHELL = cmd
      9 
     10 ROOT_DIR:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
     11 # Directory variables
     12 ifeq ($(OS),Windows_NT)
     13 define /
     14 \\
     15 endef
     16 	ANDROID_SDK ?= $(USERPROFILE)/AppData/Local/Android/sdk
     17 else
     18 	/:=/
     19 	ANDROID_SDK ?= /opt/android-sdk
     20 endif
     21 
     22 prepend_slash=$1/
     23 
     24 RES_DIR:=$(ROOT_DIR)res
     25 BIN_DIR?=out/bin
     26 GEN_DIR:=$(BIN_DIR)/gen
     27 CLASS_DIR:=$(BIN_DIR)/classes
     28 PACKAGE_PATH = $(subst .,/,$(PACKAGE_NAME))
     29 ANDROID_BUILD_TOOLS = $(ANDROID_SDK)/build-tools/$(ANDROID_SDK_VERSION)
     30 ANDROID_PLATFORMS = $(ANDROID_SDK)/platforms/android-$(ANDROID_COMPILE_SDK)
     31 
     32 LIB_DIR?=out/lib
     33 
     34 # Absolute Paths
     35 AGEN_DIR:=$(ROOT_DIR)$(GEN_DIR)
     36 
     37 # Tools and flags
     38 AAPT:=$(ANDROID_BUILD_TOOLS)/aapt
     39 AAPT2:=$(ANDROID_BUILD_TOOLS)/aapt2
     40 D8:=$(ANDROID_BUILD_TOOLS)/d8
     41 
     42 JAVAC_FLAGS := -source 8 -target 8
     43 ifeq (BUILD_TYPE,RELEASE)
     44 D8_BUILD_TYPE:=--release
     45 endif
     46 
     47 TARGET_MAIN = $(PACKAGE_NAME).Main
     48 
     49 # Repos
     50 MAVEN = https://repo1.maven.org/maven2
     51 
     52 JVM_TARGET_VESRION ?= 1.8
     53 
     54 DOWNLOAD = curl -fLs
     55 RM = rm -rf
     56 RMDIR = rm -rf
     57 MKDIR:=mkdir -p
     58 ifeq ($(OS),Windows_NT)
     59 	ifeq ($(SHELL),cmd)
     60 		RM:=del /s /q
     61 		RMDIR:=rmdir /s /q
     62 		MKDIR:=mkdir
     63 	endif
     64 endif
     65 
     66 FINAL_PROGRAM = $(PROGRAM)-$(VERSION)
     67 
     68 define space
     69  
     70 endef
     71 
     72 LIBS = $(wildcard $(LIB_DIR)/*.jar)
     73 
     74 JARFILES := $(foreach DEP, $(DEPS), \
     75 	   $(subst :,-,$(notdir $(DEP).jar)) \
     76 )
     77 
     78 pkgver = $(lastword $(subst :,$(space), $(1)))
     79 
     80 pkgname = $(firstword $(subst :, $(space), $(1)))
     81 
     82 maven_url = $(MAVEN)/$(call pkgname, $(1))/$(call pkgver, $(1))/$(notdir $(call pkgname, $(1)))-$(call pkgver, $(1))
     83 
     84 jarfile = $(notdir $(subst :,-, $(1))).jar
     85 DEPLOY_BIN = $(BIN_DIR)/$(FINAL_PROGRAM)
     86 
     87 #$(LIB_DIR)/%: $(BIN_DIR) $(LIB_DIR)
     88 #	$(info > Downloading '$*' into $(LIB_DIR)/)
     89 #	@$(DOWNLOAD) $(call maven_url, $*) --output $(LIB_DIR)/$*
     90 #
     91 #CLASSPATH := $(subst $(space),:,$(wildcard $(LIB_DIR)/*.jar))
     92 #
     93 
     94 deps: $(foreach DEP, $(DEPS), $(LIB_DIR)/$(DEP))
     95 
     96 %.class: %.scala
     97 	$(SCALAC) $< -sourcepath $(SRC) -classpath $(CLASSPATH) -target:jvm-$(JVM_TARGET_VESRION)
     98 
     99 %.class: %.kt
    100 	$(KOTLINC) $< -sourcepath $(SRC) -classpath $(CLASSPATH) -target:jvm-$(JVM_TARGET_VESRION)
    101 
    102 
    103 $(DEPLOY_BIN).jar: $(BIN_DIR)/$(PROGRAM).jar
    104 	$(info > Building '$(DEPLOY_BIN)')
    105 	:# $(MKDIR) $(BIN_DIR)/classes
    106 	:# $(foreach JARFILES, $(wildcard $(LIB_DIR)/*.jar), \
    107 	:# 	cd $(BIN_DIR)/classes; $(JAR) xvf $(realpath $(JARFILES)) \
    108 	:# )
    109 	echo "$(SCALA) -classpath "$(CLASSPATH):$(FINAL_PROGRAM).jar" $(TARGET_MAIN) $$*" > $(DEPLOY_BIN)
    110 	cd $(BIN_DIR)/classes; $(JAR) xvf $(realpath $(BIN_DIR)/$(PROGRAM)).jar
    111 	cd $(BIN_DIR)/classes && $(JAR) cvf $(realpath $(DEPLOY_BIN)).jar *
    112 	chmod +x $(DEPLOY_BIN)
    113 
    114 
    115 $(BIN_DIR)/$(PROGRAM).jar: $(SRC) $(BIN_DIR) $(LIB_DIR)
    116 	$(info > Building '$(BIN_DIR)/$(PROGRAM)')
    117 	@$(SCALAC) -classpath "${CLASSPATH}" $^ -d $@ -target:jvm-$(JVM_TARGET_VESRION)
    118 	echo "$(SCALA) -classpath "$(CLASSPATH):$(PROGRAM).jar" $(TARGET_MAIN) $$*" > $(BIN_DIR)/$(PROGRAM)
    119 	ifeq($(OS),Windows_NT)
    120 		chmod +x $(BIN_DIR)/$(PROGRAM)
    121 	endif
    122 
    123 deploy: $(BIN_DIR)/$(PROGRAM)-$(VERSION).jar
    124 
    125 # Create necessary directories
    126 %/:
    127 	$(MKDIR) "$*"
    128 
    129 STYLE_PATHS+=$(CURDIR)/test
    130 ANDROID_JAR:=$(ANDROID_PLATFORMS)/android.jar
    131 JAVAC_FLAGS:=$(JAVAC_FLAGS) -Xbootclasspath:$(ANDROID_JAR) 
    132 
    133 # Generate R.java
    134 r-files: $(RES_DIR) $(GEN_DIR)/ $(CLASS_DIR) 
    135 	:# Generate R.java from resources
    136 	$(AAPT) package --target-sdk-version $(ANDROID_COMPILE_SDK) --auto-add-overlay -f -m -J $(GEN_DIR)/ -S $(RES_DIR) -M AndroidManifest.xml -I $(ANDROID_JAR) $(foreach STYLE_PATH, $(STYLE_PATHS), -S $(STYLE_PATH)/res -I $(STYLE_PATH)/classes.jar) -S $(ANDROID_PLATFORMS)/data/res --custom-package $(PACKAGE_NAME) --generate-dependencies
    137 
    138 rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
    139 
    140 #RES_SRCS:=$(call rwildcard,.,*.xml)
    141 #
    142 #$(GEN_DIR)/%.arsc.flat: $(RES_DIR)/%.xml
    143 #	$(MKDIR) $(dir $@)
    144 #	:# TODO Use speciazied AAPT2 tool to avoid
    145 #	:# "error: bad resource path." error
    146 #	$(AAPT2) compile -o $(dir $@) $(dir $<)$(notdir $<)
    147 
    148 RES_SRCS:=appcompat-1.2.0.zip core-1.3.2.zip res.zip
    149 RES_SRCS:=$(foreach RES_SRC,$(RES_SRCS),out/$(RES_SRC) )
    150 
    151 out/%.zip: out/lib/%.aar
    152 	unzip $^ -d $(basename $^)
    153 	$(AAPT2) compile -o $@ --dir $(basename $^)/res
    154 
    155 out/res.zip: res
    156 	$(AAPT2) compile -o $@ --dir res
    157 
    158 # Generate resources and compile R.class
    159 out/app-resource.apk: $(RES_SRCS) $(call prepend_slash,$(GEN_DIR)) $(call prepend_slash,$(CLASS_DIR))
    160 	:# Generate R.java from resources
    161 	$(AAPT2) link $(RES_SRCS) -I $(ANDROID_JAR) --manifest AndroidManifest.xml -o $@ --java $(CLASS_DIR)
    162 
    163 $(CLASS_DIR)/$(PACKAGE_PATH)/R.class: $(CLASS_DIR)/$(PACKAGE_PATH)/R.java
    164 	:# Compile R.java to R.class
    165 	$(JAVAC) $(JAVAC_FLAGS)  -d $(CLASS_DIR) $<
    166 
    167 #out/$(PACKAGE_PATH)/%.class: out/$(PACKAGE_PATH)/%.java
    168 #	@echo # Compile R.java to R.class
    169 #	$(JAVAC) $(JAVAC_FLAGS) $^
    170 
    171 LIBS=picasso appcompat
    172 
    173 ANDROID_CLASSPATH= $(CLASS_DIR);$(PACKAGE_PATH)$(subst $(space);,;,$(foreach LIB,$(LIBS),;$(CURDIR)/$(LIB_DIR)/$(LIB)/classes.jar))
    174 
    175 out/%.class: java/%.java
    176 	$(JAVAC) $(JAVAC_FLAGS) -classpath $(ANDROID_CLASSPATH) -d $(BIN_DIR) $^
    177 
    178 out/classes.dex: out/app-resource.apk $(CLASS_DIR)
    179 	$(D8) $(D8_BUILD_TYPE) $(wildcard $(CLASS_DIR)/$(PACKAGE_PATH)/*.class) --output $(dir $@) --lib $(ANDROID_JAR) $(foreach LIB,$(LIBS),--lib $(LIB_DIR)/$(LIB)/classes.jar)
    180 
    181 # Verify with: $(ANDROID_BUILD_TOOLS)/zipalign -c -v 4 $@
    182 out/app-aligned.apk: out/app-resource.apk out/classes.dex
    183 	zip.exe -uj "$<" "out/classes.dex"
    184 	$(ANDROID_BUILD_TOOLS)/zipalign -p -f -v 4 $< $@
    185 
    186 %.keystore:
    187 	keytool -genkey -v -keystore $@ -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000
    188 
    189 out/app-debug.apk: out/app-aligned.apk
    190 	$(ANDROID_BUILD_TOOLS)/apksigner sign --min-sdk-version $(ANDROID_MIN_SDK) --ks $(ANDROID_KEYSTORE) --ks-pass pass:android --ks-key-alias androiddebugkey --out $@ $< 
    191 
    192 clean-dex:
    193 	$(RM) "$(CURDIR)/out$(/)classes.dex"
    194 
    195 # Clean generated files
    196 clean-r:
    197 	$(RM) $(GEN_DIR)/$(PACKAGE_PATH)/R.java
    198 	$(RM) $(CLASS_DIR)/$(PACKAGE_PATH)/R.class
    199 	$(RM) $(CLASS_DIR)/$(PACKAGE_PATH)/R$$*.class
    200 
    201 .PHONY: r-files r-files2 clean-r