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