133 lines
5.2 KiB
Makefile
133 lines
5.2 KiB
Makefile
.ONESHELL:
|
|
|
|
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
|
|
|
|
# litanay of variabes used
|
|
NDK:=./android-sdk/ndk/21.1.6352462
|
|
NDK_TOOLCHAIN:=$(NDK)/toolchains/llvm/prebuilt/linux-x86_64
|
|
NDK_TOOLCHAIN_INCLUDE:=$(NDK_TOOLCHAIN)/sysroot/usr/include
|
|
ANDROIDVERSION:=29
|
|
CC_ARM64:=$(NDK_TOOLCHAIN)/bin/aarch64-linux-android29-clang
|
|
CFLAGS?=-ffunction-sections -Os -fdata-sections -Wall -fvisibility=hidden
|
|
CFLAGS += -fvisibility=hidden
|
|
# APP_PACKAGE is set to (-D) i.e preprocessor value and used to set string when logging
|
|
CFLAGS+=-Os -DANDROID -DAPP_PACKAGE=\"$(APP_PACKAGE)\"
|
|
# the -D will likely set a Variable to be used in the Preprocessor
|
|
CFLAGS +=-DANDROID_FULLSCREEN
|
|
CFLAGS+= -I./src/nativecode/rawdraw -I./src/nativecode -I$(NDK)/sysroot/usr/include
|
|
CFLAGS+= -I$(NDK)/sysroot/usr/include/android -I$(NDK_TOOLCHAIN_INCLUDE) -I$(NDK_TOOLCHAIN_INCLUDE)/android
|
|
CFLAGS+= -fPIC -DANDROIDVERSION=$(ANDROIDVERSION)
|
|
CFLAGS_ARM64:=-m64
|
|
LDFLAGS?=-Wl,--gc-sections -Wl,-Map=output.map -s
|
|
LDFLAGS += -s
|
|
# LDFLAGS += -static-libstdc++
|
|
LDFLAGS += -lm -lGLESv3 -lEGL -landroid -llog -lOpenSLES
|
|
LDFLAGS += -shared -uANativeActivity_onCreate
|
|
# locatoins of "mostly c" source files
|
|
SRC?=./src/nativecode/main.c
|
|
RAWDRAWANDROIDSRCS=./src/nativecode/android_native_app_glue.c
|
|
ANDROIDSRCS:= $(SRC) $(RAWDRAWANDROIDSRCS)
|
|
|
|
|
|
# symlink
|
|
./app.apk: ./result/app.apk
|
|
ln -sfrv ./result/app.apk ./app.apk
|
|
|
|
# zipalign and sign again (second signing)
|
|
./result/app.apk : ./result/unsigned.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 ./keystore
|
|
# jarsigner -verbose -keystore ./keystore -storepass armena -keypass armena -signedjar $@ $< helljniKey
|
|
|
|
# make a "keystore" for the cryptographic signing stuff
|
|
./keystore :
|
|
keytool -genkeypair -validity 2000 -dname "CN=$(APP_PACKAGE),O=Android,C=IT" -keystore $@ \
|
|
-storepass armena -keypass armena -alias helljniKey -keyalg RSA -v
|
|
|
|
# aapt "package" together the dalvik/hex stuff (and "assets" and "res")
|
|
./result/unsigned.apk : ./assets ./AndroidManifest.xml ./result/bin/lib/arm64-v8a/libnativecode.so $(shell find ./res -type f)
|
|
rm -rvf "$@"
|
|
$(BUILDTOOLS)/aapt package \
|
|
-v -u -f -M ./AndroidManifest.xml -S ./res \
|
|
-I $(ANDROID_JAR) -A ./assets -F $@ ./result/bin
|
|
|
|
supi:
|
|
echo $(shell find ./res -type f)
|
|
|
|
alex: ./result/bin/classes.dex
|
|
echo $< > $@
|
|
|
|
## 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
|
|
# $(BUILDTOOLS)/d8 ./obj/$(PACKAGE)/*.class \
|
|
# --lib $(ANDROID_JAR) --output ./result/bin; RESULT=$$?; echo result was $$RESULT; (exit $$RESULT)
|
|
|
|
|
|
./result/bin/lib/arm64-v8a/libnativecode.so: $(ANDROIDSRCS)
|
|
mkdir -p "$$(dirname "$@")"
|
|
$(CC_ARM64) $(CFLAGS) $(CFLAGS_ARM64) -o $@ $^ -L$(NDK_TOOLCHAIN)/sysroot/usr/lib/aarch64-linux-android/$(ANDROIDVERSION) $(LDFLAGS)
|
|
|
|
|
|
|
|
## compile (javac) the class from
|
|
#./obj/$(PACKAGE)/AppActivity.class : ./src/$(PACKAGE)/AppActivity.java ./src/$(PACKAGE)/R.java
|
|
# mkdir -p ./obj/$(PACKAGE)
|
|
# javac -d ./obj -classpath $(ANDROID_JAR) -sourcepath ./src $<
|
|
#
|
|
#
|
|
## make the resources "R.java" thing
|
|
#./src/$(PACKAGE)/R.java : $(shell find ./res -type f) app-config.sh ./AndroidManifest.xml ./android-sdk/installed | ./src/$(PACKAGE)
|
|
# $(BUILDTOOLS)/aapt package \
|
|
# -v -f -m -S ./res -J ./src -M ./AndroidManifest.xml \
|
|
# -I $(ANDROID_JAR)
|
|
|
|
# generate the AppActivity.java (template
|
|
# the "|" denotes an "order-only" prerequiste (as in https://stackoverflow.com/a/58040049/1711186)
|
|
./src/$(PACKAGE)/AppActivity.java: app-config.sh | ./src/$(PACKAGE)
|
|
./.Makefile.scripts/make--AppActivity.java.sh > $@
|
|
|
|
./src/$(PACKAGE):
|
|
mkdir -p $@
|
|
|
|
# install the necessary android sdks
|
|
./android-sdk/installed: app-config.sh ./.Makefile.scripts/make--android-sdk.sh
|
|
./.Makefile.scripts/make--android-sdk.sh
|
|
|
|
# generate the AndroidManifest.xml
|
|
./AndroidManifest.xml: app-config.sh ./.Makefile.scripts/make--AndroidManifest.xml
|
|
./.Makefile.scripts/make--AndroidManifest.xml
|
|
|
|
Makefile.app-config: app-config.sh Makefile
|
|
source app-config.sh; \
|
|
tee $@ << MAKEFILE_APP_CONFIG
|
|
ANDROIDVERSION:=$$APP_VERSION_SDK_TARGET;
|
|
BUILDTOOLS:=$${ANDROID_SDK_ROOT}/build-tools/29.0.3/
|
|
ANDROID_JAR:=$${ANDROID_SDK_ROOT}/platforms/android-29/android.jar
|
|
PACKAGE:=$$(echo "$$APP_PACKAGE" | tr '.' '/')
|
|
APP_PACKAGE=$${APP_PACKAGE}
|
|
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
|
|
|
|
# rule to effectuate a cleanup
|
|
clean:
|
|
rm -rf obj/* result/*
|
|
|
|
# this rule's purpose is to run "by force" no matter what, doing nothing
|
|
# as listed prerequisite to another rule it causes that rule to be made/run
|
|
# unconditionally every time
|
|
FORCE:
|
|
@true
|