Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / native_client_sdk / src / tools / host_gcc.mk
blob6c98369666c833eeb1433e196e12cff71a3bb147
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
10 ifdef ASAN
11 CLANG = 1
12 endif
14 ifdef TSAN
15 CLANG = 1
16 endif
18 ifdef MSAN
19 CLANG = 1
20 endif
23 # Macros for TOOLS
25 # We use the C++ compiler for everything and then use the -Wl,-as-needed flag
26 # in the linker to drop libc++ unless it's actually needed.
28 ifdef CLANG
29 CC = clang
30 CXX = clang++
31 endif
33 ifdef NACL_COMPILER_PREFIX
34 CC = $(NACL_COMPILER_PREFIX) $(CC)
35 CXX = $(NACL_COMPILER_PREFIX) $(CXX)
36 endif
38 LINK ?= $(CXX)
39 AR ?= ar
40 ARFLAGS = -crs
41 STRIP ?= strip
43 ifeq (,$(findstring gcc,$(shell $(WHICH) gcc)))
44 $(warning To skip the host build use:)
45 $(warning "make all_versions NO_HOST_BUILDS=1")
46 $(error Unable to find gcc in PATH while building Host build)
47 endif
49 HOST_WARNINGS ?= -Wno-long-long -Wall -Werror
50 HOST_CFLAGS = -fPIC -pthread $(HOST_WARNINGS) -I$(NACL_SDK_ROOT)/include
52 ifneq ($(OSNAME),mac)
53 # Adding -Wl,-Bsymbolic means that symbols defined within the module are always
54 # used by the module, and not shadowed by symbols already loaded in, for
55 # exmaple, libc. Without this the libc symbols (or anything injected with
56 # LD_PRELOAD will take precedence).
57 # -pthread is not needed on mac (libpthread is a symlink to libSystem) and
58 # in fact generated a warning if passed at link time.
59 HOST_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET).map -Wl,-Bsymbolic -pthread
60 HOST_CFLAGS += -I$(NACL_SDK_ROOT)/include/mac
61 else
62 HOST_LDFLAGS ?= -Wl,-map -Wl,$(OUTDIR)/$(TARGET).map
63 HOST_CFLAGS += -I$(NACL_SDK_ROOT)/include/linux
64 endif
66 ifdef ASAN
67 HOST_CFLAGS += -fsanitize=address
68 HOST_LDFLAGS += -pie -fsanitize=address
69 endif
71 ifdef TSAN
72 HOST_CFLAGS += -fsanitize=thread
73 HOST_LDFLAGS += -pie -fsanitize=thread
74 endif
76 ifdef MSAN
77 HOST_CFLAGS += -fsanitize=memory
78 HOST_LDFLAGS += -pie -fsanitize=memory
79 endif
82 # Individual Macros
84 # $1 = Source name
85 # $2 = Compile flags
87 define C_COMPILER_RULE
88 -include $(call SRC_TO_DEP,$(1))
89 $(call SRC_TO_OBJ,$(1)): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
90 $(call LOG,CC ,$$@,$(CC) -o $$@ -c $$< $(POSIX_CFLAGS) $(HOST_CFLAGS) $(CFLAGS) $(2))
91 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1))
92 endef
94 define CXX_COMPILER_RULE
95 -include $(call SRC_TO_DEP,$(1))
96 $(call SRC_TO_OBJ,$(1)): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
97 $(call LOG,CXX ,$$@,$(CXX) -o $$@ -c $$< $(POSIX_CFLAGS) $(HOST_CFLAGS) $(CXXFLAGS) $(2))
98 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1))
99 endef
102 # Compile Macro
104 # $1 = Source name
105 # $2 = POSIX compiler flags
106 # $3 = VC compiler flags (unused)
108 define COMPILE_RULE
109 ifeq ($(suffix $(1)),.c)
110 $(call C_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc)))
111 else
112 $(call CXX_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc)))
113 endif
114 endef
118 # SO Macro
120 # $1 = Target name
121 # $2 = list of source files
123 define SO_RULE
124 $(error 'Shared libraries not supported by Host')
125 endef
129 # LIB Macro
131 # $1 = Target name
132 # $2 = List of source files
134 define LIB_RULE
135 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(OSNAME)_host/$(CONFIG_DIR)/lib$(1).a
136 @echo "TOUCHED $$@" > $(STAMPDIR)/$(1).stamp
138 all: $(LIBDIR)/$(OSNAME)_host/$(CONFIG_DIR)/lib$(1).a
139 $(LIBDIR)/$(OSNAME)_host/$(CONFIG_DIR)/lib$(1).a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src)))
140 $(MKDIR) -p $$(dir $$@)
141 $(RM) -f $$@
142 $(call LOG,LIB,$$@,$(AR) $(ARFLAGS) $$@ $$^)
143 endef
147 # Link Macro
149 # $1 = Target name
150 # $2 = List of inputs
151 # $3 = List of libs
152 # $4 = List of deps
153 # $5 = List of lib dirs
154 # $6 = Linker flags
156 ifdef STANDALONE
157 define LINKER_RULE
158 all: $(1)
159 $(1): $(2) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
160 $(call LOG,LINK,$$@,$(LINK) -o $(1) $(2) $(HOST_LDFLAGS) $(LDFLAGS) $(foreach path,$(5),-L$(path)/$(OSNAME)_host/$(CONFIG_DIR) -L$(path)/$(OSNAME)_host/$(CONFIG)) $(foreach lib,$(3),-l$(lib)) $(6))
161 endef
162 else
163 define LINKER_RULE
164 all: $(1)
165 $(1): $(2) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
166 $(call LOG,LINK,$$@,$(LINK) -shared -o $(1) $(2) $(HOST_LDFLAGS) $(LDFLAGS) $(foreach path,$(5),-L$(path)/$(OSNAME)_host/$(CONFIG_DIR) -L$(path)/$(OSNAME)_host/$(CONFIG)) $(foreach lib,$(3),-l$(lib)) $(6))
167 endef
168 endif
172 # Link Macro
174 # $1 = Target Name
175 # $2 = List of source files
176 # $3 = List of LIBS
177 # $4 = List of DEPS
178 # $5 = POSIX linker flags
179 # $6 = VC linker flags
181 define LINK_RULE
182 $(call LINKER_RULE,$(OUTDIR)/$(1)$(HOST_EXT),$(foreach src,$(2),$(call SRC_TO_OBJ,$(src))),$(filter-out pthread,$(3)),$(4),$(LIB_PATHS),$(5))
183 endef
185 all: $(LIB_LIST) $(DEPS_LIST)
189 # Strip Macro
190 # The host build makes shared libraries, so the best we can do is -S, which
191 # only strip debug symbols. We don't strip the symbol names.
193 # $1 = Target name
194 # $2 = Input name
196 define STRIP_RULE
197 all: $(OUTDIR)/$(1)$(HOST_EXT)
198 $(OUTDIR)/$(1)$(HOST_EXT): $(OUTDIR)/$(2)$(HOST_EXT)
199 $(call LOG,STRIP,$$@,$(STRIP) -S -o $$@ $$^)
200 endef
204 # Run standalone builds (command line builds outside of chrome)
206 ifdef STANDALONE
207 run: all
208 $(RUN_UNDER) $(OUTDIR)/$(TARGET)$(HOST_EXT) $(EXE_ARGS)
209 endif