OSDN Git Service

c4ac8fe1b4838677d0c7d92c059edaf397df939b
[android-x86/development.git] / ndk / build / core / main.mk
1 # Copyright (C) 2009 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
16 # ====================================================================
17 #
18 # Define the main configuration variables, and read the host-specific
19 # configuration file that is normally generated by build/host-setup.sh
20 #
21 # ====================================================================
22
23 # Include common definitions
24 include build/core/definitions.mk
25
26 # The location of the build system files
27 BUILD_SYSTEM := build/core
28
29 # Where all generated files will be stored during a build
30 NDK_OUT := out
31
32 # Read the host-specific configuration file in $(NDK_OUT)
33 #
34 HOST_CONFIG_MAKE := $(NDK_OUT)/host/config.mk
35
36 ifeq ($(strip $(wildcard $(HOST_CONFIG_MAKE))),)
37     $(call __ndk_info,\
38     The configuration file '$(HOST_CONFIG_MAKE)' doesnt' exist.)
39     $(call __ndk_info,\
40        Please run 'build/host-setup.sh' to generate it.)
41     $(call __ndk_error, Aborting)
42 endif
43
44 include $(HOST_CONFIG_MAKE)
45 HOST_PREBUILT_TAG := $(HOST_TAG)
46
47 # Location where all prebuilt binaries for a given host architectures
48 # will be stored.
49 HOST_PREBUILT := build/prebuilt/$(HOST_TAG)
50
51 # Where all app-specific generated files will be stored
52 NDK_APP_OUT := $(NDK_OUT)/apps
53
54 # Where all host-specific generated files will be stored
55 NDK_HOST_OUT := $(NDK_OUT)/host/$(HOST_TAG)
56
57 # ====================================================================
58 #
59 # Read all toolchain-specific configuration files.
60 #
61 # Each toolchain must have a corresponding config.mk file located
62 # in build/toolchains/<name>/ that will be included here.
63 #
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.
67 #
68 # Then, it should include $(ADD_TOOLCHAIN) which will perform
69 # book-keeping for the build system.
70 #
71 # ====================================================================
72
73 # the build script to include in each toolchain config.mk
74 ADD_TOOLCHAIN := $(BUILD_SYSTEM)/add-toolchain.mk
75
76 # the list of all toolchains in this NDK
77 NDK_ALL_TOOLCHAINS :=
78 NDK_ALL_ABIS       :=
79
80 TOOLCHAIN_CONFIGS := $(wildcard build/toolchains/*/config.mk)
81 $(foreach _config_mk,$(TOOLCHAIN_CONFIGS),\
82   $(eval include $(BUILD_SYSTEM)/add-toolchain.mk)\
83 )
84
85 #$(info ALL_TOOLCHAINS=$(ALL_TOOLCHAINS))
86 NDK_TARGET_TOOLCHAIN := $(firstword $(NDK_ALL_TOOLCHAINS))
87 $(call ndk_log, Default toolchain is $(NDK_TARGET_TOOLCHAIN))
88
89 NDK_ALL_TOOLCHAINS   := $(call uniq,$(NDK_ALL_TOOLCHAINS))
90 NDK_ALL_ABIS         := $(call uniq,$(NDK_ALL_ABIS))
91
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))\
95 )
96
97 # ====================================================================
98 #
99 # Read all application configuration files
100 #
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
104 #
105 # Each one of these files should define the following required
106 # variables:
107 #
108 #   APP_MODULES   the list of modules needed by this application
109 #
110 #   APP_PROJECT_PATH
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.
116 #
117 # As well as the following *optional* variables:
118 #
119 #   APP_OPTIM     either 'release' or 'debug'
120 #
121 #   APP_CPPFLAGS  extra flags passed when building C and C++ sources
122 #                 of application modules
123 #
124 #   APP_CFLAGS    extra flags passed when building C sources of
125 #                 application's modules (not C++ ones)
126 #
127 #   APP_CXXFLAGS  extra flags passed when building C++ sources of
128 #                 application's modules (not C ones)
129 #
130 # ====================================================================
131
132 NDK_ALL_APPS :=
133
134 NDK_APPLICATIONS := $(wildcard apps/*/Application.mk)
135 $(foreach _application_mk, $(NDK_APPLICATIONS),\
136   $(eval include $(BUILD_SYSTEM)/add-application.mk)\
137 )
138
139 # clean up environment, just to be safe
140 $(call clear-vars, $(NDK_APP_VARS))
141
142 ifeq ($(strip $(NDK_ALL_APPS)),)
143   $(call __ndk_info,\
144     The NDK could not find a proper application description under apps/*/Application.mk)
145   $(call __ndk_info,\
146     Please follow the instructions in docs/NDK-APPS.TXT to write one.)
147   $(call __ndk_error, Aborting)
148 endif
149
150 ifeq ($(strip $(APP)),)
151   $(call __ndk_info,\
152     The APP variable is undefined or empty.)
153   $(call __ndk_info,\
154     Please define it to one of: $(NDK_ALL_APPS))
155   $(call __ndk_info,\
156     You can also add new applications by writing an Application.mk file.)
157   $(call __ndk_info,\
158     See docs/APPLICATION-MK.TXT for details.)
159   $(call __ndk_error, Aborting)
160 endif
161
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
165 #
166 _unknown_apps := $(filter-out $(NDK_ALL_APPS),$(APP))
167 _known_apps   := $(filter     $(NDK_ALL_APPS),$(APP))
168
169 NDK_APPS := $(APP)
170
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))\
176    ,\
177     $(call __ndk_info,\
178         The APP variable contains unknown app names: $(_unknown_apps))\
179     $(call __ndk_info,\
180         Please use one of: $(NDK_ALL_APPS))\
181     $(call __ndk_error, Aborting)\
182   )\
183 )
184
185 $(call __ndk_info,Building for application '$(NDK_APPS)')
186
187 # ====================================================================
188 #
189 # Prepare the build for parsing Android.mk files
190 #
191 # ====================================================================
192
193 # These phony targets are used to control various stages of the build
194 .PHONY: all \
195         host_libraries host_executables \
196         installed_modules \
197         executables libraries static_libraries shared_libraries \
198         clean clean-config clean-objs-dir \
199         clean-executables clean-libraries \
200         clean-installed-modules
201
202 # These macros are used in Android.mk to include the corresponding
203 # build script that will parse the LOCAL_XXX variable definitions.
204 #
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
211
212 ANDROID_MK_INCLUDED := \
213   $(CLEAR_VARS) \
214   $(BUILD_HOST_EXECUTABLE) \
215   $(BUILD_HOST_STATIC_LIBRARY) \
216   $(BUILD_STATIC_LIBRARY) \
217   $(BUILD_SHARED_LIBRARY) \
218   $(BUILD_EXECUTABLE) \
219
220
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.
224 #
225 ALL_DEPENDENCY_DIRS :=
226
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      :=
232 ALL_EXECUTABLES           :=
233 ALL_INSTALLED_MODULES     :=
234
235 # the first rule
236 all: installed_modules host_libraries host_executables
237
238 # ====================================================================
239 #
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.
243 #
244 # All this work is performed by build/core/setup-toolchain.mk
245 #
246 # ====================================================================
247
248
249 # XXX: For now, only support one platform and one target ABI with
250 #      only one toolchain.
251 #
252 TARGET_PLATFORM  := android-3
253 TARGET_ARCH_ABI  := arm
254 TARGET_ARCH      := arm
255 TARGET_TOOLCHAIN := $(NDK_TARGET_TOOLCHAIN)
256
257 include build/core/setup-toolchain.mk
258
259 # ====================================================================
260 #
261 # Now finish the build preparation with a few rules that depend on
262 # what has been effectively parsed and recorded previously
263 #
264 # ====================================================================
265
266 clean: clean-intermediates clean-installed-modules
267
268 distclean: clean clean-config
269
270 installed_modules: libraries $(ALL_INSTALLED_MODULES)
271 host_libraries: $(HOST_STATIC_LIBRARIES)
272 host_executables: $(HOST_EXECUTABLES)
273
274 static_libraries: $(STATIC_LIBRARIES)
275 shared_libraries: $(SHARED_LIBRARIES)
276 executables: $(EXECUTABLES)
277
278 libraries: static_libraries shared_libraries
279
280 clean-host-intermediates:
281         $(hide) rm -rf $(HOST_EXECUTABLES) $(HOST_STATIC_LIBRARIES)
282
283 clean-intermediates: clean-host-intermediates
284         $(hide) rm -rf $(EXECUTABLES) $(STATIC_LIBRARIES) $(SHARED_LIBRARIES)
285
286 clean-installed-modules:
287         $(hide) rm -rf $(ALL_INSTALLED_MODULES)
288
289 clean-config:
290         $(hide) rm -f $(CONFIG_MAKE) $(CONFIG_H)
291
292 # include dependency information
293 ALL_DEPENDENCY_DIRS := $(sort $(ALL_DEPENDENCY_DIRS))
294 -include $(wildcard $(ALL_DEPENDENCY_DIRS:%=%/*.d))