summaryrefslogtreecommitdiffstats
path: root/tools/aapt2/data/Makefile
blob: 91ff5fee6477e5619b52733f43b76baa6909fd4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
##
# Environment dependent variables
##

AAPT := aapt2
ZIPALIGN := zipalign -f 4
FRAMEWORK := ../../../../../out/target/common/obj/APPS/framework-res_intermediates/package-export.apk

##
# Project depenedent variables
##

LOCAL_PACKAGE := com.android.app
LOCAL_RESOURCE_DIR := res
LOCAL_LIBS := lib/out/package.apk
LOCAL_OUT := out
LOCAL_GEN := out/gen
LOCAL_PROGUARD := out/proguard.rule

##
# AAPT2 custom rules.
##

PRIVATE_APK_UNALIGNED := $(LOCAL_OUT)/package-unaligned.apk
PRIVATE_APK_ALIGNED := $(LOCAL_OUT)/package.apk

# Eg: framework.apk, etc.
PRIVATE_INCLUDES := $(FRAMEWORK)
$(info PRIVATE_INCLUDES = $(PRIVATE_INCLUDES))

# Eg: gen/com/android/app/R.java
PRIVATE_R_JAVA := $(LOCAL_GEN)/$(subst .,/,$(LOCAL_PACKAGE))/R.java
$(info PRIVATE_R_JAVA = $(PRIVATE_R_JAVA))

# Eg: res/drawable/icon.png, res/values/styles.xml
PRIVATE_RESOURCES := $(shell find $(LOCAL_RESOURCE_DIR) -mindepth 1 -maxdepth 2 -type f)
$(info PRIVATE_RESOURCES = $(PRIVATE_RESOURCES))

# Eg: drawable, values, layouts
PRIVATE_RESOURCE_TYPES := \
	$(patsubst $(LOCAL_RESOURCE_DIR)/%/,%,$(sort $(dir $(PRIVATE_RESOURCES))))
$(info PRIVATE_RESOURCE_TYPES = $(PRIVATE_RESOURCE_TYPES))

# Eg: out/values-v4.apk, out/drawable-xhdpi.apk
PRIVATE_INTERMEDIATE_TABLES := $(patsubst %,$(LOCAL_OUT)/%.apk,$(PRIVATE_RESOURCE_TYPES))
$(info PRIVATE_INTERMEDIATE_TABLES = $(PRIVATE_INTERMEDIATE_TABLES))

# Generates rules for collect phase.
# $1: Resource type (values-v4)
# returns: out/values-v4.apk: res/values-v4/styles.xml res/values-v4/colors.xml
define make-collect-rule
$(LOCAL_OUT)/$1.apk: $(filter $(LOCAL_RESOURCE_DIR)/$1/%,$(PRIVATE_RESOURCES))
	$(AAPT) compile -o $$@ $$^
endef

# Collect: out/values-v4.apk <- res/values-v4/styles.xml res/values-v4/colors.xml
$(foreach d,$(PRIVATE_RESOURCE_TYPES),$(eval $(call make-collect-rule,$d)))

# Link: out/package-unaligned.apk <- out/values-v4.apk out/drawable-v4.apk
$(PRIVATE_APK_UNALIGNED): $(PRIVATE_INTERMEDIATE_TABLES) $(PRIVATE_INCLUDES) $(LOCAL_LIBS) AndroidManifest.xml
	$(AAPT) link --manifest AndroidManifest.xml $(addprefix -I ,$(PRIVATE_INCLUDES)) --java $(LOCAL_GEN) -o $@ $(PRIVATE_INTERMEDIATE_TABLES) $(LOCAL_LIBS) --proguard $(LOCAL_PROGUARD) -v

# R.java: gen/com/android/app/R.java <- out/resources.arsc
# No action since R.java is generated when out/resources.arsc is.
$(PRIVATE_R_JAVA): $(PRIVATE_APK_UNALIGNED)

# Assemble: zip out/resources.arsc AndroidManifest.xml and res/**/*
$(PRIVATE_APK_ALIGNED): $(PRIVATE_APK_UNALIGNED)
	$(ZIPALIGN) $< $@

# Create the out directory if needed.
dummy := $(shell test -d $(LOCAL_OUT) || mkdir -p $(LOCAL_OUT))

.PHONY: java
java: $(PRIVATE_R_JAVA)

.PHONY: assemble
assemble: $(PRIVATE_APK_ALIGNED)

.PHONY: all
all: assemble java

.DEFAULT_GOAL := all