Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / native_client_sdk / src / tools / nacl_gcc.mk
blobd2c3f1346647e832fc6c2f9acf5b22058166b6e4
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
6 # GNU Make based build file. For details on GNU Make see:
7 # http://www.gnu.org/software/make/manual/make.html
11 # Macros for TOOLS
13 ifneq ($(TOOLCHAIN),bionic)
14 X86_32_CC := $(NACL_COMPILER_PREFIX) $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_32 --tool=cc)
15 X86_32_CXX := $(NACL_COMPILER_PREFIX) $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_32 --tool=c++)
16 X86_32_LINK := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_32 --tool=c++)
17 X86_32_LIB := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_32 --tool=ar)
18 X86_32_STRIP := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_32 --tool=strip)
19 X86_32_NM := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_32 --tool=nm)
21 X86_64_CC := $(NACL_COMPILER_PREFIX) $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_64 --tool=cc)
22 X86_64_CXX := $(NACL_COMPILER_PREFIX) $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_64 --tool=c++)
23 X86_64_LINK := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_64 --tool=c++)
24 X86_64_LIB := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_64 --tool=ar)
25 X86_64_STRIP := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_64 --tool=strip)
26 X86_64_NM := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_64 --tool=nm)
27 endif
29 ARM_CC := $(NACL_COMPILER_PREFIX) $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=cc)
30 ARM_CXX := $(NACL_COMPILER_PREFIX) $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=c++)
31 ARM_LINK := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=c++)
32 ARM_LIB := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=ar)
33 ARM_STRIP := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=strip)
34 ARM_NM := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=nm)
36 NCVAL ?= python $(NACL_SDK_ROOT)/tools/ncval.py
38 # Architecture-specific variables
39 ifeq (,$(MULTI_PLATFORM))
40 X86_32_OUTDIR ?= $(OUTDIR)
41 X86_64_OUTDIR ?= $(OUTDIR)
42 ARM_OUTDIR ?= $(OUTDIR)
43 else
44 X86_32_OUTDIR ?= $(OUTDIR)/_platform_specific/x86-32
45 X86_64_OUTDIR ?= $(OUTDIR)/_platform_specific/x86-64
46 ARM_OUTDIR ?= $(OUTDIR)/_platform_specific/arm
47 endif
49 # Architecture-specific flags
50 X86_32_CFLAGS ?=
51 X86_64_CFLAGS ?=
52 X86_32_CXXFLAGS ?=
53 X86_64_CXXFLAGS ?=
55 # Use DWARF v3 which is more commonly available when debugging
56 ifeq ($(CONFIG),Debug)
57 ARM_CFLAGS ?= -gdwarf-3
58 ARM_CXXFLAGS ?= -gdwarf-3
59 else
60 ARM_CFLAGS ?=
61 ARM_CXXFLAGS ?=
62 endif
64 ifeq (,$(MULTI_PLATFORM))
65 X86_32_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_x86_32.map
66 X86_64_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_x86_64.map
67 ARM_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_arm.map
68 else
69 X86_32_LDFLAGS ?= -Wl,-Map,$(X86_32_OUTDIR)/$(TARGET)_x86_32.map
70 X86_64_LDFLAGS ?= -Wl,-Map,$(X86_64_OUTDIR)/$(TARGET)_x86_64.map
71 ARM_LDFLAGS ?= -Wl,-Map,$(ARM_OUTDIR)/$(TARGET)_arm.map
72 endif
75 # Choose between static and dynamic linking for Bionic
76 # (Default to dynamic)
78 ifeq ($(TOOLCHAIN),bionic)
79 ifeq (,$(BIONIC_USE_DYNAMIC))
80 BIONIC_LINK:=-static
81 else
82 BIONIC_LINK:=-Wl,-Ttext-segment=0x100000
83 endif
84 endif
86 LDFLAGS_SHARED = -shared
89 # Compile Macro
91 # $1 = Source name
92 # $2 = Compiler flags
94 define C_COMPILER_RULE
95 -include $(call SRC_TO_DEP,$(1),_x86_32)
96 $(call SRC_TO_OBJ,$(1),_x86_32): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
97 $(call LOG,CC ,$$@,$(X86_32_CC) -o $$@ -c $$< $(POSIX_CFLAGS) $(NACL_CFLAGS) $(X86_32_CFLAGS) $(CFLAGS) $(2))
98 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_32)
100 -include $(call SRC_TO_DEP,$(1),_x86_64)
101 $(call SRC_TO_OBJ,$(1),_x86_64): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
102 $(call LOG,CC ,$$@,$(X86_64_CC) -o $$@ -c $$< $(POSIX_CFLAGS) $(NACL_CFLAGS) $(X86_64_CFLAGS) $(CFLAGS) $(2))
103 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_64)
105 -include $(call SRC_TO_DEP,$(1),_arm)
106 $(call SRC_TO_OBJ,$(1),_arm): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
107 $(call LOG,CC ,$$@,$(ARM_CC) -o $$@ -c $$< $(POSIX_CFLAGS) $(NACL_CFLAGS) $(ARM_CFLAGS) $(CFLAGS) $(2))
108 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_arm)
110 -include $(call SRC_TO_DEP,$(1),_x86_32_pic)
111 $(call SRC_TO_OBJ,$(1),_x86_32_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
112 $(call LOG,CC ,$$@,$(X86_32_CC) -o $$@ -c $$< -fPIC $(POSIX_CFLAGS) $(NACL_CFLAGS) $(X86_32_CFLAGS) $(CFLAGS) $(2))
113 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_32_pic)
115 -include $(call SRC_TO_DEP,$(1),_x86_64_pic)
116 $(call SRC_TO_OBJ,$(1),_x86_64_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
117 $(call LOG,CC ,$$@,$(X86_64_CC) -o $$@ -c $$< -fPIC $(POSIX_CFLAGS) $(NACL_CFLAGS) $(X86_64_CFLAGS) $(CFLAGS) $(2))
118 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_64_pic)
120 -include $(call SRC_TO_DEP,$(1),_arm_pic)
121 $(call SRC_TO_OBJ,$(1),_arm_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
122 $(call LOG,CC ,$$@,$(ARM_CC) -o $$@ -c $$< -fPIC $(POSIX_CFLAGS) $(NACL_CFLAGS) $(ARM_CFLAGS) $(CFLAGS) $(2))
123 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_arm_pic)
124 endef
126 define CXX_COMPILER_RULE
127 -include $(call SRC_TO_DEP,$(1),_x86_32)
128 $(call SRC_TO_OBJ,$(1),_x86_32): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
129 $(call LOG,CXX ,$$@,$(X86_32_CXX) -o $$@ -c $$< $(POSIX_CFLAGS) $(NACL_CXXFLAGS) $(X86_32_CXXFLAGS) $(CXXFLAGS) $(2))
130 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_32)
132 -include $(call SRC_TO_DEP,$(1),_x86_64)
133 $(call SRC_TO_OBJ,$(1),_x86_64): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
134 $(call LOG,CXX ,$$@,$(X86_64_CXX) -o $$@ -c $$< $(POSIX_CFLAGS) $(NACL_CXXFLAGS) $(X86_64_CXXFLAGS) $(CXXFLAGS) $(2))
135 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_64)
137 -include $(call SRC_TO_DEP,$(1),_arm)
138 $(call SRC_TO_OBJ,$(1),_arm): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
139 $(call LOG,CXX ,$$@,$(ARM_CXX) -o $$@ -c $$< $(POSIX_CFLAGS) $(NACL_CXXFLAGS) $(ARM_CXXFLAGS) $(CXXFLAGS) $(2))
140 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_arm)
142 -include $(call SRC_TO_DEP,$(1),_x86_32_pic)
143 $(call SRC_TO_OBJ,$(1),_x86_32_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
144 $(call LOG,CXX ,$$@,$(X86_32_CXX) -o $$@ -c $$< -fPIC $(POSIX_CFLAGS) $(NACL_CXXFLAGS) $(X86_32_CXXFLAGS) $(CXXFLAGS) $(2))
145 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_32_pic)
147 -include $(call SRC_TO_DEP,$(1),_x86_64_pic)
148 $(call SRC_TO_OBJ,$(1),_x86_64_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
149 $(call LOG,CXX ,$$@,$(X86_64_CXX) -o $$@ -c $$< -fPIC $(POSIX_CFLAGS) $(NACL_CXXFLAGS) $(X86_64_CXXFLAGS) $(CXXFLAGS) $(2))
150 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_64_pic)
152 -include $(call SRC_TO_DEP,$(1),_arm_pic)
153 $(call SRC_TO_OBJ,$(1),_arm_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
154 $(call LOG,CXX ,$$@,$(ARM_CXX) -o $$@ -c $$< -fPIC $(POSIX_CFLAGS) $(NACL_CXXFLAGS) $(ARM_CXXFLAGS) $(CXXFLAGS) $(2))
155 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_arm_pic)
156 endef
160 # $1 = Source name
161 # $2 = POSIX compiler flags
162 # $3 = Include directories
163 # $4 = VC flags (unused)
165 define COMPILE_RULE
166 ifeq ($(suffix $(1)),.c)
167 $(call C_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc)) $(3))
168 else
169 $(call CXX_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc)) $(3))
170 endif
171 endef
174 # Determine which architectures to build for. The user can set NACL_ARCH or
175 # ARCHES in the environment to control this.
177 ifneq ($(TOOLCHAIN),bionic)
178 VALID_ARCHES := x86_32 x86_64
179 endif
180 VALID_ARCHES += arm
182 ifdef NACL_ARCH
183 ifeq (,$(findstring $(NACL_ARCH),$(VALID_ARCHES)))
184 $(error Invalid arch specified in NACL_ARCH: $(NACL_ARCH). Valid values are: $(VALID_ARCHES))
185 endif
186 ARCHES = ${NACL_ARCH}
187 else
188 ARCHES ?= ${VALID_ARCHES}
189 endif
191 GLIBC_REMAP :=
194 # SO Macro
196 # As well as building and installing a shared library this rule adds dependencies
197 # on the library's .stamp file in STAMPDIR. However, the rule for creating the stamp
198 # file is part of LIB_RULE, so users of the DEPS system are currently required to
199 # use the LIB_RULE macro as well as the SO_RULE for each shared library.
201 # $1 = Target name
202 # $2 = List of source files
203 # $3 = List of LIBS
204 # $4 = List of DEPS
205 # $5 = Library paths
206 # $6 = 1 => Don't add to NMF.
208 define SO_LINKER_RULE
209 ifneq (,$(findstring x86_32,$(ARCHES)))
210 all: $(X86_32_OUTDIR)/lib$(1)_x86_32.so
211 $(X86_32_OUTDIR)/lib$(1)_x86_32.so: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_32_pic)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
212 $(MKDIR) -p $$(dir $$@)
213 $(call LOG,LINK,$$@,$(X86_32_LINK) -o $$@ $$(filter %.o,$$^) $(LDFLAGS_SHARED) -m32 $(NACL_LDFLAGS) $(X86_32_LDFLAGS) $(LDFLAGS) $(foreach path,$(5),-L$(path)/$(TOOLCHAIN)_x86_32/$(CONFIG_DIR) -L$(path)/$(TOOLCHAIN)_x86_32/$(CONFIG)) $(foreach lib,$(3),-l$(lib)))
214 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
216 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG_DIR)/lib$(1).so
217 install: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG_DIR)/lib$(1).so
218 $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG_DIR)/lib$(1).so: $(X86_32_OUTDIR)/lib$(1)_x86_32.so
219 $(MKDIR) -p $$(dir $$@)
220 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
221 ifneq ($(6),1)
222 GLIBC_SO_LIST += $(X86_32_OUTDIR)/lib$(1)_x86_32.so
223 GLIBC_REMAP += -n lib$(1)_x86_32.so,lib$(1).so
224 endif
225 endif
227 ifneq (,$(findstring x86_64,$(ARCHES)))
228 all: $(X86_64_OUTDIR)/lib$(1)_x86_64.so
229 $(X86_64_OUTDIR)/lib$(1)_x86_64.so: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_64_pic)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
230 $(MKDIR) -p $$(dir $$@)
231 $(call LOG,LINK,$$@,$(X86_32_LINK) -o $$@ $$(filter %.o,$$^) $(LDFLAGS_SHARED) -m64 $(NACL_LDFLAGS) $(X86_64_LDFLAGS) $(LDFLAGS) $(foreach path,$(5),-L$(path)/$(TOOLCHAIN)_x86_64/$(CONFIG_DIR) -L$(path)/$(TOOLCHAIN)_x86_64/$(CONFIG)) $(foreach lib,$(3),-l$(lib)))
232 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
234 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG_DIR)/lib$(1).so
235 install: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG_DIR)/lib$(1).so
236 $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG_DIR)/lib$(1).so: $(X86_64_OUTDIR)/lib$(1)_x86_64.so
237 $(MKDIR) -p $$(dir $$@)
238 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
239 ifneq ($(6),1)
240 GLIBC_SO_LIST += $(X86_64_OUTDIR)/lib$(1)_x86_64.so
241 GLIBC_REMAP += -n lib$(1)_x86_64.so,lib$(1).so
242 endif
243 endif
245 ifneq (,$(findstring arm,$(ARCHES)))
246 all: $(ARM_OUTDIR)/lib$(1)_arm.so
247 $(ARM_OUTDIR)/lib$(1)_arm.so: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_arm_pic)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
248 $(MKDIR) -p $$(dir $$@)
249 $(call LOG,LINK,$$@,$(ARM_LINK) -o $$@ $$(filter %.o,$$^) $(LDFLAGS_SHARED) -marm $(NACL_LDFLAGS) $(ARM_LDFLAGS) $(LDFLAGS) $(foreach path,$(5),-L$(path)/$(TOOLCHAIN)_arm/$(CONFIG_DIR) -L$(path)/$(TOOLCHAIN)_arm/$(CONFIG)) $(foreach lib,$(3),-l$(lib)))
250 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
252 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG_DIR)/lib$(1).so
253 install: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG_DIR)/lib$(1).so
254 $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG_DIR)/lib$(1).so: $(ARM_OUTDIR)/lib$(1)_arm.so
255 $(MKDIR) -p $$(dir $$@)
256 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
257 ifneq ($(6),1)
258 GLIBC_SO_LIST += $(ARM_OUTDIR)/lib$(1)_arm.so
259 GLIBC_REMAP += -n lib$(1)_arm.so,lib$(1).so
260 endif
261 endif
262 endef
265 # $1 = Target name
266 # $2 = List of source files
267 # $3 = List of LIBS
268 # $4 = List of DEPS
269 # $5 = 1 => Don't add to NMF.
271 define SO_RULE
272 $(call SO_LINKER_RULE,$(1),$(2),$(filter-out pthread,$(3)),$(4),$(LIB_PATHS),$(5))
273 endef
276 # LIB Macro
278 # $1 = Target name
279 # $2 = List of source files
280 # $3 = POSIX linker flags
281 # $4 = VC linkr flags (unused)
283 define LIB_RULE
284 $(STAMPDIR)/$(1).stamp:
285 @echo " STAMP $$@"
286 @echo "TOUCHED $$@" > $(STAMPDIR)/$(1).stamp
288 ifneq (,$(findstring x86_32,$(ARCHES)))
289 all: $(X86_32_OUTDIR)/lib$(1)_x86_32.a
290 $(X86_32_OUTDIR)/lib$(1)_x86_32.a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_32))
291 $(MKDIR) -p $$(dir $$@)
292 $(RM) -f $$@
293 $(call LOG,LIB ,$$@,$(X86_32_LIB) -cr $$@ $$^)
295 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG_DIR)/lib$(1).a
296 install: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG_DIR)/lib$(1).a
297 $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG_DIR)/lib$(1).a: $(X86_32_OUTDIR)/lib$(1)_x86_32.a
298 $(MKDIR) -p $$(dir $$@)
299 $(RM) -f $$@
300 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
301 endif
303 ifneq (,$(findstring x86_64,$(ARCHES)))
304 all: $(X86_64_OUTDIR)/lib$(1)_x86_64.a
305 $(X86_64_OUTDIR)/lib$(1)_x86_64.a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_64))
306 $(MKDIR) -p $$(dir $$@)
307 $(RM) -f $$@
308 $(call LOG,LIB ,$$@,$(X86_64_LIB) -cr $$@ $$^)
310 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG_DIR)/lib$(1).a
311 install: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG_DIR)/lib$(1).a
312 $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG_DIR)/lib$(1).a: $(X86_64_OUTDIR)/lib$(1)_x86_64.a
313 $(MKDIR) -p $$(dir $$@)
314 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
315 endif
317 ifneq (,$(findstring arm,$(ARCHES)))
318 all: $(ARM_OUTDIR)/lib$(1)_arm.a
319 $(ARM_OUTDIR)/lib$(1)_arm.a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_arm))
320 $(MKDIR) -p $$(dir $$@)
321 $(RM) -f $$@
322 $(call LOG,LIB ,$$@,$(ARM_LIB) -cr $$@ $$^)
324 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG_DIR)/lib$(1).a
325 install: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG_DIR)/lib$(1).a
326 $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG_DIR)/lib$(1).a: $(ARM_OUTDIR)/lib$(1)_arm.a
327 $(MKDIR) -p $$(dir $$@)
328 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
329 endif
330 endef
334 # Specific Link Macro
336 # $1 = Target name
337 # $2 = List of source files
338 # $3 = List of LIBS
339 # $4 = List of DEPS
340 # $5 = Linkr flags
341 # $6 = Library paths
343 define LINKER_RULE
344 ifneq (,$(findstring x86_32,$(ARCHES)))
345 all: $(X86_32_OUTDIR)/$(1)_x86_32.nexe
346 $(X86_32_OUTDIR)/$(1)_x86_32.nexe: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_32)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
347 $(MKDIR) -p $$(dir $$@)
348 $(call LOG,LINK,$$@,$(X86_32_LINK) -o $$@ $$(filter %.o,$$^) $(NACL_LDFLAGS) $(X86_32_LDFLAGS) $(LDFLAGS) $(foreach path,$(6),-L$(path)/$(TOOLCHAIN)_x86_32/$(CONFIG_DIR) -L$(path)/$(TOOLCHAIN)_x86_32/$(CONFIG)) $(foreach lib,$(3),-l$(lib)) $(5))
349 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
350 endif
352 ifneq (,$(findstring x86_64,$(ARCHES)))
353 all: $(X86_64_OUTDIR)/$(1)_x86_64.nexe
354 $(X86_64_OUTDIR)/$(1)_x86_64.nexe: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_64)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
355 $(MKDIR) -p $$(dir $$@)
356 $(call LOG,LINK,$$@,$(X86_64_LINK) -o $$@ $$(filter %.o,$$^) $(NACL_LDFLAGS) $(X86_64_LDFLAGS) $(LDFLAGS) $(foreach path,$(6),-L$(path)/$(TOOLCHAIN)_x86_64/$(CONFIG_DIR) -L$(path)/$(TOOLCHAIN)_x86_64/$(CONFIG)) $(foreach lib,$(3),-l$(lib)) $(5))
357 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
358 endif
360 ifneq (,$(findstring arm,$(ARCHES)))
361 all: $(ARM_OUTDIR)/$(1)_arm.nexe
362 $(ARM_OUTDIR)/$(1)_arm.nexe: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_arm)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
363 $(MKDIR) -p $$(dir $$@)
364 $(call LOG,LINK,$$@,$(ARM_LINK) $(BIONIC_LINK) -o $$@ $$(filter %.o,$$^) $(NACL_LDFLAGS) $(ARM_LDFLAGS) $(LDFLAGS) $(foreach path,$(6),-L$(path)/$(TOOLCHAIN)_arm/$(CONFIG_DIR) -L$(path)/$(TOOLCHAIN)_arm/$(CONFIG)) $(foreach lib,$(3),-l$(lib)) $(5))
365 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
366 endif
367 endef
371 # Generalized Link Macro
373 # $1 = Target name
374 # $2 = List of source files
375 # $3 = List of LIBS
376 # $4 = List of DEPS
377 # $5 = POSIX linker flags
378 # $6 = VC linker flags
380 define LINK_RULE
381 $(call LINKER_RULE,$(1),$(2),$(filter-out pthread,$(3)),$(4),$(5),$(LIB_PATHS))
382 endef
386 # Strip Macro for each arch (e.g., each arch supported by LINKER_RULE).
388 # $1 = Target Name
389 # $2 = Source Name
391 define STRIP_ALL_RULE
392 ifneq (,$(findstring x86_32,$(ARCHES)))
393 $(X86_32_OUTDIR)/$(1)_x86_32.nexe: $(X86_32_OUTDIR)/$(2)_x86_32.nexe
394 $(call LOG,STRIP,$$@,$(X86_32_STRIP) -o $$@ $$^)
395 endif
397 ifneq (,$(findstring x86_64,$(ARCHES)))
398 $(X86_64_OUTDIR)/$(1)_x86_64.nexe: $(X86_64_OUTDIR)/$(2)_x86_64.nexe
399 $(call LOG,STRIP,$$@,$(X86_64_STRIP) -o $$@ $$^)
400 endif
402 ifneq (,$(findstring arm,$(ARCHES)))
403 $(ARM_OUTDIR)/$(1)_arm.nexe: $(ARM_OUTDIR)/$(2)_arm.nexe
404 $(call LOG,STRIP,$$@,$(ARM_STRIP) -o $$@ $$^)
405 endif
406 endef
410 # Top-level Strip Macro
412 # $1 = Target Basename
413 # $2 = Source Basename
415 define STRIP_RULE
416 $(call STRIP_ALL_RULE,$(1),$(2))
417 endef
421 # Strip Macro for each arch (e.g., each arch supported by MAP_RULE).
423 # $1 = Target Name
424 # $2 = Source Name
426 define MAP_ALL_RULE
427 ifneq (,$(findstring x86_32,$(ARCHES)))
428 all: $(X86_32_OUTDIR)/$(1)_x86_32.map
429 $(X86_32_OUTDIR)/$(1)_x86_32.map: $(X86_32_OUTDIR)/$(2)_x86_32.nexe
430 $(call LOG,MAP,$$@,$(X86_32_NM) -l $$^ > $$@)
431 endif
433 ifneq (,$(findstring x86_64,$(ARCHES)))
434 all: $(X86_64_OUTDIR)/$(1)_x86_64.map
435 $(X86_64_OUTDIR)/$(1)_x86_64.map: $(X86_64_OUTDIR)/$(2)_x86_64.nexe
436 $(call LOG,MAP,$$@,$(X86_64_NM) -l $$^ > $$@)
437 endif
439 ifneq (,$(findstring arm,$(ARCHES)))
440 all: $(ARM_OUTDIR)/$(1)_arm.map
441 $(ARM_OUTDIR)/$(1)_arm.map: $(ARM_OUTDIR)/$(2)_arm.nexe
442 $(call LOG,MAP,$$@,$(ARM_NM) -l $$^ > $$@ )
443 endif
444 endef
448 # Top-level MAP Generation Macro
450 # $1 = Target Basename
451 # $2 = Source Basename
453 define MAP_RULE
454 $(call MAP_ALL_RULE,$(1),$(2))
455 endef
459 # NMF Manifiest generation
461 # Use the python script create_nmf to scan the binaries for dependencies using
462 # objdump. Pass in the (-L) paths to the default library toolchains so that we
463 # can find those libraries and have it automatically copy the files (-s) to
464 # the target directory for us.
466 # $1 = Target Name (the basename of the nmf
467 # $2 = Additional create_nmf.py arguments
469 NMF := python $(NACL_SDK_ROOT)/tools/create_nmf.py
470 NMF_FLAGS += --config=$(CONFIG_DIR)
471 SEL_LDR_ARGS += --config=$(CONFIG_DIR)
473 EXECUTABLES = $(GLIBC_SO_LIST)
474 ifneq (,$(findstring x86_32,$(ARCHES)))
475 EXECUTABLES += $(X86_32_OUTDIR)/$(1)_x86_32.nexe
476 endif
477 ifneq (,$(findstring x86_64,$(ARCHES)))
478 EXECUTABLES += $(X86_64_OUTDIR)/$(1)_x86_64.nexe
479 endif
480 ifneq (,$(findstring arm,$(ARCHES)))
481 EXECUTABLES += $(ARM_OUTDIR)/$(1)_arm.nexe
482 endif
484 ifneq (,$(MULTI_PLATFORM))
485 # When building a multi-platform package, stage all dependent shared libraries
486 # in the same directory as the .nexe (which will be an architecture-specific
487 # directory under _platform_specific).
488 NMF_FLAGS += -s $(OUTDIR) --no-arch-prefix
489 else
490 # Otherwise stage dependent libraries the normal way, under lib32 for x86_32
491 # libraries, and lib64 for x86_64 libraries.
492 NMF_FLAGS += -s $(OUTDIR)
493 endif
495 ifneq (,$(MULTI_PLATFORM))
496 # This script fixes the manifest.json file for this App to point to:
498 # <toolchain>/<config>/_platform_specific/<arch>/
500 # instead of
502 # _platform_specific/<arch>
503 FIX_MANIFEST := python $(NACL_SDK_ROOT)/tools/fix_manifest.py
504 MANIFEST_JSON ?= manifest.json
505 endif
507 define NMF_RULE
508 all: $(OUTDIR)/$(1).nmf
509 $(OUTDIR)/$(1).nmf $(MANIFEST_JSON): $(EXECUTABLES)
510 $(call LOG,CREATE_NMF,$$@,$(NMF) $(NMF_FLAGS) -o $$@ $$^ $(GLIBC_PATHS) $(2) $(GLIBC_REMAP))
511 ifneq (,$(MULTI_PLATFORM))
512 $(call LOG,FIX_MANIFEST,$(MANIFEST_JSON),$(FIX_MANIFEST) $(MANIFEST_JSON)) -p "$(TOOLCHAIN)/$(CONFIG)"
513 endif
514 endef
517 # HTML file generation
519 CREATE_HTML := python $(NACL_SDK_ROOT)/tools/create_html.py
521 define HTML_RULE
522 all: $(OUTDIR)/$(1).html
523 $(OUTDIR)/$(1).html: $(EXECUTABLES)
524 $(call LOG,CREATE_HTML,$$@,$(CREATE_HTML) $(HTML_FLAGS) -o $$@ $$^)
525 endef
529 # Determine which executable to pass into the debugger. For newlib
530 # this is the NEXE which will actually be used. For glibc, runnable-ld.so
531 # is the "app", and the "app" is actual an .so we load.
533 ifeq (x86_32,$(SYSARCH))
534 LIB_NAME = lib32
535 ifeq (x86_64,$(SYSARCH))
536 LIB_NAME = lib64
537 else
538 LIB_NAME = lib
539 endif
540 endif
543 ifeq (newlib,$(TOOLCHAIN))
544 GDB_DEBUG_TARGET = $(abspath $(OUTDIR))/$(TARGET)_$(SYSARCH).nexe
545 else
546 GDB_DEBUG_TARGET = $(abspath $(OUTDIR))/$(LIB_NAME)/runnable-ld.so
547 endif
549 ifdef STANDALONE
550 run: all
551 ifndef NACL_ARCH
552 $(error Cannot run in sel_ldr unless $$NACL_ARCH is set)
553 endif
554 $(SEL_LDR_PATH) $(SEL_LDR_ARGS) $(OUTDIR)/$(TARGET)_$(NACL_ARCH).nexe -- $(EXE_ARGS)
556 debug: all
557 ifndef NACL_ARCH
558 $(error Cannot run in sel_ldr unless $$NACL_ARCH is set)
559 endif
560 $(SEL_LDR_PATH) -d $(SEL_LDR_ARGS) $(OUTDIR)/$(TARGET)_$(NACL_ARCH).nexe -- $(EXE_ARGS)
561 endif