From 602941104ec038d3042f91b818b55d2a20ebb677 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 15 Mar 2023 23:55:22 +0000 Subject: [PATCH] Support building both debug and release APKs. Release is too big. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4226 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- Makefile | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 08026b8d..ae715519 100644 --- a/Makefile +++ b/Makefile @@ -37,11 +37,22 @@ ANDROID_TARGETS := \ $(ANDROID_X86_64_TARGETS) \ $(ANDROID_ARM64_TARGETS) -debug windebug $(ANDROID_TARGETS): CFLAGS += -Og +DEBUG_TARGETS := \ + out/debug/tildefriends \ + out/windebug/tildefriends \ + out/androiddebug/tildefriends \ + out/androiddebug-x86_64/tildefriends +RELEASE_TARGETS := \ + out/release/tildefriends \ + out/winrelease/tildefriends \ + out/androidrelease/tildefriends \ + out/androidrelease-x86_64/tildefriends + debug release out/androidrelease/tildefriends out/androidrelease-x86_64/tildefriends: LDFLAGS += -rdynamic $(ANDROID_TARGETS): CFLAGS += --sysroot $(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC $(ANDROID_TARGETS): LDFLAGS += --sysroot $(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -release winrelease: CFLAGS += -DNDEBUG -O3 +$(DEBUG_TARGETS): CFLAGS += -DDEBUG -Og +$(RELEASE_TARGETS): CFLAGS += -DNDEBUG -O3 windebug winrelease: CC = x86_64-w64-mingw32-gcc-win32 windebug winrelease: AS = $(CC) windebug winrelease: CFLAGS += \ @@ -399,10 +410,10 @@ $(foreach build_type,$(BUILD_TYPES),$(eval $(call build_rules,$(build_type)))) out/res/layout_activity_main.xml.flat: src/android/res/layout/activity_main.xml @mkdir -p $(dir $@) @echo [aapt2] $@ - $(ANDROID_BUILD_TOOLS)/aapt2 compile -o out/res/ src/android/res/layout/activity_main.xml + @$(ANDROID_BUILD_TOOLS)/aapt2 compile -o out/res/ src/android/res/layout/activity_main.xml out/res.apk out/gen/com/unprompted/tildefriends/R.java: out/res/layout_activity_main.xml.flat src/android/AndroidManifest.xml - $(ANDROID_BUILD_TOOLS)/aapt2 link -I $(ANDROID_PLATFORM)/android.jar out/res/layout_activity_main.xml.flat --manifest src/android/AndroidManifest.xml -o out/res.apk --java out/gen/ + @$(ANDROID_BUILD_TOOLS)/aapt2 link -I $(ANDROID_PLATFORM)/android.jar out/res/layout_activity_main.xml.flat --manifest src/android/AndroidManifest.xml -o out/res.apk --java out/gen/ JAVA_FILES := out/gen/com/unprompted/tildefriends/R.java $(wildcard src/android/com/unprompted/tildefriends/*.java) CLASS_FILES := $(foreach src,$(JAVA_FILES),out/classes/com/unprompted/tildefriends/$(notdir $(src:.java=.class))) @@ -412,9 +423,9 @@ $(CLASS_FILES) &: $(JAVA_FILES) @javac --release 8 -Xlint:deprecation -classpath $(ANDROID_PLATFORM)/android.jar -d out/classes $(JAVA_FILES) out/apk/classes.dex: $(CLASS_FILES) - mkdir -p $(dir $@) - echo [d8] $@ - $(ANDROID_BUILD_TOOLS)/d8 --lib $(ANDROID_PLATFORM)/android.jar --output $(dir $@) out/classes/com/unprompted/tildefriends/*.class + @mkdir -p $(dir $@) + @echo [d8] $@ + @$(ANDROID_BUILD_TOOLS)/d8 --$(BUILD_TYPE) --lib $(ANDROID_PLATFORM)/android.jar --output $(dir $@) out/classes/com/unprompted/tildefriends/*.class PACKAGE_DIRS := \ apps/ \ @@ -425,22 +436,28 @@ PACKAGE_DIRS := \ RAW_FILES := $(shell find $(PACKAGE_DIRS) -type f) -out/TildeFriends.unsigned.apk: out/apk/classes.dex out/androiddebug/tildefriends out/androiddebug-x86_64/tildefriends $(RAW_FILES) out/res.apk - @mkdir -p $(dir $@) out/apk/lib/arm64-v8a/ out/apk/lib/x86_64/ +out/TildeFriends-debug.unsigned.apk: BUILD_TYPE := debug +out/TildeFriends-release.unsigned.apk: BUILD_TYPE := release + +out/%.unsigned.apk: + @mkdir -p $(dir $@) out/apk$(BUILD_TYPE)/lib/arm64-v8a/ out/apk$(BUILD_TYPE)/lib/x86_64/ @echo [aapt] $@ - @cp out/androiddebug/tildefriends out/apk/lib/arm64-v8a/ - @cp out/androiddebug-x86_64/tildefriends out/apk/lib/x86_64/ - @/usr/lib/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk/lib/arm64-v8a/tildefriends - @/usr/lib/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk/lib/x86_64/tildefriends + @cp out/android$(BUILD_TYPE)/tildefriends out/apk$(BUILD_TYPE)/lib/arm64-v8a/ + @cp out/android$(BUILD_TYPE)-x86_64/tildefriends out/apk$(BUILD_TYPE)/lib/x86_64/ + @/usr/lib/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk$(BUILD_TYPE)/lib/arm64-v8a/tildefriends + @/usr/lib/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip out/apk$(BUILD_TYPE)/lib/x86_64/tildefriends @cp out/res.apk $@ - @cd out/apk && zip -u ../../$@ -q -9 -r . && cd ../../ + @cd out/apk$(BUILD_TYPE) && zip -u ../../$@ -q -9 -r . && cd ../../ @zip -u $@ -q -9 -r $(PACKAGE_DIRS) $(RAW_FILES) -out/TildeFriends.apk: out/TildeFriends.unsigned.apk +out/TildeFriends-debug.unsigned.apk: out/apk/classes.dex out/androiddebug/tildefriends out/androiddebug-x86_64/tildefriends $(RAW_FILES) out/res.apk +out/TildeFriends-release.unsigned.apk: out/apk/classes.dex out/androidrelease/tildefriends out/androidrelease-x86_64/tildefriends $(RAW_FILES) out/res.apk + +out/%.apk: out/%.unsigned.apk @echo [apksigner] $(notdir $@) @$(ANDROID_BUILD_TOOLS)/apksigner sign --ks keystore.jks --ks-key-alias androidKey --ks-pass pass:android --key-pass pass:android --out $@ $< -apk: out/TildeFriends.apk +apk: out/TildeFriends-debug.apk .PHONY: apk clean: