nacl_llvm.mk revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
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)_x86_$(TOOLCHAIN)/newlib/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
20
21#
22# Compile Macro
23#
24# $1 = Source Name
25# $2 = Compile Flags
26# $3 = Include Directories
27#
28define C_COMPILER_RULE
29-include $(call SRC_TO_DEP,$(1),_pnacl)
30$(call SRC_TO_OBJ,$(1),_pnacl): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
31	$(call LOG,CC  ,$$@,$(PNACL_CC) -o $$@ -c $$< $(POSIX_FLAGS) $(2) $(NACL_CFLAGS))
32	@$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_pnacl)
33endef
34
35define CXX_COMPILER_RULE
36-include $(call SRC_TO_DEP,$(1),_pnacl)
37$(call SRC_TO_OBJ,$(1),_pnacl): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp
38	$(call LOG,CXX ,$$@,$(PNACL_CXX) -o $$@ -c $$< $(POSIX_FLAGS) $(2) $(NACL_CFLAGS))
39	@$(FIXDEPS) $(call SRC_TO_DEP_PRE_FIXUP,$(1),_pnacl)
40endef
41
42
43# $1 = Source Name
44# $2 = POSIX Compile Flags
45# $3 = Include Directories
46# $4 = VC Flags (unused)
47define COMPILE_RULE
48ifeq ($(suffix $(1)),.c)
49$(call C_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc)) $(3))
50else
51$(call CXX_COMPILER_RULE,$(1),$(2) $(foreach inc,$(INC_PATHS),-I$(inc)) $(3))
52endif
53endef
54
55
56#
57# SO Macro
58#
59# $1 = Target Name
60# $2 = List of Sources
61#
62#
63define SO_RULE
64$(error 'Shared libraries not supported by PNaCl')
65endef
66
67
68#
69# LIB Macro
70#
71# $1 = Target Name
72# $2 = List of Sources
73# $3 = POSIX Link Flags
74# $4 = VC Link Flags (unused)
75define LIB_RULE
76$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(TOOLCHAIN)/$(CONFIG)/lib$(1).a
77	@echo "TOUCHED $$@" > $(STAMPDIR)/$(1).stamp
78
79all: $(LIBDIR)/$(TOOLCHAIN)/$(CONFIG)/lib$(1).a
80$(LIBDIR)/$(TOOLCHAIN)/$(CONFIG)/lib$(1).a: $(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_pnacl))
81	$(MKDIR) -p $$(dir $$@)
82	$(call LOG,LIB,$$@,$(PNACL_LIB) -cr $$@ $$^ $(3))
83endef
84
85
86#
87# Specific Link Macro
88#
89# $1 = Target Name
90# $2 = List of inputs
91# $3 = List of libs
92# $4 = List of deps
93# $5 = List of lib dirs
94# $6 = Other Linker Args
95#
96define LINKER_RULE
97all: $(1).pexe
98$(1).pexe: $(2) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
99	$(call LOG,LINK,$(1).bc,$(PNACL_LINK) -o $(1).bc $(2) $(foreach path,$(5),-L$(path)/pnacl/$(CONFIG)) $(foreach lib,$(3),-l$(lib)) $(6))
100	$(call LOG,FINALIZE,$(1).pexe,$(PNACL_FINALIZE) -o $(1).pexe $(1).bc)
101endef
102
103
104#
105# Generalized Link Macro
106#
107# $1 = Target Name
108# $2 = List of Sources
109# $3 = List of LIBS
110# $4 = List of DEPS
111# $5 = POSIX Linker Switches
112# $6 = VC Linker Switches
113#
114define LINK_RULE
115$(call LINKER_RULE,$(OUTDIR)/$(1),$(foreach src,$(2),$(call SRC_TO_OBJ,$(src),_pnacl)),$(filter-out pthread,$(3)),$(4),$(LIB_PATHS),$(5))
116endef
117
118
119#
120# Strip Macro
121#
122# NOTE: pnacl-strip does not currently support stripping finalized pexes (in a
123# sense, they are already stripped). So we just copy the file instead.
124#
125# See https://code.google.com/p/nativeclient/issues/detail?id=3534
126#
127# $1 = Target Name
128# $2 = Input Name
129#
130define STRIP_RULE
131all: $(OUTDIR)/$(1).pexe
132$(OUTDIR)/$(1).pexe: $(OUTDIR)/$(2).pexe
133	$(CP) $$^ $$@
134endef
135
136
137#
138# NMF Manifiest generation
139#
140# Use the python script create_nmf to scan the binaries for dependencies using
141# objdump.  Pass in the (-L) paths to the default library toolchains so that we
142# can find those libraries and have it automatically copy the files (-s) to
143# the target directory for us.
144#
145# $1 = Target Name (the basename of the nmf
146# $2 = Additional create_nmf.py arguments
147#
148NMF:=python $(NACL_SDK_ROOT)/tools/create_nmf.py
149
150define NMF_RULE
151all: $(OUTDIR)/$(1).nmf
152$(OUTDIR)/$(1).nmf: $(OUTDIR)/$(1).pexe
153	$(call LOG,CREATE_NMF,$$@,$(NMF) -o $$@ $$^ -s $(OUTDIR) $(2))
154endef
155
156#
157# HTML file generation
158#
159CREATE_HTML := python $(NACL_SDK_ROOT)/tools/create_html.py
160
161define HTML_RULE
162all: $(OUTDIR)/$(1).html
163$(OUTDIR)/$(1).html: $(OUTDIR)/$(1).pexe
164	$(call LOG,CREATE_HTML,$$@,$(CREATE_HTML) -o $$@ $$^)
165endef
166