Refactor lookup_or_add to contain _MUCH_ less duplicated code. Add support for
[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/System and lib/Support, 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 ifndef RC_ARCHS  # Normal build (not "Apple-style").
23 ifeq ($(BUILD_DIRS_ONLY),1)
24   DIRS := lib/System lib/Support utils
25   OPTIONAL_DIRS :=
26 else
27   DIRS := lib/System lib/Support utils lib/VMCore lib tools/llvm-config \
28           tools runtime docs unittests
29   OPTIONAL_DIRS := examples projects bindings
30 endif
31
32 EXTRA_DIST := test unittests llvm.spec include win32 Xcode
33
34 include $(LEVEL)/Makefile.config
35
36 # llvm-gcc4 doesn't need runtime libs.  llvm-gcc4 is the only supported one.
37 # FIXME: Remove runtime entirely once we have an understanding of where
38 # libprofile etc should go.
39 #ifeq ($(LLVMGCC_MAJVERS),4)
40 #  DIRS := $(filter-out runtime, $(DIRS))
41 #endif
42
43 ifeq ($(MAKECMDGOALS),libs-only)
44   DIRS := $(filter-out tools runtime docs, $(DIRS))
45   OPTIONAL_DIRS :=
46 endif
47
48 ifeq ($(MAKECMDGOALS),install-libs)
49   DIRS := $(filter-out tools runtime docs, $(DIRS))
50   OPTIONAL_DIRS := $(filter bindings, $(OPTIONAL_DIRS))
51 endif
52
53 ifeq ($(MAKECMDGOALS),tools-only)
54   DIRS := $(filter-out runtime docs, $(DIRS))
55   OPTIONAL_DIRS :=
56 endif
57
58 ifeq ($(MAKECMDGOALS),install-clang)
59   DIRS := tools/clang/tools/driver tools/clang/tools/clang-cc \
60         tools/clang/lib/Headers tools/clang/docs
61   OPTIONAL_DIRS :=
62   NO_INSTALL = 1
63 endif
64
65 ifeq ($(MAKECMDGOALS),clang-only)
66   DIRS := $(filter-out tools runtime docs unittests, $(DIRS)) tools/clang
67   OPTIONAL_DIRS :=
68 endif
69
70 ifeq ($(MAKECMDGOALS),unittests)
71   DIRS := $(filter-out tools runtime docs, $(DIRS)) utils unittests
72   OPTIONAL_DIRS :=
73 endif
74
75 # Use NO_INSTALL define of the Makefile of each directory for deciding
76 # if the directory is installed or not
77 ifeq ($(MAKECMDGOALS),install)
78   OPTIONAL_DIRS := $(filter bindings, $(OPTIONAL_DIRS))
79 endif
80
81 # If we're cross-compiling, build the build-hosted tools first
82 ifeq ($(LLVM_CROSS_COMPILING),1)
83 all:: cross-compile-build-tools
84
85 clean::
86         $(Verb) rm -rf BuildTools
87
88 cross-compile-build-tools:
89         $(Verb) if [ ! -f BuildTools/Makefile ]; then \
90           $(MKDIR) BuildTools; \
91           cd BuildTools ; \
92           $(PROJ_SRC_DIR)/configure --build=$(BUILD_TRIPLE) \
93                 --host=$(BUILD_TRIPLE) --target=$(BUILD_TRIPLE); \
94           cd .. ; \
95         fi; \
96         ($(MAKE) -C BuildTools \
97           BUILD_DIRS_ONLY=1 \
98           UNIVERSAL= \
99           ENABLE_OPTIMIZED=$(ENABLE_OPTIMIZED) \
100           ENABLE_PROFILING=$(ENABLE_PROFILING) \
101           ENABLE_COVERAGE=$(ENABLE_COVERAGE) \
102           DISABLE_ASSERTIONS=$(DISABLE_ASSERTIONS) \
103           ENABLE_EXPENSIVE_CHECKS=$(ENABLE_EXPENSIVE_CHECKS) \
104         ) || exit 1;
105 endif
106
107 # Include the main makefile machinery.
108 include $(LLVM_SRC_ROOT)/Makefile.rules
109
110 # Specify options to pass to configure script when we're
111 # running the dist-check target
112 DIST_CHECK_CONFIG_OPTIONS = --with-llvmgccdir=$(LLVMGCCDIR)
113
114 .PHONY: debug-opt-prof
115 debug-opt-prof:
116         $(Echo) Building Debug Version
117         $(Verb) $(MAKE)
118         $(Echo)
119         $(Echo) Building Optimized Version
120         $(Echo)
121         $(Verb) $(MAKE) ENABLE_OPTIMIZED=1
122         $(Echo)
123         $(Echo) Building Profiling Version
124         $(Echo)
125         $(Verb) $(MAKE) ENABLE_PROFILING=1
126
127 dist-hook::
128         $(Echo) Eliminating files constructed by configure
129         $(Verb) $(RM) -f \
130           $(TopDistDir)/include/llvm/Config/config.h  \
131           $(TopDistDir)/include/llvm/Support/DataTypes.h  \
132           $(TopDistDir)/include/llvm/Support/ThreadSupport.h
133
134 clang-only: all
135 tools-only: all
136 libs-only: all
137 install-clang: install
138 install-libs: install
139
140 #------------------------------------------------------------------------
141 # Make sure the generated headers are up-to-date. This must be kept in
142 # sync with the AC_CONFIG_HEADER invocations in autoconf/configure.ac
143 #------------------------------------------------------------------------
144 FilesToConfig := \
145   include/llvm/Config/config.h \
146   include/llvm/Config/Targets.def \
147         include/llvm/Config/AsmPrinters.def \
148   include/llvm/Support/DataTypes.h \
149         tools/llvmc/plugins/Base/Base.td
150 FilesToConfigPATH  := $(addprefix $(LLVM_OBJ_ROOT)/,$(FilesToConfig))
151
152 all-local:: $(FilesToConfigPATH)
153 $(FilesToConfigPATH) : $(LLVM_OBJ_ROOT)/% : $(LLVM_SRC_ROOT)/%.in
154         $(Echo) Regenerating $*
155         $(Verb) cd $(LLVM_OBJ_ROOT) && $(ConfigStatusScript) $*
156 .PRECIOUS: $(FilesToConfigPATH)
157
158 # NOTE: This needs to remain as the last target definition in this file so
159 # that it gets executed last.
160 ifneq ($(BUILD_DIRS_ONLY),1)
161 all::
162         $(Echo) '*****' Completed $(BuildMode)$(AssertMode) Build
163 ifeq ($(BuildMode),Debug)
164         $(Echo) '*****' Note: Debug build can be 10 times slower than an
165         $(Echo) '*****' optimized build. Use 'make ENABLE_OPTIMIZED=1' to
166         $(Echo) '*****' make an optimized build. Alternatively you can
167         $(Echo) '*****' configure with --enable-optimized.
168 endif
169 endif
170
171 check-llvm2cpp:
172         $(Verb)$(MAKE) check TESTSUITE=Feature RUNLLVM2CPP=1
173
174 check-one:
175         $(Verb)$(MAKE) -C test check-one TESTONE=$(TESTONE)
176
177 srpm: $(LLVM_OBJ_ROOT)/llvm.spec
178         rpmbuild -bs $(LLVM_OBJ_ROOT)/llvm.spec
179
180 rpm: $(LLVM_OBJ_ROOT)/llvm.spec
181         rpmbuild -bb --target $(TARGET_TRIPLE) $(LLVM_OBJ_ROOT)/llvm.spec
182
183 show-footprint:
184         $(Verb) du -sk $(LibDir)
185         $(Verb) du -sk $(ToolDir)
186         $(Verb) du -sk $(ExmplDir)
187         $(Verb) du -sk $(ObjDir)
188
189 build-for-llvm-top:
190         $(Verb) if test ! -f ./config.status ; then \
191           ./configure --prefix="$(LLVM_TOP)/install" \
192             --with-llvm-gcc="$(LLVM_TOP)/llvm-gcc" ; \
193         fi
194         $(Verb) $(MAKE) tools-only
195
196 SVN = svn
197 SVN-UPDATE-OPTIONS =
198 AWK = awk
199 SUB-SVN-DIRS = $(AWK) '/\?\ \ \ \ \ \ / {print $$2}'   \
200                 | LC_ALL=C xargs $(SVN) info 2>/dev/null \
201                 | $(AWK) '/Path:\ / {print $$2}'
202
203 update:
204         $(SVN) $(SVN-UPDATE-OPTIONS) update $(LLVM_SRC_ROOT)
205         @ $(SVN) status $(LLVM_SRC_ROOT) | $(SUB-SVN-DIRS) | xargs $(SVN) $(SVN-UPDATE-OPTIONS) update
206
207 happiness: update all check unittests
208
209 .PHONY: srpm rpm update happiness
210
211 # declare all targets at this level to be serial:
212
213 .NOTPARALLEL:
214
215 else # Building "Apple-style."
216 # N.B. In an Apple-style build, once configuration is done, lines
217 # marked "Apple-style" are removed with sed!  See utils/buildit/build_llvm.
218 include utils/buildit/GNUmakefile # Building "Apple-style."
219 endif # Building "Apple-style."