[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / native_client_sdk / src / tools / nacl_gcc.mk
blob9f7c4785387c1a2454f2dd3bdc7517f181a520e7
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 ifeq (,$(findstring $(TOOLCHAIN),glibc))
30 ARM_CC := $(NACL_COMPILER_PREFIX) $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=cc)
31 ARM_CXX := $(NACL_COMPILER_PREFIX) $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=c++)
32 ARM_LINK := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=c++)
33 ARM_LIB := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=ar)
34 ARM_STRIP := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=strip)
35 ARM_NM := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=nm)
36 endif
38 NCVAL ?= python $(NACL_SDK_ROOT)/tools/ncval.py
40 # Architecture-specific variables
41 ifeq (,$(MULTI_PLATFORM))
42 X86_32_OUTDIR ?= $(OUTDIR)
43 X86_64_OUTDIR ?= $(OUTDIR)
44 ARM_OUTDIR ?= $(OUTDIR)
45 else
46 X86_32_OUTDIR ?= $(OUTDIR)/_platform_specific/x86-32
47 X86_64_OUTDIR ?= $(OUTDIR)/_platform_specific/x86-64
48 ARM_OUTDIR ?= $(OUTDIR)/_platform_specific/arm
49 endif
51 # Architecture-specific flags
52 X86_32_CFLAGS ?=
53 X86_64_CFLAGS ?=
54 X86_32_CXXFLAGS ?=
55 X86_64_CXXFLAGS ?=
57 # Use DWARF v3 which is more commonly available when debugging
58 ifeq ($(CONFIG),Debug)
59 ARM_CFLAGS ?= -gdwarf-3
60 ARM_CXXFLAGS ?= -gdwarf-3
61 else
62 ARM_CFLAGS ?=
63 ARM_CXXFLAGS ?=
64 endif
66 ifeq (,$(MULTI_PLATFORM))
67 X86_32_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_x86_32.map
68 X86_64_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_x86_64.map
69 ARM_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_arm.map
70 else
71 X86_32_LDFLAGS ?= -Wl,-Map,$(X86_32_OUTDIR)/$(TARGET)_x86_32.map
72 X86_64_LDFLAGS ?= -Wl,-Map,$(X86_64_OUTDIR)/$(TARGET)_x86_64.map
73 ARM_LDFLAGS ?= -Wl,-Map,$(ARM_OUTDIR)/$(TARGET)_arm.map
74 endif
77 # Choose between static and dynamic linking for Bionic
78 # (Default to dynamic)
80 ifeq ($(TOOLCHAIN),bionic)
81 ifeq (,$(BIONIC_USE_DYNAMIC))
82 BIONIC_LINK:=-static
83 else
84 BIONIC_LINK:=-Wl,-Ttext-segment=0x100000
85 endif
86 endif
88 LDFLAGS_SHARED = -shared
91 # Compile Macro
93 # $1 = Source Name
94 # $2 = Compile Flags
96 define C_COMPILER_RULE
97 -include $(call SRC_TO_DEP,$(1),_x86_32)
98 $(call SRC_TO_OBJ,$(1),_x86_32): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
99 $(call LOG,CC ,$$@,$(X86_32_CC) -o $$@ -c $$< $(POSIX_FLAGS) $(2) $(NACL_CFLAGS) $(X86_32_CFLAGS))
100 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_32)
102 -include $(call SRC_TO_DEP,$(1),_x86_64)
103 $(call SRC_TO_OBJ,$(1),_x86_64): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
104 $(call LOG,CC ,$$@,$(X86_64_CC) -o $$@ -c $$< $(POSIX_FLAGS) $(2) $(NACL_CFLAGS) $(X86_64_CFLAGS))
105 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_64)
107 -include $(call SRC_TO_DEP,$(1),_arm)
108 $(call SRC_TO_OBJ,$(1),_arm): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
109 $(call LOG,CC ,$$@,$(ARM_CC) -o $$@ -c $$< $(POSIX_FLAGS) $(2) $(NACL_CFLAGS) $(ARM_CFLAGS))
110 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_arm)
112 -include $(call SRC_TO_DEP,$(1),_x86_32_pic)
113 $(call SRC_TO_OBJ,$(1),_x86_32_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
114 $(call LOG,CC ,$$@,$(X86_32_CC) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(NACL_CFLAGS) $(X86_32_CFLAGS))
115 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_32_pic)
117 -include $(call SRC_TO_DEP,$(1),_x86_64_pic)
118 $(call SRC_TO_OBJ,$(1),_x86_64_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
119 $(call LOG,CC ,$$@,$(X86_64_CC) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(NACL_CFLAGS) $(X86_64_CFLAGS))
120 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_64_pic)
122 -include $(call SRC_TO_DEP,$(1),_arm_pic)
123 $(call SRC_TO_OBJ,$(1),_arm_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
124 $(call LOG,CC ,$$@,$(ARM_CC) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(NACL_CFLAGS) $(ARM_CFLAGS))
125 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_arm_pic)
126 endef
128 define CXX_COMPILER_RULE
129 -include $(call SRC_TO_DEP,$(1),_x86_32)
130 $(call SRC_TO_OBJ,$(1),_x86_32): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
131 $(call LOG,CXX ,$$@,$(X86_32_CXX) -o $$@ -c $$< $(POSIX_FLAGS) $(2) $(NACL_CXXFLAGS) $(X86_32_CXXFLAGS))
132 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_32)
134 -include $(call SRC_TO_DEP,$(1),_x86_64)
135 $(call SRC_TO_OBJ,$(1),_x86_64): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
136 $(call LOG,CXX ,$$@,$(X86_64_CXX) -o $$@ -c $$< $(POSIX_FLAGS) $(2) $(NACL_CXXFLAGS) $(X86_64_CXXFLAGS))
137 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_64)
139 -include $(call SRC_TO_DEP,$(1),_arm)
140 $(call SRC_TO_OBJ,$(1),_arm): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
141 $(call LOG,CXX ,$$@,$(ARM_CXX) -o $$@ -c $$< $(POSIX_FLAGS) $(2) $(NACL_CXXFLAGS) $(ARM_CXXFLAGS))
142 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_arm)
144 -include $(call SRC_TO_DEP,$(1),_x86_32_pic)
145 $(call SRC_TO_OBJ,$(1),_x86_32_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
146 $(call LOG,CXX ,$$@,$(X86_32_CXX) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(NACL_CXXFLAGS) $(X86_32_CXXFLAGS))
147 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_32_pic)
149 -include $(call SRC_TO_DEP,$(1),_x86_64_pic)
150 $(call SRC_TO_OBJ,$(1),_x86_64_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
151 $(call LOG,CXX ,$$@,$(X86_64_CXX) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(NACL_CXXFLAGS) $(X86_64_CXXFLAGS))
152 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_64_pic)
154 -include $(call SRC_TO_DEP,$(1),_arm_pic)
155 $(call SRC_TO_OBJ,$(1),_arm_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
156 $(call LOG,CXX ,$$@,$(ARM_CXX) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(NACL_CXXFLAGS) $(ARM_CXXFLAGS))
157 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_arm_pic)
158 endef
162 # $1 = Source Name
163 # $2 = POSIX Compile Flags
164 # $3 = Include Directories
165 # $4 = VC Flags (unused)
167 define COMPILE_RULE
168 ifeq ($(suffix $(1)),.c)
169 $(call C_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc)) $(3))
170 else
171 $(call CXX_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc)) $(3))
172 endif
173 endef
176 # Determine which architectures to build for. The user can set NACL_ARCH or
177 # ARCHES in the environment to control this.
179 ifneq ($(TOOLCHAIN),bionic)
180 VALID_ARCHES := x86_32 x86_64
181 endif
182 ifneq (glibc,$(TOOLCHAIN))
183 VALID_ARCHES += arm
184 endif
186 ifdef NACL_ARCH
187 ifeq (,$(findstring $(NACL_ARCH),$(VALID_ARCHES)))
188 $(error Invalid arch specified in NACL_ARCH: $(NACL_ARCH). Valid values are: $(VALID_ARCHES))
189 endif
190 ARCHES = ${NACL_ARCH}
191 else
192 ARCHES ?= ${VALID_ARCHES}
193 endif
195 GLIBC_REMAP :=
198 # SO Macro
200 # As well as building and installing a shared library this rule adds dependencies
201 # on the library's .stamp file in STAMPDIR. However, the rule for creating the stamp
202 # file is part of LIB_RULE, so users of the DEPS system are currently required to
203 # use the LIB_RULE macro as well as the SO_RULE for each shared library.
205 # $1 = Target Name
206 # $2 = List of Sources
207 # $3 = List of LIBS
208 # $4 = List of DEPS
209 # $5 = Library Paths
210 # $6 = 1 => Don't add to NMF.
212 define SO_LINKER_RULE
213 ifneq (,$(findstring x86_32,$(ARCHES)))
214 all: $(X86_32_OUTDIR)/lib$(1)_x86_32.so
215 $(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)
216 $(MKDIR) -p $$(dir $$@)
217 $(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)))
218 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
220 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so
221 install: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so
222 $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so: $(X86_32_OUTDIR)/lib$(1)_x86_32.so
223 $(MKDIR) -p $$(dir $$@)
224 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
225 ifneq ($(6),1)
226 GLIBC_SO_LIST += $(X86_32_OUTDIR)/lib$(1)_x86_32.so
227 GLIBC_REMAP += -n lib$(1)_x86_32.so,lib$(1).so
228 endif
229 endif
231 ifneq (,$(findstring x86_64,$(ARCHES)))
232 all: $(X86_64_OUTDIR)/lib$(1)_x86_64.so
233 $(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)
234 $(MKDIR) -p $$(dir $$@)
235 $(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)))
236 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
238 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so
239 install: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so
240 $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so: $(X86_64_OUTDIR)/lib$(1)_x86_64.so
241 $(MKDIR) -p $$(dir $$@)
242 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
243 ifneq ($(6),1)
244 GLIBC_SO_LIST += $(X86_64_OUTDIR)/lib$(1)_x86_64.so
245 GLIBC_REMAP += -n lib$(1)_x86_64.so,lib$(1).so
246 endif
247 endif
249 ifneq (,$(findstring arm,$(ARCHES)))
250 all: $(ARM_OUTDIR)/lib$(1)_arm.so
251 $(ARM_OUTDIR)/lib$(1)_arm.so: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_arm_pic)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
252 $(MKDIR) -p $$(dir $$@)
253 $(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)))
254 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
256 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).so
257 install: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).so
258 $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).so: $(ARM_OUTDIR)/lib$(1)_arm.so
259 $(MKDIR) -p $$(dir $$@)
260 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
261 ifneq ($(6),1)
262 GLIBC_SO_LIST += $(ARM_OUTDIR)/lib$(1)_arm.so
263 GLIBC_REMAP += -n lib$(1)_arm.so,lib$(1).so
264 endif
265 endif
266 endef
269 # $1 = Target Name
270 # $2 = List of Sources
271 # $3 = List of LIBS
272 # $4 = List of DEPS
273 # $5 = 1 => Don't add to NMF.
275 define SO_RULE
276 $(call SO_LINKER_RULE,$(1),$(2),$(filter-out pthread,$(3)),$(4),$(LIB_PATHS),$(5))
277 endef
280 # LIB Macro
282 # $1 = Target Name
283 # $2 = List of Sources
284 # $3 = POSIX Link Flags
285 # $4 = VC Link Flags (unused)
287 define LIB_RULE
288 $(STAMPDIR)/$(1).stamp:
289 @echo " STAMP $$@"
290 @echo "TOUCHED $$@" > $(STAMPDIR)/$(1).stamp
292 ifneq (,$(findstring x86_32,$(ARCHES)))
293 all: $(X86_32_OUTDIR)/lib$(1)_x86_32.a
294 $(X86_32_OUTDIR)/lib$(1)_x86_32.a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_32))
295 $(MKDIR) -p $$(dir $$@)
296 $(RM) -f $$@
297 $(call LOG,LIB ,$$@,$(X86_32_LIB) -cr $$@ $$^)
299 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).a
300 install: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).a
301 $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).a: $(X86_32_OUTDIR)/lib$(1)_x86_32.a
302 $(MKDIR) -p $$(dir $$@)
303 $(RM) -f $$@
304 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
305 endif
307 ifneq (,$(findstring x86_64,$(ARCHES)))
308 all: $(X86_64_OUTDIR)/lib$(1)_x86_64.a
309 $(X86_64_OUTDIR)/lib$(1)_x86_64.a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_64))
310 $(MKDIR) -p $$(dir $$@)
311 $(RM) -f $$@
312 $(call LOG,LIB ,$$@,$(X86_64_LIB) -cr $$@ $$^)
314 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).a
315 install: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).a
316 $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).a: $(X86_64_OUTDIR)/lib$(1)_x86_64.a
317 $(MKDIR) -p $$(dir $$@)
318 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
319 endif
321 ifneq (,$(findstring arm,$(ARCHES)))
322 ifneq ($(TOOLCHAIN),glibc)
323 all: $(ARM_OUTDIR)/lib$(1)_arm.a
324 $(ARM_OUTDIR)/lib$(1)_arm.a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_arm))
325 $(MKDIR) -p $$(dir $$@)
326 $(RM) -f $$@
327 $(call LOG,LIB ,$$@,$(ARM_LIB) -cr $$@ $$^)
329 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).a
330 install: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).a
331 $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).a: $(ARM_OUTDIR)/lib$(1)_arm.a
332 $(MKDIR) -p $$(dir $$@)
333 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@)
334 endif
335 endif
336 endef
340 # Specific Link Macro
342 # $1 = Target Name
343 # $2 = List of Sources
344 # $3 = List of LIBS
345 # $4 = List of DEPS
346 # $5 = Link Flags
347 # $6 = Library Paths
349 define LINKER_RULE
350 ifneq (,$(findstring x86_32,$(ARCHES)))
351 all: $(X86_32_OUTDIR)/$(1)_x86_32.nexe
352 $(X86_32_OUTDIR)/$(1)_x86_32.nexe: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_32)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
353 $(MKDIR) -p $$(dir $$@)
354 $(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))
355 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
356 endif
358 ifneq (,$(findstring x86_64,$(ARCHES)))
359 all: $(X86_64_OUTDIR)/$(1)_x86_64.nexe
360 $(X86_64_OUTDIR)/$(1)_x86_64.nexe: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_64)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
361 $(MKDIR) -p $$(dir $$@)
362 $(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))
363 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
364 endif
366 ifneq (,$(findstring arm,$(ARCHES)))
367 all: $(ARM_OUTDIR)/$(1)_arm.nexe
368 $(ARM_OUTDIR)/$(1)_arm.nexe: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_arm)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
369 $(MKDIR) -p $$(dir $$@)
370 $(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))
371 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@)
372 endif
373 endef
377 # Generalized Link Macro
379 # $1 = Target Name
380 # $2 = List of Sources
381 # $3 = List of LIBS
382 # $4 = List of DEPS
383 # $5 = POSIX Linker Switches
384 # $6 = VC Linker Switches
386 define LINK_RULE
387 $(call LINKER_RULE,$(1),$(2),$(filter-out pthread,$(3)),$(4),$(5),$(LIB_PATHS))
388 endef
392 # Strip Macro for each arch (e.g., each arch supported by LINKER_RULE).
394 # $1 = Target Name
395 # $2 = Source Name
397 define STRIP_ALL_RULE
398 ifneq (,$(findstring x86_32,$(ARCHES)))
399 $(X86_32_OUTDIR)/$(1)_x86_32.nexe: $(X86_32_OUTDIR)/$(2)_x86_32.nexe
400 $(call LOG,STRIP,$$@,$(X86_32_STRIP) -o $$@ $$^)
401 endif
403 ifneq (,$(findstring x86_64,$(ARCHES)))
404 $(X86_64_OUTDIR)/$(1)_x86_64.nexe: $(X86_64_OUTDIR)/$(2)_x86_64.nexe
405 $(call LOG,STRIP,$$@,$(X86_64_STRIP) -o $$@ $$^)
406 endif
408 ifneq (,$(findstring arm,$(ARCHES)))
409 $(ARM_OUTDIR)/$(1)_arm.nexe: $(ARM_OUTDIR)/$(2)_arm.nexe
410 $(call LOG,STRIP,$$@,$(ARM_STRIP) -o $$@ $$^)
411 endif
412 endef
416 # Top-level Strip Macro
418 # $1 = Target Basename
419 # $2 = Source Basename
421 define STRIP_RULE
422 $(call STRIP_ALL_RULE,$(1),$(2))
423 endef
427 # Strip Macro for each arch (e.g., each arch supported by MAP_RULE).
429 # $1 = Target Name
430 # $2 = Source Name
432 define MAP_ALL_RULE
433 ifneq (,$(findstring x86_32,$(ARCHES)))
434 all: $(X86_32_OUTDIR)/$(1)_x86_32.map
435 $(X86_32_OUTDIR)/$(1)_x86_32.map: $(X86_32_OUTDIR)/$(2)_x86_32.nexe
436 $(call LOG,MAP,$$@,$(X86_32_NM) -l $$^ > $$@)
437 endif
439 ifneq (,$(findstring x86_64,$(ARCHES)))
440 all: $(X86_64_OUTDIR)/$(1)_x86_64.map
441 $(X86_64_OUTDIR)/$(1)_x86_64.map: $(X86_64_OUTDIR)/$(2)_x86_64.nexe
442 $(call LOG,MAP,$$@,$(X86_64_NM) -l $$^ > $$@)
443 endif
445 ifneq (,$(findstring arm,$(ARCHES)))
446 all: $(ARM_OUTDIR)/$(1)_arm.map
447 $(ARM_OUTDIR)/$(1)_arm.map: $(ARM_OUTDIR)/$(2)_arm.nexe
448 $(call LOG,MAP,$$@,$(ARM_NM) -l $$^ > $$@ )
449 endif
450 endef
454 # Top-level MAP Generation Macro
456 # $1 = Target Basename
457 # $2 = Source Basename
459 define MAP_RULE
460 $(call MAP_ALL_RULE,$(1),$(2))
461 endef
465 # NMF Manifiest generation
467 # Use the python script create_nmf to scan the binaries for dependencies using
468 # objdump. Pass in the (-L) paths to the default library toolchains so that we
469 # can find those libraries and have it automatically copy the files (-s) to
470 # the target directory for us.
472 # $1 = Target Name (the basename of the nmf
473 # $2 = Additional create_nmf.py arguments
475 NMF := python $(NACL_SDK_ROOT)/tools/create_nmf.py
476 ifeq ($(CONFIG),Debug)
477 NMF_FLAGS += --debug-libs
478 HTML_FLAGS += --debug-libs
479 endif
481 EXECUTABLES = $(GLIBC_SO_LIST)
482 ifneq (,$(findstring x86_32,$(ARCHES)))
483 EXECUTABLES += $(X86_32_OUTDIR)/$(1)_x86_32.nexe
484 endif
485 ifneq (,$(findstring x86_64,$(ARCHES)))
486 EXECUTABLES += $(X86_64_OUTDIR)/$(1)_x86_64.nexe
487 endif
488 ifneq (,$(findstring arm,$(ARCHES)))
489 EXECUTABLES += $(ARM_OUTDIR)/$(1)_arm.nexe
490 endif
492 ifneq (,$(MULTI_PLATFORM))
493 # When building a multi-platform package, stage all dependent shared libraries
494 # in the same directory as the .nexe (which will be an architecture-specific
495 # directory under _platform_specific).
496 NMF_FLAGS += -s $(OUTDIR) --no-arch-prefix
497 else
498 # Otherwise stage dependent libraries the normal way, under lib32 for x86_32
499 # libraries, and lib64 for x86_64 libraries.
500 NMF_FLAGS += -s $(OUTDIR)
501 endif
503 ifneq (,$(MULTI_PLATFORM))
504 # This script fixes the manifest.json file for this App to point to:
506 # <toolchain>/<config>/_platform_specific/<arch>/
508 # instead of
510 # _platform_specific/<arch>
511 FIX_MANIFEST := python $(NACL_SDK_ROOT)/tools/fix_manifest.py
512 MANIFEST_JSON ?= manifest.json
513 endif
515 define NMF_RULE
516 all: $(OUTDIR)/$(1).nmf
517 $(OUTDIR)/$(1).nmf $(MANIFEST_JSON): $(EXECUTABLES)
518 $(call LOG,CREATE_NMF,$$@,$(NMF) $(NMF_FLAGS) -o $$@ $$^ $(GLIBC_PATHS) $(2) $(GLIBC_REMAP))
519 ifneq (,$(MULTI_PLATFORM))
520 $(call LOG,FIX_MANIFEST,$(MANIFEST_JSON),$(FIX_MANIFEST) $(MANIFEST_JSON)) -p "$(TOOLCHAIN)/$(CONFIG)"
521 endif
522 endef
525 # HTML file generation
527 CREATE_HTML := python $(NACL_SDK_ROOT)/tools/create_html.py
529 define HTML_RULE
530 all: $(OUTDIR)/$(1).html
531 $(OUTDIR)/$(1).html: $(EXECUTABLES)
532 $(call LOG,CREATE_HTML,$$@,$(CREATE_HTML) $(HTML_FLAGS) -o $$@ $$^)
533 endef
537 # Determine which executable to pass into the debugger. For newlib
538 # this is the NEXE which will actually be used. For glibc, runnable-ld.so
539 # is the "app", and the "app" is actual an .so we load.
541 ifeq (x86_32,$(SYSARCH))
542 LIB_NAME = lib32
543 else
544 LIB_NAME = lib64
545 endif
548 ifeq (newlib,$(TOOLCHAIN))
549 GDB_DEBUG_TARGET = $(abspath $(OUTDIR))/$(TARGET)_$(SYSARCH).nexe
550 else
551 GDB_DEBUG_TARGET = $(abspath $(OUTDIR))/$(LIB_NAME)/runnable-ld.so
552 endif
554 ifdef STANDALONE
555 run: all
556 ifndef NACL_ARCH
557 $(error Cannot run in sel_ldr unless $$NACL_ARCH is set)
558 endif
559 $(SEL_LDR_PATH) $(SEL_LDR_ARGS) $(OUTDIR)/$(TARGET)_$(NACL_ARCH).nexe -- $(EXE_ARGS)
561 debug: all
562 ifndef NACL_ARCH
563 $(error Cannot run in sel_ldr unless $$NACL_ARCH is set)
564 endif
565 $(SEL_LDR_PATH) -d $(SEL_LDR_ARGS) $(OUTDIR)/$(TARGET)_$(NACL_ARCH).nexe -- $(EXE_ARGS)
566 endif