Dima Zavin | 884147c | 2012-03-16 16:18:15 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2012 The Android Open-Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | |
| 17 | # |
| 18 | # This file does the bulk of the work to auto post-process kernel headers |
| 19 | # provided by the device, board, and/or product. |
| 20 | # |
| 21 | # The build system exposes several variables for where to find the kernel |
| 22 | # headers: |
| 23 | # TARGET_DEVICE_KERNEL_HEADERS is automatically created for the current |
| 24 | # device being built. It is set as $(TARGET_DEVICE_DIR)/kernel-headers, |
| 25 | # e.g. device/samsung/tuna/kernel-headers. This directory is not |
| 26 | # explicitly set by anyone, the build system always adds this subdir. |
| 27 | # |
| 28 | # TARGET_BOARD_KERNEL_HEADERS is specified by the BoardConfig.mk file |
| 29 | # to allow other directories to be included. This is useful if there's |
| 30 | # some common place where a few headers are being kept for a group |
| 31 | # of devices. For example, device/<vendor>/common/kernel-headers could |
| 32 | # contain some headers for several of <vendor>'s devices. |
| 33 | # |
| 34 | # TARGET_PRODUCT_KERNEL_HEADERS is generated by the product inheritance |
| 35 | # graph. This allows architecture products to provide headers for the |
| 36 | # devices using that architecture. For example, |
| 37 | # hardware/ti/omap4xxx/omap4.mk will specify |
| 38 | # PRODUCT_VENDOR_KERNEL_HEADERS variable that specify where the omap4 |
| 39 | # specific headers are, e.g. hardware/ti/omap4xxx/kernel-headers. |
| 40 | # The build system then combines all the values specified by all the |
| 41 | # PRODUCT_VENDOR_KERNEL_HEADERS directives in the product inheritance |
| 42 | # tree and then exports a TARGET_PRODUCT_KERNEL_HEADERS variable. |
| 43 | # |
| 44 | # The directories specified in these three variables are scanned for header |
| 45 | # files (files with .h suffix), processed with the clean_header.py script, |
| 46 | # and dumped under TARGET_OUT_KERNEL_HEADERS |
| 47 | # (typically $OUT/obj/kernel-headers). This subdirectory is then |
| 48 | # automatically added to the include path. |
| 49 | # |
| 50 | # The files to be generated are added as a dependency to the |
| 51 | # all_copied_headers rule to make sure that they are generated before |
| 52 | # any C/C++ file that may need them. |
| 53 | # |
| 54 | # |
| 55 | |
| 56 | LOCAL_PATH:= $(call my-dir) |
| 57 | |
| 58 | include $(CLEAR_VARS) |
| 59 | |
| 60 | _all_kernel_header_dirs := \ |
| 61 | $(TARGET_DEVICE_KERNEL_HEADERS) \ |
| 62 | $(TARGET_BOARD_KERNEL_HEADERS) \ |
| 63 | $(TARGET_PRODUCT_KERNEL_HEADERS) |
| 64 | |
| 65 | define add-kernel-header-dir |
| 66 | $(eval _headers := $(patsubst $(1)/%.h,%.h,$(shell find $(1)/ -type f -name '*.h'))) |
| 67 | $(eval GEN := $(addprefix $(TARGET_OUT_KERNEL_HEADERS)/,$(_headers))) |
| 68 | $(GEN) : PRIVATE_PATH := $(LOCAL_PATH) |
| 69 | $(GEN) : PRIVATE_MODULE := kernel-headers |
| 70 | $(GEN) : PRIVATE_CUSTOM_TOOL = \ |
| 71 | $$(LOCAL_PATH)/tools/clean_header.py \ |
| 72 | -k $(1) -d $$(TARGET_OUT_KERNEL_HEADERS) $$< > $$@ |
| 73 | $(GEN) : $$(LOCAL_PATH)/tools/clean_header.py |
| 74 | $(GEN) : $$(TARGET_OUT_KERNEL_HEADERS)/%.h : $(1)/%.h |
| 75 | $$(transform-generated-source) |
| 76 | all_copied_headers: $(GEN) |
| 77 | $(eval GEN :=) |
| 78 | $(eval _headers :=) |
| 79 | endef |
| 80 | |
| 81 | $(foreach d,$(_all_kernel_header_dirs),\ |
| 82 | $(eval $(call add-kernel-header-dir,$(d)))) |