Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: native_client_sdk/src/tools/common.mk

Issue 11882012: Convert all project to use common.mk (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 # 5 #
6 # GNU Make based build file. For details on GNU Make see: 6 # GNU Make based build file. For details on GNU Make see:
7 # http://www.gnu.org/software/make/manual/make.html 7 # http://www.gnu.org/software/make/manual/make.html
8 # 8 #
9 # 9 #
10 10
11 # 11 #
12 # Toolchain 12 # Toolchain
13 # 13 #
14 # This makefile is designed to work with the NEWLIB toolchain which is 14 # This makefile is designed to work with the NEWLIB toolchain which is
15 # currently supported by x86 and ARM. To switch to glibc, you would need 15 # currently supported by x86 and ARM. To switch to glibc, you would need
16 # to drop support for ARM. 16 # to drop support for ARM.
17 # 17 #
18 TOOLCHAIN?=newlib 18 VALID_TOOLCHAINS?=newlib
19 TOOLCHAIN?=$(word 1,$(VALID_TOOLCHAINS))
20
21
22 #
23 # Top Make file, which we want to trigger a rebuild on if it changes
24 #
25 TOP_MAKE:=$(word 1,$(MAKEFILE_LIST))
26
27
28 #
29 # Verify we selected a valid toolchain for this example
30 #
31 ifeq (,$(findstring $(TOOLCHAIN),$(VALID_TOOLCHAINS)))
32 $(warning Availbile choices are: $(VALID_TOOLCHAINS))
33 $(error Can not use TOOLCHAIN=$(TOOLCHAIN) on this example.)
34 endif
35
19 36
20 # 37 #
21 # Build Configuration 38 # Build Configuration
22 # 39 #
23 # The SDK provides two sets of libraries, Debug and Release. Debug libraries 40 # The SDK provides two sets of libraries, Debug and Release. Debug libraries
24 # are compiled without optimizations to make debugging easier. By default 41 # are compiled without optimizations to make debugging easier. By default
25 # this will build a Debug configuration. 42 # this will build a Debug configuration.
26 # 43 #
27 CONFIG?=Debug 44 CONFIG?=Debug
28 45
29 46
47
30 # Note for Windows: 48 # Note for Windows:
31 # Both GCC and LLVM bases tools (include the version of Make.exe that comes 49 # Both GCC and LLVM bases tools (include the version of Make.exe that comes
32 # with the SDK) both expect and are capable of dealing with the '/' seperator. 50 # with the SDK) both expect and are capable of dealing with the '/' seperator.
33 # For that reason, the tools in the SDK, including build, compilers, scripts 51 # For that reason, the tools in the SDK, including build, compilers, scripts
34 # all have a preference for POSIX style command-line arguments. 52 # all have a preference for POSIX style command-line arguments.
35 # 53 #
36 # Keep in mind however that the shell is responsible for command-line escaping, 54 # Keep in mind however that the shell is responsible for command-line escaping,
37 # globbing, and variable expansion, so those may change based on which shell 55 # globbing, and variable expansion, so those may change based on which shell
38 # is used. For Cygwin shells this can include automatic and incorrect expansion 56 # is used. For Cygwin shells this can include automatic and incorrect expansion
39 # of response files (files starting with '@'). 57 # of response files (files starting with '@').
40 # 58 #
41
42 # Disable DOS PATH warning when using Cygwin based NaCl tools on Windows. 59 # Disable DOS PATH warning when using Cygwin based NaCl tools on Windows.
43 # 60 #
44 CYGWIN?=nodosfilewarning 61 CYGWIN?=nodosfilewarning
45 export CYGWIN 62 export CYGWIN
46 63
47 64
48 # 65 #
49 # Get pepper directory for toolchain and includes. 66 # Alias for standard POSIX file system commands
50 # 67 #
51 # If NACL_SDK_ROOT is not set, then assume it can be found a two directories up, 68 CP:=python $(NACL_SDK_ROOT)/tools/oshelpers.py cp
52 # from the default example directory location. 69 MKDIR:=python $(NACL_SDK_ROOT)/tools/oshelpers.py mkdir
53 # 70 MV:=python $(NACL_SDK_ROOT)/tools/oshelpers.py mv
54 THIS_MAKEFILE:=$(abspath $(lastword $(MAKEFILE_LIST))) 71 RM:=python $(NACL_SDK_ROOT)/tools/oshelpers.py rm
55 THIS_DIR:=$(abspath $(dir $(THIS_MAKEFILE)))
56 NACL_SDK_ROOT?=$(abspath $(dir $(THIS_MAKEFILE))../..)
57 72
58 73
59 # 74 #
60 # Defaults build flags
61 #
62 # Convert warnings to errors, and build with no optimization.
63 #
64 NACL_WARNINGS:=-Wno-long-long -Werror
65 OPT_FLAGS:=-g -O0
66 CXX_FLAGS:=-pthread -I$(NACL_SDK_ROOT)/include
67 LD_FLAGS:=-pthread
68
69
70 #
71 # Library Paths
72 #
73 # Libraries are stored in different directories for each achitecture as well
74 # as different subdirectories for Debug vs Release configurations. This make
75 # only supports the Debug configuration for simplicity.
76 #
77 # By default for x86 32 bit this expands to:
78 # $(NACL_SDK_ROOT)/lib/newlib_x86_32/Debug
79 #
80 LD_X86_32:=-L$(NACL_SDK_ROOT)/lib/$(TOOLCHAIN)_x86_32/$(CONFIG)
81 LD_X86_64:=-L$(NACL_SDK_ROOT)/lib/$(TOOLCHAIN)_x86_64/$(CONFIG)
82 LD_ARM:=-L$(NACL_SDK_ROOT)/lib/$(TOOLCHAIN)_arm/$(CONFIG)
83
84
85 #
86 # Compute path to requested NaCl Toolchain 75 # Compute path to requested NaCl Toolchain
87 # 76 #
88 OSNAME:=$(shell python $(NACL_SDK_ROOT)/tools/getos.py) 77 OSNAME:=$(shell python $(NACL_SDK_ROOT)/tools/getos.py)
89 TC_PATH:=$(abspath $(NACL_SDK_ROOT)/toolchain) 78 TC_PATH:=$(abspath $(NACL_SDK_ROOT)/toolchain)
90 79
91 80
92 #
93 # Alias for standard POSIX file system commands
94 #
95 CP:=python $(NACL_SDK_ROOT)/tools/oshelpers.py cp
96 MKDIR:=python $(NACL_SDK_ROOT)/tools/oshelpers.py mkdir
97 MV:=python $(NACL_SDK_ROOT)/tools/oshelpers.py mv
98 RM:=python $(NACL_SDK_ROOT)/tools/oshelpers.py rm
99 81
100 82
101 # 83 #
102 # The default target 84 # The default target
103 # 85 #
104 # If no targets are specified on the command-line, the first target listed in 86 # If no targets are specified on the command-line, the first target listed in
105 # the makefile becomes the default target. By convention this is usually called 87 # the makefile becomes the default target. By convention this is usually called
106 # the 'all' target. Here we leave it blank to be first, but define it later 88 # the 'all' target. Here we leave it blank to be first, but define it later
107 # 89 #
108 all: 90 all:
109 91
110 92
111 # 93 #
94 # Target a toolchain
95 #
96 # $1 = Toolchain Name
97 #
98 define TOOLCHAIN_RULE
99 .PHONY: all_$(1)
100 all_$(1):
101 +$(MAKE) TOOLCHAIN=$(1)
102 TOOLCHAIN_LIST+=all_$(1)
103 endef
104
105
106 #
107 # The target for all versions
108 #
109 USABLE_TOOLCHAINS=$(filter $(OSNAME) newlib glibc pnacl,$(VALID_TOOLCHAINS))
110 $(foreach tool,$(USABLE_TOOLCHAINS),$(eval $(call TOOLCHAIN_RULE,$(tool),$(dep)) ))
111 all_versions: $(TOOLCHAIN_LIST)
112
113 #
112 # Target to remove temporary files 114 # Target to remove temporary files
113 # 115 #
114 .PHONY: clean 116 .PHONY: clean
115 clean: 117 clean:
116 $(RM) $(TARGET).nmf 118 $(RM) $(TARGET).nmf
117 $(RM) -fr $(TOOLCHAIN) 119 $(RM) -fr $(TOOLCHAIN)
118 120
119 #
120 # Macros for TOOLS
121 #
122 # We use the C++ compiler for everything and then use the -Wl,-as-needed flag
123 # in the linker to drop libc++ unless it's actually needed.
124 #
125 X86_CXX?=$(TC_PATH)/$(OSNAME)_x86_$(TOOLCHAIN)/bin/i686-nacl-g++
126 X86_LINK?=$(TC_PATH)/$(OSNAME)_x86_$(TOOLCHAIN)/bin/i686-nacl-g++ -Wl,-as-needed
127
128 ARM_CXX?=$(TC_PATH)/$(OSNAME)_arm_$(TOOLCHAIN)/bin/arm-nacl-g++
129 ARM_LINK?=$(TC_PATH)/$(OSNAME)_arm_$(TOOLCHAIN)/bin/arm-nacl-g++ -Wl,-as-needed
130
131 PNACL_CXX?=$(TC_PATH)/$(OSNAME)_x86_$(TOOLCHAIN)/newlib/bin/pnacl-clang++ -c
132 PNACL_LINK?=$(TC_PATH)/$(OSNAME)_x86_$(TOOLCHAIN)/newlib/bin/pnacl-clang++
133
134 121
135 # 122 #
136 # Rules for output directories. 123 # Rules for output directories.
137 # 124 #
138 # Output will be places in a directory name based on Toolchain and configuration 125 # Output will be places in a directory name based on Toolchain and configuration
139 # be default this will be "newlib/Debug". We use a python wrapped MKDIR to 126 # be default this will be "newlib/Debug". We use a python wrapped MKDIR to
140 # proivde a cross platform solution. The use of '|' checks for existance instead 127 # proivde a cross platform solution. The use of '|' checks for existance instead
141 # of timestamp, since the directory can update when files change. 128 # of timestamp, since the directory can update when files change.
142 # 129 #
143 $(TOOLCHAIN): 130 $(TOOLCHAIN):
144 $(MKDIR) $(TOOLCHAIN) 131 $(MKDIR) $(TOOLCHAIN)
145 132
146 $(TOOLCHAIN)/$(CONFIG): | $(TOOLCHAIN) 133 $(TOOLCHAIN)/$(CONFIG): | $(TOOLCHAIN)
147 $(MKDIR) $(TOOLCHAIN)/$(CONFIG) 134 $(MKDIR) $(TOOLCHAIN)/$(CONFIG)
148 135
149 OUTDIR:=$(TOOLCHAIN)/$(CONFIG) 136 OUTDIR:=$(TOOLCHAIN)/$(CONFIG)
137 -include $(OUTDIR)/*.d
150 138
151 139
152 # 140 #
153 # Dependency Macro 141 # Dependency Macro
154 # 142 #
155 # $1 = Name of dependency 143 # $1 = Name of dependency
156 # 144 #
157 define DEPEND_RULE 145 define DEPEND_RULE
158 .PHONY: $(1) 146 .PHONY: $(1)
159 $(1): 147 $(1):
148 ifeq (,$(IGNORE_DEPS))
149 @echo "Checking library: $(1)"
160 +$(MAKE) -C $(NACL_SDK_ROOT)/src/$(1) 150 +$(MAKE) -C $(NACL_SDK_ROOT)/src/$(1)
161 DEPS_LIST+=$(1) 151 DEPS_LIST+=$(1)
162 endef 152 else
163 153 » @echo "Ignore DEPS: $(1)"
164 # 154 endif
165 # Compile Macro
166 #
167 # $1 = Source Name
168 #
169 # By default, if $(1) = source.c, this rule expands to:
170 # newlib/Debug/source_x86_32.o : souce.c Makefile | newlib/Debug
171 #
172 # Which means if 'source.c' or Makefile are newer than the object
173 # newlib/Debug/source_x86_32.o, then run the step:
174 # $(X86_CC) -o newlib/Debug/source_x86_32.o -c source.c ....
175 #
176 # We repeat this expansion for 64 bit X86 and conditionally for ARM if
177 # TOOLCHAIN=newlib
178 #
179 define COMPILE_RULE
180 $(OUTDIR)/$(basename $(1))_x86_32.o : $(1) $(THIS_MAKE) | $(OUTDIR)
181 » $(X86_CXX) -o $$@ -c $$< -m32 $(OPT_FLAGS) $(CXX_FLAGS) $(NACL_WARNINGS)
182
183 $(OUTDIR)/$(basename $(1))_x86_64.o : $(1) $(THIS_MAKE) | $(OUTDIR)
184 » $(X86_CXX) -o $$@ -c $$< -m64 $(OPT_FLAGS) $(CXX_FLAGS) $(NACL_WARNINGS)
185
186 $(OUTDIR)/$(basename $(1))_arm.o : $(1) $(THIS_MAKE) | $(OUTDIR)
187 » $(ARM_CXX) -o $$@ -c $$< $(OPT_FLAGS) $(CXX_FLAGS) $(NACL_WARNINGS)
188
189 $(OUTDIR)/$(basename $(1))_pnacl.o : $(1) $(THIS_MAKE) | $(OUTDIR)
190 » $(PNACL_CXX) -o $$@ -c $$< $(OPT_FLAGS) $(CXX_FLAGS) $(NACL_WARNINGS)
191 endef 155 endef
192 156
193 157
194 # 158 ifeq ('win','$(TOOLCHAIN)')
195 # Link Macro 159 HOST_EXT=.dll
196 # 160 else
197 # $1 = Target Name 161 HOST_EXT=.so
198 # $2 = List of Sources
199 #
200 # By default, if $(1) = foo $(2) = A.c B.cc, this rule expands to:
201 # newlib/Debug/foo_x86_32.nexe : newlib/Debug/A_x86_32.o ...
202 #
203 # Which means if A_x86_32.o or sourceB_32.o is newer than the nexe then
204 # run the build step:
205 # $(X86_LINK) -o newlib/Debug/foo_x86_32.nexe newlib/Debug/A_x86_32.o ...
206 #
207 # Note:
208 # We expand each library as '-l<name>' which will look for lib<name> in the
209 # directory specified by $(LD_X86_32)
210 #
211 # We repeat this expansion for 64 bit X86 and conditionally for ARM if
212 # TOOLCHAIN=newlib
213 #
214 define LINK_RULE
215 NMF_TARGETS+=$(OUTDIR)/$(1)_x86_32.nexe
216 $(OUTDIR)/$(1)_x86_32.nexe : $(foreach src,$(2),$(OUTDIR)/$(basename $(src))_x86 _32.o)
217 » $(X86_LINK) -o $$@ $$^ -m32 $(LD_X86_32) $(LD_FLAGS) $(foreach lib,$(LIB S),-l$(lib))
218
219 NMF_TARGETS+=$(OUTDIR)/$(1)_x86_64.nexe
220 $(OUTDIR)/$(1)_x86_64.nexe : $(foreach src,$(2),$(OUTDIR)/$(basename $(src))_x86 _64.o)
221 » $(X86_LINK) -o $$@ $$^ -m64 $(LD_X86_64) $(LD_FLAGS) $(foreach lib,$(LIB S),-l$(lib))
222
223 NMF_TARGETS+=$(OUTDIR)/$(1)_arm.nexe
224 $(OUTDIR)/$(1)_arm.nexe : $(foreach src,$(2),$(OUTDIR)/$(basename $(src))_arm.o)
225 » $(ARM_LINK) -o $$@ $$^ $(LD_ARM) $(LD_FLAGS) $(foreach lib,$(LIBS),-l$(l ib))
226
227 NMF_TARGETS+=$(OUTDIR)/$(1).pexe
228 $(OUTDIR)/$(1).pexe : $(foreach src,$(2),$(OUTDIR)/$(basename $(src))_pnacl.o)
229 » $(PNACL_LINK) -o $$@ $$^ $(LD_PNACL) $(LD_FLAGS) $(foreach lib,$(LIBS),- l$(lib))
230 endef
231
232
233
234 #
235 # Generate NMF_TARGETS
236 #
237 ARCHES=x86_32 x86_64
238 ifeq "newlib" "$(TOOLCHAIN)"
239 ARCHES+=arm
240 endif
241 NMF_ARCHES:=$(foreach arch,$(ARCHES),_$(arch).nexe)
242
243 ifeq "pnacl" "$(TOOLCHAIN)"
244 NMF_ARCHES:=.pexe
245 endif 162 endif
246 163
247 164
248 # 165 #
249 # NMF Manifiest generation 166 # Common Compile Options
250 # 167 #
251 # Use the python script create_nmf to scan the binaries for dependencies using 168 ifeq ('Release','$(CONFIG)')
252 # objdump. Pass in the (-L) paths to the default library toolchains so that we 169 POSIX_OPT_FLAGS?=-g -O2 -pthread
253 # can find those libraries and have it automatically copy the files (-s) to 170 else
254 # the target directory for us. 171 POSIX_OPT_FLAGS?=-g -O0 -pthread
172 endif
173
174 NACL_CFLAGS?=-Wno-long-long -Werror
175 NACL_CXXFLAGS?=-Wno-long-long -Werror
176
255 # 177 #
256 # $1 = Target Name (the basename of the nmf 178 # Default Paths
257 # $2 = Additional create_nmf.py arguments
258 # 179 #
259 NMF:=python $(NACL_SDK_ROOT)/tools/create_nmf.py 180 ifeq (,$(findstring $(TOOLCHAIN),linux mac win))
260 GLIBC_DUMP:=$(TC_PATH)/$(OSNAME)_x86_glibc/x86_64-nacl/bin/objdump 181 INC_PATHS?=$(NACL_SDK_ROOT)/include $(EXTRA_INC_PATHS)
261 GLIBC_PATHS:=-L $(TC_PATH)/$(OSNAME)_x86_glibc/x86_64-nacl/lib32 182 else
262 GLIBC_PATHS+=-L $(TC_PATH)/$(OSNAME)_x86_glibc/x86_64-nacl/lib 183 INC_PATHS?=$(NACL_SDK_ROOT)/include/$(OSNAME) $(NACL_SDK_ROOT)/include $(EXTRA_I NC_PATHS)
184 endif
263 185
264 define NMF_RULE 186 LIB_PATHS?=$(NACL_SDK_ROOT)/lib $(EXTRA_LIB_PATHS)
265 $(OUTDIR)/$(1).nmf : $(foreach arch,$(NMF_ARCHES),$(OUTDIR)/$(1)$(arch))
266 » $(NMF) -o $$@ $$^ -D $(GLIBC_DUMP) $(GLIBC_PATHS) -s $(OUTDIR) $(2)
267
268 all : $(DEPS_LIST) $(OUTDIR)/$(1).nmf
269 endef
270 187
271 188
272 # 189 #
190 # If the requested toolchain is a NaCl or PNaCl toolchain, the use the
191 # macros and targets defined in nacl.mk, otherwise use the host sepecific
192 # macros and targets.
193 #
194 ifneq (,$(findstring $(TOOLCHAIN),linux mac))
195 include $(NACL_SDK_ROOT)/tools/host_gcc.mk
196 endif
197
198 ifneq (,$(findstring $(TOOLCHAIN),win))
199 include $(NACL_SDK_ROOT)/tools/host_vc.mk
200 endif
201
202 ifneq (,$(findstring $(TOOLCHAIN),glibc newlib))
203 include $(NACL_SDK_ROOT)/tools/nacl_gcc.mk
204 endif
205
206 ifneq (,$(findstring $(TOOLCHAIN),pnacl))
207 include $(NACL_SDK_ROOT)/tools/nacl_llvm.mk
208 endif
209
210
211 #
273 # Verify we can find the Chrome executable if we need to launch it. 212 # Verify we can find the Chrome executable if we need to launch it.
274 # 213 #
275 .PHONY: CHECK_FOR_CHROME RUN LAUNCH 214 .PHONY: CHECK_FOR_CHROME RUN LAUNCH
276 CHECK_FOR_CHROME: 215 CHECK_FOR_CHROME:
277 ifeq (,$(wildcard $(CHROME_PATH))) 216 ifeq (,$(wildcard $(CHROME_PATH)))
278 $(warning No valid Chrome found at CHROME_PATH=$(CHROME_PATH)) 217 $(warning No valid Chrome found at CHROME_PATH=$(CHROME_PATH))
279 $(error Set CHROME_PATH via an environment variable, or command-line.) 218 $(error Set CHROME_PATH via an environment variable, or command-line.)
280 else 219 else
281 $(warning Using chrome at: $(CHROME_PATH)) 220 $(warning Using chrome at: $(CHROME_PATH))
282 endif 221 endif
283 222
284 223
285 # 224 #
286 # Variables for running examples with Chrome. 225 # Variables for running examples with Chrome.
287 # 226 #
288 RUN_PY:=python $(NACL_SDK_ROOT)/tools/run.py 227 RUN_PY:=python $(NACL_SDK_ROOT)/tools/run.py
289 228
290 # Add this to launch Chrome with additional environment variables defined. 229 # Add this to launch Chrome with additional environment variables defined.
291 # Each element should be specified as KEY=VALUE, with whitespace separating 230 # Each element should be specified as KEY=VALUE, with whitespace separating
292 # key-value pairs. e.g. 231 # key-value pairs. e.g.
293 # CHROME_ENV=FOO=1 BAR=2 BAZ=3 232 # CHROME_ENV=FOO=1 BAR=2 BAZ=3
294 CHROME_ENV?= 233 CHROME_ENV?=
295 234
296 # Additional arguments to pass to Chrome. 235 # Additional arguments to pass to Chrome.
297 CHROME_ARGS+=--enable-nacl --enable-pnacl --incognito --ppapi-out-of-process 236 CHROME_ARGS+=--enable-nacl --enable-pnacl --incognito --ppapi-out-of-process
298 237
299 238
300 CONFIG?=Debug 239 # Paths to Debug and Release versions of the Host Pepper plugins
240 PPAPI_DEBUG=$(abspath $(OSNAME)/Debug/$(TARGET)$(HOST_EXT));application/x-ppapi- debug
241 PPAPI_RELEASE=$(abspath $(OSNAME)/Release/$(TARGET)$(HOST_EXT));application/x-pp api-release
242
243 info:
244 » @echo "DEBUG=$(PPAPI_DEBUG)"
245
301 PAGE?=index_$(TOOLCHAIN)_$(CONFIG).html 246 PAGE?=index_$(TOOLCHAIN)_$(CONFIG).html
302 247
303 RUN: LAUNCH 248 RUN: LAUNCH
304 LAUNCH: CHECK_FOR_CHROME all 249 LAUNCH: CHECK_FOR_CHROME all
305 ifeq (,$(wildcard $(PAGE))) 250 ifeq (,$(wildcard $(PAGE)))
306 $(warning No valid HTML page found at $(PAGE)) 251 $(warning No valid HTML page found at $(PAGE))
307 $(error Make sure TOOLCHAIN and CONFIG are properly set) 252 $(error Make sure TOOLCHAIN and CONFIG are properly set)
308 endif 253 endif
309 » $(RUN_PY) -C $(THIS_DIR) -P $(PAGE) $(addprefix -E ,$(CHROME_ENV)) -- \ 254 » $(RUN_PY) -C $(CURDIR) -P $(PAGE) $(addprefix -E ,$(CHROME_ENV)) -- \
310 $(CHROME_PATH) $(CHROME_ARGS) \ 255 $(CHROME_PATH) $(CHROME_ARGS) \
311 --register-pepper-plugins="$(PPAPI_DEBUG),$(PPAPI_RELEASE)" 256 --register-pepper-plugins="$(PPAPI_DEBUG),$(PPAPI_RELEASE)"
312 257
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/ppapi_main/ppapi_instance.cc ('k') | native_client_sdk/src/tools/host_gcc.mk » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698