Add more checks to investigate SupervisedUserPrefStore crash at startup.
[chromium-blink-merge.git] / native_client_sdk / src / tools / nacl_gcc.mk
blobedd95a196f06110f8b2a8431e646e56ccd8ae1f2
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 ifneq (,$(findstring $(TOOLCHAIN),newlib bionic clang-newlib))
30 ARM_SUPPORT=1
31 endif
33 ifeq ($(ARM_SUPPORT),1)
34 ARM_CC := $(NACL_COMPILER_PREFIX) $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=cc)
35 ARM_CXX := $(NACL_COMPILER_PREFIX) $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=c++)
36 ARM_LINK := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=c++)
37 ARM_LIB := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=ar)
38 ARM_STRIP := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=strip)
39 ARM_NM := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=nm)
40 endif
42 NCVAL ?= python $(NACL_SDK_ROOT)/tools/ncval.py
44 # Architecture-specific variables
45 ifeq (,$(MULTI_PLATFORM))
46 X86_32_OUTDIR ?= $(OUTDIR)
47 X86_64_OUTDIR ?= $(OUTDIR)
48 ARM_OUTDIR ?= $(OUTDIR)
49 else
50 X86_32_OUTDIR ?= $(OUTDIR)/_platform_specific/x86-32
51 X86_64_OUTDIR ?= $(OUTDIR)/_platform_specific/x86-64
52 ARM_OUTDIR ?= $(OUTDIR)/_platform_specific/arm
53 endif
55 # Architecture-specific flags
56 X86_32_CFLAGS ?=
57 X86_64_CFLAGS ?=
58 X86_32_CXXFLAGS ?=
59 X86_64_CXXFLAGS ?=
61 # Use DWARF v3 which is more commonly available when debugging
62 ifeq ($(CONFIG),Debug)
63 ARM_CFLAGS ?= -gdwarf-3
64 ARM_CXXFLAGS ?= -gdwarf-3
65 else
66 ARM_CFLAGS ?=
67 ARM_CXXFLAGS ?=
68 endif
70 ifeq (,$(MULTI_PLATFORM))
71 X86_32_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_x86_32.map
72 X86_64_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_x86_64.map
73 ARM_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_arm.map
74 else
75 X86_32_LDFLAGS ?= -Wl,-Map,$(X86_32_OUTDIR)/$(TARGET)_x86_32.map
76 X86_64_LDFLAGS ?= -Wl,-Map,$(X86_64_OUTDIR)/$(TARGET)_x86_64.map
77 ARM_LDFLAGS ?= -Wl,-Map,$(ARM_OUTDIR)/$(TARGET)_arm.map
78 endif
81 # Choose between static and dynamic linking for Bionic
82 # (Default to dynamic)
84 ifeq ($(TOOLCHAIN),bionic)
85 ifeq (,$(BIONIC_USE_DYNAMIC))
86 BIONIC_LINK:=-static
87 else
88 BIONIC_LINK:=-Wl,-Ttext-segment=0x100000
89 endif
90 endif
92 LDFLAGS_SHARED = -shared
95 # Compile Macro
97 # $1 = Source Name
98 # $2 = Compile Flags
100 define C_COMPILER_RULE
101 -include $(call SRC_TO_DEP,$(1),_x86_32)
102 $(call SRC_TO_OBJ,$(1),_x86_32): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
103 $(call LOG,CC ,$$@,$(X86_32_CC) -o $$@ -c $$< $(POSIX_CFLAGS) $(2) $(NACL_CFLAGS) $(X86_32_CFLAGS))
104 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_32)
106 -include $(call SRC_TO_DEP,$(1),_x86_64)
107 $(call SRC_TO_OBJ,$(1),_x86_64): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
108 $(call LOG,CC ,$$@,$(X86_64_CC) -o $$@ -c $$< $(POSIX_CFLAGS) $(2) $(NACL_CFLAGS) $(X86_64_CFLAGS))
109 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_64)
111 -include $(call SRC_TO_DEP,$(1),_arm)
112 $(call SRC_TO_OBJ,$(1),_arm): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
113 $(call LOG,CC ,$$@,$(ARM_CC) -o $$@ -c $$< $(POSIX_CFLAGS) $(2) $(NACL_CFLAGS) $(ARM_CFLAGS))
114 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_arm)
116 -include $(call SRC_TO_DEP,$(1),_x86_32_pic)
117 $(call SRC_TO_OBJ,$(1),_x86_32_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
118 $(call LOG,CC ,$$@,$(X86_32_CC) -o $$@ -c $$< -fPIC $(POSIX_CFLAGS) $(2) $(NACL_CFLAGS) $(X86_32_CFLAGS))
119 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_32_pic)
121 -include $(call SRC_TO_DEP,$(1),_x86_64_pic)
122 $(call SRC_TO_OBJ,$(1),_x86_64_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
123 $(call LOG,CC ,$$@,$(X86_64_CC) -o $$@ -c $$< -fPIC $(POSIX_CFLAGS) $(2) $(NACL_CFLAGS) $(X86_64_CFLAGS))
124 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_64_pic)
126 -include $(call SRC_TO_DEP,$(1),_arm_pic)
127 $(call SRC_TO_OBJ,$(1),_arm_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
128 $(call LOG,CC ,$$@,$(ARM_CC) -o $$@ -c $$< -fPIC $(POSIX_CFLAGS) $(2) $(NACL_CFLAGS) $(ARM_CFLAGS))
129 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_arm_pic)
130 endef
132 define CXX_COMPILER_RULE
133 -include $(call SRC_TO_DEP,$(1),_x86_32)
134 $(call SRC_TO_OBJ,$(1),_x86_32): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
135 $(call LOG,CXX ,$$@,$(X86_32_CXX) -o $$@ -c $$< $(POSIX_CFLAGS) $(2) $(NACL_CXXFLAGS) $(X86_32_CXXFLAGS))
136 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_32)
138 -include $(call SRC_TO_DEP,$(1),_x86_64)
139 $(call SRC_TO_OBJ,$(1),_x86_64): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
140 $(call LOG,CXX ,$$@,$(X86_64_CXX) -o $$@ -c $$< $(POSIX_CFLAGS) $(2) $(NACL_CXXFLAGS) $(X86_64_CXXFLAGS))
141 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_64)
143 -include $(call SRC_TO_DEP,$(1),_arm)
144 $(call SRC_TO_OBJ,$(1),_arm): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
145 $(call LOG,CXX ,$$@,$(ARM_CXX) -o $$@ -c $$< $(POSIX_CFLAGS) $(2) $(NACL_CXXFLAGS) $(ARM_CXXFLAGS))
146 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_arm)
148 -include $(call SRC_TO_DEP,$(1),_x86_32_pic)
149 $(call SRC_TO_OBJ,$(1),_x86_32_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
150 $(call LOG,CXX ,$$@,$(X86_32_CXX) -o $$@ -c $$< -fPIC $(POSIX_CFLAGS) $(2) $(NACL_CXXFLAGS) $(X86_32_CXXFLAGS))
151 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_32_pic)
153 -include $(call SRC_TO_DEP,$(1),_x86_64_pic)
154 $(call SRC_TO_OBJ,$(1),_x86_64_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
155 $(call LOG,CXX ,$$@,$(X86_64_CXX) -o $$@ -c $$< -fPIC $(POSIX_CFLAGS) $(2) $(NACL_CXXFLAGS) $(X86_64_CXXFLAGS))
156 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_64_pic)
158 -include $(call SRC_TO_DEP,$(1),_arm_pic)
159 $(call SRC_TO_OBJ,$(1),_arm_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
160 $(call LOG,CXX ,$$@,$(ARM_CXX) -o $$@ -c $$< -fPIC $(POSIX_CFLAGS) $(2) $(NACL_CXXFLAGS) $(ARM_CXXFLAGS))
161 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_arm_pic)
162 endef
166 # $1 = Source Name
167 # $2 = POSIX Compile Flags
168 # $3 = Include Directories
169 # $4 = VC Flags (unused)
171 define COMPILE_RULE
172 ifeq ($(suffix $(1)),.c)
173 $(call C_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc)) $(3))
174 else
175 $(call CXX_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc)) $(3))
176 endif
177 endef
180 # Determine which architectures to build for. The user can set NACL_ARCH or
181 # ARCHES in the environment to control this.
183 ifneq ($(TOOLCHAIN),bionic)
184 VALID_ARCHES := x86_32 x86_64
185 endif
186 ifeq ($(ARM_SUPPORT),1)
187 VALID_ARCHES += arm
188 endif
190 ifdef NACL_ARCH
191 ifeq (,$(findstring $(NACL_ARCH),$(VALID_ARCHES)))
192 $(error Invalid arch specified in NACL_ARCH: $(NACL_ARCH). Valid values are: $(VALID_ARCHES))
193 endif
194 ARCHES = ${NACL_ARCH}
195 else
196 ARCHES ?= ${VALID_ARCHES}
197 endif
199 GLIBC_REMAP :=
202 # SO Macro
204 # As well as building and installing a shared library this rule adds dependencies
205 # on the library's .stamp file in STAMPDIR. However, the rule for creating the stamp
206 # file is part of LIB_RULE, so users of the DEPS system are currently required to
207 # use the LIB_RULE macro as well as the SO_RULE for each shared library.
209 # $1 = Target Name
210 # $2 = List of Sources
211 # $3 = List of LIBS
212 # $4 = List of DEPS
213 # $5 = Library Paths
214 # $6 = 1 => Don't add to NMF.
216 define SO_LINKER_RULE
217 ifneq (,$(findstring x86_32,$(ARCHES)))
218 all: $(X86_32_OUTDIR)/lib$(1)_x86_32.so
219 $(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)
220 $(MKDIR) -p $$(dir $$@)
221 $(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)) $(foreach lib,$(3),-l$(lib)))
222 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
224 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so
225 install: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so
226 $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so: $(X86_32_OUTDIR)/lib$(1)_x86_32.so
227 $(MKDIR) -p $$(dir $$@)
228 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
229 ifneq ($(6),1)
230 GLIBC_SO_LIST += $(X86_32_OUTDIR)/lib$(1)_x86_32.so
231 GLIBC_REMAP += -n lib$(1)_x86_32.so,lib$(1).so
232 endif
233 endif
235 ifneq (,$(findstring x86_64,$(ARCHES)))
236 all: $(X86_64_OUTDIR)/lib$(1)_x86_64.so
237 $(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)
238 $(MKDIR) -p $$(dir $$@)
239 $(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)) $(foreach lib,$(3),-l$(lib)))
240 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
242 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so
243 install: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so
244 $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so: $(X86_64_OUTDIR)/lib$(1)_x86_64.so
245 $(MKDIR) -p $$(dir $$@)
246 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
247 ifneq ($(6),1)
248 GLIBC_SO_LIST += $(X86_64_OUTDIR)/lib$(1)_x86_64.so
249 GLIBC_REMAP += -n lib$(1)_x86_64.so,lib$(1).so
250 endif
251 endif
253 ifneq (,$(findstring arm,$(ARCHES)))
254 all: $(ARM_OUTDIR)/lib$(1)_arm.so
255 $(ARM_OUTDIR)/lib$(1)_arm.so: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_arm_pic)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
256 $(MKDIR) -p $$(dir $$@)
257 $(call LOG,LINK,$$@,$(ARM_LINK) -o $$@ $$(filter %.o,$$^) $(LDFLAGS_SHARED) -marm $(NACL_LDFLAGS) $(ARM_LDFLAGS) $(LDFLAGS) $(foreach path,$(5),-L$(path)/$(TOOLCHAIN)_arm/$(CONFIG)) $(foreach lib,$(3),-l$(lib)))
258 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
260 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).so
261 install: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).so
262 $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).so: $(ARM_OUTDIR)/lib$(1)_arm.so
263 $(MKDIR) -p $$(dir $$@)
264 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
265 ifneq ($(6),1)
266 GLIBC_SO_LIST += $(ARM_OUTDIR)/lib$(1)_arm.so
267 GLIBC_REMAP += -n lib$(1)_arm.so,lib$(1).so
268 endif
269 endif
270 endef
273 # $1 = Target Name
274 # $2 = List of Sources
275 # $3 = List of LIBS
276 # $4 = List of DEPS
277 # $5 = 1 => Don't add to NMF.
279 define SO_RULE
280 $(call SO_LINKER_RULE,$(1),$(2),$(filter-out pthread,$(3)),$(4),$(LIB_PATHS),$(5))
281 endef
284 # LIB Macro
286 # $1 = Target Name
287 # $2 = List of Sources
288 # $3 = POSIX Link Flags
289 # $4 = VC Link Flags (unused)
291 define LIB_RULE
292 $(STAMPDIR)/$(1).stamp:
293 @echo " STAMP $$@"
294 @echo "TOUCHED $$@" > $(STAMPDIR)/$(1).stamp
296 ifneq (,$(findstring x86_32,$(ARCHES)))
297 all: $(X86_32_OUTDIR)/lib$(1)_x86_32.a
298 $(X86_32_OUTDIR)/lib$(1)_x86_32.a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_32))
299 $(MKDIR) -p $$(dir $$@)
300 $(RM) -f $$@
301 $(call LOG,LIB ,$$@,$(X86_32_LIB) -cr $$@ $$^)
303 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).a
304 install: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).a
305 $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).a: $(X86_32_OUTDIR)/lib$(1)_x86_32.a
306 $(MKDIR) -p $$(dir $$@)
307 $(RM) -f $$@
308 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
309 endif
311 ifneq (,$(findstring x86_64,$(ARCHES)))
312 all: $(X86_64_OUTDIR)/lib$(1)_x86_64.a
313 $(X86_64_OUTDIR)/lib$(1)_x86_64.a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_64))
314 $(MKDIR) -p $$(dir $$@)
315 $(RM) -f $$@
316 $(call LOG,LIB ,$$@,$(X86_64_LIB) -cr $$@ $$^)
318 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).a
319 install: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).a
320 $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).a: $(X86_64_OUTDIR)/lib$(1)_x86_64.a
321 $(MKDIR) -p $$(dir $$@)
322 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
323 endif
325 ifneq (,$(findstring arm,$(ARCHES)))
326 ifeq ($(ARM_SUPPORT),1)
327 all: $(ARM_OUTDIR)/lib$(1)_arm.a
328 $(ARM_OUTDIR)/lib$(1)_arm.a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_arm))
329 $(MKDIR) -p $$(dir $$@)
330 $(RM) -f $$@
331 $(call LOG,LIB ,$$@,$(ARM_LIB) -cr $$@ $$^)
333 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).a
334 install: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).a
335 $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).a: $(ARM_OUTDIR)/lib$(1)_arm.a
336 $(MKDIR) -p $$(dir $$@)
337 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
338 endif
339 endif
340 endef
344 # Specific Link Macro
346 # $1 = Target Name
347 # $2 = List of Sources
348 # $3 = List of LIBS
349 # $4 = List of DEPS
350 # $5 = Link Flags
351 # $6 = Library Paths
353 define LINKER_RULE
354 ifneq (,$(findstring x86_32,$(ARCHES)))
355 all: $(X86_32_OUTDIR)/$(1)_x86_32.nexe
356 $(X86_32_OUTDIR)/$(1)_x86_32.nexe: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_32)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
357 $(MKDIR) -p $$(dir $$@)
358 $(call LOG,LINK,$$@,$(X86_32_LINK) -o $$@ $$(filter %.o,$$^) $(NACL_LDFLAGS) $(X86_32_LDFLAGS) $(foreach path,$(6),-L$(path)/$(TOOLCHAIN)_x86_32/$(CONFIG)) $(foreach lib,$(3),-l$(lib)) $(5))
359 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
360 endif
362 ifneq (,$(findstring x86_64,$(ARCHES)))
363 all: $(X86_64_OUTDIR)/$(1)_x86_64.nexe
364 $(X86_64_OUTDIR)/$(1)_x86_64.nexe: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_64)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
365 $(MKDIR) -p $$(dir $$@)
366 $(call LOG,LINK,$$@,$(X86_64_LINK) -o $$@ $$(filter %.o,$$^) $(NACL_LDFLAGS) $(X86_64_LDFLAGS) $(foreach path,$(6),-L$(path)/$(TOOLCHAIN)_x86_64/$(CONFIG)) $(foreach lib,$(3),-l$(lib)) $(5))
367 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
368 endif
370 ifneq (,$(findstring arm,$(ARCHES)))
371 all: $(ARM_OUTDIR)/$(1)_arm.nexe
372 $(ARM_OUTDIR)/$(1)_arm.nexe: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_arm)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
373 $(MKDIR) -p $$(dir $$@)
374 $(call LOG,LINK,$$@,$(ARM_LINK) $(BIONIC_LINK) -o $$@ $$(filter %.o,$$^) $(NACL_LDFLAGS) $(ARM_LDFLAGS) $(foreach path,$(6),-L$(path)/$(TOOLCHAIN)_arm/$(CONFIG)) $(foreach lib,$(3),-l$(lib)) $(5))
375 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
376 endif
377 endef
381 # Generalized Link Macro
383 # $1 = Target Name
384 # $2 = List of Sources
385 # $3 = List of LIBS
386 # $4 = List of DEPS
387 # $5 = POSIX Linker Switches
388 # $6 = VC Linker Switches
390 define LINK_RULE
391 $(call LINKER_RULE,$(1),$(2),$(filter-out pthread,$(3)),$(4),$(5),$(LIB_PATHS))
392 endef
396 # Strip Macro for each arch (e.g., each arch supported by LINKER_RULE).
398 # $1 = Target Name
399 # $2 = Source Name
401 define STRIP_ALL_RULE
402 ifneq (,$(findstring x86_32,$(ARCHES)))
403 $(X86_32_OUTDIR)/$(1)_x86_32.nexe: $(X86_32_OUTDIR)/$(2)_x86_32.nexe
404 $(call LOG,STRIP,$$@,$(X86_32_STRIP) -o $$@ $$^)
405 endif
407 ifneq (,$(findstring x86_64,$(ARCHES)))
408 $(X86_64_OUTDIR)/$(1)_x86_64.nexe: $(X86_64_OUTDIR)/$(2)_x86_64.nexe
409 $(call LOG,STRIP,$$@,$(X86_64_STRIP) -o $$@ $$^)
410 endif
412 ifneq (,$(findstring arm,$(ARCHES)))
413 $(ARM_OUTDIR)/$(1)_arm.nexe: $(ARM_OUTDIR)/$(2)_arm.nexe
414 $(call LOG,STRIP,$$@,$(ARM_STRIP) -o $$@ $$^)
415 endif
416 endef
420 # Top-level Strip Macro
422 # $1 = Target Basename
423 # $2 = Source Basename
425 define STRIP_RULE
426 $(call STRIP_ALL_RULE,$(1),$(2))
427 endef
431 # Strip Macro for each arch (e.g., each arch supported by MAP_RULE).
433 # $1 = Target Name
434 # $2 = Source Name
436 define MAP_ALL_RULE
437 ifneq (,$(findstring x86_32,$(ARCHES)))
438 all: $(X86_32_OUTDIR)/$(1)_x86_32.map
439 $(X86_32_OUTDIR)/$(1)_x86_32.map: $(X86_32_OUTDIR)/$(2)_x86_32.nexe
440 $(call LOG,MAP,$$@,$(X86_32_NM) -l $$^ > $$@)
441 endif
443 ifneq (,$(findstring x86_64,$(ARCHES)))
444 all: $(X86_64_OUTDIR)/$(1)_x86_64.map
445 $(X86_64_OUTDIR)/$(1)_x86_64.map: $(X86_64_OUTDIR)/$(2)_x86_64.nexe
446 $(call LOG,MAP,$$@,$(X86_64_NM) -l $$^ > $$@)
447 endif
449 ifneq (,$(findstring arm,$(ARCHES)))
450 all: $(ARM_OUTDIR)/$(1)_arm.map
451 $(ARM_OUTDIR)/$(1)_arm.map: $(ARM_OUTDIR)/$(2)_arm.nexe
452 $(call LOG,MAP,$$@,$(ARM_NM) -l $$^ > $$@ )
453 endif
454 endef
458 # Top-level MAP Generation Macro
460 # $1 = Target Basename
461 # $2 = Source Basename
463 define MAP_RULE
464 $(call MAP_ALL_RULE,$(1),$(2))
465 endef
469 # NMF Manifiest generation
471 # Use the python script create_nmf to scan the binaries for dependencies using
472 # objdump. Pass in the (-L) paths to the default library toolchains so that we
473 # can find those libraries and have it automatically copy the files (-s) to
474 # the target directory for us.
476 # $1 = Target Name (the basename of the nmf
477 # $2 = Additional create_nmf.py arguments
479 NMF := python $(NACL_SDK_ROOT)/tools/create_nmf.py
480 ifeq ($(CONFIG),Debug)
481 NMF_FLAGS += --debug-libs
482 HTML_FLAGS += --debug-libs
483 endif
485 EXECUTABLES = $(GLIBC_SO_LIST)
486 ifneq (,$(findstring x86_32,$(ARCHES)))
487 EXECUTABLES += $(X86_32_OUTDIR)/$(1)_x86_32.nexe
488 endif
489 ifneq (,$(findstring x86_64,$(ARCHES)))
490 EXECUTABLES += $(X86_64_OUTDIR)/$(1)_x86_64.nexe
491 endif
492 ifneq (,$(findstring arm,$(ARCHES)))
493 EXECUTABLES += $(ARM_OUTDIR)/$(1)_arm.nexe
494 endif
496 ifneq (,$(MULTI_PLATFORM))
497 # When building a multi-platform package, stage all dependent shared libraries
498 # in the same directory as the .nexe (which will be an architecture-specific
499 # directory under _platform_specific).
500 NMF_FLAGS += -s $(OUTDIR) --no-arch-prefix
501 else
502 # Otherwise stage dependent libraries the normal way, under lib32 for x86_32
503 # libraries, and lib64 for x86_64 libraries.
504 NMF_FLAGS += -s $(OUTDIR)
505 endif
507 ifneq (,$(MULTI_PLATFORM))
508 # This script fixes the manifest.json file for this App to point to:
510 # <toolchain>/<config>/_platform_specific/<arch>/
512 # instead of
514 # _platform_specific/<arch>
515 FIX_MANIFEST := python $(NACL_SDK_ROOT)/tools/fix_manifest.py
516 MANIFEST_JSON ?= manifest.json
517 endif
519 define NMF_RULE
520 all: $(OUTDIR)/$(1).nmf
521 $(OUTDIR)/$(1).nmf $(MANIFEST_JSON): $(EXECUTABLES)
522 $(call LOG,CREATE_NMF,$$@,$(NMF) $(NMF_FLAGS) -o $$@ $$^ $(GLIBC_PATHS) $(2) $(GLIBC_REMAP))
523 ifneq (,$(MULTI_PLATFORM))
524 $(call LOG,FIX_MANIFEST,$(MANIFEST_JSON),$(FIX_MANIFEST) $(MANIFEST_JSON)) -p "$(TOOLCHAIN)/$(CONFIG)"
525 endif
526 endef
529 # HTML file generation
531 CREATE_HTML := python $(NACL_SDK_ROOT)/tools/create_html.py
533 define HTML_RULE
534 all: $(OUTDIR)/$(1).html
535 $(OUTDIR)/$(1).html: $(EXECUTABLES)
536 $(call LOG,CREATE_HTML,$$@,$(CREATE_HTML) $(HTML_FLAGS) -o $$@ $$^)
537 endef
541 # Determine which executable to pass into the debugger. For newlib
542 # this is the NEXE which will actually be used. For glibc, runnable-ld.so
543 # is the "app", and the "app" is actual an .so we load.
545 ifeq (x86_32,$(SYSARCH))
546 LIB_NAME = lib32
547 else
548 LIB_NAME = lib64
549 endif
552 ifeq (newlib,$(TOOLCHAIN))
553 GDB_DEBUG_TARGET = $(abspath $(OUTDIR))/$(TARGET)_$(SYSARCH).nexe
554 else
555 GDB_DEBUG_TARGET = $(abspath $(OUTDIR))/$(LIB_NAME)/runnable-ld.so
556 endif
558 ifdef STANDALONE
559 run: all
560 ifndef NACL_ARCH
561 $(error Cannot run in sel_ldr unless $$NACL_ARCH is set)
562 endif
563 $(SEL_LDR_PATH) $(SEL_LDR_ARGS) $(OUTDIR)/$(TARGET)_$(NACL_ARCH).nexe -- $(EXE_ARGS)
565 debug: all
566 ifndef NACL_ARCH
567 $(error Cannot run in sel_ldr unless $$NACL_ARCH is set)
568 endif
569 $(SEL_LDR_PATH) -d $(SEL_LDR_ARGS) $(OUTDIR)/$(TARGET)_$(NACL_ARCH).nexe -- $(EXE_ARGS)
570 endif