1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/config/makefiles/java-build.mk Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,124 @@ 1.4 +# -*- makefile -*- 1.5 +# vim:set ts=8 sw=8 sts=8 noet: 1.6 +# 1.7 +# This Source Code Form is subject to the terms of the Mozilla Public 1.8 +# License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.9 +# You can obtain one at http://mozilla.org/MPL/2.0/. 1.10 + 1.11 +ifndef INCLUDED_JAVA_BUILD_MK #{ 1.12 + 1.13 +ifdef JAVAFILES #{ 1.14 +GENERATED_DIRS += classes 1.15 + 1.16 +export:: classes 1.17 +classes: $(call mkdir_deps,classes) 1.18 +endif #} JAVAFILES 1.19 + 1.20 + 1.21 +ifdef ANDROID_APK_NAME #{ 1.22 +android_res_dirs := $(addprefix $(srcdir)/,$(or $(ANDROID_RES_DIRS),res)) 1.23 +_ANDROID_RES_FLAG := $(addprefix -S ,$(android_res_dirs)) 1.24 +_ANDROID_ASSETS_FLAG := $(addprefix -A ,$(ANDROID_ASSETS_DIR)) 1.25 +android_manifest := $(or $(ANDROID_MANIFEST_FILE),AndroidManifest.xml) 1.26 + 1.27 +GENERATED_DIRS += classes 1.28 + 1.29 +classes.dex: $(call mkdir_deps,classes) 1.30 +classes.dex: R.java 1.31 +classes.dex: $(ANDROID_APK_NAME).ap_ 1.32 +classes.dex: $(ANDROID_EXTRA_JARS) 1.33 +classes.dex: $(JAVAFILES) 1.34 + $(JAVAC) $(JAVAC_FLAGS) -d classes $(filter %.java,$^) \ 1.35 + $(if $(strip $(ANDROID_EXTRA_JARS)),-classpath $(subst $(NULL) ,:,$(strip $(ANDROID_EXTRA_JARS)))) 1.36 + $(DX) --dex --output=$@ classes $(ANDROID_EXTRA_JARS) 1.37 + 1.38 +# R.java and $(ANDROID_APK_NAME).ap_ are both produced by aapt. To 1.39 +# save an aapt invocation, we produce them both at the same time. The 1.40 +# trailing semi-colon defines an empty recipe; defining no recipe at 1.41 +# all causes Make to treat the target differently, in a way that 1.42 +# defeats our dependencies. 1.43 + 1.44 +R.java: .aapt.deps ; 1.45 +$(ANDROID_APK_NAME).ap_: .aapt.deps ; 1.46 + 1.47 +# This uses the fact that Android resource directories list all 1.48 +# resource files one subdirectory below the parent resource directory. 1.49 +android_res_files := $(wildcard $(addsuffix /*,$(wildcard $(addsuffix /*,$(android_res_dirs))))) 1.50 + 1.51 +.aapt.deps: $(android_manifest) $(android_res_files) $(wildcard $(ANDROID_ASSETS_DIR)) 1.52 + @$(TOUCH) $@ 1.53 + $(AAPT) package -f -M $< -I $(ANDROID_SDK)/android.jar $(_ANDROID_RES_FLAG) $(_ANDROID_ASSETS_FLAG) \ 1.54 + -J ${@D} \ 1.55 + -F $(ANDROID_APK_NAME).ap_ 1.56 + 1.57 +$(ANDROID_APK_NAME)-unsigned-unaligned.apk: $(ANDROID_APK_NAME).ap_ classes.dex 1.58 + cp $< $@ 1.59 + $(ZIP) -0 $@ classes.dex 1.60 + 1.61 +$(ANDROID_APK_NAME)-unaligned.apk: $(ANDROID_APK_NAME)-unsigned-unaligned.apk 1.62 + cp $< $@ 1.63 + $(DEBUG_JARSIGNER) $@ 1.64 + 1.65 +$(ANDROID_APK_NAME).apk: $(ANDROID_APK_NAME)-unaligned.apk 1.66 + $(ZIPALIGN) -f -v 4 $< $@ 1.67 + 1.68 +GARBAGE += \ 1.69 + R.java \ 1.70 + classes.dex \ 1.71 + $(ANDROID_APK_NAME).ap_ \ 1.72 + $(ANDROID_APK_NAME)-unsigned-unaligned.apk \ 1.73 + $(ANDROID_APK_NAME)-unaligned.apk \ 1.74 + $(ANDROID_APK_NAME).apk \ 1.75 + $(NULL) 1.76 + 1.77 +JAVA_CLASSPATH := $(ANDROID_SDK)/android.jar 1.78 + 1.79 +# Include Android specific java flags, instead of what's in rules.mk. 1.80 +include $(topsrcdir)/config/android-common.mk 1.81 +endif #} ANDROID_APK_NAME 1.82 + 1.83 + 1.84 +ifdef JAVA_JAR_TARGETS #{ 1.85 +# Arg 1: Output target name with .jar suffix, like jars/jarfile.jar. 1.86 +# Intermediate class files are generated in jars/jarfile-classes. 1.87 +# Arg 2: Java sources list. We use VPATH and $^ so sources can be 1.88 +# relative to $(srcdir) or $(CURDIR). 1.89 +# Arg 3: List of extra jars to link against. We do not use VPATH so 1.90 +# jars must be relative to $(CURDIR). 1.91 +# Arg 4: Additional JAVAC_FLAGS. 1.92 + 1.93 +# Note: Proguard fails when stale .class files corresponding to 1.94 +# removed inner classes are present in the object directory. These 1.95 +# stale class files get packaged into the .jar file, which then gets 1.96 +# processed by Proguard. To work around this, we always delete any 1.97 +# existing jarfile-classes directory and start fresh. 1.98 + 1.99 +define java_jar_template 1.100 +$(1): $(2) $(3) 1.101 + $$(REPORT_BUILD) 1.102 + @$$(RM) -rf $(1:.jar=)-classes 1.103 + @$$(NSINSTALL) -D $(1:.jar=)-classes 1.104 + @$$(if $$(filter-out .,$$(@D)),$$(NSINSTALL) -D $$(@D)) 1.105 + $$(JAVAC) $$(JAVAC_FLAGS)\ 1.106 + $(4)\ 1.107 + -d $(1:.jar=)-classes\ 1.108 + $(if $(strip $(3)),-classpath $(subst $(NULL) ,:,$(strip $(3))))\ 1.109 + $$(filter %.java,$$^) 1.110 + $$(JAR) cMf $$@ -C $(1:.jar=)-classes . 1.111 + 1.112 +GARBAGE += $(1) 1.113 + 1.114 +GARBAGE_DIRS += $(1:.jar=)-classes 1.115 +endef 1.116 + 1.117 +$(foreach jar,$(JAVA_JAR_TARGETS),\ 1.118 + $(if $($(jar)_DEST),,$(error Missing $(jar)_DEST))\ 1.119 + $(if $($(jar)_JAVAFILES) $($(jar)_PP_JAVAFILES),,$(error Must provide at least one of $(jar)_JAVAFILES and $(jar)_PP_JAVAFILES))\ 1.120 + $(eval $(call java_jar_template,$($(jar)_DEST),$($(jar)_JAVAFILES) $($(jar)_PP_JAVAFILES),$($(jar)_EXTRA_JARS),$($(jar)_JAVAC_FLAGS)))\ 1.121 +) 1.122 +endif #} JAVA_JAR_TARGETS 1.123 + 1.124 + 1.125 +INCLUDED_JAVA_BUILD_MK := 1 1.126 + 1.127 +endif #} INCLUDED_JAVA_BUILD_MK