Mike Ritter | 429fbd8 | 2009-05-19 11:28:10 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2008 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 | # Assemble the Native Development Kit |
| 18 | # Assembled using the generic build by default. |
| 19 | # (set in device/config/product_config.make) |
| 20 | |
| 21 | # A macro to make rules to copy all newer files in a directory tree matching an |
| 22 | # optional find filter and add the files to a list variable for dependencies. |
| 23 | # Designed after copy_headers.make: Create a rule to copy each file; |
| 24 | # copy-one-file defines the actual rule. |
| 25 | # $(1): source directory tree root |
| 26 | # $(2): destination directory tree root |
| 27 | # $(3): list variable to append destination files to |
| 28 | # $(4): optional find(1) arguments |
| 29 | define define-tree-copy-rules |
| 30 | $(eval _src_files := $(shell find $(1) -type f $(4))) \ |
| 31 | $(foreach _src, $(_src_files), \ |
| 32 | $(eval _dest := $(patsubst $(1)%,$(2)%,$(_src))) \ |
| 33 | $(eval $(3) := $($(3)) $(_dest)) \ |
| 34 | $(eval $(call copy-one-file,$(_src),$(_dest))) \ |
| 35 | ) |
| 36 | endef |
| 37 | |
| 38 | #------------------------------------------------------------------------------- |
| 39 | # Install all the files needed to build the pndk. |
| 40 | # We build three versions of the pndk |
| 41 | # (1) The full version, with source. |
| 42 | # (2) The full version, without source. |
| 43 | # (3) A JNI-only version, with source. |
| 44 | # |
| 45 | # We make five sets of trees: |
| 46 | # (A) Common files used in all versions of the pndk |
| 47 | # (B) Common files used in the full versions of the pndk |
| 48 | # (C) Files used in the standard pndk (no source files included) |
| 49 | # (D) Files used in both the JNI-only and full-with-source version |
| 50 | # (E) Files used in just the full-with-source version |
| 51 | # |
| 52 | # Each pndk version is created by combining the appropriate trees: |
| 53 | # |
| 54 | # (A) (B) (C) (D) (E) |
| 55 | # (1) yes yes yes yes |
| 56 | # (2) yes yes yes |
| 57 | # (3) yes yes |
| 58 | # |
| 59 | # Source is provided for partners who want to recompile our libraries for optimization. |
| 60 | # The JNI-only version is provided for partners that want to create shared |
| 61 | # libraries that can be packaged with APK files and called from Java code. |
| 62 | |
| 63 | LOCAL_PATH := $(call my-dir) |
| 64 | |
| 65 | # Source trees for the pndk |
| 66 | samples_src_dir := $(LOCAL_PATH)/samples |
| 67 | sample_src_dir := $(samples_src_dir)/sample |
| 68 | samplejni_src_dir := $(samples_src_dir)/samplejni |
| 69 | config_src_dir := $(LOCAL_PATH)/config |
| 70 | kernel_common_src_dir := $(KERNEL_HEADERS_COMMON) |
| 71 | kernel_arch_src_dir := $(KERNEL_HEADERS_ARCH) |
| 72 | bionic_src_dir := bionic |
| 73 | jni_src_dir := $(JNI_H_INCLUDE) |
| 74 | |
| 75 | # Workspace directory |
| 76 | pndk_intermediates := $(call intermediates-dir-for,PACKAGING,pndk) |
| 77 | |
| 78 | # Common destination trees for the pndk |
| 79 | pndk_common_tree := $(pndk_intermediates)/common |
| 80 | pndk_common_dest_dir := $(pndk_common_tree)/pndk |
| 81 | samplejni_dest_dir := $(pndk_common_dest_dir)/samples/samplejni |
| 82 | config_dest_dir := $(pndk_common_dest_dir)/config |
| 83 | kernel_dest_dir := $(pndk_common_dest_dir)/include/kernel/include |
| 84 | gcc_dest_dir := $(pndk_common_dest_dir)/toolchain |
| 85 | jni_dest_dir := $(pndk_common_dest_dir)/include/nativehelper |
| 86 | |
| 87 | # Common-full destination trees for the pndk |
| 88 | pndk_common_full_tree := $(pndk_intermediates)/common_full |
| 89 | pndk_common_full_dest_dir := $(pndk_common_full_tree)/pndk |
| 90 | sample_dest_dir := $(pndk_common_full_dest_dir)/samples/sample |
| 91 | |
| 92 | # Destination trees without source for the standard pndk (without source) |
| 93 | pndk_no_src_tree := $(pndk_intermediates)/no_src |
| 94 | pndk_no_src_dest_dir := $(pndk_no_src_tree)/pndk |
| 95 | bionic_no_src_dest_dir := $(pndk_no_src_dest_dir)/include/bionic |
| 96 | |
| 97 | # Destination trees including source for the pndk with source |
| 98 | pndk_src_tree := $(pndk_intermediates)/with_src |
| 99 | pndk_src_dest_dir := $(pndk_src_tree)/pndk |
| 100 | bionic_src_dest_dir := $(pndk_src_dest_dir)/include/bionic |
| 101 | |
| 102 | # Destinations of all common files (not picked up by tree rules below) |
| 103 | pndk_common_dest_files := $(pndk_common_dest_dir)/Android_PNDK_README.html \ |
| 104 | $(pndk_common_dest_dir)/config/armelf.x \ |
| 105 | $(pndk_common_dest_dir)/config/armelflib.x \ |
| 106 | $(pndk_common_dest_dir)/lib/crtbegin_dynamic.o \ |
| 107 | $(pndk_common_dest_dir)/lib/crtend_android.o \ |
| 108 | $(pndk_common_dest_dir)/lib/libc.so \ |
| 109 | $(pndk_common_dest_dir)/lib/libm.so |
| 110 | |
| 111 | # Destinations of files used by the full, non-jni-only configurations |
| 112 | pndk_common_full_dest_files := \ |
| 113 | $(pndk_common_full_dest_dir)/lib/libdl.so \ |
| 114 | $(pndk_common_full_dest_dir)/lib/libstdc++.so |
| 115 | |
| 116 | # Install common files outside common trees |
| 117 | $(pndk_common_dest_dir)/Android_PNDK_README.html: $(LOCAL_PATH)/Android_PNDK_README.html | $(ACP) |
| 118 | @echo "pndk Android_PNDK_README.html: from $? to $@" |
| 119 | $(copy-file-to-target) |
| 120 | |
| 121 | $(pndk_common_dest_dir)/config/armelf.x: $(BUILD_SYSTEM)/armelf.x | $(ACP) |
| 122 | @echo "pndk config: $@" |
| 123 | $(copy-file-to-target) |
| 124 | |
| 125 | $(pndk_common_dest_dir)/config/armelflib.x: $(BUILD_SYSTEM)/armelflib.x | $(ACP) |
| 126 | @echo "pndk config: $@" |
| 127 | $(copy-file-to-target) |
| 128 | |
| 129 | $(pndk_common_dest_dir)/lib/%: $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/% | $(ACP) |
| 130 | @echo "pndk lib: $@" |
| 131 | $(copy-file-to-target) |
| 132 | |
| 133 | # Install common_full files outside common trees |
| 134 | $(pndk_common_full_dest_dir)/lib/%: $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/% | $(ACP) |
| 135 | @echo "pndk lib full: $@" |
| 136 | $(copy-file-to-target) |
| 137 | |
| 138 | # Install files in common trees |
| 139 | listvar := pndk_common_dest_files |
| 140 | $(call define-tree-copy-rules,$(samplejni_src_dir),$(samplejni_dest_dir),$(listvar)) |
| 141 | $(call define-tree-copy-rules,$(config_src_dir),$(config_dest_dir),$(listvar)) |
| 142 | $(call define-tree-copy-rules,$(kernel_common_src_dir),$(kernel_dest_dir),$(listvar)) |
| 143 | $(call define-tree-copy-rules,$(kernel_arch_src_dir),$(kernel_dest_dir),$(listvar)) |
| 144 | $(call define-tree-copy-rules,$(jni_src_dir),$(jni_dest_dir),$(listvar), -name jni.h) |
| 145 | |
| 146 | # Install files common to the full builds but not the JNI build |
| 147 | listvar := pndk_common_full_dest_files |
| 148 | $(call define-tree-copy-rules,$(sample_src_dir),$(sample_dest_dir),$(listvar)) |
| 149 | |
| 150 | # Install files without sources |
| 151 | listvar := pndk_no_src_dest_files |
| 152 | $(call define-tree-copy-rules,$(bionic_src_dir),$(bionic_no_src_dest_dir),$(listvar),-name '*.h') |
| 153 | |
| 154 | # Install files including sources |
| 155 | listvar := pndk_with_src_dest_files |
| 156 | $(call define-tree-copy-rules,$(bionic_src_dir),$(bionic_src_dest_dir),$(listvar)) |
| 157 | |
| 158 | |
| 159 | #------------------------------------------------------------------------------- |
| 160 | # Create the multiple versions of the pndk: |
| 161 | # pndk_no_src all files without source |
| 162 | # pndk_with_source all files with source |
| 163 | # pndk_jni_with_source just files for building JNI shared libraries with source. |
| 164 | |
| 165 | # Name the tar files |
| 166 | name := android_pndk-$(TARGET_PRODUCT) |
| 167 | ifeq ($(TARGET_BUILD_TYPE),debug) |
| 168 | name := $(name)_debug |
| 169 | endif |
| 170 | name := $(name)-$(BUILD_NUMBER) |
| 171 | pndk_tarfile := $(pndk_intermediates)/$(name).tar |
| 172 | pndk_tarfile_zipped := $(pndk_tarfile).gz |
| 173 | pndk_with_src_tarfile := $(pndk_intermediates)/$(name)-src.tar |
| 174 | pndk_with_src_tarfile_zipped := $(pndk_with_src_tarfile).gz |
| 175 | pndk_jni_with_src_tarfile := $(pndk_intermediates)/$(name)-jni-src.tar |
| 176 | pndk_jni_with_src_tarfile_zipped := $(pndk_jni_with_src_tarfile).gz |
| 177 | |
| 178 | .PHONY: pndk pndk_with_src pndk_no_src pndk_jni_with_src pndk_debug |
| 179 | |
| 180 | pndk: pndk_no_src pndk_with_src pndk_jni_with_src |
| 181 | pndk_no_src: $(pndk_tarfile_zipped) |
| 182 | pndk_with_src: $(pndk_with_src_tarfile_zipped) |
| 183 | pndk_jni_with_src: $(pndk_jni_with_src_tarfile_zipped) |
| 184 | |
| 185 | # Put the pndk zip files in the distribution directory |
| 186 | $(call dist-for-goals,pndk,$(pndk_tarfile_zipped)) |
| 187 | $(call dist-for-goals,pndk,$(pndk_with_src_tarfile_zipped)) |
| 188 | $(call dist-for-goals,pndk,$(pndk_jni_with_src_tarfile_zipped)) |
| 189 | |
| 190 | # zip up tar files |
| 191 | %.tar.gz: %.tar |
| 192 | @echo "pndk: zipped $<" |
| 193 | $(hide) gzip -cf $< > $@ |
| 194 | |
| 195 | # tar up the files without our sources to make the pndk. |
| 196 | $(pndk_tarfile): $(pndk_common_dest_files) $(pndk_common_full_dest_files) $(pndk_no_src_dest_files) |
| 197 | @echo "pndk: $@" |
| 198 | @mkdir -p $(dir $@) |
| 199 | @rm -f $@ |
| 200 | $(hide) tar rf $@ -C $(pndk_common_tree) pndk |
| 201 | $(hide) tar rf $@ -C $(pndk_common_full_tree) pndk |
| 202 | $(hide) tar rf $@ -C $(pndk_no_src_tree) pndk |
| 203 | |
| 204 | # tar up the full sources to make the pndk with sources. |
| 205 | $(pndk_with_src_tarfile): $(pndk_common_dest_files) $(pndk_common_full_dest_files) $(pndk_with_src_dest_files) $(pndk_full_with_src_dest_files) |
| 206 | @echo "pndk: $@" |
| 207 | @mkdir -p $(dir $@) |
| 208 | @rm -f $@ |
| 209 | $(hide) tar rf $@ -C $(pndk_common_tree) pndk |
| 210 | $(hide) tar rf $@ -C $(pndk_common_full_tree) pndk |
| 211 | $(hide) tar rf $@ -C $(pndk_src_tree) pndk |
| 212 | |
| 213 | # tar up the sources to make the pndk with JNI support. |
| 214 | $(pndk_jni_with_src_tarfile): $(pndk_common_dest_files) $(pndk_with_src_dest_files) |
| 215 | @echo "pndk: $@" |
| 216 | @mkdir -p $(dir $@) |
| 217 | @rm -f $@ |
| 218 | $(hide) tar rf $@ -C $(pndk_common_tree) pndk |
| 219 | $(hide) tar rf $@ -C $(pndk_src_tree) pndk |
| 220 | |
| 221 | # Debugging reporting can go here, add it as a target to get output. |
| 222 | pndk_debug: pndk |
| 223 | @echo "You are here: $@" |
| 224 | @echo "pndk tar file: $(pndk_tarfile_zipped)" |
| 225 | @echo "pndk_with_src tar file: $(pndk_with_src_tarfile_zipped)" |
| 226 | @echo "pndk_jni_with_src tar file: $(pndk_jni_with_src_tarfile_zipped)" |
| 227 | @echo "pndk_files: $(pndk_no_src_dest_files)" |
| 228 | @echo "pndk_with_src files: $(pndk_with_src_dest_files)" |
| 229 | @echo "pndk_full_with_src files: $(pndk_full_with_src_dest_files)" |
| 230 | @echo "pndk_common_files: $(pndk_common_dest_files)" |
| 231 | @echo "pndk_common_full_dest_files: $(pndk_common_full_dest_files)" |
| 232 | |