From ba9d3ebca240b89eb804dc5e0f27a44cd25ac112 Mon Sep 17 00:00:00 2001 From: Alexander Mahr Date: Sat, 28 Dec 2024 19:11:21 +0100 Subject: [PATCH] simplify/cleanup Makefile via include --- app/Makefile | 75 +++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/app/Makefile b/app/Makefile index 1f6b411..68459db 100644 --- a/app/Makefile +++ b/app/Makefile @@ -2,53 +2,59 @@ SHELL=/bin/makefile-bash-wrapper.sh +# the include of the Makefile.app-config defines the Makefile +# variables $(BUILDTOOLS), $(ANDROID_JAR) and $(PACKAGE) +# which depend on the configuration and are necessary to have the Makefile work +# the rule whose target is Makefile.app-config will trigger a reload of this include as ncessary +# (as explained https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#include) +include Makefile.app-config + # symlink ./app.apk: ./result/app.apk ln -sfrv ./result/app.apk ./app.apk # zipalign and sign again (second signing) -./result/app.apk : ./result/signed.apk app-config.sh - source app-config.sh; $${ANDROID_SDK_ROOT}/$$(tr ';' '/' < android-sdk/.installed.buildtools.version.current)/zipalign -v -f 4 $< $@ - source app-config.sh; $${ANDROID_SDK_ROOT}/$$(tr ';' '/' < android-sdk/.installed.buildtools.version.current)/apksigner sign \ - --ks ToyKey.keystore --key-pass pass:armena --ks-pass pass:armena $@ +./result/app.apk : ./result/signed.apk app-config.sh ./keystore + $(BUILDTOOLS)/zipalign -v -f 4 $< $@ + $(BUILDTOOLS)/apksigner sign --ks keystore --key-pass pass:armena --ks-pass pass:armena $@ # sign the apk file (first sign) -./result/signed.apk : ./result/unsigned.apk ./ToyKey.keystore ./result - jarsigner -verbose -keystore ./ToyKey.keystore -storepass armena -keypass armena -signedjar $@ $< helljniKey +./result/signed.apk : ./result/unsigned.apk ./keystore + jarsigner -verbose -keystore ./keystore -storepass armena -keypass armena -signedjar $@ $< helljniKey # make a "keystore" for the cryptographic signing stuff -./ToyKey.keystore : +./keystore : keytool -genkeypair -validity 1000 -dname "CN=alexander,O=Android,C=JPN" -keystore $@ \ -storepass armena -keypass armena -alias helljniKey -keyalg RSA -v # aapt "package" together the dalvik/hex stuff (and "assets" and "res") ./result/unsigned.apk : ./result/bin/classes.dex ./assets ./AndroidManifest.xml rm -rvf "$@" - source app-config.sh; $${ANDROID_SDK_ROOT}/$$(tr ';' '/' < android-sdk/.installed.buildtools.version.current)/aapt package \ + $(BUILDTOOLS)/aapt package \ -v -u -f -M ./AndroidManifest.xml -S ./res \ - -I $${ANDROID_SDK_ROOT}/$$(tr ';' '/' < android-sdk/.installed.platforms.version.current)/android.jar -A ./assets -F $@ ./result/bin + -I $(ANDROID_JAR) -A ./assets -F $@ ./result/bin -# convert "java class"es files (i.e bytecode to dalvic/d8 android thing -./result/bin/classes.dex : ./obj/package/AppActivity.class +# convert "java class"es files (i.e bytecode) to dalvic/d8 android thing +./result/bin/classes.dex : ./obj/$(PACKAGE)/AppActivity.class mkdir -p ./result/bin - ls ./obj/package/*.class - source app-config.sh; $${ANDROID_SDK_ROOT}/$$(tr ';' '/' < android-sdk/.installed.buildtools.version.current)/d8 $$(realpath --relative-to=. $<)/*.class \ - --lib $${ANDROID_SDK_ROOT}/$$(tr ';' '/' < android-sdk/.installed.platforms.version.current)/android.jar --output ./result/bin + $(BUILDTOOLS)/d8 ./obj/$(PACKAGE)/*.class \ + --lib $(ANDROID_JAR) --output ./result/bin # compile (javac) the class from -./obj/package/AppActivity.class : ./src/package/AppActivity.java ./src/package/R.java ./obj/package - javac -d ./obj -classpath $${ANDROID_SDK_ROOT}/$$(tr ';' '/' < android-sdk/.installed.platforms.version.current)/android.jar \ - -sourcepath ./src $$(realpath --relative-to=/src $<) +./obj/$(PACKAGE)/AppActivity.class : ./src/$(PACKAGE)/AppActivity.java ./src/$(PACKAGE)/R.java + mkdir -p ./obj/$(PACKAGE) + javac -d ./obj -classpath $(ANDROID_JAR) -sourcepath ./src $< -# generate teh AppActivity.java (template) -./src/package/AppActivity.java: app-config.sh - ./.Makefile.scripts/make--AppActivity.java.sh > $@ # make the resources "R.java" thing -./src/package/R.java : $(shell find ./res -type f) app-config.sh ./src/package ./AndroidManifest.xml ./android-sdk/installed - source app-config.sh; $${ANDROID_SDK_ROOT}/$$(tr ';' '/' < android-sdk/.installed.buildtools.version.current)/aapt package \ +./src/PACKAGE/R.java : $(shell find ./res -type f) app-config.sh ./AndroidManifest.xml ./android-sdk/installed + $(BUILDTOOLS)/aapt package \ -v -f -m -S ./res -J ./src -M ./AndroidManifest.xml \ - -I $${ANDROID_SDK_ROOT}/$$(tr ';' '/' < android-sdk/.installed.platforms.version.current)/android.jar + -I $(ANDROID_JAR) + +# generate the AppActivity.java (template) +./src/package/AppActivity.java: app-config.sh + ./.Makefile.scripts/make--AppActivity.java.sh > $@ # install the necessary android sdks ./android-sdk/installed: app-config.sh @@ -58,23 +64,20 @@ SHELL=/bin/makefile-bash-wrapper.sh ./AndroidManifest.xml: app-config.sh ./.Makefile.scripts/make--AndroidManifest.xml -app/.s: - source app-config.sh - +Makefile.app-config: app-config.sh Makefile + source app-config.sh; \ + tee $@ << MAKEFILE_APP_CONFIG + BUILDTOOLS:=$${ANDROID_SDK_ROOT}/$$(tr ';' '/' < android-sdk/.installed.buildtools.version.current) + ANDROID_JAR:=$${ANDROID_SDK_ROOT}/$$(tr ';' '/' < android-sdk/.installed.platforms.version.current)/android.jar + PACKAGE:=$$(echo "$$APP_PACKAGE" | tr '.' '/') + MAKEFILE_APP_CONFIG +# use whiptail textgui to make configuration (android API level, app-name, app-label etc...) app-config.sh: ./.Makefile.scripts/make--app-config.sh - # make symlinks and directories (to cater for the "helpful" java thing, to use folders for package names and yes we need a package name :( ) - #source app-config.sh - #PKGDIR=$$(echo "$$APP_PACKAGE" | tr '.' '/') - #for DIR in src obj - #do - # mkdir -p $$DIR/$$PKGDIR - # ln -snfrv $$DIR/$$PKGDIR $$DIR/package - #done clean: - rm -rf obj/* - rm -rf result/* + rm -rf obj/* result/* + FORCE: @true