• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5#
6# GNU Make based build file.  For details on GNU Make see:
7#   http://www.gnu.org/software/make/manual/make.html
8#
9
10#
11# Macros for TOOLS
12#
13ifneq ($(TOOLCHAIN),bionic)
14X86_32_CC := $(NACL_COMPILER_PREFIX) $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_32 --tool=cc)
15X86_32_CXX := $(NACL_COMPILER_PREFIX) $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_32 --tool=c++)
16X86_32_LINK := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_32 --tool=c++)
17X86_32_LIB := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_32 --tool=ar)
18X86_32_STRIP := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_32 --tool=strip)
19X86_32_NM := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_32 --tool=nm)
20
21X86_64_CC := $(NACL_COMPILER_PREFIX) $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_64 --tool=cc)
22X86_64_CXX := $(NACL_COMPILER_PREFIX) $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_64 --tool=c++)
23X86_64_LINK := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_64 --tool=c++)
24X86_64_LIB := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_64 --tool=ar)
25X86_64_STRIP := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_64 --tool=strip)
26X86_64_NM := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a x86_64 --tool=nm)
27endif
28
29ifeq (,$(findstring $(TOOLCHAIN),glibc))
30ARM_CC := $(NACL_COMPILER_PREFIX) $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=cc)
31ARM_CXX := $(NACL_COMPILER_PREFIX) $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=c++)
32ARM_LINK := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=c++)
33ARM_LIB := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=ar)
34ARM_STRIP := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=strip)
35ARM_NM := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) -a arm --tool=nm)
36endif
37
38NCVAL ?= python $(NACL_SDK_ROOT)/tools/ncval.py
39
40# Architecture-specific variables
41ifeq (,$(MULTI_PLATFORM))
42X86_32_OUTDIR ?= $(OUTDIR)
43X86_64_OUTDIR ?= $(OUTDIR)
44ARM_OUTDIR ?= $(OUTDIR)
45else
46X86_32_OUTDIR ?= $(OUTDIR)/_platform_specific/x86-32
47X86_64_OUTDIR ?= $(OUTDIR)/_platform_specific/x86-64
48ARM_OUTDIR ?= $(OUTDIR)/_platform_specific/arm
49endif
50
51# Architecture-specific flags
52X86_32_CFLAGS ?=
53X86_64_CFLAGS ?=
54X86_32_CXXFLAGS ?=
55X86_64_CXXFLAGS ?=
56
57# Use DWARF v3 which is more commonly available when debugging
58ifeq ($(CONFIG),Debug)
59ARM_CFLAGS ?= -gdwarf-3
60ARM_CXXFLAGS ?= -gdwarf-3
61else
62ARM_CFLAGS ?=
63ARM_CXXFLAGS ?=
64endif
65
66ifeq (,$(MULTI_PLATFORM))
67X86_32_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_x86_32.map
68X86_64_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_x86_64.map
69ARM_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_arm.map
70else
71X86_32_LDFLAGS ?= -Wl,-Map,$(X86_32_OUTDIR)/$(TARGET)_x86_32.map
72X86_64_LDFLAGS ?= -Wl,-Map,$(X86_64_OUTDIR)/$(TARGET)_x86_64.map
73ARM_LDFLAGS ?= -Wl,-Map,$(ARM_OUTDIR)/$(TARGET)_arm.map
74endif
75
76#
77# Choose between static and dynamic linking for Bionic
78# (Default to dynamic)
79#
80ifeq ($(TOOLCHAIN),bionic)
81ifeq (,$(BIONIC_USE_DYNAMIC))
82BIONIC_LINK:=-static
83else
84BIONIC_LINK:=-Wl,-Ttext-segment=0x100000
85endif
86endif
87
88LDFLAGS_SHARED = -shared
89
90#
91# Compile Macro
92#
93# $1 = Source Name
94# $2 = Compile Flags
95#
96define 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)
101
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)
106
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)
111
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)
116
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)
121
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)
126endef
127
128define 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)
133
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)
138
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)
143
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)
148
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)
153
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)
158endef
159
160
161#
162# $1 = Source Name
163# $2 = POSIX Compile Flags
164# $3 = Include Directories
165# $4 = VC Flags (unused)
166#
167define COMPILE_RULE
168ifeq ($(suffix $(1)),.c)
169$(call C_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc)) $(3))
170else
171$(call CXX_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc)) $(3))
172endif
173endef
174
175#
176# Determine which architectures to build for.  The user can set NACL_ARCH or
177# ARCHES in the environment to control this.
178#
179ifneq ($(TOOLCHAIN),bionic)
180VALID_ARCHES := x86_32 x86_64
181endif
182ifneq (glibc,$(TOOLCHAIN))
183VALID_ARCHES += arm
184endif
185
186ifdef NACL_ARCH
187ifeq (,$(findstring $(NACL_ARCH),$(VALID_ARCHES)))
188$(error Invalid arch specified in NACL_ARCH: $(NACL_ARCH).  Valid values are: $(VALID_ARCHES))
189endif
190ARCHES = ${NACL_ARCH}
191else
192ARCHES ?= ${VALID_ARCHES}
193endif
194
195GLIBC_REMAP :=
196
197#
198# SO Macro
199#
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.
204#
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.
211#
212define SO_LINKER_RULE
213ifneq (,$(findstring x86_32,$(ARCHES)))
214all: $(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) $$@)
219
220$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so
221install: $(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 $$^ $$@)
225ifneq ($(6),1)
226GLIBC_SO_LIST += $(X86_32_OUTDIR)/lib$(1)_x86_32.so
227GLIBC_REMAP += -n lib$(1)_x86_32.so,lib$(1).so
228endif
229endif
230
231ifneq (,$(findstring x86_64,$(ARCHES)))
232all: $(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) $$@)
237
238$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so
239install: $(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 $$^ $$@)
243ifneq ($(6),1)
244GLIBC_SO_LIST += $(X86_64_OUTDIR)/lib$(1)_x86_64.so
245GLIBC_REMAP += -n lib$(1)_x86_64.so,lib$(1).so
246endif
247endif
248
249ifneq (,$(findstring arm,$(ARCHES)))
250all: $(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) $$@)
255
256$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).so
257install: $(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 $$^ $$@)
261ifneq ($(6),1)
262GLIBC_SO_LIST += $(ARM_OUTDIR)/lib$(1)_arm.so
263GLIBC_REMAP += -n lib$(1)_arm.so,lib$(1).so
264endif
265endif
266endef
267
268#
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.
274#
275define SO_RULE
276$(call SO_LINKER_RULE,$(1),$(2),$(filter-out pthread,$(3)),$(4),$(LIB_PATHS),$(5))
277endef
278
279#
280# LIB Macro
281#
282# $1 = Target Name
283# $2 = List of Sources
284# $3 = POSIX Link Flags
285# $4 = VC Link Flags (unused)
286#
287define LIB_RULE
288$(STAMPDIR)/$(1).stamp:
289	@echo "  STAMP $$@"
290	@echo "TOUCHED $$@" > $(STAMPDIR)/$(1).stamp
291
292ifneq (,$(findstring x86_32,$(ARCHES)))
293all: $(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 $$@ $$^)
298
299$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).a
300install: $(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 $$^ $$@)
305endif
306
307ifneq (,$(findstring x86_64,$(ARCHES)))
308all: $(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 $$@ $$^)
313
314$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).a
315install: $(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 $$^ $$@)
319endif
320
321ifneq (,$(findstring arm,$(ARCHES)))
322ifneq ($(TOOLCHAIN),glibc)
323all: $(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 $$@ $$^)
328
329$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).a
330install: $(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 $$^ $$@)
334endif
335endif
336endef
337
338
339#
340# Specific Link Macro
341#
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
348#
349define LINKER_RULE
350ifneq (,$(findstring x86_32,$(ARCHES)))
351all: $(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) $$@)
356endif
357
358ifneq (,$(findstring x86_64,$(ARCHES)))
359all: $(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) $$@)
364endif
365
366ifneq (,$(findstring arm,$(ARCHES)))
367all: $(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) $$@)
372endif
373endef
374
375
376#
377# Generalized Link Macro
378#
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
385#
386define LINK_RULE
387$(call LINKER_RULE,$(1),$(2),$(filter-out pthread,$(3)),$(4),$(5),$(LIB_PATHS))
388endef
389
390
391#
392# Strip Macro for each arch (e.g., each arch supported by LINKER_RULE).
393#
394# $1 = Target Name
395# $2 = Source Name
396#
397define STRIP_ALL_RULE
398ifneq (,$(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 $$@ $$^)
401endif
402
403ifneq (,$(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 $$@ $$^)
406endif
407
408ifneq (,$(findstring arm,$(ARCHES)))
409$(ARM_OUTDIR)/$(1)_arm.nexe: $(ARM_OUTDIR)/$(2)_arm.nexe
410	$(call LOG,STRIP,$$@,$(ARM_STRIP) -o $$@ $$^)
411endif
412endef
413
414
415#
416# Top-level Strip Macro
417#
418# $1 = Target Basename
419# $2 = Source Basename
420#
421define STRIP_RULE
422$(call STRIP_ALL_RULE,$(1),$(2))
423endef
424
425
426#
427# Strip Macro for each arch (e.g., each arch supported by MAP_RULE).
428#
429# $1 = Target Name
430# $2 = Source Name
431#
432define MAP_ALL_RULE
433ifneq (,$(findstring x86_32,$(ARCHES)))
434all: $(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 $$^ > $$@)
437endif
438
439ifneq (,$(findstring x86_64,$(ARCHES)))
440all: $(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 $$^ > $$@)
443endif
444
445ifneq (,$(findstring arm,$(ARCHES)))
446all: $(ARM_OUTDIR)/$(1)_arm.map
447$(ARM_OUTDIR)/$(1)_arm.map: $(ARM_OUTDIR)/$(2)_arm.nexe
448	$(call LOG,MAP,$$@,$(ARM_NM) -l $$^ > $$@ )
449endif
450endef
451
452
453#
454# Top-level MAP Generation Macro
455#
456# $1 = Target Basename
457# $2 = Source Basename
458#
459define MAP_RULE
460$(call MAP_ALL_RULE,$(1),$(2))
461endef
462
463
464#
465# NMF Manifiest generation
466#
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.
471#
472# $1 = Target Name (the basename of the nmf
473# $2 = Additional create_nmf.py arguments
474#
475NMF := python $(NACL_SDK_ROOT)/tools/create_nmf.py
476ifeq ($(CONFIG),Debug)
477NMF_FLAGS += --debug-libs
478HTML_FLAGS += --debug-libs
479endif
480
481EXECUTABLES = $(GLIBC_SO_LIST)
482ifneq (,$(findstring x86_32,$(ARCHES)))
483EXECUTABLES += $(X86_32_OUTDIR)/$(1)_x86_32.nexe
484endif
485ifneq (,$(findstring x86_64,$(ARCHES)))
486EXECUTABLES += $(X86_64_OUTDIR)/$(1)_x86_64.nexe
487endif
488ifneq (,$(findstring arm,$(ARCHES)))
489EXECUTABLES += $(ARM_OUTDIR)/$(1)_arm.nexe
490endif
491
492ifneq (,$(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).
496NMF_FLAGS += -s $(OUTDIR) --no-arch-prefix
497else
498# Otherwise stage dependent libraries the normal way, under lib32 for x86_32
499# libraries, and lib64 for x86_64 libraries.
500NMF_FLAGS += -s $(OUTDIR)
501endif
502
503ifneq (,$(MULTI_PLATFORM))
504# This script fixes the manifest.json file for this App to point to:
505#
506#   <toolchain>/<config>/_platform_specific/<arch>/
507#
508# instead of
509#
510#   _platform_specific/<arch>
511FIX_MANIFEST := python $(NACL_SDK_ROOT)/tools/fix_manifest.py
512MANIFEST_JSON ?= manifest.json
513endif
514
515define NMF_RULE
516all: $(OUTDIR)/$(1).nmf
517$(OUTDIR)/$(1).nmf $(MANIFEST_JSON): $(EXECUTABLES)
518	$(call LOG,CREATE_NMF,$$@,$(NMF) $(NMF_FLAGS) -o $$@ $$^ $(GLIBC_PATHS) $(2) $(GLIBC_REMAP))
519ifneq (,$(MULTI_PLATFORM))
520	$(call LOG,FIX_MANIFEST,$(MANIFEST_JSON),$(FIX_MANIFEST) $(MANIFEST_JSON)) -p "$(TOOLCHAIN)/$(CONFIG)"
521endif
522endef
523
524#
525# HTML file generation
526#
527CREATE_HTML := python $(NACL_SDK_ROOT)/tools/create_html.py
528
529define HTML_RULE
530all: $(OUTDIR)/$(1).html
531$(OUTDIR)/$(1).html: $(EXECUTABLES)
532	$(call LOG,CREATE_HTML,$$@,$(CREATE_HTML) $(HTML_FLAGS) -o $$@ $$^)
533endef
534
535
536#
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.
540#
541ifeq (x86_32,$(SYSARCH))
542LIB_NAME = lib32
543else
544LIB_NAME = lib64
545endif
546
547
548ifeq (newlib,$(TOOLCHAIN))
549GDB_DEBUG_TARGET = $(abspath $(OUTDIR))/$(TARGET)_$(SYSARCH).nexe
550else
551GDB_DEBUG_TARGET = $(abspath $(OUTDIR))/$(LIB_NAME)/runnable-ld.so
552endif
553
554ifdef STANDALONE
555run: all
556ifndef NACL_ARCH
557	$(error Cannot run in sel_ldr unless $$NACL_ARCH is set)
558endif
559	$(SEL_LDR_PATH) $(SEL_LDR_ARGS) $(OUTDIR)/$(TARGET)_$(NACL_ARCH).nexe -- $(EXE_ARGS)
560
561debug: all
562ifndef NACL_ARCH
563	$(error Cannot run in sel_ldr unless $$NACL_ARCH is set)
564endif
565	$(SEL_LDR_PATH) -d $(SEL_LDR_ARGS) $(OUTDIR)/$(TARGET)_$(NACL_ARCH).nexe -- $(EXE_ARGS)
566endif
567