Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / native_client_sdk / src / tools / common.mk
blobdf2939d49fb1a81f213553e4b7ce16d2c651e641
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
11 # Toolchain
13 # By default the VALID_TOOLCHAINS list contains pnacl, newlib and glibc. If
14 # your project only builds in one or the other then this should be overridden
15 # accordingly.
17 ifneq ($(ENABLE_BIONIC),)
18 ALL_TOOLCHAINS ?= pnacl newlib glibc bionic
19 else
20 ALL_TOOLCHAINS ?= pnacl newlib glibc
21 endif
23 VALID_TOOLCHAINS ?= $(ALL_TOOLCHAINS)
24 TOOLCHAIN ?= $(word 1,$(VALID_TOOLCHAINS))
27 # Top Make file, which we want to trigger a rebuild on if it changes
29 TOP_MAKE := $(word 1,$(MAKEFILE_LIST))
33 # Figure out which OS we are running on.
35 GETOS := python $(NACL_SDK_ROOT)/tools/getos.py
36 NACL_CONFIG := python $(NACL_SDK_ROOT)/tools/nacl_config.py
37 FIXDEPS := python $(NACL_SDK_ROOT)/tools/fix_deps.py -c
38 OSNAME := $(shell $(GETOS))
39 GDB_PATH := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) --tool=gdb)
43 # TOOLCHAIN=all recursively calls this Makefile for all VALID_TOOLCHAINS.
45 ifeq ($(TOOLCHAIN),all)
47 # Define the default target
48 all:
51 # Generate a new MAKE command for each TOOLCHAIN.
53 # Note: We use targets for each toolchain (instead of an explicit recipe) so
54 # each toolchain can be built in parallel.
56 # $1 = Toolchain Name
58 define TOOLCHAIN_RULE
59 TOOLCHAIN_TARGETS += $(1)_TARGET
60 .PHONY: $(1)_TARGET
61 $(1)_TARGET:
62 +$(MAKE) TOOLCHAIN=$(1) $(MAKECMDGOALS)
63 endef
66 # The target for all versions
68 USABLE_TOOLCHAINS=$(filter $(OSNAME) $(ALL_TOOLCHAINS),$(VALID_TOOLCHAINS))
70 ifeq ($(NO_HOST_BUILDS),1)
71 USABLE_TOOLCHAINS:=$(filter-out $(OSNAME),$(USABLE_TOOLCHAINS))
72 endif
74 # Define the toolchain targets for all usable toolchains via the macro.
75 $(foreach tool,$(USABLE_TOOLCHAINS),$(eval $(call TOOLCHAIN_RULE,$(tool))))
77 .PHONY: all clean install
78 all: $(TOOLCHAIN_TARGETS)
79 clean: $(TOOLCHAIN_TARGETS)
80 install: $(TOOLCHAIN_TARGETS)
82 else # TOOLCHAIN=all
85 # Verify we selected a valid toolchain for this example
87 ifeq (,$(findstring $(TOOLCHAIN),$(VALID_TOOLCHAINS)))
89 # Only fail to build if this is a top-level make. When building recursively, we
90 # don't care if an example can't build with this toolchain.
91 ifeq ($(MAKELEVEL),0)
92 $(warning Availbile choices are: $(VALID_TOOLCHAINS))
93 $(error Can not use TOOLCHAIN=$(TOOLCHAIN) on this example.)
94 else
96 # Dummy targets for recursive make with unsupported toolchain...
97 .PHONY: all clean install
98 all:
99 clean:
100 install:
102 endif
104 else # TOOLCHAIN is valid...
107 # Build Configuration
109 # The SDK provides two sets of libraries, Debug and Release. Debug libraries
110 # are compiled without optimizations to make debugging easier. By default
111 # this will build a Release configuration. When debugging via "make debug",
112 # build the debug configuration by default instead.
114 ifneq (,$(findstring debug,$(MAKECMDGOALS)))
115 CONFIG ?= Debug
116 else
117 CONFIG ?= Release
118 endif
122 # Verify we selected a valid configuration for this example.
124 VALID_CONFIGS ?= Debug Release
125 ifeq (,$(findstring $(CONFIG),$(VALID_CONFIGS)))
126 $(warning Availbile choices are: $(VALID_CONFIGS))
127 $(error Can not use CONFIG=$(CONFIG) on this example.)
128 endif
132 # Note for Windows:
133 # The GCC and LLVM toolchains (include the version of Make.exe that comes
134 # with the SDK) expect and are capable of dealing with the '/' seperator.
135 # For this reason, the tools in the SDK, including Makefiles and build scripts
136 # have a preference for POSIX style command-line arguments.
138 # Keep in mind however that the shell is responsible for command-line escaping,
139 # globbing, and variable expansion, so those may change based on which shell
140 # is used. For Cygwin shells this can include automatic and incorrect expansion
141 # of response files (files starting with '@').
143 # Disable DOS PATH warning when using Cygwin based NaCl tools on Windows.
145 ifeq ($(OSNAME),win)
146 CYGWIN?=nodosfilewarning
147 export CYGWIN
148 endif
152 # If NACL_SDK_ROOT is not already set, then set it relative to this makefile.
154 THIS_MAKEFILE := $(CURDIR)/$(lastword $(MAKEFILE_LIST))
155 NACL_SDK_ROOT ?= $(realpath $(dir $(THIS_MAKEFILE))/..)
159 # Check that NACL_SDK_ROOT is set to a valid location.
160 # We use the existence of tools/oshelpers.py to verify the validity of the SDK
161 # root.
163 ifeq (,$(wildcard $(NACL_SDK_ROOT)/tools/oshelpers.py))
164 $(error NACL_SDK_ROOT is set to an invalid location: $(NACL_SDK_ROOT))
165 endif
169 # If this makefile is part of a valid nacl SDK, but NACL_SDK_ROOT is set
170 # to a different location this is almost certainly a local configuration
171 # error.
173 LOCAL_ROOT := $(realpath $(dir $(THIS_MAKEFILE))/..)
174 ifneq (,$(wildcard $(LOCAL_ROOT)/tools/oshelpers.py))
175 ifneq ($(realpath $(NACL_SDK_ROOT)), $(realpath $(LOCAL_ROOT)))
176 $(error common.mk included from an SDK that does not match the current NACL_SDK_ROOT)
177 endif
178 endif
182 # Alias for standard POSIX file system commands
184 OSHELPERS = python $(NACL_SDK_ROOT)/tools/oshelpers.py
185 WHICH := $(OSHELPERS) which
186 ifdef V
187 RM := $(OSHELPERS) rm
188 CP := $(OSHELPERS) cp
189 MKDIR := $(OSHELPERS) mkdir
190 MV := $(OSHELPERS) mv
191 else
192 RM := @$(OSHELPERS) rm
193 CP := @$(OSHELPERS) cp
194 MKDIR := @$(OSHELPERS) mkdir
195 MV := @$(OSHELPERS) mv
196 endif
201 # Compute path to requested NaCl Toolchain
203 TC_PATH := $(abspath $(NACL_SDK_ROOT)/toolchain)
207 # Check for required minimum SDK version.
209 ifdef NACL_SDK_VERSION_MIN
210 VERSION_CHECK:=$(shell $(GETOS) --check-version=$(NACL_SDK_VERSION_MIN) 2>&1)
211 ifneq ($(VERSION_CHECK),)
212 $(error $(VERSION_CHECK))
213 endif
214 endif
218 # The default target
220 # If no targets are specified on the command-line, the first target listed in
221 # the makefile becomes the default target. By convention this is usually called
222 # the 'all' target. Here we leave it blank to be first, but define it later
224 all:
225 .PHONY: all
229 # The install target is used to install built libraries to thier final destination.
230 # By default this is the NaCl SDK 'lib' folder.
232 install:
233 .PHONY: install
235 ifdef SEL_LDR
236 STANDALONE = 1
237 endif
239 OUTBASE ?= .
240 ifdef STANDALONE
241 OUTDIR := $(OUTBASE)/$(TOOLCHAIN)/standalone_$(CONFIG)
242 else
243 OUTDIR := $(OUTBASE)/$(TOOLCHAIN)/$(CONFIG)
244 endif
245 STAMPDIR ?= $(OUTDIR)
246 LIBDIR ?= $(NACL_SDK_ROOT)/lib
250 # Target to remove temporary files
252 .PHONY: clean
253 clean:
254 $(RM) -f $(TARGET).nmf
255 $(RM) -rf $(OUTDIR)
256 $(RM) -rf user-data-dir
260 # Rules for output directories.
262 # Output will be places in a directory name based on Toolchain and configuration
263 # be default this will be "newlib/Debug". We use a python wrapped MKDIR to
264 # proivde a cross platform solution. The use of '|' checks for existance instead
265 # of timestamp, since the directory can update when files change.
267 %dir.stamp :
268 $(MKDIR) -p $(dir $@)
269 @echo Directory Stamp > $@
273 # Dependency Macro
275 # $1 = Name of stamp
276 # $2 = Directory for the sub-make
277 # $3 = Extra Settings
279 define DEPEND_RULE
280 ifndef IGNORE_DEPS
281 .PHONY: rebuild_$(1)
283 rebuild_$(1) :| $(STAMPDIR)/dir.stamp
284 ifeq (,$(2))
285 +$(MAKE) -C $(NACL_SDK_ROOT)/src/$(1) STAMPDIR=$(abspath $(STAMPDIR)) $(abspath $(STAMPDIR)/$(1).stamp) $(3)
286 else
287 +$(MAKE) -C $(2) STAMPDIR=$(abspath $(STAMPDIR)) $(abspath $(STAMPDIR)/$(1).stamp) $(3)
288 endif
290 all: rebuild_$(1)
291 $(STAMPDIR)/$(1).stamp: rebuild_$(1)
293 else
295 .PHONY: $(STAMPDIR)/$(1).stamp
296 $(STAMPDIR)/$(1).stamp:
297 @echo Ignore $(1)
298 endif
299 endef
301 ifeq ($(TOOLCHAIN),win)
302 ifdef STANDALONE
303 HOST_EXT = .exe
304 else
305 HOST_EXT = .dll
306 endif
307 else
308 ifdef STANDALONE
309 HOST_EXT =
310 else
311 HOST_EXT = .so
312 endif
313 endif
317 # Common Compile Options
319 # For example, -DNDEBUG is added to release builds by default
320 # so that calls to assert(3) are not included in the build.
322 ifeq ($(CONFIG),Release)
323 POSIX_FLAGS ?= -g -O2 -pthread -MMD -DNDEBUG
324 NACL_LDFLAGS ?= -O2
325 PNACL_LDFLAGS ?= -O2
326 else
327 POSIX_FLAGS ?= -g -O0 -pthread -MMD -DNACL_SDK_DEBUG
328 endif
330 ifdef STANDALONE
331 POSIX_FLAGS += -DSEL_LDR=1
332 endif
334 NACL_CFLAGS ?= -Wno-long-long -Werror
335 NACL_CXXFLAGS ?= -Wno-long-long -Werror
336 NACL_LDFLAGS += -Wl,-as-needed -pthread
339 # Default Paths
341 INC_PATHS := $(shell $(NACL_CONFIG) -t $(TOOLCHAIN) --include-dirs) $(EXTRA_INC_PATHS)
342 LIB_PATHS := $(NACL_SDK_ROOT)/lib $(EXTRA_LIB_PATHS)
345 # Define a LOG macro that allow a command to be run in quiet mode where
346 # the command echoed is not the same as the actual command executed.
347 # The primary use case for this is to avoid echoing the full compiler
348 # and linker command in the default case. Defining V=1 will restore
349 # the verbose behavior
351 # $1 = The name of the tool being run
352 # $2 = The target file being built
353 # $3 = The full command to run
355 ifdef V
356 define LOG
357 $(3)
358 endef
359 else
360 ifeq ($(OSNAME),win)
361 define LOG
362 @echo $(1) $(2) && $(3)
363 endef
364 else
365 define LOG
366 @echo " $(1) $(2)" && $(3)
367 endef
368 endif
369 endif
373 # Convert a source path to a object file path.
375 # $1 = Source Name
376 # $2 = Arch suffix
378 define SRC_TO_OBJ
379 $(OUTDIR)/$(basename $(subst ..,__,$(1)))$(2).o
380 endef
384 # Convert a source path to a dependency file path.
385 # We use the .deps extension for dependencies. These files are generated by
386 # fix_deps.py based on the .d files which gcc generates. We don't reference
387 # the .d files directly so that we can avoid the the case where the compile
388 # failed but still generated a .d file (in that case the .d file would not
389 # be processed by fix_deps.py)
391 # $1 = Source Name
392 # $2 = Arch suffix
394 define SRC_TO_DEP
395 $(patsubst %.o,%.deps,$(call SRC_TO_OBJ,$(1),$(2)))
396 endef
399 # The gcc-generated deps files end in .d
401 define SRC_TO_DEP_PRE_FIXUP
402 $(patsubst %.o,%.d,$(call SRC_TO_OBJ,$(1),$(2)))
403 endef
407 # If the requested toolchain is a NaCl or PNaCl toolchain, the use the
408 # macros and targets defined in nacl.mk, otherwise use the host sepecific
409 # macros and targets.
411 ifneq (,$(findstring $(TOOLCHAIN),linux mac))
412 include $(NACL_SDK_ROOT)/tools/host_gcc.mk
413 endif
415 ifneq (,$(findstring $(TOOLCHAIN),win))
416 include $(NACL_SDK_ROOT)/tools/host_vc.mk
417 endif
419 ifneq (,$(findstring $(TOOLCHAIN),glibc newlib bionic))
420 include $(NACL_SDK_ROOT)/tools/nacl_gcc.mk
421 endif
423 ifneq (,$(findstring $(TOOLCHAIN),pnacl))
424 include $(NACL_SDK_ROOT)/tools/nacl_llvm.mk
425 endif
428 # File to redirect to to in order to hide output.
430 ifeq ($(OSNAME),win)
431 DEV_NULL = nul
432 else
433 DEV_NULL = /dev/null
434 endif
438 # Variables for running examples with Chrome.
440 RUN_PY := python $(NACL_SDK_ROOT)/tools/run.py
441 HTTPD_PY := python $(NACL_SDK_ROOT)/tools/httpd.py
443 # Add this to launch Chrome with additional environment variables defined.
444 # Each element should be specified as KEY=VALUE, with whitespace separating
445 # key-value pairs. e.g.
446 # CHROME_ENV=FOO=1 BAR=2 BAZ=3
447 CHROME_ENV ?=
449 # Additional arguments to pass to Chrome.
450 CHROME_ARGS += --enable-nacl --enable-pnacl --no-first-run
451 CHROME_ARGS += --user-data-dir=$(CURDIR)/user-data-dir
454 # Paths to Debug and Release versions of the Host Pepper plugins
455 PPAPI_DEBUG = $(abspath $(OSNAME)/Debug/$(TARGET)$(HOST_EXT));application/x-ppapi-debug
456 PPAPI_RELEASE = $(abspath $(OSNAME)/Release/$(TARGET)$(HOST_EXT));application/x-ppapi-release
459 SYSARCH := $(shell $(GETOS) --nacl-arch)
460 SEL_LDR_PATH := python $(NACL_SDK_ROOT)/tools/sel_ldr.py
463 # Common Compile Options
465 ifeq ($(CONFIG),Debug)
466 SEL_LDR_ARGS += --debug-libs
467 endif
469 ifndef STANDALONE
471 # Assign a sensible default to CHROME_PATH.
473 CHROME_PATH ?= $(shell $(GETOS) --chrome 2> $(DEV_NULL))
476 # Verify we can find the Chrome executable if we need to launch it.
479 NULL :=
480 SPACE := $(NULL) # one space after NULL is required
481 CHROME_PATH_ESCAPE := $(subst $(SPACE),\ ,$(CHROME_PATH))
483 .PHONY: check_for_chrome
484 check_for_chrome:
485 ifeq (,$(wildcard $(CHROME_PATH_ESCAPE)))
486 $(warning No valid Chrome found at CHROME_PATH=$(CHROME_PATH))
487 $(error Set CHROME_PATH via an environment variable, or command-line.)
488 else
489 $(warning Using chrome at: $(CHROME_PATH))
490 endif
491 PAGE ?= index.html
492 PAGE_TC_CONFIG ?= "$(PAGE)?tc=$(TOOLCHAIN)&config=$(CONFIG)"
494 .PHONY: run
495 run: check_for_chrome all $(PAGE)
496 $(RUN_PY) -C $(CURDIR) -P $(PAGE_TC_CONFIG) \
497 $(addprefix -E ,$(CHROME_ENV)) -- $(CHROME_PATH_ESCAPE) \
498 $(CHROME_ARGS) --no-sandbox \
499 --register-pepper-plugins="$(PPAPI_DEBUG),$(PPAPI_RELEASE)"
501 .PHONY: run_package
502 run_package: check_for_chrome all
503 @echo "$(TOOLCHAIN) $(CONFIG)" > $(CURDIR)/run_package_config
504 $(CHROME_PATH_ESCAPE) --load-and-launch-app=$(CURDIR) $(CHROME_ARGS)
506 GDB_ARGS += -D $(GDB_PATH)
507 # PNaCl's nexe is acquired with "remote get nexe <path>" instead of the NMF.
508 ifeq (,$(findstring $(TOOLCHAIN),pnacl))
509 GDB_ARGS += -D --eval-command="nacl-manifest $(abspath $(OUTDIR))/$(TARGET).nmf"
510 GDB_ARGS += -D $(GDB_DEBUG_TARGET)
511 endif
513 .PHONY: debug
514 debug: check_for_chrome all $(PAGE)
515 $(RUN_PY) $(GDB_ARGS) \
516 -C $(CURDIR) -P $(PAGE_TC_CONFIG) \
517 $(addprefix -E ,$(CHROME_ENV)) -- $(CHROME_PATH_ESCAPE) \
518 $(CHROME_ARGS) --enable-nacl-debug \
519 --register-pepper-plugins="$(PPAPI_DEBUG),$(PPAPI_RELEASE)"
521 .PHONY: serve
522 serve: all
523 $(HTTPD_PY) -C $(CURDIR)
524 endif
526 # uppercase aliases (for backward compatibility)
527 .PHONY: CHECK_FOR_CHROME DEBUG LAUNCH RUN
528 CHECK_FOR_CHROME: check_for_chrome
529 DEBUG: debug
530 LAUNCH: run
531 RUN: run
533 endif # TOOLCHAIN is valid...
535 endif # TOOLCHAIN=all