Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 1 | # Copyright (C) 2017 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 | current_makefile := $(lastword $(MAKEFILE_LIST)) |
| 16 | |
| 17 | # BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot. |
| 18 | ifeq ($(BOARD_VNDK_VERSION),current) |
| 19 | |
| 20 | # Returns arch-specific libclang_rt.ubsan* library name. |
| 21 | # Because VNDK_CORE_LIBRARIES includes all arch variants for libclang_rt.ubsan* |
| 22 | # libs, the arch-specific libs are selected separately. |
| 23 | # |
| 24 | # Args: |
| 25 | # $(1): if not empty, evaluates for TARGET_2ND_ARCH |
| 26 | define clang-ubsan-vndk-core |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 27 | $(strip \ |
| 28 | $(eval prefix := $(if $(1),2ND_,)) \ |
| 29 | $(addsuffix .vendor,$($(addprefix $(prefix),UBSAN_RUNTIME_LIBRARY))) \ |
| 30 | ) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 31 | endef |
| 32 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 33 | # Returns list of file paths of the intermediate objs |
| 34 | # |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 35 | # Args: |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 36 | # $(1): list of obj names (e.g., libfoo.vendor, ld.config.txt, ...) |
| 37 | # $(2): target class (e.g., SHARED_LIBRARIES, STATIC_LIBRARIES, ETC) |
| 38 | # $(3): if not empty, evaluates for TARGET_2ND_ARCH |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 39 | define paths-of-intermediates |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 40 | $(strip \ |
| 41 | $(foreach obj,$(1), \ |
| 42 | $(eval file_name := $(if $(filter SHARED_LIBRARIES,$(2)),$(patsubst %.so,%,$(obj)).so,$(obj))) \ |
| 43 | $(eval dir := $(call intermediates-dir-for,$(2),$(obj),,,$(3))) \ |
| 44 | $(call append-path,$(dir),$(file_name)) \ |
| 45 | ) \ |
| 46 | ) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 47 | endef |
| 48 | |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 49 | # If in the future libclang_rt.ubsan* is removed from the VNDK-core list, |
| 50 | # need to update the related logic in this file. |
| 51 | ifeq (,$(filter libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES))) |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 52 | $(warning libclang_rt.ubsan* is no longer a VNDK-core library. Please update this file.) |
| 53 | vndk_core_libs := $(addsuffix .vendor,$(VNDK_CORE_LIBRARIES)) |
| 54 | else |
| 55 | vndk_core_libs := $(addsuffix .vendor,$(filter-out libclang_rt.ubsan%,$(VNDK_CORE_LIBRARIES))) |
| 56 | |
| 57 | # for TARGET_ARCH |
| 58 | vndk_core_libs += $(call clang-ubsan-vndk-core) |
| 59 | |
| 60 | # TODO(b/69834489): Package additional arch variants |
| 61 | # ifdef TARGET_2ND_ARCH |
| 62 | # vndk_core_libs += $(call clang-ubsan-vndk-core,true) |
| 63 | # endif |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 64 | endif |
| 65 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 66 | vndk_sp_libs := $(addsuffix .vendor,$(VNDK_SAMEPROCESS_LIBRARIES)) |
| 67 | vndk_private_libs := $(addsuffix .vendor,$(VNDK_PRIVATE_LIBRARIES)) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 68 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 69 | vndk_snapshot_libs := \ |
| 70 | $(vndk_core_libs) \ |
| 71 | $(vndk_sp_libs) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 72 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 73 | vndk_prebuilt_txts := \ |
| 74 | ld.config.txt \ |
| 75 | vndksp.libraries.txt \ |
| 76 | llndk.libraries.txt |
| 77 | |
| 78 | vndk_snapshot_top := $(call intermediates-dir-for,PACKAGING,vndk-snapshot) |
| 79 | vndk_snapshot_out := $(vndk_snapshot_top)/vndk-snapshot |
| 80 | vndk_snapshot_configs_out := $(vndk_snapshot_top)/configs |
| 81 | |
| 82 | ####################################### |
| 83 | # vndkcore.libraries.txt |
| 84 | vndkcore.libraries.txt := $(vndk_snapshot_configs_out)/vndkcore.libraries.txt |
| 85 | $(vndkcore.libraries.txt): $(vndk_core_libs) |
| 86 | @echo 'Generating: $@' |
| 87 | @rm -f $@ |
| 88 | @mkdir -p $(dir $@) |
| 89 | $(hide) echo -n > $@ |
| 90 | $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so >> $@;) |
| 91 | |
| 92 | |
| 93 | ####################################### |
| 94 | # vndkprivate.libraries.txt |
| 95 | vndkprivate.libraries.txt := $(vndk_snapshot_configs_out)/vndkprivate.libraries.txt |
| 96 | $(vndkprivate.libraries.txt): $(vndk_private_libs) |
| 97 | @echo 'Generating: $@' |
| 98 | @rm -f $@ |
| 99 | @mkdir -p $(dir $@) |
| 100 | $(hide) echo -n > $@ |
| 101 | $(hide) $(foreach lib,$^,echo $(patsubst %.vendor,%,$(lib)).so >> $@;) |
| 102 | |
| 103 | |
| 104 | vndk_snapshot_configs := \ |
| 105 | $(vndkcore.libraries.txt) \ |
| 106 | $(vndkprivate.libraries.txt) |
| 107 | |
| 108 | ####################################### |
| 109 | # vndk_snapshot_zip |
| 110 | vndk_snapshot_arch := $(vndk_snapshot_out)/arch-$(TARGET_ARCH)-$(TARGET_ARCH_VARIANT) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 111 | vndk_snapshot_zip := $(PRODUCT_OUT)/android-vndk-$(TARGET_ARCH).zip |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 112 | |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 113 | $(vndk_snapshot_zip): PRIVATE_VNDK_SNAPSHOT_OUT := $(vndk_snapshot_out) |
| 114 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 115 | $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT := $(vndk_snapshot_arch)/shared/vndk-core |
| 116 | $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES := \ |
| 117 | $(call paths-of-intermediates,$(vndk_core_libs),SHARED_LIBRARIES) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 118 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 119 | $(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT := $(vndk_snapshot_arch)/shared/vndk-sp |
| 120 | $(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES := \ |
| 121 | $(call paths-of-intermediates,$(vndk_sp_libs),SHARED_LIBRARIES) |
| 122 | |
| 123 | $(vndk_snapshot_zip): PRIVATE_CONFIGS_OUT := $(vndk_snapshot_arch)/configs |
| 124 | $(vndk_snapshot_zip): PRIVATE_CONFIGS_INTERMEDIATES := \ |
| 125 | $(call paths-of-intermediates,$(vndk_prebuilt_txts),ETC) \ |
| 126 | $(vndk_snapshot_configs) |
| 127 | |
| 128 | # TODO(b/69834489): Package additional arch variants |
| 129 | # ifdef TARGET_2ND_ARCH |
| 130 | # vndk_snapshot_arch_2ND := $(vndk_snapshot_out)/arch-$(TARGET_2ND_ARCH)-$(TARGET_2ND_ARCH_VARIANT) |
| 131 | # $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_OUT_2ND := $(vndk_snapshot_arch_2ND)/shared/vndk-core |
| 132 | # $(vndk_snapshot_zip): PRIVATE_VNDK_CORE_INTERMEDIATES_2ND := \ |
| 133 | # $(call paths-of-intermediates,$(vndk_core_libs),SHARED_LIBRARIES,true) |
| 134 | # $(vndk_snapshot_zip): PRIVATE_VNDK_SP_OUT_2ND := $(vndk_snapshot_arch_2ND)/shared/vndk-sp |
| 135 | # $(vndk_snapshot_zip): PRIVATE_VNDK_SP_INTERMEDIATES_2ND := \ |
| 136 | # $(call paths-of-intermediates,$(vndk_sp_libs),SHARED_LIBRARIES,true) |
| 137 | # endif |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 138 | |
| 139 | # Args |
| 140 | # $(1): destination directory |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 141 | # $(2): list of files to copy |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 142 | $(vndk_snapshot_zip): private-copy-vndk-intermediates = \ |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 143 | $(if $(2),$(strip \ |
| 144 | @mkdir -p $(1); \ |
| 145 | $(foreach file,$(2), \ |
| 146 | if [ -e $(file) ]; then \ |
| 147 | cp -p $(file) $(call append-path,$(1),$(subst .vendor,,$(notdir $(file)))); \ |
| 148 | fi; \ |
| 149 | ) \ |
| 150 | )) |
| 151 | |
| 152 | vndk_snapshot_dependencies := \ |
| 153 | $(vndk_snapshot_libs) \ |
| 154 | $(vndk_prebuilt_txts) \ |
| 155 | $(vndk_snapshot_configs) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 156 | |
| 157 | $(vndk_snapshot_zip): $(vndk_snapshot_dependencies) $(SOONG_ZIP) |
| 158 | @echo 'Generating VNDK snapshot: $@' |
| 159 | @rm -f $@ |
| 160 | @rm -rf $(PRIVATE_VNDK_SNAPSHOT_OUT) |
| 161 | @mkdir -p $(PRIVATE_VNDK_SNAPSHOT_OUT) |
| 162 | $(call private-copy-vndk-intermediates, \ |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 163 | $(PRIVATE_VNDK_CORE_OUT),$(PRIVATE_VNDK_CORE_INTERMEDIATES)) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 164 | $(call private-copy-vndk-intermediates, \ |
Jae Shin | c13c0ea | 2017-12-04 13:16:21 +0900 | [diff] [blame^] | 165 | $(PRIVATE_VNDK_SP_OUT),$(PRIVATE_VNDK_SP_INTERMEDIATES)) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 166 | $(call private-copy-vndk-intermediates, \ |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 167 | $(PRIVATE_CONFIGS_OUT),$(PRIVATE_CONFIGS_INTERMEDIATES)) |
| 168 | # TODO(b/69834489): Package additional arch variants |
| 169 | # ifdef TARGET_2ND_ARCH |
| 170 | # $(call private-copy-vndk-intermediates, \ |
| 171 | # $(PRIVATE_VNDK_CORE_OUT_2ND),$(PRIVATE_VNDK_CORE_INTERMEDIATES_2ND)) |
| 172 | # $(call private-copy-vndk-intermediates, \ |
| 173 | # $(PRIVATE_VNDK_SP_OUT_2ND),$(PRIVATE_VNDK_SP_INTERMEDIATES_2ND)) |
| 174 | # endif |
Jae Shin | c13c0ea | 2017-12-04 13:16:21 +0900 | [diff] [blame^] | 175 | $(hide) $(SOONG_ZIP) -o $@ -C $(PRIVATE_VNDK_SNAPSHOT_OUT) -D $(PRIVATE_VNDK_SNAPSHOT_OUT) |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 176 | |
| 177 | .PHONY: vndk |
| 178 | vndk: $(vndk_snapshot_zip) |
| 179 | |
| 180 | $(call dist-for-goals, vndk, $(vndk_snapshot_zip)) |
| 181 | |
Jae Shin | 4736dc1 | 2017-11-22 19:25:36 +0900 | [diff] [blame] | 182 | # clear global vars |
| 183 | clang-ubsan-vndk-core := |
| 184 | paths-of-intermediates := |
| 185 | vndk_core_libs := |
| 186 | vndk_sp_libs := |
| 187 | vndk_snapshot_libs := |
| 188 | vndk_prebuilt_txts := |
| 189 | vndk_snapshot_configs := |
| 190 | vndk_snapshot_top := |
| 191 | vndk_snapshot_out := |
| 192 | vndk_snapshot_configs_out := |
| 193 | vndk_snapshot_arch := |
| 194 | vndk_snapshot_dependencies := |
| 195 | # TODO(b/69834489): Package additional arch variants |
| 196 | # ifdef TARGET_2ND_ARCH |
| 197 | # vndk_snapshot_arch_2ND := |
| 198 | # endif |
| 199 | |
Jae Shin | e6b7c84 | 2017-10-20 17:46:46 +0900 | [diff] [blame] | 200 | else # BOARD_VNDK_VERSION is NOT set to 'current' |
| 201 | |
| 202 | .PHONY: vndk |
| 203 | vndk: |
| 204 | $(call echo-error,$(current_makefile),CANNOT generate VNDK snapshot. BOARD_VNDK_VERSION must be set to 'current'.) |
| 205 | exit 1 |
| 206 | |
| 207 | endif # BOARD_VNDK_VERSION |