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
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
16 # to drop support for ARM.
18 VALID_TOOLCHAINS?
=newlib
19 TOOLCHAIN?
=$(word 1,$(VALID_TOOLCHAINS
))
23 # Top Make file, which we want to trigger a rebuild on if it changes
25 TOP_MAKE
:=$(word 1,$(MAKEFILE_LIST
))
29 # Verify we selected a valid toolchain for this example
31 ifeq (,$(findstring $(TOOLCHAIN
),$(VALID_TOOLCHAINS
)))
32 $(warning Availbile choices are
: $(VALID_TOOLCHAINS
))
33 $(error Can not use TOOLCHAIN
=$(TOOLCHAIN
) on this example.
)
40 # The SDK provides two sets of libraries, Debug and Release. Debug libraries
41 # are compiled without optimizations to make debugging easier. By default
42 # this will build a Debug configuration.
49 # Both GCC and LLVM bases tools (include the version of Make.exe that comes
50 # with the SDK) both expect and are capable of dealing with the '/' seperator.
51 # For that reason, the tools in the SDK, including build, compilers, scripts
52 # all have a preference for POSIX style command-line arguments.
54 # Keep in mind however that the shell is responsible for command-line escaping,
55 # globbing, and variable expansion, so those may change based on which shell
56 # is used. For Cygwin shells this can include automatic and incorrect expansion
57 # of response files (files starting with '@').
59 # Disable DOS PATH warning when using Cygwin based NaCl tools on Windows.
61 CYGWIN?
=nodosfilewarning
66 # Alias for standard POSIX file system commands
68 CP
:=python
$(NACL_SDK_ROOT
)/tools
/oshelpers.py cp
69 MKDIR
:=python
$(NACL_SDK_ROOT
)/tools
/oshelpers.py mkdir
70 MV
:=python
$(NACL_SDK_ROOT
)/tools
/oshelpers.py mv
71 RM
:=python
$(NACL_SDK_ROOT
)/tools
/oshelpers.py
rm
75 # Compute path to requested NaCl Toolchain
77 OSNAME
:=$(shell python
$(NACL_SDK_ROOT
)/tools
/getos.py
)
78 TC_PATH
:=$(abspath
$(NACL_SDK_ROOT
)/toolchain
)
86 # If no targets are specified on the command-line, the first target listed in
87 # the makefile becomes the default target. By convention this is usually called
88 # the 'all' target. Here we leave it blank to be first, but define it later
101 +$(MAKE
) TOOLCHAIN
=$(1)
102 TOOLCHAIN_LIST
+=all_
$(1)
107 # The target for all versions
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
)
114 # Target to remove temporary files
119 $(RM
) -fr
$(TOOLCHAIN
)
123 # Rules for output directories.
125 # Output will be places in a directory name based on Toolchain and configuration
126 # be default this will be "newlib/Debug". We use a python wrapped MKDIR to
127 # proivde a cross platform solution. The use of '|' checks for existance instead
128 # of timestamp, since the directory can update when files change.
131 $(MKDIR
) $(TOOLCHAIN
)
133 $(TOOLCHAIN
)/$(CONFIG
): |
$(TOOLCHAIN
)
134 $(MKDIR
) $(TOOLCHAIN
)/$(CONFIG
)
136 OUTDIR
:=$(TOOLCHAIN
)/$(CONFIG
)
137 -include $(OUTDIR
)/*.d
143 # $1 = Name of dependency
148 ifeq (,$(IGNORE_DEPS
))
149 @echo
"Checking library: $(1)"
150 +$(MAKE
) -C
$(NACL_SDK_ROOT
)/src
/$(1)
153 @echo
"Ignore DEPS: $(1)"
158 ifeq ('win','$(TOOLCHAIN)')
166 # Common Compile Options
168 ifeq ('Release','$(CONFIG)')
169 POSIX_FLAGS?
=-g
-O2
-pthread
-MMD
171 POSIX_FLAGS?
=-g
-O0
-pthread
-MMD
174 NACL_CFLAGS?
=-Wno-long-long
-Werror
175 NACL_CXXFLAGS?
=-Wno-long-long
-Werror
180 ifeq (,$(findstring $(TOOLCHAIN
),linux mac win
))
181 INC_PATHS?
=$(NACL_SDK_ROOT
)/include $(EXTRA_INC_PATHS
)
183 INC_PATHS?
=$(NACL_SDK_ROOT
)/include/$(OSNAME
) $(NACL_SDK_ROOT
)/include $(EXTRA_INC_PATHS
)
186 LIB_PATHS?
=$(NACL_SDK_ROOT
)/lib
$(EXTRA_LIB_PATHS
)
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.
194 ifneq (,$(findstring $(TOOLCHAIN
),linux mac
))
195 include $(NACL_SDK_ROOT
)/tools
/host_gcc.mk
198 ifneq (,$(findstring $(TOOLCHAIN
),win
))
199 include $(NACL_SDK_ROOT
)/tools
/host_vc.mk
202 ifneq (,$(findstring $(TOOLCHAIN
),glibc newlib
))
203 include $(NACL_SDK_ROOT
)/tools
/nacl_gcc.mk
206 ifneq (,$(findstring $(TOOLCHAIN
),pnacl
))
207 include $(NACL_SDK_ROOT
)/tools
/nacl_llvm.mk
212 # Verify we can find the Chrome executable if we need to launch it.
214 .PHONY
: CHECK_FOR_CHROME RUN LAUNCH
216 ifeq (,$(wildcard $(CHROME_PATH
)))
217 $(warning No valid Chrome found at CHROME_PATH
=$(CHROME_PATH
))
218 $(error Set CHROME_PATH via an environment variable
, or command-line.
)
220 $(warning Using chrome at
: $(CHROME_PATH
))
225 # Variables for running examples with Chrome.
227 RUN_PY
:=python
$(NACL_SDK_ROOT
)/tools
/run.py
229 # Add this to launch Chrome with additional environment variables defined.
230 # Each element should be specified as KEY=VALUE, with whitespace separating
231 # key-value pairs. e.g.
232 # CHROME_ENV=FOO=1 BAR=2 BAZ=3
235 # Additional arguments to pass to Chrome.
236 CHROME_ARGS
+=--enable-nacl
--enable-pnacl
--incognito
--ppapi-out-of-process
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-ppapi-release
244 PAGE?
=index_
$(TOOLCHAIN
)_
$(CONFIG
).html
247 LAUNCH
: CHECK_FOR_CHROME
all
248 ifeq (,$(wildcard $(PAGE
)))
249 $(warning No valid HTML page found at
$(PAGE
))
250 $(error Make sure TOOLCHAIN and CONFIG are properly set
)
252 $(RUN_PY
) -C
$(CURDIR
) -P
$(PAGE
) $(addprefix -E
,$(CHROME_ENV
)) -- \
253 $(CHROME_PATH
) $(CHROME_ARGS
) \
254 --register-pepper-plugins
="$(PPAPI_DEBUG),$(PPAPI_RELEASE)"
257 SYSARCH
=$(shell python
$(NACL_SDK_ROOT
)/tools
/getos.py
--chrome
)
258 GDB_ARGS
+=-D
$(TC_PATH
)/$(OSNAME
)_x86_
$(TOOLCHAIN
)/bin
/$(SYSARCH
)-nacl-gdb
259 GDB_ARGS
+=-D
$(CURDIR
)/$(OUTDIR
)/$(TARGET
)_
$(SYSARCH
).nexe
261 DEBUG
: CHECK_FOR_CHROME
all
262 $(RUN_PY
) $(GDB_ARGS
) \
263 -C
$(CURDIR
) -P
$(PAGE
) $(addprefix -E
,$(CHROME_ENV
)) -- \
264 $(CHROME_PATH
) $(CHROME_ARGS
) --enable-nacl-debug \
265 --register-pepper-plugins
="$(PPAPI_DEBUG),$(PPAPI_RELEASE)"