blob: b36943b673e54b6728d79f032cf7aab8f86d653e [file] [log] [blame]
Thomas Martitzf8381d92010-09-02 00:24:40 +00001# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id$
8#
9
Thomas Martitz7d613762011-12-19 19:58:44 +000010PACKAGE=org.rockbox
11PACKAGE_PATH=org/rockbox
Frank Gevaertsd1560e52012-06-11 22:06:34 +020012BINLIB_DIR=$(BUILDDIR)/libs/$(ANDROID_ARCH)
Thomas Martitz7d613762011-12-19 19:58:44 +000013ANDROID_DIR=$(ROOTDIR)/android
14
Thomas Martitz287454d2011-12-19 15:42:04 +000015# this is a glibc compatibility hack to provide a get_nprocs() replacement.
16# The NDK ships cpu-features.c which has a compatible function android_getCpuCount()
Thomas Martitzd798c722013-01-09 10:29:29 +010017CPUFEAT = $(ANDROID_NDK_PATH)/sources/android/cpufeatures
18CPUFEAT_BUILD = $(BUILDDIR)
Thomas Martitz287454d2011-12-19 15:42:04 +000019INCLUDES += -I$(CPUFEAT)
20OTHER_SRC += $(CPUFEAT)/cpu-features.c
Thomas Martitz7d613762011-12-19 19:58:44 +000021CLEANOBJS += $(CPUFEAT_BUILD)/cpu-features.o
22$(CPUFEAT_BUILD)/cpu-features.o: $(CPUFEAT)/cpu-features.c
23 $(SILENT)mkdir -p $(dir $@)
Thomas Martitzd798c722013-01-09 10:29:29 +010024 $(call PRINTS,CC $(subst $(CPUFEAT)/,,$<))$(CC) -o $@ -c $^ $(GCCOPTS) -Wno-unused
Thomas Martitz287454d2011-12-19 15:42:04 +000025
Thomas Martitz4e982d32010-09-02 03:40:02 +000026.SECONDEXPANSION: # $$(JAVA_OBJ) is not populated until after this
Thomas Martitzf8381d92010-09-02 00:24:40 +000027.SECONDEXPANSION: # $$(OBJ) is not populated until after this
Frank Gevaerts276321e2011-02-02 22:13:51 +000028.PHONY: apk classes clean dex dirs libs jar
Thomas Martitz4e982d32010-09-02 03:40:02 +000029
Björn Stenberg40e61a72010-09-21 09:22:52 +000030# API version
Thomas Martitz6499ce32014-03-09 18:08:06 +010031ANDROID_PLATFORM_VERSION=19
Thomas Martitz4e982d32010-09-02 03:40:02 +000032ANDROID_PLATFORM=$(ANDROID_SDK_PATH)/platforms/android-$(ANDROID_PLATFORM_VERSION)
Björn Stenberg40e61a72010-09-21 09:22:52 +000033
34# android tools
Frank Gevaertsbe9c2272014-09-25 00:24:38 +020035BUILD_TOOLS_VERSION=$(notdir $(firstword $(wildcard $(ANDROID_SDK_PATH)/build-tools/$(ANDROID_PLATFORM_VERSION).*)))
Thomas Martitz6499ce32014-03-09 18:08:06 +010036AAPT=$(ANDROID_SDK_PATH)/build-tools/$(BUILD_TOOLS_VERSION)/aapt
37DX=$(ANDROID_SDK_PATH)/build-tools/$(BUILD_TOOLS_VERSION)/dx
Frank Gevaerts1d586672017-09-06 18:26:07 +020038ifneq ("$(wildcard $(ANDROID_SDK_PATH)/tools/zipalign)","")
39 ZIPALIGN=$(ANDROID_SDK_PATH)/tools/zipalign
40else
41 ZIPALIGN=$(ANDROID_SDK_PATH)/build-tools/$(BUILD_TOOLS_VERSION)/zipalign
42endif
Björn Stenberg40e61a72010-09-21 09:22:52 +000043KEYSTORE=$(HOME)/.android/debug.keystore
Antoine Celleriera448d8b2011-01-24 17:06:04 +000044ADB=$(ANDROID_SDK_PATH)/platform-tools/adb
Thomas Martitz6499ce32014-03-09 18:08:06 +010045BUILDAPK=$(ANDROID_DIR)/buildapk.sh
Thomas Martitz4e982d32010-09-02 03:40:02 +000046
Thomas Martitze9cb9532012-01-03 21:15:21 +000047CLASSPATH := $(BUILDDIR)/bin/classes
48
Dominik Riebelingfc68a0d2011-05-29 18:44:42 +000049MANIFEST := $(BUILDDIR)/bin/AndroidManifest.xml
Dominik Riebelingbc3f9c12011-05-29 17:23:52 +000050MANIFEST_SRC := $(ANDROID_DIR)/AndroidManifest.xml
Thomas Martitz4e982d32010-09-02 03:40:02 +000051
52R_JAVA := $(BUILDDIR)/gen/$(PACKAGE_PATH)/R.java
Thomas Martitze9cb9532012-01-03 21:15:21 +000053R_OBJ := $(CLASSPATH)/$(PACKAGE_PATH)/R.class
Thomas Martitz4e982d32010-09-02 03:40:02 +000054
Thomas Martitz33de9cd2011-07-18 21:02:47 +000055JAVA_SRC := $(wildcard $(ANDROID_DIR)/src/$(PACKAGE_PATH)/*.java)
56JAVA_SRC += $(wildcard $(ANDROID_DIR)/src/$(PACKAGE_PATH)/Helper/*.java)
Antoine Cellerierc0c769c2011-01-29 20:47:32 +000057JAVA_SRC += $(wildcard $(ANDROID_DIR)/src/$(PACKAGE_PATH)/widgets/*.java)
Thomas Martitz33de9cd2011-07-18 21:02:47 +000058JAVA_SRC += $(wildcard $(ANDROID_DIR)/src/$(PACKAGE_PATH)/monitors/*.java)
Thomas Martitze9cb9532012-01-03 21:15:21 +000059
60java2class = $(addsuffix .class,$(basename $(subst $(ANDROID_DIR)/src,$(CLASSPATH),$(1))))
61
62JAVA_OBJ := $(call java2class,$(JAVA_SRC))
Thomas Martitz4e982d32010-09-02 03:40:02 +000063
Thomas Martitz50a9d502010-10-31 14:13:52 +000064
Thomas Martitz994aba12010-09-02 14:58:36 +000065LIBS := $(BINLIB_DIR)/$(BINARY) $(BINLIB_DIR)/libmisc.so
Dominik Riebeling70b81e62011-05-31 21:26:18 +000066LIBS += $(addprefix $(BINLIB_DIR)/lib,$(patsubst %.codec,%.so,$(notdir $(CODECS))))
Thomas Martitze9cb9532012-01-03 21:15:21 +000067
Björn Stenberga8ed3392010-09-24 12:03:15 +000068TEMP_APK := $(BUILDDIR)/bin/_rockbox.apk
69TEMP_APK2 := $(BUILDDIR)/bin/__rockbox.apk
Thomas Martitzd798c722013-01-09 10:29:29 +010070DEX := $(BUILDDIR)/bin/classes.dex
71JAR := $(BUILDDIR)/bin/classes.jar
72AP_ := $(BUILDDIR)/bin/resources.ap_
73APK := $(BUILDDIR)/rockbox.apk
Thomas Martitz4e982d32010-09-02 03:40:02 +000074
Thomas Martitz994aba12010-09-02 14:58:36 +000075_DIRS := $(BUILDDIR)/___/$(PACKAGE_PATH)
Thomas Martitz994aba12010-09-02 14:58:36 +000076DIRS += $(subst ___,gen,$(_DIRS))
77DIRS += $(subst ___,data,$(_DIRS))
Frank Gevaertsd1560e52012-06-11 22:06:34 +020078DIRS += $(BUILDDIR)/libs/$(ANDROID_ARCH)
Thomas Martitz7d613762011-12-19 19:58:44 +000079DIRS += $(CPUFEAT_BUILD)
Thomas Martitze9cb9532012-01-03 21:15:21 +000080DIRS += $(CLASSPATH)
Thomas Martitz994aba12010-09-02 14:58:36 +000081
Maurus Cuelenaere13f7dff2010-11-06 02:02:54 +000082RES := $(wildcard $(ANDROID_DIR)/res/*/*)
83
Björn Stenberga8ed3392010-09-24 12:03:15 +000084CLEANOBJS += bin gen libs data
85
Frank Gevaerts190577e2012-06-13 23:43:39 +020086JAVAC_OPTS += -source 1.6 -target 1.6 -implicit:none -classpath $(ANDROID_PLATFORM)/android.jar:$(CLASSPATH)
Thomas Martitz0f4dfc42011-02-02 13:57:01 +000087
Dominik Riebelingbc3f9c12011-05-29 17:23:52 +000088.PHONY:
Dominik Riebelingfc68a0d2011-05-29 18:44:42 +000089$(MANIFEST): $(MANIFEST_SRC) $(DIRS)
Dominik Riebeling26a92fa2011-06-04 10:36:34 +000090 $(call PRINTS,MANIFEST $(@F))sed -e 's/versionName="1.0"/versionName="$(SVNVERSION)"/;s/screenOrientation="portrait"/screenOrientation="$(LCDORIENTATION)"/' $(MANIFEST_SRC) > $(MANIFEST)
Dominik Riebelingbc3f9c12011-05-29 17:23:52 +000091
Frank Gevaerts38084782011-02-02 23:10:51 +000092$(R_JAVA) $(AP_): $(MANIFEST) $(RES) | $(DIRS)
Björn Stenberg40e61a72010-09-21 09:22:52 +000093 $(call PRINTS,AAPT $(subst $(BUILDDIR)/,,$@))$(AAPT) package -f -m \
94 -J $(BUILDDIR)/gen -M $(MANIFEST) -S $(ANDROID_DIR)/res \
95 -I $(ANDROID_PLATFORM)/android.jar -F $(AP_)
Thomas Martitz4e982d32010-09-02 03:40:02 +000096
Thomas Martitze9cb9532012-01-03 21:15:21 +000097$(CLASSPATH)/$(PACKAGE_PATH)/R.class: $(R_JAVA)
Thomas Martitz994aba12010-09-02 14:58:36 +000098 $(call PRINTS,JAVAC $(subst $(ROOTDIR)/,,$<))javac -d $(BUILDDIR)/bin \
Thomas Martitze9cb9532012-01-03 21:15:21 +000099 $(JAVAC_OPTS) -sourcepath $(ANDROID_DIR)/gen $<
Thomas Martitz4e982d32010-09-02 03:40:02 +0000100
Thomas Martitze9cb9532012-01-03 21:15:21 +0000101$(CLASSPATH)/$(PACKAGE_PATH)/%.class: $(ANDROID_DIR)/src/$(PACKAGE_PATH)/%.java $(CLASSPATH)/$(PACKAGE_PATH)/R.class
102 $(call PRINTS,JAVAC $(subst $(ROOTDIR)/,,$<))javac -d $(CLASSPATH) \
103 $(JAVAC_OPTS) -sourcepath $(ANDROID_DIR)/src $<
Thomas Martitz4e982d32010-09-02 03:40:02 +0000104
Frank Gevaerts276321e2011-02-02 22:13:51 +0000105$(JAR): $(JAVA_SRC) $(R_JAVA)
Thomas Martitze9cb9532012-01-03 21:15:21 +0000106 $(call PRINTS,JAVAC $(subst $(ROOTDIR)/,,$?))javac -d $(CLASSPATH) \
107 $(JAVAC_OPTS) -sourcepath $(ANDROID_DIR)/src:$(ANDROID_DIR)/gen $?
108 $(call PRINTS,JAR $(subst $(BUILDDIR)/,,$@))jar cf $(JAR) -C $(CLASSPATH) org
Thomas Martitz4e982d32010-09-02 03:40:02 +0000109
Frank Gevaerts276321e2011-02-02 22:13:51 +0000110jar: $(JAR)
111
112$(DEX): $(JAR)
113 @echo "Checking for deleted class files" && $(foreach obj,$(JAVA_OBJ) $(R_OBJ), \
114 (test -f $(obj) || (echo "$(obj) is missing. Run 'make classes' to fix." && false)) && ) true
115 $(call PRINTS,DX $(subst $(BUILDDIR)/,,$@))$(DX) --dex --output=$@ $<
Thomas Martitza9944012010-09-12 16:35:02 +0000116
117dex: $(DEX)
Thomas Martitz4e982d32010-09-02 03:40:02 +0000118
Frank Gevaerts276321e2011-02-02 22:13:51 +0000119classes: $(R_OBJ) $(JAVA_OBJ)
120
Thomas Martitz287454d2011-12-19 15:42:04 +0000121
Thomas Martitzf269aa02012-03-26 22:24:57 +0200122$(BUILDDIR)/$(BINARY): $$(OBJ) $(FIRMLIB) $(VOICESPEEXLIB) $(CORE_LIBS) $(CPUFEAT_BUILD)/cpu-features.o
Thomas Martitz6d192752012-01-17 15:08:08 +0100123 $(call PRINTS,LD $(BINARY))$(CC) -o $@ $^ $(LDOPTS) $(GLOBAL_LDOPTS) -Wl,-Map,$(BUILDDIR)/rockbox.map
Thomas Martitz4b56ee02012-04-04 21:43:22 +0200124 $(call PRINTS,OC $(@F))$(call objcopy,$@,$@)
Thomas Martitz287454d2011-12-19 15:42:04 +0000125
Thomas Martitz994aba12010-09-02 14:58:36 +0000126$(BINLIB_DIR)/$(BINARY): $(BUILDDIR)/$(BINARY)
Thomas Martitz4e982d32010-09-02 03:40:02 +0000127 $(call PRINTS,CP $(BINARY))cp $^ $@
128
Thomas Martitz7f9e7652010-09-22 20:58:54 +0000129$(BINLIB_DIR)/libmisc.so: $(BUILDDIR)/rockbox.zip
Thomas Martitz4e982d32010-09-02 03:40:02 +0000130 $(call PRINTS,CP rockbox.zip)cp $^ $@
131
Sean Bartellf40bfc92011-06-25 21:32:25 -0400132$(BINLIB_DIR)/lib%.so: $(RBCODEC_BLD)/codecs/%.codec
Dominik Riebeling70b81e62011-05-31 21:26:18 +0000133 $(call PRINTS,CP $(@F))cp $^ $@
134
Thomas Martitze9cb9532012-01-03 21:15:21 +0000135libs: $(DIRS) $(LIBS)
Thomas Martitz4e982d32010-09-02 03:40:02 +0000136
Frank Gevaerts38084782011-02-02 23:10:51 +0000137$(TEMP_APK): $(AP_) $(LIBS) $(DEX) | $(DIRS)
Thomas Martitz6499ce32014-03-09 18:08:06 +0100138 $(call PRINTS,APK $(subst $(BUILDDIR)/,,$@))$(BUILDAPK) $(BUILDDIR) $(notdir $@) $(BUILD_TOOLS_VERSION)
Thomas Martitz4e982d32010-09-02 03:40:02 +0000139
Björn Stenberg40e61a72010-09-21 09:22:52 +0000140$(KEYSTORE):
Thomas Martitzc77b0142011-04-21 09:35:35 +0000141 $(SILENT)mkdir -p $(HOME)/.android
Björn Stenberg40e61a72010-09-21 09:22:52 +0000142 $(call PRINTS,KEYTOOL debug.keystore)keytool -genkey \
143 -alias androiddebugkey -keystore $@ \
144 -storepass android -keypass android -validity 365 \
Thiago Kenji Okadaa6713a52012-11-28 23:26:55 -0200145 -sigalg MD5withRSA -keyalg RSA -keysize 1024 \
Björn Stenberg40e61a72010-09-21 09:22:52 +0000146 -dname "CN=Android Debug,O=Android,C=US"
147
Björn Stenberg35cd4082011-06-22 14:14:49 +0000148ifdef NODEPS
149$(APK): $(TEMP_APK) $(KEYSTORE)
150else
Björn Stenberg40e61a72010-09-21 09:22:52 +0000151$(APK): $(TEMP_APK) $(BUILDDIR)/rockbox.zip $(KEYSTORE)
Björn Stenberg35cd4082011-06-22 14:14:49 +0000152endif
Thomas Martitz4e982d32010-09-02 03:40:02 +0000153 $(SILENT)rm -f $@
154 $(call PRINTS,SIGN $(subst $(BUILDDIR)/,,$@))jarsigner \
Björn Stenberg40e61a72010-09-21 09:22:52 +0000155 -keystore "$(KEYSTORE)" -storepass "android" -keypass "android" \
Frank Gevaerts190577e2012-06-13 23:43:39 +0200156 -signedjar $(TEMP_APK2) $(TEMP_APK) "androiddebugkey" \
157 -sigalg MD5withRSA -digestalg SHA1
Thomas Martitz994aba12010-09-02 14:58:36 +0000158 $(SILENT)$(ZIPALIGN) -v 4 $(TEMP_APK2) $@ > /dev/null
Thomas Martitz4e982d32010-09-02 03:40:02 +0000159
Thomas Martitzaa0f8952010-09-12 20:50:30 +0000160$(DIRS):
161 $(SILENT)mkdir -p $@
Thomas Martitz994aba12010-09-02 14:58:36 +0000162
Thomas Martitzaa0f8952010-09-12 20:50:30 +0000163dirs: $(DIRS)
164
Björn Stenberg40e61a72010-09-21 09:22:52 +0000165apk: $(APK)
Antoine Celleriera448d8b2011-01-24 17:06:04 +0000166
167install: apk
Maurus Cuelenaere42f69c22011-03-11 15:45:55 +0000168 $(SILENT)$(ADB) install -r $(APK)
Antoine Celleriera448d8b2011-01-24 17:06:04 +0000169
Maurus Cuelenaere42f69c22011-03-11 15:45:55 +0000170launch:
171 $(SILENT)echo 'am start -a android.intent.action.MAIN -n org.rockbox/.RockboxActivity; exit' | $(ADB) shell >/dev/null