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 # 17 HOST_CC ?= $(NACL_COMPILER_PREFIX) gcc 18 HOST_CXX ?= $(NACL_COMPILER_PREFIX) g++ 19 HOST_LINK ?= g++ 20 HOST_LIB ?= ar 21 HOST_STRIP ?= strip 22 23 ifeq (,$(findstring gcc,$(shell $(WHICH) gcc))) 24 $(warning To skip the host build use:) 25 $(warning "make all_versions NO_HOST_BUILDS=1") 26 $(error Unable to find gcc in PATH while building Host build) 27 endif 28 29 30 LINUX_WARNINGS ?= -Wno-long-long -Wall -Werror 31 LINUX_CFLAGS = -fPIC -pthread $(LINUX_WARNINGS) -I$(NACL_SDK_ROOT)/include -I$(NACL_SDK_ROOT)/include/linux 32 33 34 # 35 # Individual Macros 36 # 37 # $1 = Source Name 38 # $2 = Compile Flags 39 # 40 define C_COMPILER_RULE 41 -include $(call SRC_TO_DEP,$(1)) 42 $(call SRC_TO_OBJ,$(1)): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 43 $(call LOG,CC ,$$@,$(HOST_CC) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(LINUX_CFLAGS)) 44 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1)) 45 endef 46 47 define CXX_COMPILER_RULE 48 -include $(call SRC_TO_DEP,$(1)) 49 $(call SRC_TO_OBJ,$(1)): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 50 $(call LOG,CXX ,$$@,$(HOST_CXX) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(LINUX_CFLAGS)) 51 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1)) 52 endef 53 54 # 55 # Compile Macro 56 # 57 # $1 = Source Name 58 # $2 = POSIX Compile Flags 59 # $3 = VC Flags (unused) 60 # 61 define COMPILE_RULE 62 ifeq ($(suffix $(1)),.c) 63 $(call C_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc))) 64 else 65 $(call CXX_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc))) 66 endif 67 endef 68 69 70 # 71 # SO Macro 72 # 73 # $1 = Target Name 74 # $2 = List of Sources 75 # 76 # 77 define SO_RULE 78 $(error 'Shared libraries not supported by Host') 79 endef 80 81 82 # 83 # LIB Macro 84 # 85 # $1 = Target Name 86 # $2 = List of Sources 87 # 88 # 89 define LIB_RULE 90 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(OSNAME)_host/$(CONFIG)/lib$(1).a 91 @echo "TOUCHED $$@" > $(STAMPDIR)/$(1).stamp 92 93 all: $(LIBDIR)/$(OSNAME)_host/$(CONFIG)/lib$(1).a 94 $(LIBDIR)/$(OSNAME)_host/$(CONFIG)/lib$(1).a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src))) 95 $(MKDIR) -p $$(dir $$@) 96 $(call LOG,LIB,$$@,$(HOST_LIB) -cr $$@ $$^) 97 endef 98 99 100 # 101 # Link Macro 102 # 103 # $1 = Target Name 104 # $2 = List of inputs 105 # $3 = List of libs 106 # $4 = List of deps 107 # $5 = List of lib dirs 108 # $6 = Other Linker Args 109 # 110 define LINKER_RULE 111 all: $(1) 112 $(1): $(2) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp) 113 $(call LOG,LINK,$$@,$(HOST_LINK) -shared -o $(1) $(2) $(NACL_LDFLAGS) $(foreach path,$(5),-L$(path)/$(OSNAME)_host)/$(CONFIG) $(foreach lib,$(3),-l$(lib)) $(6)) 114 endef 115 116 117 # 118 # Link Macro 119 # 120 # $1 = Target Name 121 # $2 = List of Sources 122 # $3 = List of LIBS 123 # $4 = List of DEPS 124 # $5 = POSIX Linker Switches 125 # $6 = VC Linker Switches 126 # 127 define LINK_RULE 128 $(call LINKER_RULE,$(OUTDIR)/$(1)$(HOST_EXT),$(foreach src,$(2),$(call SRC_TO_OBJ,$(src))),$(filter-out pthread,$(3)),$(4),$(LIB_PATHS),$(5)) 129 endef 130 131 all: $(LIB_LIST) $(DEPS_LIST) 132 133 134 # 135 # Strip Macro 136 # The host build makes shared libraries, so the best we can do is strip-debug. 137 # We cannot strip the symbol names. 138 # 139 # $1 = Target Name 140 # $2 = Input Name 141 # 142 define STRIP_RULE 143 all: $(OUTDIR)/$(1)$(HOST_EXT) 144 $(OUTDIR)/$(1)$(HOST_EXT): $(OUTDIR)/$(2)$(HOST_EXT) 145 $(call LOG,STRIP,$$@,$(HOST_STRIP) --strip-debug -o $$@ $$^) 146 endef 147