Home | History | Annotate | Download | only in fs_config
      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 
     15 LOCAL_PATH := $(call my-dir)
     16 
     17 include $(CLEAR_VARS)
     18 
     19 LOCAL_SRC_FILES := fs_config.c
     20 LOCAL_MODULE := fs_config
     21 LOCAL_SHARED_LIBRARIES := libcutils libselinux
     22 LOCAL_CFLAGS := -Werror
     23 
     24 include $(BUILD_HOST_EXECUTABLE)
     25 
     26 # One can override the default android_filesystem_config.h file in one of two ways:
     27 #
     28 # 1. The old way:
     29 #   To Build the custom target binary for the host to generate the fs_config
     30 #   override files. The executable is hard coded to include the
     31 #   $(TARGET_ANDROID_FILESYSTEM_CONFIG_H) file if it exists.
     32 #   Expectations:
     33 #      device/<vendor>/<device>/android_filesystem_config.h
     34 #          fills in struct fs_path_config android_device_dirs[] and
     35 #                   struct fs_path_config android_device_files[]
     36 #      device/<vendor>/<device>/device.mk
     37 #          PRODUCT_PACKAGES += fs_config_dirs fs_config_files
     38 #   If not specified, check if default one to be found
     39 #
     40 # 2. The new way:
     41 #   set TARGET_FS_CONFIG_GEN to contain a list of intermediate format files
     42 #   for generating the android_filesystem_config.h file.
     43 #
     44 # More information can be found in the README
     45 ANDROID_FS_CONFIG_H := android_filesystem_config.h
     46 
     47 ifneq ($(TARGET_ANDROID_FILESYSTEM_CONFIG_H),)
     48 ifneq ($(TARGET_FS_CONFIG_GEN),)
     49 $(error Cannot set TARGET_ANDROID_FILESYSTEM_CONFIG_H and TARGET_FS_CONFIG_GEN simultaneously)
     50 endif
     51 
     52 # One and only one file can be specified.
     53 ifneq ($(words $(TARGET_ANDROID_FILESYSTEM_CONFIG_H)),1)
     54 $(error Multiple fs_config files specified, \
     55  see "$(TARGET_ANDROID_FILESYSTEM_CONFIG_H)".)
     56 endif
     57 
     58 ifeq ($(filter %/$(ANDROID_FS_CONFIG_H),$(TARGET_ANDROID_FILESYSTEM_CONFIG_H)),)
     59 $(error TARGET_ANDROID_FILESYSTEM_CONFIG_H file name must be $(ANDROID_FS_CONFIG_H), \
     60  see "$(notdir $(TARGET_ANDROID_FILESYSTEM_CONFIG_H))".)
     61 endif
     62 
     63 my_fs_config_h := $(TARGET_ANDROID_FILESYSTEM_CONFIG_H)
     64 else ifneq ($(wildcard $(TARGET_DEVICE_DIR)/$(ANDROID_FS_CONFIG_H)),)
     65 
     66 ifneq ($(TARGET_FS_CONFIG_GEN),)
     67 $(error Cannot provide $(TARGET_DEVICE_DIR)/$(ANDROID_FS_CONFIG_H) and set TARGET_FS_CONFIG_GEN simultaneously)
     68 endif
     69 my_fs_config_h := $(TARGET_DEVICE_DIR)/$(ANDROID_FS_CONFIG_H)
     70 
     71 else
     72 my_fs_config_h := $(LOCAL_PATH)/default/$(ANDROID_FS_CONFIG_H)
     73 endif
     74 
     75 ##################################
     76 include $(CLEAR_VARS)
     77 LOCAL_SRC_FILES := fs_config_generate.c
     78 LOCAL_MODULE := fs_config_generate_$(TARGET_DEVICE)
     79 LOCAL_MODULE_CLASS := EXECUTABLES
     80 LOCAL_SHARED_LIBRARIES := libcutils
     81 LOCAL_CFLAGS := -Werror -Wno-error=\#warnings
     82 
     83 ifneq ($(TARGET_FS_CONFIG_GEN),)
     84 system_android_filesystem_config := system/core/include/private/android_filesystem_config.h
     85 
     86 # Generate the "generated_oem_aid.h" file
     87 oem := $(local-generated-sources-dir)/generated_oem_aid.h
     88 $(oem): PRIVATE_LOCAL_PATH := $(LOCAL_PATH)
     89 $(oem): PRIVATE_TARGET_FS_CONFIG_GEN := $(TARGET_FS_CONFIG_GEN)
     90 $(oem): PRIVATE_ANDROID_FS_HDR := $(system_android_filesystem_config)
     91 $(oem): PRIVATE_CUSTOM_TOOL = $(PRIVATE_LOCAL_PATH)/fs_config_generator.py oemaid --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
     92 $(oem): $(TARGET_FS_CONFIG_GEN) $(LOCAL_PATH)/fs_config_generator.py
     93 	$(transform-generated-source)
     94 
     95 # Generate the fs_config header
     96 gen := $(local-generated-sources-dir)/$(ANDROID_FS_CONFIG_H)
     97 $(gen): PRIVATE_LOCAL_PATH := $(LOCAL_PATH)
     98 $(gen): PRIVATE_TARGET_FS_CONFIG_GEN := $(TARGET_FS_CONFIG_GEN)
     99 $(gen): PRIVATE_ANDROID_FS_HDR := $(system_android_filesystem_config)
    100 $(gen): PRIVATE_CUSTOM_TOOL = $(PRIVATE_LOCAL_PATH)/fs_config_generator.py fsconfig --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
    101 $(gen): $(TARGET_FS_CONFIG_GEN) $(system_android_filesystem_config) $(LOCAL_PATH)/fs_config_generator.py
    102 	$(transform-generated-source)
    103 
    104 LOCAL_GENERATED_SOURCES := $(oem) $(gen)
    105 
    106 my_fs_config_h := $(gen)
    107 my_gen_oem_aid := $(oem)
    108 gen :=
    109 oem :=
    110 endif
    111 
    112 LOCAL_C_INCLUDES := $(dir $(my_fs_config_h)) $(dir $(my_gen_oem_aid))
    113 
    114 include $(BUILD_HOST_EXECUTABLE)
    115 fs_config_generate_bin := $(LOCAL_INSTALLED_MODULE)
    116 # List of all supported vendor, oem and odm Partitions
    117 fs_config_generate_extra_partition_list := $(strip \
    118   $(if $(BOARD_USES_VENDORIMAGE)$(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE),vendor) \
    119   $(if $(BOARD_USES_OEMIMAGE)$(BOARD_OEMIMAGE_FILE_SYSTEM_TYPE),oem) \
    120   $(if $(BOARD_USES_ODMIMAGE)$(BOARD_ODMIMAGE_FILE_SYSTEM_TYPE),odm))
    121 
    122 ##################################
    123 # Generate the system/etc/fs_config_dirs binary file for the target
    124 # Add fs_config_dirs to PRODUCT_PACKAGES in the device make file to enable
    125 include $(CLEAR_VARS)
    126 
    127 LOCAL_MODULE := fs_config_dirs
    128 LOCAL_MODULE_CLASS := ETC
    129 LOCAL_REQUIRED_MODULES := $(foreach t,$(fs_config_generate_extra_partition_list),$(LOCAL_MODULE)_$(t))
    130 include $(BUILD_SYSTEM)/base_rules.mk
    131 $(LOCAL_BUILT_MODULE): $(fs_config_generate_bin)
    132 	@mkdir -p $(dir $@)
    133 	$< -D $(if $(fs_config_generate_extra_partition_list), \
    134 	   -P '$(subst $(space),$(comma),$(addprefix -,$(fs_config_generate_extra_partition_list)))') \
    135 	   -o $@
    136 
    137 ##################################
    138 # Generate the system/etc/fs_config_files binary file for the target
    139 # Add fs_config_files to PRODUCT_PACKAGES in the device make file to enable
    140 include $(CLEAR_VARS)
    141 
    142 LOCAL_MODULE := fs_config_files
    143 LOCAL_MODULE_CLASS := ETC
    144 LOCAL_REQUIRED_MODULES := $(foreach t,$(fs_config_generate_extra_partition_list),$(LOCAL_MODULE)_$(t))
    145 include $(BUILD_SYSTEM)/base_rules.mk
    146 $(LOCAL_BUILT_MODULE): $(fs_config_generate_bin)
    147 	@mkdir -p $(dir $@)
    148 	$< -F $(if $(fs_config_generate_extra_partition_list), \
    149 	   -P '$(subst $(space),$(comma),$(addprefix -,$(fs_config_generate_extra_partition_list)))') \
    150 	   -o $@
    151 
    152 ifneq ($(filter vendor,$(fs_config_generate_extra_partition_list)),)
    153 ##################################
    154 # Generate the vendor/etc/fs_config_dirs binary file for the target
    155 # Add fs_config_dirs or fs_config_dirs_vendor to PRODUCT_PACKAGES in
    156 # the device make file to enable.
    157 include $(CLEAR_VARS)
    158 
    159 LOCAL_MODULE := fs_config_dirs_vendor
    160 LOCAL_MODULE_CLASS := ETC
    161 LOCAL_INSTALLED_MODULE_STEM := fs_config_dirs
    162 LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc
    163 include $(BUILD_SYSTEM)/base_rules.mk
    164 $(LOCAL_BUILT_MODULE): $(fs_config_generate_bin)
    165 	@mkdir -p $(dir $@)
    166 	$< -D -P vendor -o $@
    167 
    168 ##################################
    169 # Generate the vendor/etc/fs_config_files binary file for the target
    170 # Add fs_config_files or fs_config_files_vendor to PRODUCT_PACKAGES in
    171 # the device make file to enable
    172 include $(CLEAR_VARS)
    173 
    174 LOCAL_MODULE := fs_config_files_vendor
    175 LOCAL_MODULE_CLASS := ETC
    176 LOCAL_INSTALLED_MODULE_STEM := fs_config_files
    177 LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc
    178 include $(BUILD_SYSTEM)/base_rules.mk
    179 $(LOCAL_BUILT_MODULE): $(fs_config_generate_bin)
    180 	@mkdir -p $(dir $@)
    181 	$< -F -P vendor -o $@
    182 
    183 endif
    184 
    185 ifneq ($(filter oem,$(fs_config_generate_extra_partition_list)),)
    186 ##################################
    187 # Generate the oem/etc/fs_config_dirs binary file for the target
    188 # Add fs_config_dirs or fs_config_dirs_oem to PRODUCT_PACKAGES in
    189 # the device make file to enable
    190 include $(CLEAR_VARS)
    191 
    192 LOCAL_MODULE := fs_config_dirs_oem
    193 LOCAL_MODULE_CLASS := ETC
    194 LOCAL_INSTALLED_MODULE_STEM := fs_config_dirs
    195 LOCAL_MODULE_PATH := $(TARGET_OUT_OEM)/etc
    196 include $(BUILD_SYSTEM)/base_rules.mk
    197 $(LOCAL_BUILT_MODULE): $(fs_config_generate_bin)
    198 	@mkdir -p $(dir $@)
    199 	$< -D -P oem -o $@
    200 
    201 ##################################
    202 # Generate the oem/etc/fs_config_files binary file for the target
    203 # Add fs_config_files or fs_config_files_oem to PRODUCT_PACKAGES in
    204 # the device make file to enable
    205 include $(CLEAR_VARS)
    206 
    207 LOCAL_MODULE := fs_config_files_oem
    208 LOCAL_MODULE_CLASS := ETC
    209 LOCAL_INSTALLED_MODULE_STEM := fs_config_files
    210 LOCAL_MODULE_PATH := $(TARGET_OUT_OEM)/etc
    211 include $(BUILD_SYSTEM)/base_rules.mk
    212 $(LOCAL_BUILT_MODULE): $(fs_config_generate_bin)
    213 	@mkdir -p $(dir $@)
    214 	$< -F -P oem -o $@
    215 
    216 endif
    217 
    218 ifneq ($(filter odm,$(fs_config_generate_extra_partition_list)),)
    219 ##################################
    220 # Generate the odm/etc/fs_config_dirs binary file for the target
    221 # Add fs_config_dirs or fs_config_dirs_odm to PRODUCT_PACKAGES in
    222 # the device make file to enable
    223 include $(CLEAR_VARS)
    224 
    225 LOCAL_MODULE := fs_config_dirs_odm
    226 LOCAL_MODULE_CLASS := ETC
    227 LOCAL_INSTALLED_MODULE_STEM := fs_config_dirs
    228 LOCAL_MODULE_PATH := $(TARGET_OUT_ODM)/etc
    229 include $(BUILD_SYSTEM)/base_rules.mk
    230 $(LOCAL_BUILT_MODULE): $(fs_config_generate_bin)
    231 	@mkdir -p $(dir $@)
    232 	$< -D -P odm -o $@
    233 
    234 ##################################
    235 # Generate the odm/etc/fs_config_files binary file for the target
    236 # Add fs_config_files of fs_config_files_odm to PRODUCT_PACKAGES in
    237 # the device make file to enable
    238 include $(CLEAR_VARS)
    239 
    240 LOCAL_MODULE := fs_config_files_odm
    241 LOCAL_MODULE_CLASS := ETC
    242 LOCAL_INSTALLED_MODULE_STEM := fs_config_files
    243 LOCAL_MODULE_PATH := $(TARGET_OUT_ODM)/etc
    244 include $(BUILD_SYSTEM)/base_rules.mk
    245 $(LOCAL_BUILT_MODULE): $(fs_config_generate_bin)
    246 	@mkdir -p $(dir $@)
    247 	$< -F -P odm -o $@
    248 
    249 endif
    250 
    251 # The newer passwd/group targets are only generated if you
    252 # use the new TARGET_FS_CONFIG_GEN method.
    253 ifneq ($(TARGET_FS_CONFIG_GEN),)
    254 
    255 ##################################
    256 # Build the oemaid library when fs config files are present.
    257 # Intentionally break build if you require generated AIDS
    258 # header file, but are not using any fs config files.
    259 include $(CLEAR_VARS)
    260 LOCAL_MODULE := liboemaids
    261 LOCAL_EXPORT_C_INCLUDE_DIRS := $(dir $(my_gen_oem_aid))
    262 LOCAL_EXPORT_C_INCLUDE_DEPS := $(my_gen_oem_aid)
    263 include $(BUILD_STATIC_LIBRARY)
    264 
    265 ##################################
    266 # Generate the system/etc/passwd text file for the target
    267 # This file may be empty if no AIDs are defined in
    268 # TARGET_FS_CONFIG_GEN files.
    269 include $(CLEAR_VARS)
    270 
    271 LOCAL_MODULE := passwd
    272 LOCAL_MODULE_CLASS := ETC
    273 
    274 include $(BUILD_SYSTEM)/base_rules.mk
    275 
    276 $(LOCAL_BUILT_MODULE): PRIVATE_LOCAL_PATH := $(LOCAL_PATH)
    277 $(LOCAL_BUILT_MODULE): PRIVATE_TARGET_FS_CONFIG_GEN := $(TARGET_FS_CONFIG_GEN)
    278 $(LOCAL_BUILT_MODULE): PRIVATE_ANDROID_FS_HDR := $(system_android_filesystem_config)
    279 $(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/fs_config_generator.py $(TARGET_FS_CONFIG_GEN) $(system_android_filesystem_config)
    280 	@mkdir -p $(dir $@)
    281 	$(hide) $< passwd --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
    282 
    283 ##################################
    284 # Generate the system/etc/group text file for the target
    285 # This file may be empty if no AIDs are defined in
    286 # TARGET_FS_CONFIG_GEN files.
    287 include $(CLEAR_VARS)
    288 
    289 LOCAL_MODULE := group
    290 LOCAL_MODULE_CLASS := ETC
    291 
    292 include $(BUILD_SYSTEM)/base_rules.mk
    293 
    294 $(LOCAL_BUILT_MODULE): PRIVATE_LOCAL_PATH := $(LOCAL_PATH)
    295 $(LOCAL_BUILT_MODULE): PRIVATE_TARGET_FS_CONFIG_GEN := $(TARGET_FS_CONFIG_GEN)
    296 $(LOCAL_BUILT_MODULE): PRIVATE_ANDROID_FS_HDR := $(system_android_filesystem_config)
    297 $(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/fs_config_generator.py $(TARGET_FS_CONFIG_GEN) $(system_android_filesystem_config)
    298 	@mkdir -p $(dir $@)
    299 	$(hide) $< group --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
    300 
    301 system_android_filesystem_config :=
    302 endif
    303 
    304 ANDROID_FS_CONFIG_H :=
    305 my_fs_config_h :=
    306 fs_config_generate_bin :=
    307 my_gen_oem_aid :=
    308 fs_config_generate_extra_partition_list :=
    309 
    310 # -----------------------------------------------------------------------------
    311 # Unit tests.
    312 # -----------------------------------------------------------------------------
    313 
    314 test_c_flags := \
    315     -fstack-protector-all \
    316     -g \
    317     -Wall \
    318     -Wextra \
    319     -Werror \
    320     -fno-builtin \
    321     -DANDROID_FILESYSTEM_CONFIG='"android_filesystem_config_test_data.h"'
    322 
    323 ##################################
    324 # test executable
    325 include $(CLEAR_VARS)
    326 LOCAL_MODULE := fs_config_generate_test
    327 LOCAL_SRC_FILES := fs_config_generate.c
    328 LOCAL_SHARED_LIBRARIES := libcutils
    329 LOCAL_CFLAGS := $(test_c_flags)
    330 LOCAL_MODULE_RELATIVE_PATH := fs_config-unit-tests
    331 LOCAL_GTEST := false
    332 include $(BUILD_HOST_NATIVE_TEST)
    333 
    334 ##################################
    335 # gTest tool
    336 include $(CLEAR_VARS)
    337 LOCAL_MODULE := fs_config-unit-tests
    338 LOCAL_CFLAGS += $(test_c_flags) -DHOST
    339 LOCAL_SHARED_LIBRARIES := liblog libcutils libbase
    340 LOCAL_SRC_FILES := fs_config_test.cpp
    341 include $(BUILD_HOST_NATIVE_TEST)
    342