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 # Macros for TOOLS 12 # 13 # We always link with the C++ compiler but include -Wl,-as-needed flag 14 # in LDFLAGS so the linker should drop libc++ unless it's actually needed. 15 # 16 X86_TC_BIN ?= $(TC_PATH)/$(OSNAME)_x86_$(TOOLCHAIN)/bin 17 ARM_TC_BIN ?= $(TC_PATH)/$(OSNAME)_arm_$(TOOLCHAIN)/bin 18 19 X86_32_CC ?= $(NACL_COMPILER_PREFIX) $(X86_TC_BIN)/i686-nacl-gcc 20 X86_32_CXX ?= $(NACL_COMPILER_PREFIX) $(X86_TC_BIN)/i686-nacl-g++ 21 X86_32_LINK ?= $(X86_TC_BIN)/i686-nacl-g++ 22 X86_32_LIB ?= $(X86_TC_BIN)/i686-nacl-ar 23 X86_32_STRIP ?= $(X86_TC_BIN)/i686-nacl-strip 24 X86_32_NM ?= $(X86_TC_BIN)/i686-nacl-nm 25 26 X86_64_CC ?= $(NACL_COMPILER_PREFIX) $(X86_TC_BIN)/x86_64-nacl-gcc 27 X86_64_CXX ?= $(NACL_COMPILER_PREFIX) $(X86_TC_BIN)/x86_64-nacl-g++ 28 X86_64_LINK ?= $(X86_TC_BIN)/x86_64-nacl-g++ 29 X86_64_LIB ?= $(X86_TC_BIN)/x86_64-nacl-ar 30 X86_64_STRIP ?= $(X86_TC_BIN)/x86_64-nacl-strip 31 X86_64_NM ?= $(X86_TC_BIN)/x86_64-nacl-nm 32 33 ARM_CC ?= $(NACL_COMPILER_PREFIX) $(ARM_TC_BIN)/arm-nacl-gcc 34 ARM_CXX ?= $(NACL_COMPILER_PREFIX) $(ARM_TC_BIN)/arm-nacl-g++ 35 ARM_LINK ?= $(ARM_TC_BIN)/arm-nacl-g++ 36 ARM_LIB ?= $(ARM_TC_BIN)/arm-nacl-ar 37 ARM_STRIP ?= $(ARM_TC_BIN)/arm-nacl-strip 38 ARM_NM ?= $(ARM_TC_BIN)/arm-nacl-nm 39 40 NCVAL ?= python $(NACL_SDK_ROOT)/tools/ncval.py 41 42 # Architecture-specific flags 43 X86_32_CFLAGS ?= 44 X86_64_CFLAGS ?= 45 ARM_CFLAGS ?= 46 47 X86_32_CXXFLAGS ?= 48 X86_64_CXXFLAGS ?= 49 ARM_CXXFLAGS ?= 50 51 X86_32_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_x86_32.map 52 X86_64_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_x86_64.map 53 ARM_LDFLAGS ?= -Wl,-Map,$(OUTDIR)/$(TARGET)_arm.map 54 55 LDFLAGS_SHARED = -shared 56 57 # 58 # Compile Macro 59 # 60 # $1 = Source Name 61 # $2 = Compile Flags 62 # 63 define C_COMPILER_RULE 64 -include $(call SRC_TO_DEP,$(1),_x86_32) 65 $(call SRC_TO_OBJ,$(1),_x86_32): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 66 $(call LOG,CC ,$$@,$(X86_32_CC) -o $$@ -c $$< $(POSIX_FLAGS) $(2) $(NACL_CFLAGS) $(X86_32_CFLAGS)) 67 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_32) 68 69 -include $(call SRC_TO_DEP,$(1),_x86_64) 70 $(call SRC_TO_OBJ,$(1),_x86_64): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 71 $(call LOG,CC ,$$@,$(X86_64_CC) -o $$@ -c $$< $(POSIX_FLAGS) $(2) $(NACL_CFLAGS) $(X86_64_CFLAGS)) 72 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_64) 73 74 -include $(call SRC_TO_DEP,$(1),_arm) 75 $(call SRC_TO_OBJ,$(1),_arm): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 76 $(call LOG,CC ,$$@,$(ARM_CC) -o $$@ -c $$< $(POSIX_FLAGS) $(2) $(NACL_CFLAGS) $(ARM_CFLAGS)) 77 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_arm) 78 79 -include $(call SRC_TO_DEP,$(1),_x86_32_pic) 80 $(call SRC_TO_OBJ,$(1),_x86_32_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 81 $(call LOG,CC ,$$@,$(X86_32_CC) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(NACL_CFLAGS) $(X86_32_CFLAGS)) 82 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_32_pic) 83 84 -include $(call SRC_TO_DEP,$(1),_x86_64_pic) 85 $(call SRC_TO_OBJ,$(1),_x86_64_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 86 $(call LOG,CC ,$$@,$(X86_64_CC) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(NACL_CFLAGS) $(X86_64_CFLAGS)) 87 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_64_pic) 88 89 -include $(call SRC_TO_DEP,$(1),_arm_pic) 90 $(call SRC_TO_OBJ,$(1),_arm_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 91 $(call LOG,CC ,$$@,$(ARM_CC) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(NACL_CFLAGS) $(ARM_CFLAGS)) 92 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_arm_pic) 93 endef 94 95 define CXX_COMPILER_RULE 96 -include $(call SRC_TO_DEP,$(1),_x86_32) 97 $(call SRC_TO_OBJ,$(1),_x86_32): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 98 $(call LOG,CXX ,$$@,$(X86_32_CXX) -o $$@ -c $$< $(POSIX_FLAGS) $(2) $(NACL_CXXFLAGS) $(X86_32_CXXFLAGS)) 99 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_32) 100 101 -include $(call SRC_TO_DEP,$(1),_x86_64) 102 $(call SRC_TO_OBJ,$(1),_x86_64): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 103 $(call LOG,CXX ,$$@,$(X86_64_CXX) -o $$@ -c $$< $(POSIX_FLAGS) $(2) $(NACL_CXXFLAGS) $(X86_64_CXXFLAGS)) 104 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_64) 105 106 -include $(call SRC_TO_DEP,$(1),_arm) 107 $(call SRC_TO_OBJ,$(1),_arm): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 108 $(call LOG,CXX ,$$@,$(ARM_CXX) -o $$@ -c $$< $(POSIX_FLAGS) $(2) $(NACL_CXXFLAGS) $(ARM_CXXFLAGS)) 109 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_arm) 110 111 -include $(call SRC_TO_DEP,$(1),_x86_32_pic) 112 $(call SRC_TO_OBJ,$(1),_x86_32_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 113 $(call LOG,CXX ,$$@,$(X86_32_CXX) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(NACL_CXXFLAGS) $(X86_32_CXXFLAGS)) 114 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_32_pic) 115 116 -include $(call SRC_TO_DEP,$(1),_x86_64_pic) 117 $(call SRC_TO_OBJ,$(1),_x86_64_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 118 $(call LOG,CXX ,$$@,$(X86_64_CXX) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(NACL_CXXFLAGS) $(X86_64_CXXFLAGS)) 119 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_x86_64_pic) 120 121 -include $(call SRC_TO_DEP,$(1),_arm_pic) 122 $(call SRC_TO_OBJ,$(1),_arm_pic): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 123 $(call LOG,CXX ,$$@,$(ARM_CXX) -o $$@ -c $$< -fPIC $(POSIX_FLAGS) $(2) $(NACL_CXXFLAGS) $(ARM_CXXFLAGS)) 124 @$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_arm_pic) 125 endef 126 127 128 # 129 # $1 = Source Name 130 # $2 = POSIX Compile Flags 131 # $3 = Include Directories 132 # $4 = VC Flags (unused) 133 # 134 define COMPILE_RULE 135 ifeq ($(suffix $(1)),.c) 136 $(call C_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc)) $(3)) 137 else 138 $(call CXX_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc)) $(3)) 139 endif 140 endef 141 142 # 143 # Determine which architectures to build for. The user can set NACL_ARCH or 144 # ARCHES in the environment to control this. 145 # 146 VALID_ARCHES := x86_32 x86_64 147 ifeq (newlib,$(TOOLCHAIN)) 148 VALID_ARCHES += arm 149 endif 150 151 ifdef NACL_ARCH 152 ifeq (,$(findstring $(NACL_ARCH),$(VALID_ARCHES))) 153 $(error Invalid arch specified in NACL_ARCH: $(NACL_ARCH). Valid values are: $(VALID_ARCHES)) 154 endif 155 ARCHES = ${NACL_ARCH} 156 else 157 ARCHES ?= ${VALID_ARCHES} 158 endif 159 160 GLIBC_REMAP := 161 162 # 163 # SO Macro 164 # 165 # As well as building and installing a shared library this rule adds dependencies 166 # on the library's .stamp file in STAMPDIR. However, the rule for creating the stamp 167 # file is part of LIB_RULE, so users of the DEPS system are currently required to 168 # use the LIB_RULE macro as well as the SO_RULE for each shared library. 169 # 170 # $1 = Target Name 171 # $2 = List of Sources 172 # $3 = List of LIBS 173 # $4 = List of DEPS 174 # $5 = Library Paths 175 # $6 = 1 => Don't add to NMF. 176 # 177 define SO_LINKER_RULE 178 ifneq (,$(findstring x86_32,$(ARCHES))) 179 all: $(OUTDIR)/lib$(1)_x86_32.so 180 $(OUTDIR)/lib$(1)_x86_32.so: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_32_pic)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp) 181 $(call LOG,LINK,$$@,$(X86_32_LINK) -o $$@ $$(filter %.o,$$^) $(LDFLAGS_SHARED) -m32 $(NACL_LDFLAGS) $(X86_32_LDFLAGS) $(LDFLAGS) $(foreach path,$(5),-L$(path)/$(TOOLCHAIN)_x86_32/$(CONFIG)) $(foreach lib,$(3),-l$(lib))) 182 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@) 183 184 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so 185 install: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so 186 $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).so: $(OUTDIR)/lib$(1)_x86_32.so 187 $(MKDIR) -p $$(dir $$@) 188 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@) 189 ifneq ($(6),1) 190 GLIBC_SO_LIST += $(OUTDIR)/lib$(1)_x86_32.so 191 GLIBC_REMAP += -n lib$(1)_x86_32.so,lib$(1).so 192 endif 193 endif 194 195 ifneq (,$(findstring x86_64,$(ARCHES))) 196 all: $(OUTDIR)/lib$(1)_x86_64.so 197 $(OUTDIR)/lib$(1)_x86_64.so: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_64_pic)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp) 198 $(call LOG,LINK,$$@,$(X86_32_LINK) -o $$@ $$(filter %.o,$$^) $(LDFLAGS_SHARED) -m64 $(NACL_LDFLAGS) $(X86_64_LDFLAGS) $(LDFLAGS) $(foreach path,$(5),-L$(path)/$(TOOLCHAIN)_x86_64/$(CONFIG)) $(foreach lib,$(3),-l$(lib))) 199 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@) 200 201 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so 202 install: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so 203 $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).so: $(OUTDIR)/lib$(1)_x86_64.so 204 $(MKDIR) -p $$(dir $$@) 205 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@) 206 ifneq ($(6),1) 207 GLIBC_SO_LIST += $(OUTDIR)/lib$(1)_x86_64.so 208 GLIBC_REMAP += -n lib$(1)_x86_64.so,lib$(1).so 209 endif 210 endif 211 endef 212 213 # 214 # $1 = Target Name 215 # $2 = List of Sources 216 # $3 = List of LIBS 217 # $4 = List of DEPS 218 # $5 = 1 => Don't add to NMF. 219 # 220 define SO_RULE 221 $(call SO_LINKER_RULE,$(1),$(2),$(filter-out pthread,$(3)),$(4),$(LIB_PATHS),$(5)) 222 endef 223 224 # 225 # LIB Macro 226 # 227 # $1 = Target Name 228 # $2 = List of Sources 229 # $3 = POSIX Link Flags 230 # $4 = VC Link Flags (unused) 231 # 232 define LIB_RULE 233 $(STAMPDIR)/$(1).stamp: 234 @echo " STAMP $$@" 235 @echo "TOUCHED $$@" > $(STAMPDIR)/$(1).stamp 236 237 ifneq (,$(findstring x86_32,$(ARCHES))) 238 all: $(OUTDIR)/lib$(1)_x86_32.a 239 $(OUTDIR)/lib$(1)_x86_32.a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_32)) 240 $(MKDIR) -p $$(dir $$@) 241 $(RM) -f $$@ 242 $(call LOG,LIB ,$$@,$(X86_32_LIB) -cr $$@ $$^) 243 244 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).a 245 install: $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).a 246 $(LIBDIR)/$(TOOLCHAIN)_x86_32/$(CONFIG)/lib$(1).a: $(OUTDIR)/lib$(1)_x86_32.a 247 $(MKDIR) -p $$(dir $$@) 248 $(RM) -f $$@ 249 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@) 250 endif 251 252 ifneq (,$(findstring x86_64,$(ARCHES))) 253 all: $(OUTDIR)/lib$(1)_x86_64.a 254 $(OUTDIR)/lib$(1)_x86_64.a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_64)) 255 $(MKDIR) -p $$(dir $$@) 256 $(RM) -f $$@ 257 $(call LOG,LIB ,$$@,$(X86_64_LIB) -cr $$@ $$^) 258 259 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).a 260 install: $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).a 261 $(LIBDIR)/$(TOOLCHAIN)_x86_64/$(CONFIG)/lib$(1).a: $(OUTDIR)/lib$(1)_x86_64.a 262 $(MKDIR) -p $$(dir $$@) 263 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@) 264 endif 265 266 ifneq (,$(findstring arm,$(ARCHES))) 267 ifneq ($(TOOLCHAIN),glibc) 268 all: $(OUTDIR)/lib$(1)_arm.a 269 $(OUTDIR)/lib$(1)_arm.a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_arm)) 270 $(MKDIR) -p $$(dir $$@) 271 $(RM) -f $$@ 272 $(call LOG,LIB ,$$@,$(ARM_LIB) -cr $$@ $$^) 273 274 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).a 275 install: $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).a 276 $(LIBDIR)/$(TOOLCHAIN)_arm/$(CONFIG)/lib$(1).a: $(OUTDIR)/lib$(1)_arm.a 277 $(MKDIR) -p $$(dir $$@) 278 $(call LOG,CP ,$$@,$(OSHELPERS) cp $$^ $$@) 279 endif 280 endif 281 endef 282 283 284 # 285 # Specific Link Macro 286 # 287 # $1 = Target Name 288 # $2 = List of Sources 289 # $3 = List of LIBS 290 # $4 = List of DEPS 291 # $5 = Link Flags 292 # $6 = Library Paths 293 # 294 define LINKER_RULE 295 ifneq (,$(findstring x86_32,$(ARCHES))) 296 all: $(OUTDIR)/$(1)_x86_32.nexe 297 $(OUTDIR)/$(1)_x86_32.nexe: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_32)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp) 298 $(call LOG,LINK,$$@,$(X86_32_LINK) -o $$@ $$(filter %.o,$$^) $(NACL_LDFLAGS) $(X86_32_LDFLAGS) $(foreach path,$(6),-L$(path)/$(TOOLCHAIN)_x86_32/$(CONFIG)) $(foreach lib,$(3),-l$(lib)) $(5)) 299 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@) 300 endif 301 302 ifneq (,$(findstring x86_64,$(ARCHES))) 303 all: $(OUTDIR)/$(1)_x86_64.nexe 304 $(OUTDIR)/$(1)_x86_64.nexe: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_x86_64)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp) 305 $(call LOG,LINK,$$@,$(X86_64_LINK) -o $$@ $$(filter %.o,$$^) $(NACL_LDFLAGS) $(X86_64_LDFLAGS) $(foreach path,$(6),-L$(path)/$(TOOLCHAIN)_x86_64/$(CONFIG)) $(foreach lib,$(3),-l$(lib)) $(5)) 306 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@) 307 endif 308 309 ifneq (,$(findstring arm,$(ARCHES))) 310 all: $(OUTDIR)/$(1)_arm.nexe 311 $(OUTDIR)/$(1)_arm.nexe: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_arm)) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp) 312 $(call LOG,LINK,$$@,$(ARM_LINK) -o $$@ $$(filter %.o,$$^) $(NACL_LDFLAGS) $(ARM_LDFLAGS) $(foreach path,$(6),-L$(path)/$(TOOLCHAIN)_arm/$(CONFIG)) $(foreach lib,$(3),-l$(lib)) $(5)) 313 $(call LOG,VALIDATE,$$@,$(NCVAL) $$@) 314 endif 315 endef 316 317 318 # 319 # Generalized Link Macro 320 # 321 # $1 = Target Name 322 # $2 = List of Sources 323 # $3 = List of LIBS 324 # $4 = List of DEPS 325 # $5 = POSIX Linker Switches 326 # $6 = VC Linker Switches 327 # 328 define LINK_RULE 329 $(call LINKER_RULE,$(1),$(2),$(filter-out pthread,$(3)),$(4),$(5),$(LIB_PATHS)) 330 endef 331 332 333 # 334 # Strip Macro for each arch (e.g., each arch supported by LINKER_RULE). 335 # 336 # $1 = Target Name 337 # $2 = Source Name 338 # 339 define STRIP_ALL_RULE 340 ifneq (,$(findstring x86_32,$(ARCHES))) 341 $(OUTDIR)/$(1)_x86_32.nexe: $(OUTDIR)/$(2)_x86_32.nexe 342 $(call LOG,STRIP,$$@,$(X86_32_STRIP) -o $$@ $$^) 343 endif 344 345 ifneq (,$(findstring x86_64,$(ARCHES))) 346 $(OUTDIR)/$(1)_x86_64.nexe: $(OUTDIR)/$(2)_x86_64.nexe 347 $(call LOG,STRIP,$$@,$(X86_64_STRIP) -o $$@ $$^) 348 endif 349 350 ifneq (,$(findstring arm,$(ARCHES))) 351 $(OUTDIR)/$(1)_arm.nexe: $(OUTDIR)/$(2)_arm.nexe 352 $(call LOG,STRIP,$$@,$(ARM_STRIP) -o $$@ $$^) 353 endif 354 endef 355 356 357 # 358 # Top-level Strip Macro 359 # 360 # $1 = Target Basename 361 # $2 = Source Basename 362 # 363 define STRIP_RULE 364 $(call STRIP_ALL_RULE,$(1),$(2)) 365 endef 366 367 368 # 369 # Strip Macro for each arch (e.g., each arch supported by MAP_RULE). 370 # 371 # $1 = Target Name 372 # $2 = Source Name 373 # 374 define MAP_ALL_RULE 375 ifneq (,$(findstring x86_32,$(ARCHES))) 376 all: $(OUTDIR)/$(1)_x86_32.map 377 $(OUTDIR)/$(1)_x86_32.map: $(OUTDIR)/$(2)_x86_32.nexe 378 $(call LOG,MAP,$$@,$(X86_32_NM) -l $$^ > $$@) 379 endif 380 381 ifneq (,$(findstring x86_64,$(ARCHES))) 382 all: $(OUTDIR)/$(1)_x86_64.map 383 $(OUTDIR)/$(1)_x86_64.map: $(OUTDIR)/$(2)_x86_64.nexe 384 $(call LOG,MAP,$$@,$(X86_64_NM) -l $$^ > $$@) 385 endif 386 387 ifneq (,$(findstring arm,$(ARCHES))) 388 all: $(OUTDIR)/$(1)_arm.map 389 $(OUTDIR)/$(1)_arm.map: $(OUTDIR)/$(2)_arm.nexe 390 $(call LOG,MAP,$$@,$(ARM_NM) -l $$^ > $$@ ) 391 endif 392 endef 393 394 395 # 396 # Top-level MAP Generation Macro 397 # 398 # $1 = Target Basename 399 # $2 = Source Basename 400 # 401 define MAP_RULE 402 $(call MAP_ALL_RULE,$(1),$(2)) 403 endef 404 405 406 # 407 # Generate ARCH_SUFFIXES, a list of suffixes for executables corresponding to all 408 # the architectures in the current build. 409 # 410 ARCH_SUFFIXES := $(foreach arch,$(ARCHES),_$(arch).nexe) 411 412 413 # 414 # NMF Manifiest generation 415 # 416 # Use the python script create_nmf to scan the binaries for dependencies using 417 # objdump. Pass in the (-L) paths to the default library toolchains so that we 418 # can find those libraries and have it automatically copy the files (-s) to 419 # the target directory for us. 420 # 421 # $1 = Target Name (the basename of the nmf 422 # $2 = Additional create_nmf.py arguments 423 # 424 NMF := python $(NACL_SDK_ROOT)/tools/create_nmf.py 425 ifeq ($(CONFIG),Debug) 426 NMF_FLAGS += --debug-libs 427 HTML_FLAGS += --debug-libs 428 endif 429 430 EXECUTABLES=$(foreach arch,$(ARCH_SUFFIXES),$(OUTDIR)/$(1)$(arch)) $(GLIBC_SO_LIST) 431 432 define NMF_RULE 433 all: $(OUTDIR)/$(1).nmf 434 $(OUTDIR)/$(1).nmf: $(EXECUTABLES) 435 $(call LOG,CREATE_NMF,$$@,$(NMF) $(NMF_FLAGS) -o $$@ $$^ $(GLIBC_PATHS) -s $(OUTDIR) $(2) $(GLIBC_REMAP)) 436 endef 437 438 # 439 # HTML file generation 440 # 441 CREATE_HTML := python $(NACL_SDK_ROOT)/tools/create_html.py 442 443 define HTML_RULE 444 all: $(OUTDIR)/$(1).html 445 $(OUTDIR)/$(1).html: $(EXECUTABLES) 446 $(call LOG,CREATE_HTML,$$@,$(CREATE_HTML) $(HTML_FLAGS) -o $$@ $$^) 447 endef 448 449 450 # 451 # Determine which executable to pass into the debugger. For newlib 452 # this is the NEXE which will actually be used. For glibc, runnable-ld.so 453 # is the "app", and the "app" is actual an .so we load. 454 # 455 ifeq (x86_32,$(SYSARCH)) 456 LIB_NAME = lib32 457 else 458 LIB_NAME = lib64 459 endif 460 461 462 ifeq (newlib,$(TOOLCHAIN)) 463 GDB_DEBUG_TARGET = $(abspath $(OUTDIR))/$(TARGET)_$(SYSARCH).nexe 464 else 465 GDB_DEBUG_TARGET = $(abspath $(OUTDIR))/$(LIB_NAME)/runnable-ld.so 466 endif 467 468 ifdef STANDALONE 469 run: all 470 ifndef NACL_ARCH 471 $(error Cannot run in sel_ldr unless $$NACL_ARCH is set) 472 endif 473 $(SEL_LDR_PATH) $(SEL_LDR_ARGS) $(OUTDIR)/$(TARGET)_$(NACL_ARCH).nexe -- $(EXE_ARGS) 474 475 debug: all 476 ifndef NACL_ARCH 477 $(error Cannot run in sel_ldr unless $$NACL_ARCH is set) 478 endif 479 $(SEL_LDR_PATH) -d $(SEL_LDR_ARGS) $(OUTDIR)/$(TARGET)_$(NACL_ARCH).nexe -- $(EXE_ARGS) 480 endif 481