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
13 PNACL_CC
:= $(shell $(NACL_CONFIG
) -t
$(TOOLCHAIN
) --tool
=cc)
14 PNACL_CXX
:= $(shell $(NACL_CONFIG
) -t
$(TOOLCHAIN
) --tool
=c
++)
15 PNACL_LINK
:= $(shell $(NACL_CONFIG
) -t
$(TOOLCHAIN
) --tool
=c
++)
16 PNACL_LIB
:= $(shell $(NACL_CONFIG
) -t
$(TOOLCHAIN
) --tool
=ar)
17 PNACL_STRIP
:= $(shell $(NACL_CONFIG
) -t
$(TOOLCHAIN
) --tool
=strip)
18 PNACL_FINALIZE
:= $(shell $(NACL_CONFIG
) -t
$(TOOLCHAIN
) --tool
=finalize
)
19 PNACL_TRANSLATE
:= $(shell $(NACL_CONFIG
) -t
$(TOOLCHAIN
) --tool
=translate
)
26 # $3 = Include directories
28 define C_COMPILER_RULE
29 -include $(call SRC_TO_DEP
,$(1))
30 $(call SRC_TO_OBJ
,$(1)): $(1) $(TOP_MAKE
) |
$(dir $(call SRC_TO_OBJ
,$(1)))dir.stamp
31 $(call LOG
,CC
,$$@
,$(PNACL_CC
) -o
$$@
-c
$$< $(POSIX_CFLAGS
) $(NACL_CFLAGS
) $(CFLAGS
) $(2))
32 @
$(FIXDEPS
) $(call SRC_TO_DEP_PRE_FIXUP
,$(1))
35 define CXX_COMPILER_RULE
36 -include $(call SRC_TO_DEP
,$(1))
37 $(call SRC_TO_OBJ
,$(1)): $(1) $(TOP_MAKE
) |
$(dir $(call SRC_TO_OBJ
,$(1)))dir.stamp
38 $(call LOG
,CXX
,$$@
,$(PNACL_CXX
) -o
$$@
-c
$$< $(POSIX_CFLAGS
) $(NACL_CFLAGS
) $(CXXFLAGS
) $(2))
39 @
$(FIXDEPS
) $(call SRC_TO_DEP_PRE_FIXUP
,$(1))
44 # $2 = POSIX Compile Flags
45 # $3 = Include Directories
46 # $4 = VC Flags (unused)
48 ifeq ($(suffix $(1)),.c
)
49 $(call C_COMPILER_RULE
,$(1),$(2) $(foreach inc
,$(INC_PATHS
),-I
$(inc
)) $(3))
51 $(call CXX_COMPILER_RULE
,$(1),$(2) $(foreach inc
,$(INC_PATHS
),-I
$(inc
)) $(3))
60 # $2 = List of Sources
64 $(error
'Shared libraries not supported by PNaCl')
72 # $2 = List of Sources
73 # $3 = POSIX Link Flags
74 # $4 = VC Link Flags (unused)
76 $(STAMPDIR
)/$(1).stamp
: $(LIBDIR
)/$(TOOLCHAIN
)/$(CONFIG
)/lib
$(1).a
77 @echo
"TOUCHED $$@" > $(STAMPDIR
)/$(1).stamp
79 all: $(LIBDIR
)/$(TOOLCHAIN
)/$(CONFIG
)/lib
$(1).a
80 $(LIBDIR
)/$(TOOLCHAIN
)/$(CONFIG
)/lib
$(1).a
: $(foreach src
,$(2),$(call SRC_TO_OBJ
,$(src
)))
81 $(MKDIR
) -p
$$(dir $$@
)
83 $(call LOG
,LIB
,$$@
,$(PNACL_LIB
) -cr
$$@
$$^
$(3))
94 # $5 = List of lib dirs
95 # $6 = Other Linker Args
100 $(call LOG
,FINALIZE
,$$@
,$(PNACL_FINALIZE
) -o
$$@
$$^
)
102 $(1).bc
: $(2) $(foreach dep
,$(4),$(STAMPDIR
)/$(dep
).stamp
)
103 $(call LOG
,LINK
,$$@
,$(PNACL_LINK
) -o
$$@
$(2) $(PNACL_LDFLAGS
) $(LDFLAGS
) $(foreach path
,$(5),-L
$(path
)/pnacl
/$(CONFIG
)) $(foreach lib
,$(3),-l
$(lib
)) $(6))
105 $(1)_x86_32.nexe
: $(1).bc
106 $(call LOG
,TRANSLATE
,$$@
,$(PNACL_TRANSLATE
) --allow-llvm-bitcode-input
-arch x86-32
$$^
-o
$$@
)
108 $(1)_x86_64.nexe
: $(1).bc
109 $(call LOG
,TRANSLATE
,$$@
,$(PNACL_TRANSLATE
) --allow-llvm-bitcode-input
-arch x86-64
$$^
-o
$$@
)
111 $(1)_arm.nexe
: $(1).bc
112 $(call LOG
,TRANSLATE
,$$@
,$(PNACL_TRANSLATE
) --allow-llvm-bitcode-input
-arch arm
$$^
-o
$$@
)
117 # Generalized Link Macro
120 # $2 = List of Sources
123 # $5 = POSIX Linker Switches
124 # $6 = VC Linker Switches
127 $(call LINKER_RULE
,$(OUTDIR
)/$(1),$(foreach src
,$(2),$(call SRC_TO_OBJ
,$(src
))),$(filter-out pthread
,$(3)),$(4),$(LIB_PATHS
),$(5))
134 # NOTE: pnacl-strip does not really do much for finalized pexes (in a
135 # sense, they are already stripped), but set this rule up for uniformity.
141 all: $(OUTDIR
)/$(1).pexe
142 $(OUTDIR
)/$(1).pexe
: $(OUTDIR
)/$(2).pexe
143 $(call LOG
,STRIP
,$$@
,$(PNACL_STRIP
) $$^
-o
$$@
)
145 $(OUTDIR
)/$(1)_x86_32.nexe
: $(OUTDIR
)/$(2)_x86_32.nexe
146 $(call LOG
,STRIP
,$$@
,$(PNACL_STRIP
) $$^
-o
$$@
)
148 $(OUTDIR
)/$(1)_x86_64.nexe
: $(OUTDIR
)/$(2)_x86_64.nexe
149 $(call LOG
,STRIP
,$$@
,$(PNACL_STRIP
) $$^
-o
$$@
)
151 $(OUTDIR
)/$(1)_arm.nexe
: $(OUTDIR
)/$(2)_arm.nexe
152 $(call LOG
,STRIP
,$$@
,$(PNACL_STRIP
) $$^
-o
$$@
)
157 # NMF Manifest generation
159 # Use the python script create_nmf to scan the binaries for dependencies using
160 # objdump. Pass in the (-L) paths to the default library toolchains so that we
161 # can find those libraries and have it automatically copy the files (-s) to
162 # the target directory for us.
164 # $1 = Target Name (the basename of the nmf)
165 # $2 = Additional create_nmf.py arguments
167 NMF
:=python
$(NACL_SDK_ROOT
)/tools
/create_nmf.py
169 EXECUTABLES
=$(OUTDIR
)/$(1).pexe
$(OUTDIR
)/$(1)_unstripped.bc
172 all: $(OUTDIR
)/$(1).nmf
173 $(OUTDIR
)/$(1).nmf
: $(EXECUTABLES
)
174 $(call LOG
,CREATE_NMF
,$$@
,$(NMF
) -o
$$@
$$^
-s
$(OUTDIR
) $(2))
178 # HTML file generation
180 CREATE_HTML
:= python
$(NACL_SDK_ROOT
)/tools
/create_html.py
183 all: $(OUTDIR
)/$(1).html
184 $(OUTDIR
)/$(1).html
: $(EXECUTABLES
)
185 $(call LOG
,CREATE_HTML
,$$@
,$(CREATE_HTML
) -o
$$@
$$^
)
190 run
: $(OUTDIR
)/$(TARGET
)_
$(NACL_ARCH
).nexe
192 $(error Cannot run in sel_ldr unless
$$NACL_ARCH is set
)
194 $(SEL_LDR_PATH
) $(SEL_LDR_ARGS
) $(OUTDIR
)/$(TARGET
)_
$(NACL_ARCH
).nexe
-- $(EXE_ARGS
)
196 debug
: $(OUTDIR
)/$(TARGET
)_
$(NACL_ARCH
).nexe
198 $(error Cannot run in sel_ldr unless
$$NACL_ARCH is set
)
200 $(SEL_LDR_PATH
) -d
$(SEL_LDR_ARGS
) $(OUTDIR
)/$(TARGET
)_
$(NACL_ARCH
).nexe
-- $(EXE_ARGS
)