1#===- ./Makefile -------------------------------------------*- Makefile -*--===#
2#
3#                     The LLVM Compiler Infrastructure
4#
5# This file is distributed under the University of Illinois Open Source
6# License. See LICENSE.TXT for details.
7#
8#===------------------------------------------------------------------------===#
9
10LEVEL := .
11
12# Top-Level LLVM Build Stages:
13#   1. Build lib/Support and lib/TableGen, which are used by utils (tblgen).
14#   2. Build utils, which is used by VMCore.
15#   3. Build VMCore, which builds the Intrinsics.inc file used by libs.
16#   4. Build libs, which are needed by llvm-config.
17#   5. Build llvm-config, which determines inter-lib dependencies for tools.
18#   6. Build tools, runtime, docs.
19#
20# When cross-compiling, there are some things (tablegen) that need to
21# be build for the build system first.
22
23# If "RC_ProjectName" exists in the environment, and its value is
24# "llvmCore", then this is an "Apple-style" build; search for
25# "Apple-style" in the comments for more info.  Anything else is a
26# normal build.
27ifneq ($(findstring llvmCore, $(RC_ProjectName)),llvmCore)  # Normal build (not "Apple-style").
28
29ifeq ($(BUILD_DIRS_ONLY),1)
30  DIRS := lib/Support lib/TableGen utils tools/llvm-config
31  OPTIONAL_DIRS := tools/clang/utils/TableGen
32else
33  DIRS := lib/Support lib/TableGen utils lib/VMCore lib tools/llvm-shlib \
34          tools/llvm-config tools runtime docs unittests
35  OPTIONAL_DIRS := projects bindings
36endif
37
38ifeq ($(BUILD_EXAMPLES),1)
39  OPTIONAL_DIRS += examples
40endif
41
42EXTRA_DIST := test unittests llvm.spec include win32 Xcode
43
44include $(LEVEL)/Makefile.config
45
46ifneq ($(ENABLE_SHARED),1)
47  DIRS := $(filter-out tools/llvm-shlib, $(DIRS))
48endif
49
50ifneq ($(ENABLE_DOCS),1)
51  DIRS := $(filter-out docs, $(DIRS))
52endif
53
54ifeq ($(MAKECMDGOALS),libs-only)
55  DIRS := $(filter-out tools runtime docs, $(DIRS))
56  OPTIONAL_DIRS :=
57endif
58
59ifeq ($(MAKECMDGOALS),install-libs)
60  DIRS := $(filter-out tools runtime docs, $(DIRS))
61  OPTIONAL_DIRS := $(filter bindings, $(OPTIONAL_DIRS))
62endif
63
64ifeq ($(MAKECMDGOALS),tools-only)
65  DIRS := $(filter-out runtime docs, $(DIRS))
66  OPTIONAL_DIRS :=
67endif
68
69ifeq ($(MAKECMDGOALS),install-clang)
70  DIRS := tools/clang/tools/driver tools/clang/lib/Headers \
71          tools/clang/tools/libclang \
72          tools/clang/include/clang-c \
73          tools/clang/runtime tools/clang/docs \
74          tools/lto runtime
75  ifneq ($(BUILD_CLANG_ONLY),YES)
76    DIRS += tools/clang/tools/c-index-test
77  endif
78  OPTIONAL_DIRS :=
79  NO_INSTALL = 1
80endif
81
82ifeq ($(MAKECMDGOALS),clang-only)
83  BUILD_CLANG_ONLY := YES
84  DIRS := $(filter-out tools docs unittests, $(DIRS)) \
85          tools/clang tools/lto
86  OPTIONAL_DIRS :=
87endif
88
89ifeq ($(MAKECMDGOALS),unittests)
90  DIRS := $(filter-out tools runtime docs, $(DIRS)) utils unittests
91  OPTIONAL_DIRS :=
92endif
93
94# Use NO_INSTALL define of the Makefile of each directory for deciding
95# if the directory is installed or not
96ifeq ($(MAKECMDGOALS),install)
97  OPTIONAL_DIRS := $(filter bindings, $(OPTIONAL_DIRS))
98endif
99
100# Don't build unittests when ONLY_TOOLS is set.
101ifneq ($(ONLY_TOOLS),)
102  DIRS := $(filter-out unittests, $(DIRS))
103endif
104
105# If we're cross-compiling, build the build-hosted tools first
106ifeq ($(LLVM_CROSS_COMPILING),1)
107all:: cross-compile-build-tools
108
109clean::
110	$(Verb) rm -rf BuildTools
111
112cross-compile-build-tools:
113	$(Verb) if [ ! -f BuildTools/Makefile ]; then \
114          $(MKDIR) BuildTools; \
115	  cd BuildTools ; \
116	  unset CFLAGS ; \
117	  unset CXXFLAGS ; \
118	  unset SDKROOT ; \
119	  unset UNIVERSAL_SDK_PATH ; \
120	  $(PROJ_SRC_DIR)/configure --build=$(BUILD_TRIPLE) \
121		--host=$(BUILD_TRIPLE) --target=$(BUILD_TRIPLE) \
122	        --disable-polly ; \
123	  cd .. ; \
124	fi; \
125	($(MAKE) -C BuildTools \
126	  BUILD_DIRS_ONLY=1 \
127	  UNIVERSAL= \
128	  UNIVERSAL_SDK_PATH= \
129	  SDKROOT= \
130	  TARGET_NATIVE_ARCH="$(TARGET_NATIVE_ARCH)" \
131	  TARGETS_TO_BUILD="$(TARGETS_TO_BUILD)" \
132	  ENABLE_OPTIMIZED=$(ENABLE_OPTIMIZED) \
133	  ENABLE_PROFILING=$(ENABLE_PROFILING) \
134	  ENABLE_COVERAGE=$(ENABLE_COVERAGE) \
135	  DISABLE_ASSERTIONS=$(DISABLE_ASSERTIONS) \
136	  ENABLE_EXPENSIVE_CHECKS=$(ENABLE_EXPENSIVE_CHECKS) \
137	  ENABLE_LIBCPP=$(ENABLE_LIBCPP) \
138	  CFLAGS= \
139	  CXXFLAGS= \
140	) || exit 1;
141endif
142
143# Include the main makefile machinery.
144include $(LLVM_SRC_ROOT)/Makefile.rules
145
146# Specify options to pass to configure script when we're
147# running the dist-check target
148DIST_CHECK_CONFIG_OPTIONS = --with-llvmgccdir=$(LLVMGCCDIR)
149
150.PHONY: debug-opt-prof
151debug-opt-prof:
152	$(Echo) Building Debug Version
153	$(Verb) $(MAKE)
154	$(Echo)
155	$(Echo) Building Optimized Version
156	$(Echo)
157	$(Verb) $(MAKE) ENABLE_OPTIMIZED=1
158	$(Echo)
159	$(Echo) Building Profiling Version
160	$(Echo)
161	$(Verb) $(MAKE) ENABLE_PROFILING=1
162
163dist-hook::
164	$(Echo) Eliminating files constructed by configure
165	$(Verb) $(RM) -f \
166	  $(TopDistDir)/include/llvm/Config/config.h  \
167	  $(TopDistDir)/include/llvm/Support/DataTypes.h
168
169clang-only: all
170tools-only: all
171libs-only: all
172install-clang: install
173install-libs: install
174
175# If SHOW_DIAGNOSTICS is enabled, clear the diagnostics file first.
176ifeq ($(SHOW_DIAGNOSTICS),1)
177clean-diagnostics:
178	$(Verb) rm -f $(LLVM_OBJ_ROOT)/$(BuildMode)/diags
179.PHONY: clean-diagnostics
180
181all-local:: clean-diagnostics
182endif
183
184#------------------------------------------------------------------------
185# Make sure the generated files are up-to-date. This must be kept in
186# sync with the AC_CONFIG_HEADER and AC_CONFIG_FILE invocations in
187# autoconf/configure.ac.
188# Note that Makefile.config is covered by its own separate rule
189# in Makefile.rules where it can be reused by sub-projects.
190#------------------------------------------------------------------------
191FilesToConfig := \
192  bindings/ocaml/llvm/META.llvm \
193  docs/doxygen.cfg \
194  llvm.spec \
195  include/llvm/Config/config.h \
196  include/llvm/Config/llvm-config.h \
197  include/llvm/Config/Targets.def \
198  include/llvm/Config/AsmPrinters.def \
199  include/llvm/Config/AsmParsers.def \
200  include/llvm/Config/Disassemblers.def \
201  include/llvm/Support/DataTypes.h
202FilesToConfigPATH  := $(addprefix $(LLVM_OBJ_ROOT)/,$(FilesToConfig))
203
204all-local:: $(FilesToConfigPATH)
205$(FilesToConfigPATH) : $(LLVM_OBJ_ROOT)/% : $(LLVM_SRC_ROOT)/%.in
206	$(Echo) Regenerating $*
207	$(Verb) cd $(LLVM_OBJ_ROOT) && $(ConfigStatusScript) $*
208.PRECIOUS: $(FilesToConfigPATH)
209
210# NOTE: This needs to remain as the last target definition in this file so
211# that it gets executed last.
212ifneq ($(BUILD_DIRS_ONLY),1)
213all::
214	$(Echo) '*****' Completed $(BuildMode) Build
215ifneq ($(ENABLE_OPTIMIZED),1)
216	$(Echo) '*****' Note: Debug build can be 10 times slower than an
217	$(Echo) '*****' optimized build. Use 'make ENABLE_OPTIMIZED=1' to
218	$(Echo) '*****' make an optimized build. Alternatively you can
219	$(Echo) '*****' configure with --enable-optimized.
220ifeq ($(SHOW_DIAGNOSTICS),1)
221	$(Verb) if test -s $(LLVM_OBJ_ROOT)/$(BuildMode)/diags; then \
222	  $(LLVM_SRC_ROOT)/utils/clang-parse-diagnostics-file -a \
223	    $(LLVM_OBJ_ROOT)/$(BuildMode)/diags; \
224	fi
225endif
226endif
227endif
228
229check-llvm2cpp:
230	$(Verb)$(MAKE) check TESTSUITE=Feature RUNLLVM2CPP=1
231
232srpm: $(LLVM_OBJ_ROOT)/llvm.spec
233	rpmbuild -bs $(LLVM_OBJ_ROOT)/llvm.spec
234
235rpm: $(LLVM_OBJ_ROOT)/llvm.spec
236	rpmbuild -bb --target $(TARGET_TRIPLE) $(LLVM_OBJ_ROOT)/llvm.spec
237
238show-footprint:
239	$(Verb) du -sk $(LibDir)
240	$(Verb) du -sk $(ToolDir)
241	$(Verb) du -sk $(ExmplDir)
242	$(Verb) du -sk $(ObjDir)
243
244build-for-llvm-top:
245	$(Verb) if test ! -f ./config.status ; then \
246	  ./configure --prefix="$(LLVM_TOP)/install" \
247	    --with-llvm-gcc="$(LLVM_TOP)/llvm-gcc" ; \
248	fi
249	$(Verb) $(MAKE) tools-only
250
251SVN = svn
252SVN-UPDATE-OPTIONS =
253AWK = awk
254SUB-SVN-DIRS = $(AWK) '/I|\?      / {print $$2}'   \
255		| LC_ALL=C xargs $(SVN) info 2>/dev/null \
256		| $(AWK) '/^Path:\ / {print $$2}'
257
258update:
259	$(SVN) $(SVN-UPDATE-OPTIONS) update $(LLVM_SRC_ROOT)
260	@ $(SVN) status --no-ignore $(LLVM_SRC_ROOT) | $(SUB-SVN-DIRS) | xargs $(SVN) $(SVN-UPDATE-OPTIONS) update
261
262happiness: update all check-all
263
264.PHONY: srpm rpm update happiness
265
266# declare all targets at this level to be serial:
267
268.NOTPARALLEL:
269
270else # Building "Apple-style."
271# In an Apple-style build, once configuration is done, lines marked
272# "Apple-style" are removed with sed!  Please don't remove these!
273# Look for the string "Apple-style" in utils/buildit/build_llvm.
274include $(shell find . -name GNUmakefile) # Building "Apple-style."
275endif # Building "Apple-style."
276