1# Copyright (C) 2009-2010 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# This script is used to build all wanted NDK binaries. It is included
18# by several scripts.
19#
20
21# ensure that the following variables are properly defined
22$(call assert-defined,NDK_APPS NDK_APP_OUT)
23
24# ====================================================================
25#
26# Prepare the build for parsing Android.mk files
27#
28# ====================================================================
29
30# These phony targets are used to control various stages of the build
31.PHONY: all \
32        host_libraries host_executables \
33        installed_modules \
34        executables libraries static_libraries shared_libraries \
35        clean clean-objs-dir \
36        clean-executables clean-libraries \
37        clean-installed-modules \
38        clean-installed-binaries
39
40# These macros are used in Android.mk to include the corresponding
41# build script that will parse the LOCAL_XXX variable definitions.
42#
43CLEAR_VARS                := $(BUILD_SYSTEM)/clear-vars.mk
44BUILD_HOST_EXECUTABLE     := $(BUILD_SYSTEM)/build-host-executable.mk
45BUILD_HOST_STATIC_LIBRARY := $(BUILD_SYSTEM)/build-host-static-library.mk
46BUILD_STATIC_LIBRARY      := $(BUILD_SYSTEM)/build-static-library.mk
47BUILD_SHARED_LIBRARY      := $(BUILD_SYSTEM)/build-shared-library.mk
48BUILD_EXECUTABLE          := $(BUILD_SYSTEM)/build-executable.mk
49PREBUILT_SHARED_LIBRARY   := $(BUILD_SYSTEM)/prebuilt-shared-library.mk
50PREBUILT_STATIC_LIBRARY   := $(BUILD_SYSTEM)/prebuilt-static-library.mk
51
52ANDROID_MK_INCLUDED := \
53  $(CLEAR_VARS) \
54  $(BUILD_HOST_EXECUTABLE) \
55  $(BUILD_HOST_STATIC_LIBRARY) \
56  $(BUILD_STATIC_LIBRARY) \
57  $(BUILD_SHARED_LIBRARY) \
58  $(BUILD_EXECUTABLE) \
59  $(PREBUILT_SHARED_LIBRARY) \
60
61
62# this is the list of directories containing dependency information
63# generated during the build. It will be updated by build scripts
64# when module definitions are parsed.
65#
66ALL_DEPENDENCY_DIRS :=
67
68# this is the list of all generated files that we would need to clean
69ALL_HOST_EXECUTABLES      :=
70ALL_HOST_STATIC_LIBRARIES :=
71ALL_STATIC_LIBRARIES      :=
72ALL_SHARED_LIBRARIES      :=
73ALL_EXECUTABLES           :=
74
75WANTED_INSTALLED_MODULES  :=
76
77# the first rule
78all: installed_modules host_libraries host_executables
79
80
81$(foreach _app,$(NDK_APPS),\
82  $(eval include $(BUILD_SYSTEM)/setup-app.mk)\
83)
84
85ifeq (,$(strip $(WANTED_INSTALLED_MODULES)))
86    ifneq (,$(strip $(NDK_APP_MODULES)))
87        $(call __ndk_warning,WARNING: No modules to build, your APP_MODULES definition is probably incorrect!)
88    else
89        $(call __ndk_warning,WARNING: There are no modules to build in this project!)
90    endif
91endif
92
93# On Cygwin, we generate a temporary shell script that is capable of
94# process GCC-generated dependency files to convert all path references
95# in them from the Windows to the corresponding Cygwin convention.
96# (e.g. C:/Foo/foo -> /cygdrive/c/Foo/foo)
97#
98# This shell script is generated by passing the output of the cygwin
99# 'mount' command to a special Awk script.
100#
101ifeq ($(HOST_OS),cygwin)
102  GEN_CYGWIN_DEPS_CONVERTER := mount | tr '\\' '/' | awk -f $(BUILD_AWK)/gen-cygwin-deps-converter.awk
103  ifeq ($(NDK_LOG),1)
104    $(call __ndk_info,Cygwin dependency file conversion script:)
105    $(info ----- start of script ----)
106    $(info $(shell $(GEN_CYGWIN_DEPS_CONVERTER)))
107    $(info ------ end of script -----)
108  endif
109$(NDK_DEPENDENCIES_CONVERTER):
110	$(call host-echo-build-step,$(NDK_APP_ABI),Cygwin) Generating dependency file converter script
111	$(hide) mkdir -p $(dir $@)
112	$(hide) $(GEN_CYGWIN_DEPS_CONVERTER) > $@ && chmod +x $@
113
114clean-dependency-converter:
115	$(hide) $(call host-rm,$(NDK_DEPENDENCIES_CONVERTER))
116
117endif
118
119# ====================================================================
120#
121# Now finish the build preparation with a few rules that depend on
122# what has been effectively parsed and recorded previously
123#
124# ====================================================================
125
126clean: clean-intermediates clean-installed-binaries
127
128distclean: clean
129
130installed_modules: clean-installed-binaries libraries $(WANTED_INSTALLED_MODULES)
131host_libraries: $(HOST_STATIC_LIBRARIES)
132host_executables: $(HOST_EXECUTABLES)
133
134static_libraries: $(STATIC_LIBRARIES)
135shared_libraries: $(SHARED_LIBRARIES)
136executables: $(EXECUTABLES)
137
138libraries: static_libraries shared_libraries
139
140clean-host-intermediates:
141	$(hide) $(call host-rm,$(HOST_EXECUTABLES) $(HOST_STATIC_LIBRARIES))
142
143clean-intermediates: clean-host-intermediates
144	$(hide) $(call host-rm,$(EXECUTABLES) $(STATIC_LIBRARIES) $(SHARED_LIBRARIES))
145
146ifeq ($(HOST_OS),cygwin)
147clean: clean-dependency-converter
148endif
149
150# include dependency information
151ALL_DEPENDENCY_DIRS := $(patsubst %/,%,$(sort $(ALL_DEPENDENCY_DIRS)))
152-include $(wildcard $(ALL_DEPENDENCY_DIRS:%=%/*.d))
153