Revert "Merged all Chromoting Host code into remoting_core.dll (Windows)."
[chromium-blink-merge.git] / native_client_sdk / src / tools / common.mk
blob1a340fb72bf38ed3e896ad6bca33184461e90df8
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
12 # Toolchain
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.)
34 endif
38 # Build Configuration
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.
44 CONFIG?=Debug
48 # Note for Windows:
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
62 export CYGWIN
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)
84 # The default target
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
90 all:
94 # Target a toolchain
96 # $1 = Toolchain Name
98 define TOOLCHAIN_RULE
99 .PHONY: all_$(1)
100 all_$(1):
101 +$(MAKE) TOOLCHAIN=$(1)
102 TOOLCHAIN_LIST+=all_$(1)
103 endef
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
116 .PHONY: clean
117 clean:
118 $(RM) $(TARGET).nmf
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.
130 $(TOOLCHAIN):
131 $(MKDIR) $(TOOLCHAIN)
133 $(TOOLCHAIN)/$(CONFIG): | $(TOOLCHAIN)
134 $(MKDIR) $(TOOLCHAIN)/$(CONFIG)
136 OUTDIR:=$(TOOLCHAIN)/$(CONFIG)
137 -include $(OUTDIR)/*.d
141 # Dependency Macro
143 # $1 = Name of dependency
145 define DEPEND_RULE
146 .PHONY: $(1)
147 $(1):
148 ifeq (,$(IGNORE_DEPS))
149 @echo "Checking library: $(1)"
150 +$(MAKE) -C $(NACL_SDK_ROOT)/src/$(1)
151 DEPS_LIST+=$(1)
152 else
153 @echo "Ignore DEPS: $(1)"
154 endif
155 endef
158 ifeq ('win','$(TOOLCHAIN)')
159 HOST_EXT=.dll
160 else
161 HOST_EXT=.so
162 endif
166 # Common Compile Options
168 ifeq ('Release','$(CONFIG)')
169 POSIX_FLAGS?=-g -O2 -pthread -MMD
170 else
171 POSIX_FLAGS?=-g -O0 -pthread -MMD
172 endif
174 NACL_CFLAGS?=-Wno-long-long -Werror
175 NACL_CXXFLAGS?=-Wno-long-long -Werror
178 # Default Paths
180 ifeq (,$(findstring $(TOOLCHAIN),linux mac win))
181 INC_PATHS?=$(NACL_SDK_ROOT)/include $(EXTRA_INC_PATHS)
182 else
183 INC_PATHS?=$(NACL_SDK_ROOT)/include/$(OSNAME) $(NACL_SDK_ROOT)/include $(EXTRA_INC_PATHS)
184 endif
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
196 endif
198 ifneq (,$(findstring $(TOOLCHAIN),win))
199 include $(NACL_SDK_ROOT)/tools/host_vc.mk
200 endif
202 ifneq (,$(findstring $(TOOLCHAIN),glibc newlib))
203 include $(NACL_SDK_ROOT)/tools/nacl_gcc.mk
204 endif
206 ifneq (,$(findstring $(TOOLCHAIN),pnacl))
207 include $(NACL_SDK_ROOT)/tools/nacl_llvm.mk
208 endif
212 # Verify we can find the Chrome executable if we need to launch it.
214 .PHONY: CHECK_FOR_CHROME RUN LAUNCH
215 CHECK_FOR_CHROME:
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.)
219 else
220 $(warning Using chrome at: $(CHROME_PATH))
221 endif
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
233 CHROME_ENV?=
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
246 RUN: LAUNCH
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)
251 endif
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)"