Home | History | Annotate | Download | only in tools
      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 # Paths to Tools
     12 #
     13 PNACL_BIN = $(TC_PATH)/$(OSNAME)_x86_$(TOOLCHAIN)/newlib/bin
     14 PNACL_CC ?= $(PNACL_BIN)/pnacl-clang -c
     15 PNACL_CXX ?= $(PNACL_BIN)/pnacl-clang++ -c
     16 PNACL_LINK ?= $(PNACL_BIN)/pnacl-clang++
     17 PNACL_LIB ?= $(PNACL_BIN)/pnacl-ar
     18 PNACL_STRIP ?= $(PNACL_BIN)/pnacl-strip
     19 PNACL_FINALIZE ?= $(PNACL_BIN)/pnacl-finalize
     20 PNACL_TRANSLATE ?= $(PNACL_BIN)/pnacl-translate
     21 
     22 #
     23 # Compile Macro
     24 #
     25 # $1 = Source Name
     26 # $2 = Compile Flags
     27 # $3 = Include Directories
     28 #
     29 define C_COMPILER_RULE
     30 -include $(call SRC_TO_DEP,$(1),_pnacl)
     31 $(call SRC_TO_OBJ,$(1),_pnacl): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
     32 	$(call LOG,CC  ,$$@,$(PNACL_CC) -o $$@ -c $$< $(POSIX_FLAGS) $(2) $(NACL_CFLAGS))
     33 	@$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_pnacl)
     34 endef
     35 
     36 define CXX_COMPILER_RULE
     37 -include $(call SRC_TO_DEP,$(1),_pnacl)
     38 $(call SRC_TO_OBJ,$(1),_pnacl): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
     39 	$(call LOG,CXX ,$$@,$(PNACL_CXX) -o $$@ -c $$< $(POSIX_FLAGS) $(2) $(NACL_CFLAGS))
     40 	@$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_pnacl)
     41 endef
     42 
     43 
     44 # $1 = Source Name
     45 # $2 = POSIX Compile Flags
     46 # $3 = Include Directories
     47 # $4 = VC Flags (unused)
     48 define COMPILE_RULE
     49 ifeq ($(suffix $(1)),.c)
     50 $(call C_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc)) $(3))
     51 else
     52 $(call CXX_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc)) $(3))
     53 endif
     54 endef
     55 
     56 
     57 #
     58 # SO Macro
     59 #
     60 # $1 = Target Name
     61 # $2 = List of Sources
     62 #
     63 #
     64 define SO_RULE
     65 $(error 'Shared libraries not supported by PNaCl')
     66 endef
     67 
     68 
     69 #
     70 # LIB Macro
     71 #
     72 # $1 = Target Name
     73 # $2 = List of Sources
     74 # $3 = POSIX Link Flags
     75 # $4 = VC Link Flags (unused)
     76 define LIB_RULE
     77 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)/$(CONFIG)/lib$(1).a
     78 	@echo "TOUCHED $$@" > $(STAMPDIR)/$(1).stamp
     79 
     80 all: $(LIBDIR)/$(TOOLCHAIN)/$(CONFIG)/lib$(1).a
     81 $(LIBDIR)/$(TOOLCHAIN)/$(CONFIG)/lib$(1).a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_pnacl))
     82 	$(MKDIR) -p $$(dir $$@)
     83 	$(call LOG,LIB,$$@,$(PNACL_LIB) -cr $$@ $$^ $(3))
     84 endef
     85 
     86 
     87 #
     88 # Specific Link Macro
     89 #
     90 # $1 = Target Name
     91 # $2 = List of inputs
     92 # $3 = List of libs
     93 # $4 = List of deps
     94 # $5 = List of lib dirs
     95 # $6 = Other Linker Args
     96 #
     97 # For debugging, we translate the pre-finalized .bc file.
     98 #
     99 define LINKER_RULE
    100 all: $(1).pexe 
    101 $(1)_x86_32.nexe : $(1).bc
    102 	$(call LOG,TRANSLATE,$$@,$(PNACL_TRANSLATE) --allow-llvm-bitcode-input -arch x86-32 $$^ -o $$@)
    103 
    104 $(1)_x86_64.nexe : $(1).bc
    105 	$(call LOG,TRANSLATE,$$@,$(PNACL_TRANSLATE) --allow-llvm-bitcode-input -arch x86-64 $$^ -o $$@)
    106 
    107 $(1)_arm.nexe : $(1).bc
    108 	$(call LOG,TRANSLATE,$$@,$(PNACL_TRANSLATE) --allow-llvm-bitcode-input -arch arm $$^ -o $$@)
    109 
    110 $(1).pexe: $(1).bc
    111 	$(call LOG,FINALIZE,$$@,$(PNACL_FINALIZE) -o $$@ $$^)
    112 
    113 $(1).bc: $(2) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
    114 	$(call LOG,LINK,$$@,$(PNACL_LINK) -o $$@ $(2) $(foreach path,$(5),-L$(path)/pnacl/$(CONFIG)) $(foreach lib,$(3),-l$(lib)) $(6))
    115 endef
    116 
    117 
    118 #
    119 # Generalized Link Macro
    120 #
    121 # $1 = Target Name
    122 # $2 = List of Sources
    123 # $3 = List of LIBS
    124 # $4 = List of DEPS
    125 # $5 = POSIX Linker Switches
    126 # $6 = VC Linker Switches
    127 #
    128 # NOTE:  For Debug builds we translate the .bc file to a .nexe instead of
    129 # using the finalizing to a .pexe.  This enables debugging.
    130 #
    131 define LINK_RULE
    132 ifeq ($(CONFIG),Debug)
    133 EXECUTABLES=$(OUTDIR)/$(1)_x86_32.nexe $(OUTDIR)/$(1)_x86_64.nexe $(OUTDIR)/$(1)_arm.nexe
    134 else
    135 EXECUTABLES=$(OUTDIR)/$(1).pexe
    136 endif
    137 $(call LINKER_RULE,$(OUTDIR)/$(1),$(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_pnacl)),$(filter-out pthread,$(3)),$(4),$(LIB_PATHS),$(5))
    138 endef
    139 
    140 
    141 #
    142 # Strip Macro
    143 #
    144 # NOTE: pnacl-strip does not currently support stripping finalized pexes (in a
    145 # sense, they are already stripped). So we just copy the file instead.
    146 #
    147 # See https://code.google.com/p/nativeclient/issues/detail?id=3534
    148 #
    149 # $1 = Target Name
    150 # $2 = Input Name
    151 #
    152 define STRIP_RULE
    153 all: $(OUTDIR)/$(1).pexe
    154 $(OUTDIR)/$(1).pexe: $(OUTDIR)/$(2).pexe
    155 	$(CP) $$^ $$@
    156 endef
    157 
    158 
    159 #
    160 # NMF Manifiest generation
    161 #
    162 # Use the python script create_nmf to scan the binaries for dependencies using
    163 # objdump.  Pass in the (-L) paths to the default library toolchains so that we
    164 # can find those libraries and have it automatically copy the files (-s) to
    165 # the target directory for us.
    166 #
    167 # $1 = Target Name (the basename of the nmf
    168 # $2 = Additional create_nmf.py arguments
    169 #
    170 NMF:=python $(NACL_SDK_ROOT)/tools/create_nmf.py
    171 
    172 define NMF_RULE
    173 all: $(OUTDIR)/$(1).nmf
    174 $(OUTDIR)/$(1).nmf: $(EXECUTABLES)
    175 	$(call LOG,CREATE_NMF,$$@,$(NMF) -o $$@ $$^ -s $(OUTDIR) $(2))
    176 endef
    177 
    178 #
    179 # HTML file generation
    180 #
    181 CREATE_HTML := python $(NACL_SDK_ROOT)/tools/create_html.py
    182 
    183 define HTML_RULE
    184 all: $(OUTDIR)/$(1).html
    185 $(OUTDIR)/$(1).html: $(EXECUTABLES)
    186 	$(call LOG,CREATE_HTML,$$@,$(CREATE_HTML) -o $$@ $$^)
    187 endef
    188 
    189 
    190 #
    191 # Determine which executable to pass into the debugger.  For pnacl, this is
    192 # the .bc -> .nexe translated app.
    193 #
    194 GDB_DEBUG_TARGET = $(abspath $(OUTDIR))/$(TARGET)_$(SYSARCH).nexe
    195