common.mk revision 3240926e260ce088908e02ac07a6cf7b0c0cbf44
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Copyright (c) 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# GNU Make based build file. For details on GNU Make see: 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# http://www.gnu.org/software/make/manual/make.html 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 9c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Toolchain 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# By default the VALID_TOOLCHAINS list contains newlib and glibc. If your 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# project only builds in one or the other then this should be overridden 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# accordingly. 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)VALID_TOOLCHAINS ?= newlib glibc 1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TOOLCHAIN ?= $(word 1,$(VALID_TOOLCHAINS)) 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Top Make file, which we want to trigger a rebuild on if it changes 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TOP_MAKE := $(word 1,$(MAKEFILE_LIST)) 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 28c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)# Figure out which OS we are running on. 29c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)# 307dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochGETOS := python $(NACL_SDK_ROOT)/tools/getos.py 317dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochFIXDEPS := python $(NACL_SDK_ROOT)/tools/fix_deps.py -c 3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)OSNAME := $(shell $(GETOS)) 33c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 34c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 35c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)# 36a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# TOOLCHAIN=all recursively calls this Makefile for all VALID_TOOLCHAINS. 37a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# 38a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)ifeq ($(TOOLCHAIN),all) 39a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 40a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# Define the default target 41a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)all: 42a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 43a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# 44a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# Generate a new MAKE command for each TOOLCHAIN. 45a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# 46a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# Note: We use targets for each toolchain (instead of an explicit recipe) so 47a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# each toolchain can be built in parallel. 48a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# 49a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# $1 = Toolchain Name 50a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# 51a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)define TOOLCHAIN_RULE 52a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TOOLCHAIN_TARGETS += $(1)_TARGET 53a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles).PHONY: $(1)_TARGET 54a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)$(1)_TARGET: 55a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) +$(MAKE) TOOLCHAIN=$(1) $(MAKECMDGOALS) 56a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)endef 57a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 58a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# 59a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# The target for all versions 60a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# 61a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)USABLE_TOOLCHAINS=$(filter $(OSNAME) newlib glibc pnacl,$(VALID_TOOLCHAINS)) 62a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 63a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)ifeq ($(NO_HOST_BUILDS),1) 64a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)USABLE_TOOLCHAINS:=$(filter-out $(OSNAME),$(USABLE_TOOLCHAINS)) 65a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)endif 66a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 67a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# Define the toolchain targets for all usable toolchains via the macro. 68a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)$(foreach tool,$(USABLE_TOOLCHAINS),$(eval $(call TOOLCHAIN_RULE,$(tool)))) 69a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 70a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles).PHONY: all clean install 71a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)all: $(TOOLCHAIN_TARGETS) 72a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)clean: $(TOOLCHAIN_TARGETS) 73a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)install: $(TOOLCHAIN_TARGETS) 74a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 75a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)else # TOOLCHAIN=all 76a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 77a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Verify we selected a valid toolchain for this example 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifeq (,$(findstring $(TOOLCHAIN),$(VALID_TOOLCHAINS))) 81eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 82eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch# Only fail to build if this is a top-level make. When building recursively, we 83eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch# don't care if an example can't build with this toolchain. 84eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochifeq ($(MAKELEVEL),0) 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) $(warning Availbile choices are: $(VALID_TOOLCHAINS)) 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) $(error Can not use TOOLCHAIN=$(TOOLCHAIN) on this example.) 87eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochelse 88eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 89eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch# Dummy targets for recursive make with unsupported toolchain... 90eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch.PHONY: all clean install 91eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochall: 92eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochclean: 93eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochinstall: 94eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 97eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochelse # TOOLCHAIN is valid... 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Build Configuration 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# The SDK provides two sets of libraries, Debug and Release. Debug libraries 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# are compiled without optimizations to make debugging easier. By default 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# this will build a Debug configuration. 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 10690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)CONFIG ?= Debug 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 109c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)# 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Note for Windows: 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# The GCC and LLVM toolchains (include the version of Make.exe that comes 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# with the SDK) expect and are capable of dealing with the '/' seperator. 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# For this reason, the tools in the SDK, including Makefiles and build scripts 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# have a preference for POSIX style command-line arguments. 1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Keep in mind however that the shell is responsible for command-line escaping, 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# globbing, and variable expansion, so those may change based on which shell 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# is used. For Cygwin shells this can include automatic and incorrect expansion 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# of response files (files starting with '@'). 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Disable DOS PATH warning when using Cygwin based NaCl tools on Windows. 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifeq ($(OSNAME),win) 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CYGWIN?=nodosfilewarning 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) export CYGWIN 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# If NACL_SDK_ROOT is not already set, then set it relative to this makefile. 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 13290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)THIS_MAKEFILE := $(CURDIR)/$(lastword $(MAKEFILE_LIST)) 13390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)NACL_SDK_ROOT ?= $(realpath $(dir $(THIS_MAKEFILE))/..) 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Check that NACL_SDK_ROOT is set to a valid location. 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# We use the existence of tools/oshelpers.py to verify the validity of the SDK 1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# root. 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifeq (,$(wildcard $(NACL_SDK_ROOT)/tools/oshelpers.py)) 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) $(error NACL_SDK_ROOT is set to an invalid location: $(NACL_SDK_ROOT)) 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# If this makefile is part of a valid nacl SDK, but NACL_SDK_ROOT is set 1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# to a different location this is almost certainly a local configuration 1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# error. 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 15190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)LOCAL_ROOT := $(realpath $(dir $(THIS_MAKEFILE))/..) 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifneq (,$(wildcard $(LOCAL_ROOT)/tools/oshelpers.py)) 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ifneq ($(realpath $(NACL_SDK_ROOT)), $(realpath $(LOCAL_ROOT))) 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) $(error common.mk included from an SDK that does not match the current NACL_SDK_ROOT) 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) endif 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Alias for standard POSIX file system commands 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 16290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)OSHELPERS = python $(NACL_SDK_ROOT)/tools/oshelpers.py 16390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)WHICH := $(OSHELPERS) which 1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifdef V 16590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)RM := $(OSHELPERS) rm 16690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)CP := $(OSHELPERS) cp 16790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)MKDIR := $(OSHELPERS) mkdir 16890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)MV := $(OSHELPERS) mv 1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)else 17090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)RM := @$(OSHELPERS) rm 17190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)CP := @$(OSHELPERS) cp 17290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)MKDIR := @$(OSHELPERS) mkdir 17390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)MV := @$(OSHELPERS) mv 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Compute path to requested NaCl Toolchain 1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 18190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TC_PATH := $(abspath $(NACL_SDK_ROOT)/toolchain) 1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Check for required minimum SDK version. 1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifdef NACL_SDK_VERSION_MIN 1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) VERSION_CHECK:=$(shell $(GETOS) --check-version=$(NACL_SDK_VERSION_MIN) 2>&1) 1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ifneq ($(VERSION_CHECK),) 1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) $(error $(VERSION_CHECK)) 1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) endif 1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# The default target 1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# If no targets are specified on the command-line, the first target listed in 1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# the makefile becomes the default target. By convention this is usually called 2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# the 'all' target. Here we leave it blank to be first, but define it later 2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)all: 203a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles).PHONY: all 2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 207a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# The install target is used to install built libraries to thier final destination. 208a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)# By default this is the NaCl SDK 'lib' folder. 2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 210a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)install: 211a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles).PHONY: install 2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 21490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)OUTBASE ?= . 2157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochifdef SEL_LDR 2167dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochOUTDIR := $(OUTBASE)/$(TOOLCHAIN)/sel_ldr_$(CONFIG) 2177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochelse 21890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)OUTDIR := $(OUTBASE)/$(TOOLCHAIN)/$(CONFIG) 2197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochendif 22090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)STAMPDIR ?= $(OUTDIR) 22190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)LIBDIR ?= $(NACL_SDK_ROOT)/lib 2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Target to remove temporary files 2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles).PHONY: clean 2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)clean: 2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) $(RM) -f $(TARGET).nmf 23090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) $(RM) -rf $(OUTDIR) 23190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) $(RM) -rf user-data-dir 2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Rules for output directories. 2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Output will be places in a directory name based on Toolchain and configuration 2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# be default this will be "newlib/Debug". We use a python wrapped MKDIR to 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# proivde a cross platform solution. The use of '|' checks for existance instead 2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# of timestamp, since the directory can update when files change. 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)%dir.stamp : 2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) $(MKDIR) -p $(dir $@) 2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) @echo Directory Stamp > $@ 2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Dependency Macro 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# $1 = Name of stamp 2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# $2 = Directory for the sub-make 2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# $3 = Extra Settings 2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)define DEPEND_RULE 255eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochifndef IGNORE_DEPS 256a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles).PHONY: rebuild_$(1) 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)rebuild_$(1) :| $(STAMPDIR)/dir.stamp 2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifeq (,$(2)) 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) +$(MAKE) -C $(NACL_SDK_ROOT)/src/$(1) STAMPDIR=$(abspath $(STAMPDIR)) $(abspath $(STAMPDIR)/$(1).stamp) $(3) 2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)else 2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) +$(MAKE) -C $(2) STAMPDIR=$(abspath $(STAMPDIR)) $(abspath $(STAMPDIR)/$(1).stamp) $(3) 2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)all: rebuild_$(1) 2667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)$(STAMPDIR)/$(1).stamp: rebuild_$(1) 2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)else 2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 270a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles).PHONY: $(STAMPDIR)/$(1).stamp 2717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)$(STAMPDIR)/$(1).stamp: 2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) @echo Ignore $(1) 2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endef 2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifeq ($(TOOLCHAIN),win) 27890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)HOST_EXT = .dll 2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)else 28090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)HOST_EXT = .so 2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 2822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 2852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Common Compile Options 2862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 2872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifeq ($(CONFIG),Release) 28890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)POSIX_FLAGS ?= -g -O2 -pthread -MMD 2892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)else 29090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)POSIX_FLAGS ?= -g -O0 -pthread -MMD -DNACL_SDK_DEBUG 2912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 2922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2937dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochifdef SEL_LDR 2947dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochPOSIX_FLAGS += -DSEL_LDR=1 2957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochendif 2967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 29790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)NACL_CFLAGS ?= -Wno-long-long -Werror 29890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)NACL_CXXFLAGS ?= -Wno-long-long -Werror 29990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)NACL_LDFLAGS ?= -Wl,-as-needed 3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 3022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Default Paths 3032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifeq (,$(findstring $(TOOLCHAIN),linux mac win)) 3057dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochINC_PATHS ?= $(NACL_SDK_ROOT)/include $(NACL_SDK_ROOT)/include/$(TOOLCHAIN) $(EXTRA_INC_PATHS) 3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)else 30790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)INC_PATHS ?= $(NACL_SDK_ROOT)/include/$(OSNAME) $(NACL_SDK_ROOT)/include $(EXTRA_INC_PATHS) 3082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 31090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)LIB_PATHS ?= $(NACL_SDK_ROOT)/lib $(EXTRA_LIB_PATHS) 3112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 3132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Define a LOG macro that allow a command to be run in quiet mode where 3142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# the command echoed is not the same as the actual command executed. 3152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# The primary use case for this is to avoid echoing the full compiler 3162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# and linker command in the default case. Defining V=1 will restore 3172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# the verbose behavior 3182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 3192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# $1 = The name of the tool being run 3202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# $2 = The target file being built 3212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# $3 = The full command to run 3222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 3232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifdef V 3242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)define LOG 3252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)$(3) 3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endef 3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)else 3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifeq ($(OSNAME),win) 3292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)define LOG 3302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)@echo $(1) $(2) && $(3) 3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endef 3322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)else 3332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)define LOG 3342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)@echo " $(1) $(2)" && $(3) 3352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endef 3362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 3372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 3382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 3412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Convert a source path to a object file path. 3422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 3432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# $1 = Source Name 3442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# $2 = Arch suffix 3452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 3462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)define SRC_TO_OBJ 3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)$(OUTDIR)/$(basename $(subst ..,__,$(1)))$(2).o 3482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endef 3492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 3522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Convert a source path to a dependency file path. 3537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch# We use the .deps extension for dependencies. These files are generated by 3547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch# fix_deps.py based on the .d files which gcc generates. We don't reference 3557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch# the .d files directly so that we can avoid the the case where the compile 3567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch# failed but still generated a .d file (in that case the .d file would not 3577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch# be processed by fix_deps.py) 3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# $1 = Source Name 3602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# $2 = Arch suffix 3612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 3622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)define SRC_TO_DEP 3637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch$(patsubst %.o,%.deps,$(call SRC_TO_OBJ,$(1),$(2))) 3647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochendef 3657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 3667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch# 3677dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch# The gcc-generated deps files end in .d 3687dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch# 3697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochdefine SRC_TO_DEP_PRE_FIXUP 3702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)$(patsubst %.o,%.d,$(call SRC_TO_OBJ,$(1),$(2))) 3712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endef 3722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 3752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# If the requested toolchain is a NaCl or PNaCl toolchain, the use the 3762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# macros and targets defined in nacl.mk, otherwise use the host sepecific 3772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# macros and targets. 3782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 3792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifneq (,$(findstring $(TOOLCHAIN),linux mac)) 3802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)include $(NACL_SDK_ROOT)/tools/host_gcc.mk 3812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 3822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifneq (,$(findstring $(TOOLCHAIN),win)) 3842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)include $(NACL_SDK_ROOT)/tools/host_vc.mk 3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 3862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifneq (,$(findstring $(TOOLCHAIN),glibc newlib)) 3882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)include $(NACL_SDK_ROOT)/tools/nacl_gcc.mk 3892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 3902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifneq (,$(findstring $(TOOLCHAIN),pnacl)) 3922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)include $(NACL_SDK_ROOT)/tools/nacl_llvm.mk 3932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 3942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 3962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# File to redirect to to in order to hide output. 3972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 3982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifeq ($(OSNAME),win) 39990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)DEV_NULL = nul 4002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)else 40190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)DEV_NULL = /dev/null 4022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 4032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 4052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Assign a sensible default to CHROME_PATH. 4062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 407eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochCHROME_PATH ?= $(shell $(GETOS) --chrome 2> $(DEV_NULL)) 4082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 4102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Verify we can find the Chrome executable if we need to launch it. 4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 412b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles).PHONY: check_for_chrome 413b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)check_for_chrome: 4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ifeq (,$(wildcard $(CHROME_PATH))) 4152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) $(warning No valid Chrome found at CHROME_PATH=$(CHROME_PATH)) 4162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) $(error Set CHROME_PATH via an environment variable, or command-line.) 4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)else 4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) $(warning Using chrome at: $(CHROME_PATH)) 4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)endif 4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 4232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Variables for running examples with Chrome. 4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# 42590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)RUN_PY := python $(NACL_SDK_ROOT)/tools/run.py 4262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Add this to launch Chrome with additional environment variables defined. 4282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Each element should be specified as KEY=VALUE, with whitespace separating 4292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# key-value pairs. e.g. 4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# CHROME_ENV=FOO=1 BAR=2 BAZ=3 43190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)CHROME_ENV ?= 4322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Additional arguments to pass to Chrome. 4343240926e260ce088908e02ac07a6cf7b0c0cbf44Ben MurdochCHROME_ARGS += --enable-nacl --enable-pnacl --no-first-run 43590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)CHROME_ARGS += --user-data-dir=$(CURDIR)/user-data-dir 4362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Paths to Debug and Release versions of the Host Pepper plugins 43990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)PPAPI_DEBUG = $(abspath $(OSNAME)/Debug/$(TARGET)$(HOST_EXT));application/x-ppapi-debug 44090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)PPAPI_RELEASE = $(abspath $(OSNAME)/Release/$(TARGET)$(HOST_EXT));application/x-ppapi-release 4412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4437dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochSYSARCH := $(shell $(GETOS) --nacl-arch) 4447dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochSEL_LDR_PATH := python $(NACL_SDK_ROOT)/tools/sel_ldr.py 4457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 4463240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch# 4473240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch# Common Compile Options 4483240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch# 4493240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdochifeq ($(CONFIG),Debug) 4503240926e260ce088908e02ac07a6cf7b0c0cbf44Ben MurdochSEL_LDR_ARGS += --debug-libs 4513240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdochendif 4523240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch 4537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochifdef SEL_LDR 4547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochrun: all 4557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochifndef NACL_ARCH 4567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch $(error Cannot run in sel_ldr unless $$NACL_ARCH is set) 4577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochendif 4583240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch $(SEL_LDR_PATH) $(SEL_LDR_ARGS) $(OUTDIR)/$(TARGET)_$(NACL_ARCH).nexe 4597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 4607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochdebug: all 4617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochifndef NACL_ARCH 4627dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch $(error Cannot run in sel_ldr unless $$NACL_ARCH is set) 4637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochendif 4643240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch $(SEL_LDR_PATH) -d $(SEL_LDR_ARGS) $(OUTDIR)/$(TARGET)_$(NACL_ARCH).nexe 4657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochelse 46690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)PAGE ?= index.html 4677dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochPAGE_TC_CONFIG ?= "$(PAGE)?tc=$(TOOLCHAIN)&config=$(CONFIG)" 4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 469b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles).PHONY: run 4707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochrun: check_for_chrome all $(PAGE) 4712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) $(RUN_PY) -C $(CURDIR) -P $(PAGE_TC_CONFIG) \ 4722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) $(addprefix -E ,$(CHROME_ENV)) -- $(CHROME_PATH) $(CHROME_ARGS) \ 4732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) --register-pepper-plugins="$(PPAPI_DEBUG),$(PPAPI_RELEASE)" 4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 475b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles).PHONY: run_package 476b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)run_package: check_for_chrome all 47790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) $(CHROME_PATH) --load-and-launch-app=$(CURDIR) $(CHROME_ARGS) 478b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 4792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 48090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)GDB_ARGS += -D $(TC_PATH)/$(OSNAME)_x86_$(TOOLCHAIN)/bin/$(SYSARCH)-nacl-gdb 48190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)GDB_ARGS += -D $(abspath $(OUTDIR))/$(TARGET)_$(SYSARCH).nexe 4822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 483b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles).PHONY: debug 4847dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochdebug: check_for_chrome all $(PAGE) 4852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) $(RUN_PY) $(GDB_ARGS) \ 4862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) -C $(CURDIR) -P $(PAGE_TC_CONFIG) \ 4872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) $(addprefix -E ,$(CHROME_ENV)) -- $(CHROME_PATH) $(CHROME_ARGS) \ 4882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) --enable-nacl-debug \ 4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) --register-pepper-plugins="$(PPAPI_DEBUG),$(PPAPI_RELEASE)" 4907dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochendif 4912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 492b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 493b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)# uppercase aliases (for backward compatibility) 494b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles).PHONY: CHECK_FOR_CHROME DEBUG LAUNCH RUN 495b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)CHECK_FOR_CHROME: check_for_chrome 496b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)DEBUG: debug 497b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)LAUNCH: run 498b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)RUN: run 499a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 500eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochendif # TOOLCHAIN is valid... 501eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 502a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)endif # TOOLCHAIN=all 503