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
16 LD_X86_32
:=-L
$(NACL_SDK_ROOT
)/lib
/$(TOOLCHAIN
)_x86_32
/$(CONFIG
)
17 LD_X86_64
:=-L
$(NACL_SDK_ROOT
)/lib
/$(TOOLCHAIN
)_x86_64
/$(CONFIG
)
18 LD_ARM
:=-L
$(NACL_SDK_ROOT
)/lib
/$(TOOLCHAIN
)_arm
/$(CONFIG
)
24 # We use the C++ compiler for everything and then use the -Wl,-as-needed flag
25 # in the linker to drop libc++ unless it's actually needed.
27 X86_CC?
=$(TC_PATH
)/$(OSNAME
)_x86_
$(TOOLCHAIN
)/bin
/i686-nacl-gcc
28 X86_CXX?
=$(TC_PATH
)/$(OSNAME
)_x86_
$(TOOLCHAIN
)/bin
/i686-nacl-g
++
29 X86_LINK?
=$(TC_PATH
)/$(OSNAME
)_x86_
$(TOOLCHAIN
)/bin
/i686-nacl-g
++ -Wl
,-as-needed
30 X86_LIB?
=$(TC_PATH
)/$(OSNAME
)_x86_
$(TOOLCHAIN
)/bin
/i686-nacl-ar r
32 ARM_CC?
=$(TC_PATH
)/$(OSNAME
)_arm_
$(TOOLCHAIN
)/bin
/arm-nacl-gcc
33 ARM_CXX?
=$(TC_PATH
)/$(OSNAME
)_arm_
$(TOOLCHAIN
)/bin
/arm-nacl-g
++
34 ARM_LINK?
=$(TC_PATH
)/$(OSNAME
)_arm_
$(TOOLCHAIN
)/bin
/arm-nacl-g
++ -Wl
,-as-needed
35 ARM_LIB?
=$(TC_PATH
)/$(OSNAME
)_arm_
$(TOOLCHAIN
)/bin
/arm-nacl-ar r
44 define C_COMPILER_RULE
45 $(OUTDIR
)/$(basename $(1))_x86_32.o
: $(1) $(TOP_MAKE
) |
$(OUTDIR
)
46 $(X86_CC
) -o
$$@
-c
$$< -m32
$(POSIX_FLAGS
) $(2) $(NACL_CFLAGS
)
48 $(OUTDIR
)/$(basename $(1))_x86_64.o
: $(1) $(TOP_MAKE
) |
$(OUTDIR
)
49 $(X86_CC
) -o
$$@
-c
$$< -m64
$(POSIX_FLAGS
) $(2) $(NACL_CFLAGS
)
51 $(OUTDIR
)/$(basename $(1))_arm.o
: $(1) $(TOP_MAKE
) |
$(OUTDIR
)
52 $(ARM_CC
) -o
$$@
-c
$$< $(POSIX_FLAGS
) $(2) $(NACL_CFLAGS
)
55 define CXX_COMPILER_RULE
56 $(OUTDIR
)/$(basename $(1))_x86_32.o
: $(1) $(TOP_MAKE
) |
$(OUTDIR
)
57 $(X86_CXX
) -o
$$@
-c
$$< -m32
$(POSIX_FLAGS
) $(2) $(NACL_CXXFLAGS
)
59 $(OUTDIR
)/$(basename $(1))_x86_64.o
: $(1) $(TOP_MAKE
) |
$(OUTDIR
)
60 $(X86_CXX
) -o
$$@
-c
$$< -m64
$(POSIX_FLAGS
) $(2) $(NACL_CXXFLAGS
)
62 $(OUTDIR
)/$(basename $(1))_arm.o
: $(1) $(TOP_MAKE
) |
$(OUTDIR
)
63 $(ARM_CXX
) -o
$$@
-c
$$< $(POSIX_FLAGS
) $(2) $(NACL_CXXFLAGS
)
69 # $2 = POSIX Compile Flags
70 # $3 = Include Directories
71 # $4 = VC Flags (unused)
74 ifeq ('.c','$(suffix $(1))')
75 $(call C_COMPILER_RULE
,$(1),$(2) $(foreach inc
,$(INC_PATHS
),-I
$(inc
)) $(3))
77 $(call CXX_COMPILER_RULE
,$(1),$(2) $(foreach inc
,$(INC_PATHS
),-I
$(inc
)) $(3))
86 # $2 = List of Sources
91 NMF_TARGETS
+=$$(OUTDIR
)/$(1)_x86_32.so
92 $(OUTDIR
)/$(1)_x86_32.so
: $(foreach src
,$(2),$(OUTDIR
)/$(basename $(src
))_x86_32.o
) $(4)
93 $(X86_LINK
) -o
$$@
$$(filter-out $(4),$$^
) -shared
-m32
$$(LD_X86_32
) $$(LD_FLAGS
) $(foreach lib
,$(3),-l
$(lib
))
95 NMF_TARGETS
+=$(OUTDIR
)/$(1)_x86_64.so
96 $(OUTDIR
)/$(1)_x86_64.so
: $(foreach src
,$(2),$$(OUTDIR
)/$(basename $(src
))_x86_64.o
) $(4)
97 $(X86_LINK
) -o
$$@
$$(filter-out $(4),$$^
) -shared
-m64
$(LD_X86_64
) $$(LD_FLAGS
) $(foreach lib
,$(3),-l
$(lib
))
99 GLIBC_SO_LIST
+=$(OUTDIR
)/$(1)_x86_32.so
$(OUTDIR
)/$(1)_x86_64.so
100 GLIBC_REMAP
+=-n
$(1)_x86_32.so
,$(1).so
101 GLIBC_REMAP
+=-n
$(1)_x86_64.so
,$(1).so
109 # $2 = List of Sources
110 # $3 = POSIX Link Flags
111 # $4 = VC Link Flags (unused)
114 all: $(NACL_SDK_ROOT
)/lib
/$(TOOLCHAIN
)_x86_32
/$(CONFIG
)/lib
$(1).a
115 $(NACL_SDK_ROOT
)/lib
/$(TOOLCHAIN
)_x86_32
/$(CONFIG
)/lib
$(1).a
: $(foreach src
,$(2),$(OUTDIR
)/$(basename $(src
))_x86_32.o
)
116 $(MKDIR
) -p
$$(dir $$@
)
119 all: $(NACL_SDK_ROOT
)/lib
/$(TOOLCHAIN
)_x86_64
/$(CONFIG
)/lib
$(1).a
120 $(NACL_SDK_ROOT
)/lib
/$(TOOLCHAIN
)_x86_64
/$(CONFIG
)/lib
$(1).a
: $(foreach src
,$(2),$(OUTDIR
)/$(basename $(src
))_x86_64.o
)
121 $(MKDIR
) -p
$$(dir $$@
)
124 ifneq ('glibc','$(TOOLCHAIN)')
125 all: $(NACL_SDK_ROOT
)/lib
/$(TOOLCHAIN
)_arm
/$(CONFIG
)/lib
$(1).a
127 $(NACL_SDK_ROOT
)/lib
/$(TOOLCHAIN
)_arm
/$(CONFIG
)/lib
$(1).a
: $(foreach src
,$(2),$(OUTDIR
)/$(basename $(src
))_arm.o
)
128 $(MKDIR
) -p
$$(dir $$@
)
134 # Specific Link Macro
137 # $2 = List of Sources
140 # $5 = POSIX Link Flags
144 $(OUTDIR
)/$(1)_x86_32.nexe
: $(foreach src
,$(2),$(OUTDIR
)/$(basename $(src
))_x86_32.o
) $(4)
145 $(X86_LINK
) -o
$$@
$$(filter-out $(4),$$^
) -m32
$(foreach path
,$(6),-L
$(path
)/$(TOOLCHAIN
)_x86_32
/$(CONFIG
)) $(foreach lib
,$(3),-l
$(lib
)) $(5)
147 $(OUTDIR
)/$(1)_x86_64.nexe
: $(foreach src
,$(2),$$(OUTDIR
)/$(basename $(src
))_x86_64.o
) $(4)
148 $(X86_LINK
) -o
$$@
$$(filter-out $(4),$$^
) -m64
$(foreach path
,$(6),-L
$(path
)/$(TOOLCHAIN
)_x86_64
/$(CONFIG
)) $(foreach lib
,$(3),-l
$(lib
)) $(5)
150 $(OUTDIR
)/$(1)_arm.nexe
: $(foreach src
,$(2),$(OUTDIR
)/$(basename $(src
))_arm.o
) $(4)
151 $(ARM_LINK
) -o
$$@
$$(filter-out $(4),$$^
) $(foreach path
,$(6),-L
$(path
)/$(TOOLCHAIN
)_arm
/$(CONFIG
)) $(foreach lib
,$(3),-l
$(lib
)) $(5)
156 # Generalized Link Macro
159 # $2 = List of Sources
162 # $5 = POSIX Linker Switches
163 # $6 = VC Linker Switches
166 $(call LINKER_RULE
,$(1),$(2),$(filter-out pthread
,$(3)),$(4),$(5),$(LIB_PATHS
))
171 # Generate NMF_TARGETS
174 ifeq "newlib" "$(TOOLCHAIN)"
177 NMF_ARCHES
:=$(foreach arch
,$(ARCHES
),_
$(arch
).nexe
)
181 # NMF Manifiest generation
183 # Use the python script create_nmf to scan the binaries for dependencies using
184 # objdump. Pass in the (-L) paths to the default library toolchains so that we
185 # can find those libraries and have it automatically copy the files (-s) to
186 # the target directory for us.
188 # $1 = Target Name (the basename of the nmf
189 # $2 = Additional create_nmf.py arguments
191 NMF
:=python
$(NACL_SDK_ROOT
)/tools
/create_nmf.py
192 GLIBC_DUMP
:=$(TC_PATH
)/$(OSNAME
)_x86_glibc
/x86_64-nacl
/bin
/objdump
193 GLIBC_PATHS
:=-L
$(TC_PATH
)/$(OSNAME
)_x86_glibc
/x86_64-nacl
/lib32
194 GLIBC_PATHS
+=-L
$(TC_PATH
)/$(OSNAME
)_x86_glibc
/x86_64-nacl
/lib
197 all:$(OUTDIR
)/$(1).nmf
198 $(OUTDIR
)/$(1).nmf
: $(foreach arch
,$(NMF_ARCHES
),$(OUTDIR
)/$(1)$(arch
)) $(GLIBC_SO_LIST
)
199 $(NMF
) -o
$$@
$$^
-D
$(GLIBC_DUMP
) $(GLIBC_PATHS
) -s
$(OUTDIR
) $(2) $(GLIBC_REMAP
)