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