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. 4 5# 6# GNU Make based build file. For details on GNU Make see: 7# http://www.gnu.org/software/make/manual/make.html 8# 9 10 11# 12# Macros for TOOLS 13# 14# We use the C++ compiler for everything and then use the -Wl,-as-needed flag 15# in the linker to drop libc++ unless it's actually needed. 16# 17CC ?= $(NACL_COMPILER_PREFIX) gcc 18CXX ?= $(NACL_COMPILER_PREFIX) g++ 19LINK ?= $(CXX) 20LIB ?= ar 21STRIP ?= strip 22 23# Adding -Wl,-Bsymbolic means that symbols defined within the module are always 24# used by the moulde, and not shadowed by symbols already loaded in, for 25# exmaple, libc. Without this the libc symbols (or anything injected with 26# LD_PRELOAD will take precedence). 27HOST_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET).map -Wl,-Bsymbolic 28 29ifeq (,$(findstring gcc,$(shell $(WHICH) gcc))) 30$(warning To skip the host build use:) 31$(warning "make all_versions NO_HOST_BUILDS=1") 32$(error Unable to find gcc in PATH while building Host build) 33endif 34 35HOST_WARNINGS ?= -Wno-long-long -Wall -Werror 36HOST_CFLAGS = -fPIC -pthread $(HOST_WARNINGS) -I$(NACL_SDK_ROOT)/include -I$(NACL_SDK_ROOT)/include/linux 37 38 39# 40# Individual Macros 41# 42# $1 = Source Name 43# $2 = Compile Flags 44# 45define C_COMPILER_RULE 46-include $(call SRC_TO_DEP,$(1)) 47$(call SRC_TO_OBJ,$(1)): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 48 $(call LOG,CC ,$$@,$(CC) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(HOST_CFLAGS) $(2)) 49 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1)) 50endef 51 52define CXX_COMPILER_RULE 53-include $(call SRC_TO_DEP,$(1)) 54$(call SRC_TO_OBJ,$(1)): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 55 $(call LOG,CXX ,$$@,$(CXX) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(HOST_CFLAGS) $(2)) 56 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1)) 57endef 58 59# 60# Compile Macro 61# 62# $1 = Source Name 63# $2 = POSIX Compile Flags 64# $3 = VC Flags (unused) 65# 66define COMPILE_RULE 67ifeq ($(suffix $(1)),.c) 68$(call C_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc))) 69else 70$(call CXX_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc))) 71endif 72endef 73 74 75# 76# SO Macro 77# 78# $1 = Target Name 79# $2 = List of Sources 80# 81# 82define SO_RULE 83$(error 'Shared libraries not supported by Host') 84endef 85 86 87# 88# LIB Macro 89# 90# $1 = Target Name 91# $2 = List of Sources 92# 93# 94define LIB_RULE 95$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(OSNAME)_host/$(CONFIG)/lib$(1).a 96 @echo "TOUCHED $$@" > $(STAMPDIR)/$(1).stamp 97 98all: $(LIBDIR)/$(OSNAME)_host/$(CONFIG)/lib$(1).a 99$(LIBDIR)/$(OSNAME)_host/$(CONFIG)/lib$(1).a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src))) 100 $(MKDIR) -p $$(dir $$@) 101 $(RM) -f $$@ 102 $(call LOG,LIB,$$@,$(LIB) -cr $$@ $$^) 103endef 104 105 106# 107# Link Macro 108# 109# $1 = Target Name 110# $2 = List of inputs 111# $3 = List of libs 112# $4 = List of deps 113# $5 = List of lib dirs 114# $6 = Linker Args 115# 116ifdef STANDALONE 117define LINKER_RULE 118all: $(1) 119$(1): $(2) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp) 120 $(call LOG,LINK,$$@,$(LINK) -o $(1) $(2) $(HOST_LDFLAGS) $(NACL_LDFLAGS) $(LDFLAGS) $(foreach path,$(5),-L$(path)/$(OSNAME)_host)/$(CONFIG) $(foreach lib,$(3),-l$(lib)) $(6)) 121endef 122else 123define LINKER_RULE 124all: $(1) 125$(1): $(2) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp) 126 $(call LOG,LINK,$$@,$(LINK) -shared -o $(1) $(2) $(HOST_LDFLAGS) $(NACL_LDFLAGS) $(LDFLAGS) $(foreach path,$(5),-L$(path)/$(OSNAME)_host)/$(CONFIG) $(foreach lib,$(3),-l$(lib)) $(6)) 127endef 128endif 129 130 131# 132# Link Macro 133# 134# $1 = Target Name 135# $2 = List of Sources 136# $3 = List of LIBS 137# $4 = List of DEPS 138# $5 = POSIX Linker Switches 139# $6 = VC Linker Switches 140# 141define LINK_RULE 142$(call LINKER_RULE,$(OUTDIR)/$(1)$(HOST_EXT),$(foreach src,$(2),$(call SRC_TO_OBJ,$(src))),$(filter-out pthread,$(3)),$(4),$(LIB_PATHS),$(5)) 143endef 144 145all: $(LIB_LIST) $(DEPS_LIST) 146 147 148# 149# Strip Macro 150# The host build makes shared libraries, so the best we can do is strip-debug. 151# We cannot strip the symbol names. 152# 153# $1 = Target Name 154# $2 = Input Name 155# 156define STRIP_RULE 157all: $(OUTDIR)/$(1)$(HOST_EXT) 158$(OUTDIR)/$(1)$(HOST_EXT): $(OUTDIR)/$(2)$(HOST_EXT) 159 $(call LOG,STRIP,$$@,$(STRIP) --strip-debug -o $$@ $$^) 160endef 161 162 163# 164# Run standalone builds (command line builds outside of chrome) 165# 166ifdef STANDALONE 167run: all 168 $(RUN_UNDER) $(OUTDIR)/$(TARGET)$(HOST_EXT) $(EXE_ARGS) 169endif 170