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