1 # Copyright (C) 2009 The Android Open Source Project
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 # ====================================================================
18 # Define the main configuration variables, and read the host-specific
19 # configuration file that is normally generated by build/host-setup.sh
21 # ====================================================================
23 # Include common definitions
24 include build/core/definitions.mk
26 # The location of the build system files
27 BUILD_SYSTEM := build/core
29 # Where all generated files will be stored during a build
32 # Read the host-specific configuration file in $(NDK_OUT)
34 HOST_CONFIG_MAKE := $(NDK_OUT)/host/config.mk
36 ifeq ($(strip $(wildcard $(HOST_CONFIG_MAKE))),)
38 The configuration file '$(HOST_CONFIG_MAKE)' doesnt' exist.)
40 Please run 'build/host-setup.sh' to generate it.)
41 $(call __ndk_error, Aborting)
44 include $(HOST_CONFIG_MAKE)
45 HOST_PREBUILT_TAG := $(HOST_TAG)
47 # Location where all prebuilt binaries for a given host architectures
49 HOST_PREBUILT := build/prebuilt/$(HOST_TAG)
51 # Where all app-specific generated files will be stored
52 NDK_APP_OUT := $(NDK_OUT)/apps
54 # Where all host-specific generated files will be stored
55 NDK_HOST_OUT := $(NDK_OUT)/host/$(HOST_TAG)
57 # ====================================================================
59 # Read all toolchain-specific configuration files.
61 # Each toolchain must have a corresponding config.mk file located
62 # in build/toolchains/<name>/ that will be included here.
64 # Each one of these files should define the following variables:
65 # TOOLCHAIN_NAME toolchain name (e.g. arm-eabi-4.2.1)
66 # TOOLCHAIN_ABIS list of target ABIs supported by the toolchain.
68 # Then, it should include $(ADD_TOOLCHAIN) which will perform
69 # book-keeping for the build system.
71 # ====================================================================
73 # the build script to include in each toolchain config.mk
74 ADD_TOOLCHAIN := $(BUILD_SYSTEM)/add-toolchain.mk
76 # the list of all toolchains in this NDK
80 TOOLCHAIN_CONFIGS := $(wildcard build/toolchains/*/config.mk)
81 $(foreach _config_mk,$(TOOLCHAIN_CONFIGS),\
82 $(eval include $(BUILD_SYSTEM)/add-toolchain.mk)\
85 #$(info ALL_TOOLCHAINS=$(ALL_TOOLCHAINS))
86 NDK_TARGET_TOOLCHAIN := $(firstword $(NDK_ALL_TOOLCHAINS))
87 $(call ndk_log, Default toolchain is $(NDK_TARGET_TOOLCHAIN))
89 NDK_ALL_TOOLCHAINS := $(call uniq,$(NDK_ALL_TOOLCHAINS))
90 NDK_ALL_ABIS := $(call uniq,$(NDK_ALL_ABIS))
92 $(call ndk_log, This NDK supports the following toolchains and target ABIs:)
93 $(foreach tc,$(NDK_ALL_TOOLCHAINS),\
94 $(call ndk_log, $(space)$(space)$(tc): $(NDK_TOOLCHAIN.$(tc).abis))\
97 # ====================================================================
99 # Read all application configuration files
101 # Each 'application' must have a corresponding Application.mk file
102 # located in apps/<name> where <name> is a liberal name that doesn't
103 # contain any space in it, used to uniquely identify the
105 # Each one of these files should define the following required
108 # APP_MODULES the list of modules needed by this application
111 # path to the Java project root directory where the
112 # generated binaries will be copied to. The NDK will
113 # place them in appropriate locations so they are
114 # properly picked by aapt, the Android Packager tool,
115 # when generating your applications.
117 # As well as the following *optional* variables:
119 # APP_OPTIM either 'release' or 'debug'
121 # APP_CPPFLAGS extra flags passed when building C and C++ sources
122 # of application modules
124 # APP_CFLAGS extra flags passed when building C sources of
125 # application's modules (not C++ ones)
127 # APP_CXXFLAGS extra flags passed when building C++ sources of
128 # application's modules (not C ones)
130 # ====================================================================
134 NDK_APPLICATIONS := $(wildcard apps/*/Application.mk)
135 $(foreach _application_mk, $(NDK_APPLICATIONS),\
136 $(eval include $(BUILD_SYSTEM)/add-application.mk)\
139 # clean up environment, just to be safe
140 $(call clear-vars, $(NDK_APP_VARS))
142 ifeq ($(strip $(NDK_ALL_APPS)),)
144 The NDK could not find a proper application description under apps/*/Application.mk)
146 Please follow the instructions in docs/NDK-APPS.TXT to write one.)
147 $(call __ndk_error, Aborting)
150 ifeq ($(strip $(APP)),)
152 The APP variable is undefined or empty.)
154 Please define it to one of: $(NDK_ALL_APPS))
156 You can also add new applications by writing an Application.mk file.)
158 See docs/APPLICATION-MK.TXT for details.)
159 $(call __ndk_error, Aborting)
162 # now check that APP doesn't contain an unknown app name
163 # if it does, we ignore them if there is at least one known
164 # app name in the list. Otherwise, abort with an error message
166 _unknown_apps := $(filter-out $(NDK_ALL_APPS),$(APP))
167 _known_apps := $(filter $(NDK_ALL_APPS),$(APP))
171 $(if $(_unknown_apps),\
172 $(if $(_known_apps),\
173 $(call __ndk_info,WARNING:\
174 Removing unknown names from APP variable: $(_unknown_apps))\
175 $(eval NDK_APPS := $(_known_apps))\
178 The APP variable contains unknown app names: $(_unknown_apps))\
180 Please use one of: $(NDK_ALL_APPS))\
181 $(call __ndk_error, Aborting)\
185 $(call __ndk_info,Building for application '$(NDK_APPS)')
187 # ====================================================================
189 # Prepare the build for parsing Android.mk files
191 # ====================================================================
193 # These phony targets are used to control various stages of the build
195 host_libraries host_executables \
197 executables libraries static_libraries shared_libraries \
198 clean clean-config clean-objs-dir \
199 clean-executables clean-libraries \
200 clean-installed-modules
202 # These macros are used in Android.mk to include the corresponding
203 # build script that will parse the LOCAL_XXX variable definitions.
205 CLEAR_VARS := $(BUILD_SYSTEM)/clear-vars.mk
206 BUILD_HOST_EXECUTABLE := $(BUILD_SYSTEM)/build-host-executable.mk
207 BUILD_HOST_STATIC_LIBRARY := $(BUILD_SYSTEM)/build-host-static-library.mk
208 BUILD_STATIC_LIBRARY := $(BUILD_SYSTEM)/build-static-library.mk
209 BUILD_SHARED_LIBRARY := $(BUILD_SYSTEM)/build-shared-library.mk
210 BUILD_EXECUTABLE := $(BUILD_SYSTEM)/build-executable.mk
212 ANDROID_MK_INCLUDED := \
214 $(BUILD_HOST_EXECUTABLE) \
215 $(BUILD_HOST_STATIC_LIBRARY) \
216 $(BUILD_STATIC_LIBRARY) \
217 $(BUILD_SHARED_LIBRARY) \
218 $(BUILD_EXECUTABLE) \
221 # this is the list of directories containing dependency information
222 # generated during the build. It will be updated by build scripts
223 # when module definitions are parsed.
225 ALL_DEPENDENCY_DIRS :=
227 # this is the list of all generated files that we would need to clean
228 ALL_HOST_EXECUTABLES :=
229 ALL_HOST_STATIC_LIBRARIES :=
230 ALL_STATIC_LIBRARIES :=
231 ALL_SHARED_LIBRARIES :=
233 ALL_INSTALLED_MODULES :=
236 all: installed_modules host_libraries host_executables
238 # ====================================================================
240 # For each platform/abi combo supported by the application, we should
241 # setup the toolchain and parse all module definitions files again
242 # to build the right dependency tree.
244 # All this work is performed by build/core/setup-toolchain.mk
246 # ====================================================================
249 # XXX: For now, only support one platform and one target ABI with
250 # only one toolchain.
252 TARGET_PLATFORM := android-3
253 TARGET_ARCH_ABI := arm
255 TARGET_TOOLCHAIN := $(NDK_TARGET_TOOLCHAIN)
257 include build/core/setup-toolchain.mk
259 # ====================================================================
261 # Now finish the build preparation with a few rules that depend on
262 # what has been effectively parsed and recorded previously
264 # ====================================================================
266 clean: clean-intermediates clean-installed-modules
268 distclean: clean clean-config
270 installed_modules: libraries $(ALL_INSTALLED_MODULES)
271 host_libraries: $(HOST_STATIC_LIBRARIES)
272 host_executables: $(HOST_EXECUTABLES)
274 static_libraries: $(STATIC_LIBRARIES)
275 shared_libraries: $(SHARED_LIBRARIES)
276 executables: $(EXECUTABLES)
278 libraries: static_libraries shared_libraries
280 clean-host-intermediates:
281 $(hide) rm -rf $(HOST_EXECUTABLES) $(HOST_STATIC_LIBRARIES)
283 clean-intermediates: clean-host-intermediates
284 $(hide) rm -rf $(EXECUTABLES) $(STATIC_LIBRARIES) $(SHARED_LIBRARIES)
286 clean-installed-modules:
287 $(hide) rm -rf $(ALL_INSTALLED_MODULES)
290 $(hide) rm -f $(CONFIG_MAKE) $(CONFIG_H)
292 # include dependency information
293 ALL_DEPENDENCY_DIRS := $(sort $(ALL_DEPENDENCY_DIRS))
294 -include $(wildcard $(ALL_DEPENDENCY_DIRS:%=%/*.d))