blob: c40b8cc7a2fe7bb5b39892c3ddada17262216217 [file] [log] [blame]
Alexey Polyudovccdc3112016-08-01 17:41:49 -07001variant_list := $(filter AUX-%,$(MAKECMDGOALS))
2
3ifdef variant_list
4AUX_OS_VARIANT_LIST := $(patsubst AUX-%,%,$(variant_list))
5else
6AUX_OS_VARIANT_LIST := $(TARGET_AUX_OS_VARIANT_LIST)
7endif
8
9# exclude AUX targets from build
10ifeq ($(AUX_OS_VARIANT_LIST),none)
11AUX_OS_VARIANT_LIST :=
12endif
13
14# temporary workaround to support external toolchain
15ifeq ($(NANOHUB_TOOLCHAIN),)
16AUX_OS_VARIANT_LIST :=
17endif
18
19# setup toolchain paths for various CPU architectures
20# this one will come from android prebuilts eventually
21AUX_TOOLCHAIN_cortexm4 := $(NANOHUB_TOOLCHAIN)
22ifeq ($(wildcard $(AUX_TOOLCHAIN_cortexm4)gcc),)
23AUX_TOOLCHAIN_cortexm4:=
24endif
25
26# there is no MAKE var that defines path to HOST toolchain
27# all the interesting paths are hardcoded in soong, and are not available from here
28# There is no other way but to hardcode them again, as we may need host x86 toolcain for AUX
29ifeq ($(HOST_OS),linux)
30AUX_TOOLCHAIN_x86 := prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/bin/x86_64-linux-
31endif
32
33# setup AUX globals
34AUX_SHLIB_SUFFIX := .so
35AUX_GLOBAL_ARFLAGS := crsPD
36AUX_STATIC_LIB_SUFFIX := .a
37
38# Load ever-lasting "indexed" version of AUX variant environment; it is treated as READ-ONLY from this
39# moment on.
40#
41# $(1) - variant
42# no return value
43define aux-variant-setup-paths
44$(eval AUX_OUT_ROOT_$(1) := $(PRODUCT_OUT)/aux/$(1)) \
45$(eval AUX_COMMON_OUT_ROOT_$(1) := $(AUX_OUT_ROOT_$(1))/common) \
46$(eval AUX_OUT_$(1) := $(AUX_OUT_ROOT_$(1))/$(AUX_OS_$(1))-$(AUX_ARCH_$(1))-$(AUX_CPU_$(1))) \
47$(eval AUX_OUT_INTERMEDIATES_$(1) := $(AUX_OUT_$(1))/obj) \
48$(eval AUX_OUT_COMMON_INTERMEDIATES_$(1) := $(AUX_COMMON_OUT_ROOT_$(1))/obj) \
49$(eval AUX_OUT_HEADERS_$(1) := $(AUX_OUT_INTERMEDIATES_$(1))/include) \
50$(eval AUX_OUT_INTERMEDIATE_LIBRARIES_$(1) := $(AUX_OUT_INTERMEDIATES_$(1))/lib) \
51$(eval AUX_OUT_NOTICE_FILES_$(1) := $(AUX_OUT_INTERMEDIATES_$(1))/NOTICE_FILES) \
52$(eval AUX_OUT_FAKE_$(1) := $(AUX_OUT_$(1))/fake_packages) \
53$(eval AUX_OUT_GEN_$(1) := $(AUX_OUT_$(1))/gen) \
54$(eval AUX_OUT_COMMON_GEN_$(1) := $(AUX_COMMON_OUT_ROOT_$(1))/gen) \
55$(eval AUX_OUT_EXECUTABLES_$(1) := $(AUX_OUT_$(1))/bin) \
56$(eval AUX_OUT_UNSTRIPPED_$(1) := $(AUX_OUT_$(1))/symbols)
57endef
58
59# Copy "indexed" AUX environment for given VARIANT into
60# volatile not-indexed set of variables for simplicity of access.
61# Injection of index support throughout the build system is suboptimal
62# hence volatile environment is constructed
63# Unlike HOST*, TARGET* variables, AUX* variables are NOT read-only, but their
64# indexed versions are.
65#
66# $(1) - variant
67# no return value
68define aux-variant-load-env
69$(eval AUX_OS_VARIANT:=$(1)) \
70$(eval AUX_OS:=$(AUX_OS_$(1))) \
71$(eval AUX_ARCH:=$(AUX_ARCH_$(1))) \
72$(eval AUX_SUBARCH:=$(AUX_SUBARCH_$(1))) \
73$(eval AUX_CPU:=$(AUX_CPU_$(1))) \
74$(eval AUX_OS_PATH:=$(AUX_OS_PATH_$(1))) \
75$(eval AUX_OUT_ROOT := $(AUX_OUT_ROOT_$(1))) \
76$(eval AUX_COMMON_OUT_ROOT := $(AUX_COMMON_OUT_ROOT_$(1))) \
77$(eval AUX_OUT := $(AUX_OUT_$(1))) \
78$(eval AUX_OUT_INTERMEDIATES := $(AUX_OUT_INTERMEDIATES_$(1))) \
79$(eval AUX_OUT_COMMON_INTERMEDIATES := $(AUX_OUT_COMMON_INTERMEDIATES_$(1))) \
80$(eval AUX_OUT_HEADERS := $(AUX_OUT_HEADERS_$(1))) \
81$(eval AUX_OUT_INTERMEDIATE_LIBRARIES := $(AUX_OUT_INTERMEDIATE_LIBRARIES_$(1))) \
82$(eval AUX_OUT_NOTICE_FILES := $(AUX_OUT_NOTICE_FILES_$(1))) \
83$(eval AUX_OUT_FAKE := $(AUX_OUT_FAKE_$(1))) \
84$(eval AUX_OUT_GEN := $(AUX_OUT_GEN_$(1))) \
85$(eval AUX_OUT_COMMON_GEN := $(AUX_OUT_COMMON_GEN_$(1))) \
86$(eval AUX_OUT_EXECUTABLES := $(AUX_OUT_EXECUTABLES_$(1))) \
87$(eval AUX_OUT_UNSTRIPPED := $(AUX_OUT_UNSTRIPPED_$(1)))
88endef
89
90# given a variant:path pair, load the variant conviguration with aux-variant-setup-paths from file
91# this is a build system extension mechainsm, since configuration typically resides in non-build
92# project space
93#
94# $(1) - variant:path pair
95# $(2) - file suffix
96# no return value
97define aux-variant-import-from-pair
98$(eval _pair := $(subst :, ,$(1))) \
99$(eval _name:=$(word 1,$(_pair))) \
100$(eval _path:=$(word 2,$(_pair))) \
101$(eval include $(_path)/$(_name)$(2)) \
102$(eval AUX_OS_VARIANT_LIST_$(AUX_OS_$(1)):=) \
103$(call aux-variant-setup-paths,$(_name)) \
104$(eval AUX_ALL_VARIANTS += $(_name)) \
105$(eval AUX_ALL_OSES := $(filterout $(AUX_OS_$(_name)),$(AUX_ALL_OSES)) $(AUX_OS_$(_name))) \
106$(eval AUX_ALL_CPUS := $(filterout $(AUX_CPU_$(_name)),$(AUX_ALL_CPUS)) $(AUX_CPU_$(_name))) \
107$(eval AUX_ALL_ARCHS := $(filterout $(AUX_ARCH_$(_name)),$(AUX_ALL_ARCHS)) $(AUX_ARCH_$(_name))) \
108$(eval AUX_ALL_SUBARCHS := $(filterout $(AUX_SUBARCH_$(_name)),$(AUX_ALL_SUBARCHS)) $(AUX_SUBARCH_$(_name)))
109endef
110
111# Load system configuration referenced by AUX variant config;
112# this is a build extension mechanism; typically system config
113# resides in a non-build projects;
114# system config may define new rules and globally visible BUILD*
115# includes to support project-specific build steps and toolchains
116# MAintains list of valiants that reference this os config in OS "indexed" var
117# this facilitates multivariant build of the OS (or whataver it is the name of common component these variants share)
118#
119# $(1) - variant
120# no return value
121define aux-import-os-config
122$(eval _aioc_os := $(AUX_OS_$(1))) \
123$(eval AUX_OS_PATH_$(1) := $(patsubst $(_aioc_os):%,%,$(filter $(_aioc_os):%,$(AUX_ALL_OS_PATHS)))) \
124$(eval _aioc_os_cfg := $(AUX_OS_PATH_$(1))/$(_aioc_os)$(os_sfx)) \
125$(if $(wildcard $(_aioc_os_cfg)),,$(error AUX '$(_aioc_os)' OS config file [$(notdir $(_aioc_os_cfg))] required by AUX variant '$(1)' does not exist)) \
126$(if $(filter $(_aioc_os),$(_os_list)),,$(eval include $(_aioc_os_cfg))) \
127$(eval AUX_OS_VARIANT_LIST_$(_aioc_os) += $(1)) \
128$(eval _os_list += $(_aioc_os))
129endef
130
131# make sure that AUX config variables are minimally sane;
132# as a bare minimum they must contain the vars described by aux_env
133# Generate error if requirement is not met.
134#
135#$(1) - variant
136# no return value
137define aux-variant-validate
138$(eval _all:=) \
139$(eval _req:=$(addsuffix _$(1),$(aux_env))) \
140$(foreach var,$(_req),$(eval _all += $(var))) \
141$(eval _missing := $(filterout $(_all),$(_req))) \
142$(if $(_missing),$(error AUX variant $(1) must define vars: $(_missing)))
143endef
144
145AUX_ALL_VARIANTS :=
146AUX_ALL_OSES :=
147AUX_ALL_CPUS :=
148AUX_ALL_ARCHS :=
149AUX_ALL_SUBARCHS :=
150
151variant_sfx :=_aux_variant_config.mk
152os_sfx :=_aux_os_config.mk
153
Colin Crossefb30be2017-01-11 13:59:41 -0800154config_roots := $(wildcard device vendor)
155all_configs :=
156ifdef config_roots
157all_configs := $(shell find $(config_roots) -maxdepth 4 -name '*$(variant_sfx)' -o -name '*$(os_sfx)' | sort)
158endif
Alexey Polyudovccdc3112016-08-01 17:41:49 -0700159all_os_configs := $(filter %$(os_sfx),$(all_configs))
160all_variant_configs := $(filter %$(variant_sfx),$(all_configs))
161
162AUX_ALL_OS_PATHS := $(foreach f,$(all_os_configs),$(patsubst %$(os_sfx),%,$(notdir $(f))):$(patsubst %/,%,$(dir $(f))))
163AUX_ALL_OS_VARIANT_PATHS := $(foreach f,$(all_variant_configs),$(patsubst %$(variant_sfx),%,$(notdir $(f))):$(patsubst %/,%,$(dir $(f))))
164
165my_variant_pairs := $(foreach v,$(AUX_OS_VARIANT_LIST),$(filter $(v):%,$(AUX_ALL_OS_VARIANT_PATHS)))
166my_missing_variants := $(foreach v,$(AUX_OS_VARIANT_LIST),$(if $(filter $(v):%,$(AUX_ALL_OS_VARIANT_PATHS)),,$(v)))
167
168ifneq ($(strip $(my_missing_variants)),)
169$(error Don't know how to build variant(s): $(my_missing_variants))
170endif
171
172# mandatory variables
173aux_env := AUX_OS AUX_ARCH AUX_SUBARCH AUX_CPU
174
175$(foreach v,$(my_variant_pairs),$(if $(filter $(v),$(AUX_ALL_VARIANTS)),,$(call aux-variant-import-from-pair,$(v),$(variant_sfx))))
176
177ifdef AUX_ALL_VARIANTS
178_os_list :=
179$(foreach v,$(AUX_ALL_VARIANTS),\
180 $(call aux-import-os-config,$(v)) \
181 $(call aux-variant-validate,$(v)) \
182)
183endif
184
185INSTALLED_AUX_TARGETS :=
186
187droidcore: auxiliary