• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2008 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# we expect the 'my' variable to be defined, either to
17# 'HOST_' or 'TARGET_', and this allows us to call the
18# appropriate compiler with $($(my)CC)
19#
20$(call assert-defined,my)
21
22# LOCAL_MAKEFILE must also exist and name the Android.mk that
23# included the module build script.
24#
25$(call assert-defined,LOCAL_MAKEFILE)
26
27include $(BUILD_SYSTEM)/build-module.mk
28
29# list of generated object files
30LOCAL_OBJECTS :=
31
32# always define ANDROID when building binaries
33#
34LOCAL_CFLAGS := -DANDROID $(LOCAL_CFLAGS)
35
36#
37# Add the default system shared libraries to the build
38#
39ifndef LOCAL_IS_HOST_MODULE
40  ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
41    LOCAL_SHARED_LIBRARIES += $(TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES)
42  else
43    LOCAL_SHARED_LIBRARIES += $(LOCAL_SYSTEM_SHARED_LIBRARIES)
44  endif
45endif
46
47
48#
49# Check LOCAL_CPP_EXTENSION, use '.cpp' by default
50#
51LOCAL_CPP_EXTENSION := $(strip $(LOCAL_CPP_EXTENSION))
52ifeq ($(LOCAL_CPP_EXTENSION),)
53  LOCAL_CPP_EXTENSION := .cpp
54else
55  ifneq ($(words $(LOCAL_CPP_EXTENSION)),1)
56    $(call __ndk_info, LOCAL_CPP_EXTENSION in $(LOCAL_MAKEFILE) must be one word only, not '$(LOCAL_CPP_EXTENSION)')
57    $(call __ndk_error, Aborting)
58  endif
59endif
60
61#
62# If LOCAL_ALLOW_UNDEFINED_SYMBOLS, the linker will allow the generation
63# of a binary that uses undefined symbols.
64#
65ifeq ($(strip $(LOCAL_ALLOW_UNDEFINED_SYMBOLS)),)
66  LOCAL_LDFLAGS := $(LOCAL_LDFLAGS) $($(my)NO_UNDEFINED_LDFLAGS)
67endif
68
69#
70# The original Android build system allows you to use the .arm prefix
71# to a source file name to indicate that it should be defined in either
72# 'thumb' or 'arm' mode, depending on the value of LOCAL_ARM_MODE
73#
74# First, check LOCAL_ARM_MODE, it should be empty, 'thumb' or 'arm'
75# We make the default 'thumb'
76#
77LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE))
78ifeq ($(LOCAL_ARM_MODE),)
79  LOCAL_ARM_MODE := thumb
80else
81  ifneq ($(words $(LOCAL_ARM_MODE)),1)
82      $(call __ndk_info,   LOCAL_ARM_MODE in $(LOCAL_MAKEFILE) must be one word, not '$(LOCAL_ARM_MODE)')
83      $(call __ndk_error, Aborting)
84  endif
85  # check that LOCAL_ARM_MODE is defined to either 'arm' or 'thumb'
86  $(if $(filter-out thumb arm, $(LOCAL_ARM_MODE)),\
87      $(call __ndk_info,   LOCAL_ARM_MODE must be defined to either 'arm' or 'thumb' in $(LOCAL_MAKEFILE) not '$(LOCAL_ARM_MODE)')\
88      $(call __ndk_error, Aborting)\
89  )
90endif
91
92LOCAL_ARM_TEXT_arm   = arm$(space)$(space)
93LOCAL_ARM_TEXT_thumb = thumb
94
95LOCAL_ARM_CFLAGS := $(TARGET_$(LOCAL_ARM_MODE)_$(LOCAL_BUILD_MODE)_CFLAGS)
96LOCAL_ARM_TEXT   := $(LOCAL_ARM_TEXT_$(LOCAL_ARM_MODE))
97
98# As a special case, the original Android build system
99# allows one to specify that certain source files can be
100# forced to build in ARM mode by using a '.arm' suffix
101# after the extension, e.g.
102#
103#  LOCAL_SRC_FILES := foo.c.arm
104#
105# to build source file $(LOCAL_PATH)/foo.c as ARM
106#
107
108#
109# Build C source files into .o
110#
111
112ifeq ($(LOCAL_ARM_MODE),arm)
113    arm_sources   := $(LOCAL_SRC_FILES)
114else
115    arm_sources   := $(filter %.arm,$(LOCAL_SRC_FILES))
116    thumb_sources := $(filter-out %.arm,$(LOCAL_SRC_FILES))
117endif
118
119# First, build the 'thumb' sources
120#
121LOCAL_ARM_MODE := thumb
122
123$(foreach src,$(filter %.c,$(thumb_sources)), $(call compile-c-source,$(src)))
124$(foreach src,$(filter %.S,$(thumb_sources)), $(call compile-s-source,$(src)))
125
126$(foreach src,$(filter %$(LOCAL_CPP_EXTENSION),$(thumb_sources)),\
127    $(call compile-cpp-source,$(src)))
128
129# Then, the 'ARM' ones
130#
131LOCAL_ARM_MODE := arm
132arm_sources := $(arm_sources:%.arm=%)
133
134$(foreach src,$(filter %.c,$(arm_sources)), $(call compile-c-source,$(src)))
135$(foreach src,$(filter %.S,$(arm_sources)), $(call compile-s-source,$(src)))
136
137$(foreach src,$(filter %$(LOCAL_CPP_EXTENSION),$(arm_sources)),\
138    $(call compile-cpp-source,$(src)))
139
140#
141# The compile-xxx-source calls updated LOCAL_OBJECTS and LOCAL_DEPENDENCY_DIRS
142#
143ALL_DEPENDENCY_DIRS += $(sort $(LOCAL_DEPENDENCY_DIRS))
144CLEAN_OBJS_DIRS     += $(LOCAL_OBJS_DIR)
145
146#
147# Handle the static and shared libraries this module depends on
148#
149LOCAL_STATIC_LIBRARIES := $(call strip-lib-prefix,$(LOCAL_STATIC_LIBRARIES))
150LOCAL_SHARED_LIBRARIES := $(call strip-lib-prefix,$(LOCAL_SHARED_LIBRARIES))
151
152static_libraries := $(call map,static-library-path,$(LOCAL_STATIC_LIBRARIES))
153shared_libraries := $(call map,shared-library-path,$(LOCAL_SHARED_LIBRARIES)) \
154                    $(TARGET_PREBUILT_SHARED_LIBRARIES)
155
156$(LOCAL_BUILT_MODULE): $(static_libraries) $(shared_libraries)
157
158# If LOCAL_LDLIBS contains anything like -l<library> then
159# prepend a -L$(SYSROOT)/usr/lib to it to ensure that the linker
160# looks in the right location
161#
162ifneq ($(filter -l%,$(LOCAL_LDLIBS)),)
163    LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib $(LOCAL_LDLIBS)
164endif
165
166$(LOCAL_BUILT_MODULE): PRIVATE_STATIC_LIBRARIES := $(static_libraries)
167$(LOCAL_BUILT_MODULE): PRIVATE_SHARED_LIBRARIES := $(shared_libraries)
168$(LOCAL_BUILT_MODULE): PRIVATE_OBJECTS          := $(LOCAL_OBJECTS)
169
170$(LOCAL_BUILT_MODULE): PRIVATE_LDFLAGS := $(TARGET_LDFLAGS) $(LOCAL_LDFLAGS)
171$(LOCAL_BUILT_MODULE): PRIVATE_LDLIBS  := $(LOCAL_LDLIBS) $(TARGET_LDLIBS)
172
173$(LOCAL_BUILT_MODULE): PRIVATE_NAME := $(notdir $(LOCAL_BUILT_MODULE))
174