Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | # -*- makefile -*- |
michael@0 | 2 | # vim:set ts=8 sw=8 sts=8 noet: |
michael@0 | 3 | # |
michael@0 | 4 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 6 | # You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 7 | |
michael@0 | 8 | ifndef INCLUDED_JAVA_BUILD_MK #{ |
michael@0 | 9 | |
michael@0 | 10 | ifdef JAVAFILES #{ |
michael@0 | 11 | GENERATED_DIRS += classes |
michael@0 | 12 | |
michael@0 | 13 | export:: classes |
michael@0 | 14 | classes: $(call mkdir_deps,classes) |
michael@0 | 15 | endif #} JAVAFILES |
michael@0 | 16 | |
michael@0 | 17 | |
michael@0 | 18 | ifdef ANDROID_APK_NAME #{ |
michael@0 | 19 | android_res_dirs := $(addprefix $(srcdir)/,$(or $(ANDROID_RES_DIRS),res)) |
michael@0 | 20 | _ANDROID_RES_FLAG := $(addprefix -S ,$(android_res_dirs)) |
michael@0 | 21 | _ANDROID_ASSETS_FLAG := $(addprefix -A ,$(ANDROID_ASSETS_DIR)) |
michael@0 | 22 | android_manifest := $(or $(ANDROID_MANIFEST_FILE),AndroidManifest.xml) |
michael@0 | 23 | |
michael@0 | 24 | GENERATED_DIRS += classes |
michael@0 | 25 | |
michael@0 | 26 | classes.dex: $(call mkdir_deps,classes) |
michael@0 | 27 | classes.dex: R.java |
michael@0 | 28 | classes.dex: $(ANDROID_APK_NAME).ap_ |
michael@0 | 29 | classes.dex: $(ANDROID_EXTRA_JARS) |
michael@0 | 30 | classes.dex: $(JAVAFILES) |
michael@0 | 31 | $(JAVAC) $(JAVAC_FLAGS) -d classes $(filter %.java,$^) \ |
michael@0 | 32 | $(if $(strip $(ANDROID_EXTRA_JARS)),-classpath $(subst $(NULL) ,:,$(strip $(ANDROID_EXTRA_JARS)))) |
michael@0 | 33 | $(DX) --dex --output=$@ classes $(ANDROID_EXTRA_JARS) |
michael@0 | 34 | |
michael@0 | 35 | # R.java and $(ANDROID_APK_NAME).ap_ are both produced by aapt. To |
michael@0 | 36 | # save an aapt invocation, we produce them both at the same time. The |
michael@0 | 37 | # trailing semi-colon defines an empty recipe; defining no recipe at |
michael@0 | 38 | # all causes Make to treat the target differently, in a way that |
michael@0 | 39 | # defeats our dependencies. |
michael@0 | 40 | |
michael@0 | 41 | R.java: .aapt.deps ; |
michael@0 | 42 | $(ANDROID_APK_NAME).ap_: .aapt.deps ; |
michael@0 | 43 | |
michael@0 | 44 | # This uses the fact that Android resource directories list all |
michael@0 | 45 | # resource files one subdirectory below the parent resource directory. |
michael@0 | 46 | android_res_files := $(wildcard $(addsuffix /*,$(wildcard $(addsuffix /*,$(android_res_dirs))))) |
michael@0 | 47 | |
michael@0 | 48 | .aapt.deps: $(android_manifest) $(android_res_files) $(wildcard $(ANDROID_ASSETS_DIR)) |
michael@0 | 49 | @$(TOUCH) $@ |
michael@0 | 50 | $(AAPT) package -f -M $< -I $(ANDROID_SDK)/android.jar $(_ANDROID_RES_FLAG) $(_ANDROID_ASSETS_FLAG) \ |
michael@0 | 51 | -J ${@D} \ |
michael@0 | 52 | -F $(ANDROID_APK_NAME).ap_ |
michael@0 | 53 | |
michael@0 | 54 | $(ANDROID_APK_NAME)-unsigned-unaligned.apk: $(ANDROID_APK_NAME).ap_ classes.dex |
michael@0 | 55 | cp $< $@ |
michael@0 | 56 | $(ZIP) -0 $@ classes.dex |
michael@0 | 57 | |
michael@0 | 58 | $(ANDROID_APK_NAME)-unaligned.apk: $(ANDROID_APK_NAME)-unsigned-unaligned.apk |
michael@0 | 59 | cp $< $@ |
michael@0 | 60 | $(DEBUG_JARSIGNER) $@ |
michael@0 | 61 | |
michael@0 | 62 | $(ANDROID_APK_NAME).apk: $(ANDROID_APK_NAME)-unaligned.apk |
michael@0 | 63 | $(ZIPALIGN) -f -v 4 $< $@ |
michael@0 | 64 | |
michael@0 | 65 | GARBAGE += \ |
michael@0 | 66 | R.java \ |
michael@0 | 67 | classes.dex \ |
michael@0 | 68 | $(ANDROID_APK_NAME).ap_ \ |
michael@0 | 69 | $(ANDROID_APK_NAME)-unsigned-unaligned.apk \ |
michael@0 | 70 | $(ANDROID_APK_NAME)-unaligned.apk \ |
michael@0 | 71 | $(ANDROID_APK_NAME).apk \ |
michael@0 | 72 | $(NULL) |
michael@0 | 73 | |
michael@0 | 74 | JAVA_CLASSPATH := $(ANDROID_SDK)/android.jar |
michael@0 | 75 | |
michael@0 | 76 | # Include Android specific java flags, instead of what's in rules.mk. |
michael@0 | 77 | include $(topsrcdir)/config/android-common.mk |
michael@0 | 78 | endif #} ANDROID_APK_NAME |
michael@0 | 79 | |
michael@0 | 80 | |
michael@0 | 81 | ifdef JAVA_JAR_TARGETS #{ |
michael@0 | 82 | # Arg 1: Output target name with .jar suffix, like jars/jarfile.jar. |
michael@0 | 83 | # Intermediate class files are generated in jars/jarfile-classes. |
michael@0 | 84 | # Arg 2: Java sources list. We use VPATH and $^ so sources can be |
michael@0 | 85 | # relative to $(srcdir) or $(CURDIR). |
michael@0 | 86 | # Arg 3: List of extra jars to link against. We do not use VPATH so |
michael@0 | 87 | # jars must be relative to $(CURDIR). |
michael@0 | 88 | # Arg 4: Additional JAVAC_FLAGS. |
michael@0 | 89 | |
michael@0 | 90 | # Note: Proguard fails when stale .class files corresponding to |
michael@0 | 91 | # removed inner classes are present in the object directory. These |
michael@0 | 92 | # stale class files get packaged into the .jar file, which then gets |
michael@0 | 93 | # processed by Proguard. To work around this, we always delete any |
michael@0 | 94 | # existing jarfile-classes directory and start fresh. |
michael@0 | 95 | |
michael@0 | 96 | define java_jar_template |
michael@0 | 97 | $(1): $(2) $(3) |
michael@0 | 98 | $$(REPORT_BUILD) |
michael@0 | 99 | @$$(RM) -rf $(1:.jar=)-classes |
michael@0 | 100 | @$$(NSINSTALL) -D $(1:.jar=)-classes |
michael@0 | 101 | @$$(if $$(filter-out .,$$(@D)),$$(NSINSTALL) -D $$(@D)) |
michael@0 | 102 | $$(JAVAC) $$(JAVAC_FLAGS)\ |
michael@0 | 103 | $(4)\ |
michael@0 | 104 | -d $(1:.jar=)-classes\ |
michael@0 | 105 | $(if $(strip $(3)),-classpath $(subst $(NULL) ,:,$(strip $(3))))\ |
michael@0 | 106 | $$(filter %.java,$$^) |
michael@0 | 107 | $$(JAR) cMf $$@ -C $(1:.jar=)-classes . |
michael@0 | 108 | |
michael@0 | 109 | GARBAGE += $(1) |
michael@0 | 110 | |
michael@0 | 111 | GARBAGE_DIRS += $(1:.jar=)-classes |
michael@0 | 112 | endef |
michael@0 | 113 | |
michael@0 | 114 | $(foreach jar,$(JAVA_JAR_TARGETS),\ |
michael@0 | 115 | $(if $($(jar)_DEST),,$(error Missing $(jar)_DEST))\ |
michael@0 | 116 | $(if $($(jar)_JAVAFILES) $($(jar)_PP_JAVAFILES),,$(error Must provide at least one of $(jar)_JAVAFILES and $(jar)_PP_JAVAFILES))\ |
michael@0 | 117 | $(eval $(call java_jar_template,$($(jar)_DEST),$($(jar)_JAVAFILES) $($(jar)_PP_JAVAFILES),$($(jar)_EXTRA_JARS),$($(jar)_JAVAC_FLAGS)))\ |
michael@0 | 118 | ) |
michael@0 | 119 | endif #} JAVA_JAR_TARGETS |
michael@0 | 120 | |
michael@0 | 121 | |
michael@0 | 122 | INCLUDED_JAVA_BUILD_MK := 1 |
michael@0 | 123 | |
michael@0 | 124 | endif #} INCLUDED_JAVA_BUILD_MK |