1# Copyright (C) 2008 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15LOCAL_PATH := $(call my-dir)
16
17# One can override the default android_filesystem_config.h file in one of two ways:
18#
19# 1. The old way:
20#   To Build the custom target binary for the host to generate the fs_config
21#   override files. The executable is hard coded to include the
22#   $(TARGET_ANDROID_FILESYSTEM_CONFIG_H) file if it exists.
23#   Expectations:
24#      device/<vendor>/<device>/android_filesystem_config.h
25#          fills in struct fs_path_config android_device_dirs[] and
26#                   struct fs_path_config android_device_files[]
27#      device/<vendor>/<device>/device.mk
28#          PRODUCT_PACKAGES += fs_config_dirs fs_config_files
29#   If not specified, check if default one to be found
30#
31# 2. The new way:
32#   set TARGET_FS_CONFIG_GEN to contain a list of intermediate format files
33#   for generating the android_filesystem_config.h file.
34#
35# More information can be found in the README
36ANDROID_FS_CONFIG_H := android_filesystem_config.h
37
38ifneq ($(TARGET_ANDROID_FILESYSTEM_CONFIG_H),)
39ifneq ($(TARGET_FS_CONFIG_GEN),)
40$(error Cannot set TARGET_ANDROID_FILESYSTEM_CONFIG_H and TARGET_FS_CONFIG_GEN simultaneously)
41endif
42
43# One and only one file can be specified.
44ifneq ($(words $(TARGET_ANDROID_FILESYSTEM_CONFIG_H)),1)
45$(error Multiple fs_config files specified, \
46 see "$(TARGET_ANDROID_FILESYSTEM_CONFIG_H)".)
47endif
48
49ifeq ($(filter %/$(ANDROID_FS_CONFIG_H),$(TARGET_ANDROID_FILESYSTEM_CONFIG_H)),)
50$(error TARGET_ANDROID_FILESYSTEM_CONFIG_H file name must be $(ANDROID_FS_CONFIG_H), \
51 see "$(notdir $(TARGET_ANDROID_FILESYSTEM_CONFIG_H))".)
52endif
53
54my_fs_config_h := $(TARGET_ANDROID_FILESYSTEM_CONFIG_H)
55else ifneq ($(wildcard $(TARGET_DEVICE_DIR)/$(ANDROID_FS_CONFIG_H)),)
56
57ifneq ($(TARGET_FS_CONFIG_GEN),)
58$(error Cannot provide $(TARGET_DEVICE_DIR)/$(ANDROID_FS_CONFIG_H) and set TARGET_FS_CONFIG_GEN simultaneously)
59endif
60my_fs_config_h := $(TARGET_DEVICE_DIR)/$(ANDROID_FS_CONFIG_H)
61
62else
63my_fs_config_h := $(LOCAL_PATH)/default/$(ANDROID_FS_CONFIG_H)
64endif
65
66##################################
67include $(CLEAR_VARS)
68LOCAL_SRC_FILES := fs_config_generate.c
69LOCAL_MODULE := fs_config_generate_$(TARGET_DEVICE)
70LOCAL_MODULE_CLASS := EXECUTABLES
71LOCAL_SHARED_LIBRARIES := libcutils
72LOCAL_CFLAGS := -Werror -Wno-error=\#warnings
73
74ifneq ($(TARGET_FS_CONFIG_GEN),)
75system_android_filesystem_config := system/core/include/private/android_filesystem_config.h
76
77# Generate the "generated_oem_aid.h" file
78oem := $(local-generated-sources-dir)/generated_oem_aid.h
79$(oem): PRIVATE_LOCAL_PATH := $(LOCAL_PATH)
80$(oem): PRIVATE_TARGET_FS_CONFIG_GEN := $(TARGET_FS_CONFIG_GEN)
81$(oem): PRIVATE_ANDROID_FS_HDR := $(system_android_filesystem_config)
82$(oem): PRIVATE_CUSTOM_TOOL = $(PRIVATE_LOCAL_PATH)/fs_config_generator.py oemaid --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
83$(oem): $(TARGET_FS_CONFIG_GEN) $(LOCAL_PATH)/fs_config_generator.py
84	$(transform-generated-source)
85
86# Generate the fs_config header
87gen := $(local-generated-sources-dir)/$(ANDROID_FS_CONFIG_H)
88$(gen): PRIVATE_LOCAL_PATH := $(LOCAL_PATH)
89$(gen): PRIVATE_TARGET_FS_CONFIG_GEN := $(TARGET_FS_CONFIG_GEN)
90$(gen): PRIVATE_ANDROID_FS_HDR := $(system_android_filesystem_config)
91$(gen): PRIVATE_CUSTOM_TOOL = $(PRIVATE_LOCAL_PATH)/fs_config_generator.py fsconfig --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
92$(gen): $(TARGET_FS_CONFIG_GEN) $(system_android_filesystem_config) $(LOCAL_PATH)/fs_config_generator.py
93	$(transform-generated-source)
94
95LOCAL_GENERATED_SOURCES := $(oem) $(gen)
96
97my_fs_config_h := $(gen)
98my_gen_oem_aid := $(oem)
99gen :=
100oem :=
101endif
102
103LOCAL_C_INCLUDES := $(dir $(my_fs_config_h)) $(dir $(my_gen_oem_aid))
104
105include $(BUILD_HOST_EXECUTABLE)
106fs_config_generate_bin := $(LOCAL_INSTALLED_MODULE)
107# List of all supported vendor, oem and odm Partitions
108fs_config_generate_extra_partition_list := $(strip \
109  $(if $(BOARD_USES_VENDORIMAGE)$(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE),vendor) \
110  $(if $(BOARD_USES_OEMIMAGE)$(BOARD_OEMIMAGE_FILE_SYSTEM_TYPE),oem) \
111  $(if $(BOARD_USES_ODMIMAGE)$(BOARD_ODMIMAGE_FILE_SYSTEM_TYPE),odm))
112
113##################################
114# Generate the system/etc/fs_config_dirs binary file for the target
115# Add fs_config_dirs to PRODUCT_PACKAGES in the device make file to enable
116include $(CLEAR_VARS)
117
118LOCAL_MODULE := fs_config_dirs
119LOCAL_MODULE_CLASS := ETC
120LOCAL_REQUIRED_MODULES := $(foreach t,$(fs_config_generate_extra_partition_list),$(LOCAL_MODULE)_$(t))
121include $(BUILD_SYSTEM)/base_rules.mk
122$(LOCAL_BUILT_MODULE): $(fs_config_generate_bin)
123	@mkdir -p $(dir $@)
124	$< -D $(if $(fs_config_generate_extra_partition_list), \
125	   -P '$(subst $(space),$(comma),$(addprefix -,$(fs_config_generate_extra_partition_list)))') \
126	   -o $@
127
128##################################
129# Generate the system/etc/fs_config_files binary file for the target
130# Add fs_config_files to PRODUCT_PACKAGES in the device make file to enable
131include $(CLEAR_VARS)
132
133LOCAL_MODULE := fs_config_files
134LOCAL_MODULE_CLASS := ETC
135LOCAL_REQUIRED_MODULES := $(foreach t,$(fs_config_generate_extra_partition_list),$(LOCAL_MODULE)_$(t))
136include $(BUILD_SYSTEM)/base_rules.mk
137$(LOCAL_BUILT_MODULE): $(fs_config_generate_bin)
138	@mkdir -p $(dir $@)
139	$< -F $(if $(fs_config_generate_extra_partition_list), \
140	   -P '$(subst $(space),$(comma),$(addprefix -,$(fs_config_generate_extra_partition_list)))') \
141	   -o $@
142
143ifneq ($(filter vendor,$(fs_config_generate_extra_partition_list)),)
144##################################
145# Generate the vendor/etc/fs_config_dirs binary file for the target
146# Add fs_config_dirs or fs_config_dirs_vendor to PRODUCT_PACKAGES in
147# the device make file to enable.
148include $(CLEAR_VARS)
149
150LOCAL_MODULE := fs_config_dirs_vendor
151LOCAL_MODULE_CLASS := ETC
152LOCAL_INSTALLED_MODULE_STEM := fs_config_dirs
153LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc
154include $(BUILD_SYSTEM)/base_rules.mk
155$(LOCAL_BUILT_MODULE): $(fs_config_generate_bin)
156	@mkdir -p $(dir $@)
157	$< -D -P vendor -o $@
158
159##################################
160# Generate the vendor/etc/fs_config_files binary file for the target
161# Add fs_config_files or fs_config_files_vendor to PRODUCT_PACKAGES in
162# the device make file to enable
163include $(CLEAR_VARS)
164
165LOCAL_MODULE := fs_config_files_vendor
166LOCAL_MODULE_CLASS := ETC
167LOCAL_INSTALLED_MODULE_STEM := fs_config_files
168LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc
169include $(BUILD_SYSTEM)/base_rules.mk
170$(LOCAL_BUILT_MODULE): $(fs_config_generate_bin)
171	@mkdir -p $(dir $@)
172	$< -F -P vendor -o $@
173
174endif
175
176ifneq ($(filter oem,$(fs_config_generate_extra_partition_list)),)
177##################################
178# Generate the oem/etc/fs_config_dirs binary file for the target
179# Add fs_config_dirs or fs_config_dirs_oem to PRODUCT_PACKAGES in
180# the device make file to enable
181include $(CLEAR_VARS)
182
183LOCAL_MODULE := fs_config_dirs_oem
184LOCAL_MODULE_CLASS := ETC
185LOCAL_INSTALLED_MODULE_STEM := fs_config_dirs
186LOCAL_MODULE_PATH := $(TARGET_OUT_OEM)/etc
187include $(BUILD_SYSTEM)/base_rules.mk
188$(LOCAL_BUILT_MODULE): $(fs_config_generate_bin)
189	@mkdir -p $(dir $@)
190	$< -D -P oem -o $@
191
192##################################
193# Generate the oem/etc/fs_config_files binary file for the target
194# Add fs_config_files or fs_config_files_oem to PRODUCT_PACKAGES in
195# the device make file to enable
196include $(CLEAR_VARS)
197
198LOCAL_MODULE := fs_config_files_oem
199LOCAL_MODULE_CLASS := ETC
200LOCAL_INSTALLED_MODULE_STEM := fs_config_files
201LOCAL_MODULE_PATH := $(TARGET_OUT_OEM)/etc
202include $(BUILD_SYSTEM)/base_rules.mk
203$(LOCAL_BUILT_MODULE): $(fs_config_generate_bin)
204	@mkdir -p $(dir $@)
205	$< -F -P oem -o $@
206
207endif
208
209ifneq ($(filter odm,$(fs_config_generate_extra_partition_list)),)
210##################################
211# Generate the odm/etc/fs_config_dirs binary file for the target
212# Add fs_config_dirs or fs_config_dirs_odm to PRODUCT_PACKAGES in
213# the device make file to enable
214include $(CLEAR_VARS)
215
216LOCAL_MODULE := fs_config_dirs_odm
217LOCAL_MODULE_CLASS := ETC
218LOCAL_INSTALLED_MODULE_STEM := fs_config_dirs
219LOCAL_MODULE_PATH := $(TARGET_OUT_ODM)/etc
220include $(BUILD_SYSTEM)/base_rules.mk
221$(LOCAL_BUILT_MODULE): $(fs_config_generate_bin)
222	@mkdir -p $(dir $@)
223	$< -D -P odm -o $@
224
225##################################
226# Generate the odm/etc/fs_config_files binary file for the target
227# Add fs_config_files of fs_config_files_odm to PRODUCT_PACKAGES in
228# the device make file to enable
229include $(CLEAR_VARS)
230
231LOCAL_MODULE := fs_config_files_odm
232LOCAL_MODULE_CLASS := ETC
233LOCAL_INSTALLED_MODULE_STEM := fs_config_files
234LOCAL_MODULE_PATH := $(TARGET_OUT_ODM)/etc
235include $(BUILD_SYSTEM)/base_rules.mk
236$(LOCAL_BUILT_MODULE): $(fs_config_generate_bin)
237	@mkdir -p $(dir $@)
238	$< -F -P odm -o $@
239
240endif
241
242# The newer passwd/group targets are only generated if you
243# use the new TARGET_FS_CONFIG_GEN method.
244ifneq ($(TARGET_FS_CONFIG_GEN),)
245
246##################################
247# Build the oemaid header library when fs config files are present.
248# Intentionally break build if you require generated AIDs
249# header file, but are not using any fs config files.
250include $(CLEAR_VARS)
251LOCAL_MODULE := oemaids_headers
252LOCAL_EXPORT_C_INCLUDE_DIRS := $(dir $(my_gen_oem_aid))
253LOCAL_EXPORT_C_INCLUDE_DEPS := $(my_gen_oem_aid)
254include $(BUILD_HEADER_LIBRARY)
255
256##################################
257# Generate the vendor/etc/passwd text file for the target
258# This file may be empty if no AIDs are defined in
259# TARGET_FS_CONFIG_GEN files.
260include $(CLEAR_VARS)
261
262LOCAL_MODULE := passwd
263LOCAL_MODULE_CLASS := ETC
264LOCAL_VENDOR_MODULE := true
265
266include $(BUILD_SYSTEM)/base_rules.mk
267
268$(LOCAL_BUILT_MODULE): PRIVATE_LOCAL_PATH := $(LOCAL_PATH)
269$(LOCAL_BUILT_MODULE): PRIVATE_TARGET_FS_CONFIG_GEN := $(TARGET_FS_CONFIG_GEN)
270$(LOCAL_BUILT_MODULE): PRIVATE_ANDROID_FS_HDR := $(system_android_filesystem_config)
271$(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/fs_config_generator.py $(TARGET_FS_CONFIG_GEN) $(system_android_filesystem_config)
272	@mkdir -p $(dir $@)
273	$(hide) $< passwd --required-prefix=vendor_ --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
274
275##################################
276# Generate the vendor/etc/group text file for the target
277# This file may be empty if no AIDs are defined in
278# TARGET_FS_CONFIG_GEN files.
279include $(CLEAR_VARS)
280
281LOCAL_MODULE := group
282LOCAL_MODULE_CLASS := ETC
283LOCAL_VENDOR_MODULE := true
284
285include $(BUILD_SYSTEM)/base_rules.mk
286
287$(LOCAL_BUILT_MODULE): PRIVATE_LOCAL_PATH := $(LOCAL_PATH)
288$(LOCAL_BUILT_MODULE): PRIVATE_TARGET_FS_CONFIG_GEN := $(TARGET_FS_CONFIG_GEN)
289$(LOCAL_BUILT_MODULE): PRIVATE_ANDROID_FS_HDR := $(system_android_filesystem_config)
290$(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/fs_config_generator.py $(TARGET_FS_CONFIG_GEN) $(system_android_filesystem_config)
291	@mkdir -p $(dir $@)
292	$(hide) $< group --required-prefix=vendor_ --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
293
294system_android_filesystem_config :=
295endif
296
297ANDROID_FS_CONFIG_H :=
298my_fs_config_h :=
299fs_config_generate_bin :=
300my_gen_oem_aid :=
301fs_config_generate_extra_partition_list :=
302