If ARCH is x86_64, pass -m64 to the host compiler. -m32 for i386. This makes sure...
[oota-llvm.git] / Makefile.rules
1 #===-- Makefile.rules - Common make rules for LLVM ---------*- 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 # This file is included by all of the LLVM makefiles.  For details on how to use
11 # it properly, please see the document MakefileGuide.html in the docs directory.
12 #
13 #===-----------------------------------------------------------------------====#
14
15 ################################################################################
16 # TARGETS: Define standard targets that can be invoked
17 ################################################################################
18
19 #--------------------------------------------------------------------
20 # Define the various target sets
21 #--------------------------------------------------------------------
22 RecursiveTargets := all clean clean-all install uninstall install-bytecode
23 LocalTargets     := all-local clean-local clean-all-local check-local \
24                     install-local printvars uninstall-local \
25                     install-bytecode-local unittests
26 TopLevelTargets  := check dist dist-check dist-clean dist-gzip dist-bzip2 \
27                     dist-zip unittests
28 UserTargets      := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
29 InternalTargets  := preconditions distdir dist-hook
30
31 ################################################################################
32 # INITIALIZATION: Basic things the makefile needs
33 ################################################################################
34
35 #--------------------------------------------------------------------
36 # Set the VPATH so that we can find source files.
37 #--------------------------------------------------------------------
38 VPATH=$(PROJ_SRC_DIR)
39
40 #--------------------------------------------------------------------
41 # Reset the list of suffixes we know how to build.
42 #--------------------------------------------------------------------
43 .SUFFIXES:
44 .SUFFIXES: .c .cpp .cc .h .hpp .o .a .bc .td .ps .dot .ll
45 .SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
46
47 #--------------------------------------------------------------------
48 # Mark all of these targets as phony to avoid implicit rule search
49 #--------------------------------------------------------------------
50 .PHONY: $(UserTargets) $(InternalTargets)
51
52 #--------------------------------------------------------------------
53 # Make sure all the user-target rules are double colon rules and
54 # they are defined first.
55 #--------------------------------------------------------------------
56
57 $(UserTargets)::
58
59 ################################################################################
60 # PRECONDITIONS: that which must be built/checked first
61 ################################################################################
62
63 SrcMakefiles       := $(filter %Makefile %Makefile.tests,\
64                       $(wildcard $(PROJ_SRC_DIR)/Makefile*))
65 ObjMakefiles       := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
66 ConfigureScript    := $(PROJ_SRC_ROOT)/configure
67 ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
68 MakefileConfigIn   := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
69 MakefileCommonIn   := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
70 MakefileConfig     := $(PROJ_OBJ_ROOT)/Makefile.config
71 MakefileCommon     := $(PROJ_OBJ_ROOT)/Makefile.common
72 PreConditions      := $(ConfigStatusScript) $(ObjMakefiles)
73 ifneq ($(MakefileCommonIn),)
74 PreConditions      += $(MakefileCommon)
75 endif
76
77 ifneq ($(MakefileConfigIn),)
78 PreConditions      += $(MakefileConfig)
79 endif
80
81 preconditions: $(PreConditions)
82
83 #------------------------------------------------------------------------
84 # Make sure the BUILT_SOURCES are built first
85 #------------------------------------------------------------------------
86 $(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
87
88 clean-all-local::
89 ifneq ($(strip $(BUILT_SOURCES)),)
90         -$(Verb) $(RM) -f $(BUILT_SOURCES)
91 endif
92
93 ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
94 spotless:
95         $(Verb) if test -x config.status ; then \
96           $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
97           $(MKDIR) .spotless.save ; \
98           $(MV) config.status .spotless.save ; \
99           $(MV) mklib  .spotless.save ; \
100           $(MV) projects  .spotless.save ; \
101           $(RM) -rf * ; \
102           $(MV) .spotless.save/config.status . ; \
103           $(MV) .spotless.save/mklib . ; \
104           $(MV) .spotless.save/projects . ; \
105           $(RM) -rf .spotless.save ; \
106           $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
107           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
108           $(ConfigStatusScript) ; \
109         else \
110           $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
111         fi
112 else
113 spotless:
114         $(EchoCmd) "spotless target not supported for objdir == srcdir"
115 endif
116
117 $(BUILT_SOURCES) : $(ObjMakefiles)
118
119 #------------------------------------------------------------------------
120 # Make sure we're not using a stale configuration
121 #------------------------------------------------------------------------
122 reconfigure:
123         $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
124         $(Verb) cd $(PROJ_OBJ_ROOT) && \
125           if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
126             $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
127           fi ; \
128           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
129           $(ConfigStatusScript)
130
131 .PRECIOUS: $(ConfigStatusScript)
132 $(ConfigStatusScript): $(ConfigureScript)
133         $(Echo) Reconfiguring with $<
134         $(Verb) cd $(PROJ_OBJ_ROOT) && \
135           if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
136             $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
137           fi ; \
138           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
139           $(ConfigStatusScript)
140
141 #------------------------------------------------------------------------
142 # Make sure the configuration makefile is up to date
143 #------------------------------------------------------------------------
144 ifneq ($(MakefileConfigIn),)
145 $(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
146         $(Echo) Regenerating $@
147         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
148 endif
149
150 ifneq ($(MakefileCommonIn),)
151 $(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
152         $(Echo) Regenerating $@
153         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
154 endif
155
156 #------------------------------------------------------------------------
157 # If the Makefile in the source tree has been updated, copy it over into the
158 # build tree. But, only do this if the source and object makefiles differ
159 #------------------------------------------------------------------------
160 ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
161
162 Makefile: $(PROJ_SRC_DIR)/Makefile $(ExtraMakefiles)
163         $(Echo) "Updating Makefile"
164         $(Verb) $(MKDIR) $(@D)
165         $(Verb) $(CP) -f $< $@
166
167 # Copy the Makefile.* files unless we're in the root directory which avoids
168 # the copying of Makefile.config.in or other things that should be explicitly
169 # taken care of.
170 $(PROJ_OBJ_DIR)/Makefile% : $(PROJ_SRC_DIR)/Makefile%
171         @case '$?' in \
172           *Makefile.rules) ;; \
173           *.in) ;; \
174           *) $(EchoCmd) "Updating $(@F)" ; \
175              $(MKDIR) $(@D) ; \
176              $(CP) -f $< $@ ;; \
177         esac
178
179 endif
180
181 #------------------------------------------------------------------------
182 # Set up the basic dependencies
183 #------------------------------------------------------------------------
184 $(UserTargets):: $(PreConditions)
185
186 all:: all-local
187 clean:: clean-local
188 clean-all:: clean-local clean-all-local
189 install:: install-local
190 uninstall:: uninstall-local
191 install-local:: all-local
192 install-bytecode:: install-bytecode-local
193
194 ###############################################################################
195 # LLVMC: Provide rules for compiling llvmc plugins
196 ###############################################################################
197
198 ifdef LLVMC_PLUGIN
199
200 LIBRARYNAME := $(patsubst %,plugin_llvmc_%,$(LLVMC_PLUGIN))
201 REQUIRES_EH := 1
202
203 # Build a dynamic library if the user runs `make` directly from the plugin
204 # directory.
205 ifndef LLVMC_BUILTIN_PLUGIN
206 LOADABLE_MODULE = 1
207 endif
208
209 # TableGen stuff...
210 ifneq ($(BUILT_SOURCES),)
211 LLVMC_BUILD_AUTOGENERATED_INC=1
212 endif
213
214 endif # LLVMC_PLUGIN
215
216 ###############################################################################
217 # VARIABLES: Set up various variables based on configuration data
218 ###############################################################################
219
220 # Variable for if this make is for a "cleaning" target
221 ifneq ($(strip $(filter clean clean-local dist-clean,$(MAKECMDGOALS))),)
222   IS_CLEANING_TARGET=1
223 endif
224
225 #--------------------------------------------------------------------
226 # Variables derived from configuration we are building
227 #--------------------------------------------------------------------
228
229 CPP.Defines :=
230 # OPTIMIZE_OPTION - The optimization level option we want to build LLVM with
231 # this can be overridden on the make command line.
232 ifneq ($(OS),MingW)
233   OPTIMIZE_OPTION := -O3
234 else
235   OPTIMIZE_OPTION := -O2
236 endif
237
238 ifdef ENABLE_PROFILING
239   BuildMode := Profile
240   CXX.Flags += $(OPTIMIZE_OPTION) -pg -g
241   C.Flags   += $(OPTIMIZE_OPTION) -pg -g
242   LD.Flags  += $(OPTIMIZE_OPTION) -pg -g
243   KEEP_SYMBOLS := 1
244 else
245   ifeq ($(ENABLE_OPTIMIZED),1)
246     BuildMode := Release
247     # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
248     ifneq ($(OS),FreeBSD)
249     ifneq ($(OS),Darwin)
250       OmitFramePointer := -fomit-frame-pointer
251     endif
252     endif
253
254     # Darwin requires -fstrict-aliasing to be explicitly enabled.
255     ifeq ($(OS),Darwin)
256       EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
257     endif
258
259     CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
260     C.Flags   += $(OPTIMIZE_OPTION) $(OmitFramePointer)
261     LD.Flags  += $(OPTIMIZE_OPTION)
262   else
263     BuildMode := Debug
264     CXX.Flags += -g
265     C.Flags   += -g
266     LD.Flags  += -g
267     KEEP_SYMBOLS := 1
268   endif
269 endif
270
271 #ifeq ($(ENABLE_VISIBILITY_INLINES_HIDDEN),1)
272 #    CXX.Flags += -fvisibility-inlines-hidden
273 #endif
274
275 # IF REQUIRES_EH=1 is specified then don't disable exceptions
276 ifndef REQUIRES_EH
277   CXX.Flags += -fno-exceptions
278 endif
279
280 # IF REQUIRES_RTTI=1 is specified then don't disable run-time type id
281 ifndef REQUIRES_RTTI
282 #  CXX.Flags += -fno-rtti
283 endif
284
285 # If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
286 # then disable assertions by defining the appropriate preprocessor symbols.
287 ifdef DISABLE_ASSERTIONS
288   BuildMode := $(BuildMode)-Asserts
289   CPP.Defines += -DNDEBUG
290 else
291   CPP.Defines += -D_DEBUG
292 endif
293
294 # If ENABLE_EXPENSIVE_CHECKS=1 is specified (make command line or
295 # configured), then enable expensive checks by defining the
296 # appropriate preprocessor symbols.
297 ifdef ENABLE_EXPENSIVE_CHECKS
298   BuildMode := $(BuildMode)+Checks
299   CPP.Defines += -D_GLIBCXX_DEBUG -DXDEBUG
300 endif
301
302 # LOADABLE_MODULE implies several other things so we force them to be
303 # defined/on.
304 ifdef LOADABLE_MODULE
305   SHARED_LIBRARY := 1
306   DONT_BUILD_RELINKED := 1
307   LINK_LIBS_IN_SHARED := 1
308 endif
309
310 ifdef SHARED_LIBRARY
311   ENABLE_PIC := 1
312   PIC_FLAG = "(PIC)"
313 endif
314
315 ifeq ($(ENABLE_PIC),1)
316   ifeq ($(OS), $(filter $(OS), Cygwin MingW))
317     # Nothing. Win32 defaults to PIC and warns when given -fPIC
318   else
319     ifeq ($(OS),Darwin)
320       # Common symbols not allowed in dylib files
321       CXX.Flags += -fno-common
322       C.Flags   += -fno-common
323     else
324       # Linux and others; pass -fPIC
325       CXX.Flags += -fPIC
326       C.Flags   += -fPIC
327     endif
328   endif
329 endif
330
331 CXX.Flags     += $(CXXFLAGS) -Woverloaded-virtual
332 C.Flags       += $(CFLAGS)
333 CPP.Defines   += $(CPPFLAGS)
334 CPP.BaseFlags += $(CPP.Defines)
335 LD.Flags      += $(LDFLAGS)
336 AR.Flags      := cru
337
338 # Make Floating point IEEE compliant on Alpha.
339 ifeq ($(ARCH),Alpha)
340   CXX.Flags     += -mieee
341   CPP.BaseFlags += -mieee
342 ifeq ($(ENABLE_PIC),0)
343   CXX.Flags     += -fPIC
344   CPP.BaseFlags += -fPIC
345 endif
346 endif
347
348 ifeq ($(ARCH),Alpha)
349   LD.Flags += -Wl,--no-relax
350 endif
351
352 #--------------------------------------------------------------------
353 # Directory locations
354 #--------------------------------------------------------------------
355 TargetMode :=
356 ifeq ($(LLVM_CROSS_COMPILING),1)
357   BuildLLVMToolDir := $(LLVM_OBJ_ROOT)/BuildTools/$(BuildMode)/bin
358 endif
359
360 ObjRootDir  := $(PROJ_OBJ_DIR)/$(BuildMode)
361 ObjDir      := $(ObjRootDir)
362 LibDir      := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
363 ToolDir     := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
364 ExmplDir    := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
365 LLVMLibDir  := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
366 LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
367 LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
368 CFERuntimeLibDir := $(LLVMGCCDIR)/lib
369
370 #--------------------------------------------------------------------
371 # Full Paths To Compiled Tools and Utilities
372 #--------------------------------------------------------------------
373 EchoCmd  = $(ECHO) llvm[$(MAKELEVEL)]:
374 Echo     = @$(EchoCmd)
375 ifndef LLVMAS
376 LLVMAS   := $(LLVMToolDir)/llvm-as$(EXEEXT)
377 endif
378 ifndef TBLGEN
379   ifeq ($(LLVM_CROSS_COMPILING),1)
380     TBLGEN   := $(BuildLLVMToolDir)/tblgen$(BUILD_EXEEXT)
381   else
382     TBLGEN   := $(LLVMToolDir)/tblgen$(EXEEXT)
383   endif
384 endif
385 LLVM_CONFIG := $(LLVMToolDir)/llvm-config
386 ifndef LLVMLD
387 LLVMLD    := $(LLVMToolDir)/llvm-ld$(EXEEXT)
388 endif
389 ifndef LLVMDIS
390 LLVMDIS  := $(LLVMToolDir)/llvm-dis$(EXEEXT)
391 endif
392 ifndef LLI
393 LLI      := $(LLVMToolDir)/lli$(EXEEXT)
394 endif
395 ifndef LLC
396 LLC      := $(LLVMToolDir)/llc$(EXEEXT)
397 endif
398 ifndef LOPT
399 LOPT     := $(LLVMToolDir)/opt$(EXEEXT)
400 endif
401 ifndef LBUGPOINT
402 LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
403 endif
404 ifndef LUPGRADE
405 LUPGRADE := $(LLVMToolDir)/llvm-upgrade$(EXEEXT)
406 endif
407 ifeq ($(LLVMGCC_MAJVERS),3)
408 UPGRADE_MSG = $(Echo) "Upgrading $(1) assembly to latest."
409 UPGRADE_LL  = $(Verb)$(LUPGRADE) $(1) -o $(1).up.tmp -f ; $(MV) $(1).up.tmp $(1)
410 LLVMGCCWITHPATH  := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGCC)
411 LLVMGXXWITHPATH  := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGXX)
412 else
413 UPGRADE_MSG =
414 UPGRADE_LL  =
415 LLVMGCCWITHPATH  := $(LLVMGCC)
416 LLVMGXXWITHPATH  := $(LLVMGXX)
417 endif
418
419 #--------------------------------------------------------------------
420 # Adjust to user's request
421 #--------------------------------------------------------------------
422
423 # Adjust LD.Flags depending on the kind of library that is to be built. Note
424 # that if LOADABLE_MODULE is specified then the resulting shared library can
425 # be opened with dlopen.
426 ifdef LOADABLE_MODULE
427   LD.Flags += -module
428 endif
429
430 ifdef SHARED_LIBRARY
431   LD.Flags += $(RPATH) -Wl,$(LibDir)
432 endif
433
434 ifdef TOOL_VERBOSE
435   C.Flags += -v
436   CXX.Flags += -v
437   LD.Flags += -v
438   VERBOSE := 1
439 endif
440
441 # Adjust settings for verbose mode
442 ifndef VERBOSE
443   Verb := @
444   AR.Flags += >/dev/null 2>/dev/null
445   ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
446 else
447   ConfigureScriptFLAGS :=
448 endif
449
450 # By default, strip symbol information from executable
451 ifndef KEEP_SYMBOLS
452   Strip := $(PLATFORMSTRIPOPTS)
453   StripWarnMsg := "(without symbols)"
454   Install.StripFlag += -s
455 endif
456
457 # Adjust linker flags for building an executable
458 ifneq ($(OS),Darwin)
459 ifdef TOOLNAME
460 ifdef EXAMPLE_TOOL
461   LD.Flags += $(RPATH) -Wl,$(ExmplDir) -export-dynamic
462 else
463   LD.Flags += $(RPATH) -Wl,$(ToolDir) -export-dynamic
464 endif
465 endif
466 endif
467
468 ifeq ($(OS),Darwin)
469   DARWIN_VERSION := `sw_vers -productVersion`
470   SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined -Wl,suppress -bundle \
471                     -mmacosx-version-min=$(DARWIN_VERSION)
472   CompileCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
473 else
474   ifeq ($(OS),Cygwin)
475     SharedLinkOptions=-shared -nostdlib -Wl,--export-all-symbols \
476                       -Wl,--enable-auto-import -Wl,--enable-auto-image-base \
477                       -Wl,--enable-runtime-pseudo-relocs
478   else
479     SharedLinkOptions=-shared
480   endif
481 endif
482
483 #----------------------------------------------------------
484 # Options To Invoke Tools
485 #----------------------------------------------------------
486
487 CompileCommonOpts += -pedantic -Wall -W -Wwrite-strings -Wno-long-long \
488                      -Wunused -Wno-unused-parameter $(EXTRA_OPTIONS)
489
490 ifeq ($(OS),HP-UX)
491   CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
492 endif
493
494 # If we are building a universal binary on Mac OS/X, pass extra options.  This
495 # is useful to people that want to link the LLVM libraries into their universal
496 # apps.
497 #
498 # The following can be optionally specified:
499 #   UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
500 #      For Mac OS/X 10.4 Intel machines, the traditional one is:
501 #      UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
502 #   UNIVERSAL_ARCH can be optionally specified to be a list of architectures
503 #      to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64".  This defaults to
504 #      i386/ppc only.
505 ifdef UNIVERSAL
506   ifndef UNIVERSAL_ARCH
507     UNIVERSAL_ARCH := i386 ppc
508   endif
509   UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
510   CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
511   Relink.Flags := $(UNIVERSAL_ARCH_OPTIONS)
512   ifdef UNIVERSAL_SDK_PATH
513     CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
514     Relink.Flags      += -isysroot $(UNIVERSAL_SDK_PATH)
515   endif
516
517   # Building universal cannot compute dependencies automatically.
518   DISABLE_AUTO_DEPENDENCIES=1
519 else
520   ifeq ($(ARCH),x86_64)
521     CompileCommonOpts += -m64
522   else
523     ifeq ($(ARCH),i386)
524       CompileCommonOpts += -m32
525     endif
526   endif
527 endif
528
529 ifeq ($(OS),SunOS)
530 CPP.BaseFlags += -include llvm/System/Solaris.h
531 endif
532
533 LD.Flags      += -L$(LibDir) -L$(LLVMLibDir)
534 CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
535 # All -I flags should go here, so that they don't confuse llvm-config.
536 CPP.Flags     += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
537                  $(patsubst %,-I%/include,\
538                  $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
539                  $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
540                  $(CPP.BaseFlags)
541
542  ifeq ($(BUILD_COMPONENT), 1)
543   Compile.C     = $(BUILD_CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -c
544   Compile.CXX   = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) -c
545   Preprocess.CXX= $(BUILD_CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
546   Link          = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
547                   $(LD.Flags) $(Strip)
548   Relink        = $(BUILD_CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
549                   $(Relink.Flags)
550 else
551   Compile.C     = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -c
552   Compile.CXX   = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) -c
553   Preprocess.CXX= $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
554   Link          = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
555                   $(LD.Flags) $(Strip)
556   Relink        = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
557                   $(Relink.Flags)
558 endif
559
560 BCCompile.C   = $(LLVMGCCWITHPATH) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts)
561 Preprocess.C  = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -E
562
563 BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CXX.Flags) \
564                 $(CompileCommonOpts)
565
566 ProgInstall   = $(INSTALL) $(Install.StripFlag) -m 0755
567 ScriptInstall = $(INSTALL) -m 0755
568 DataInstall   = $(INSTALL) -m 0644
569
570 # When compiling under Mingw/Cygwin, the tblgen tool expects Windows
571 # paths. In this case, the SYSPATH function (defined in
572 # Makefile.config) transforms Unix paths into Windows paths.
573 TableGen      = $(TBLGEN) -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
574                 -I $(call SYSPATH, $(LLVM_SRC_ROOT)/include) \
575                 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
576                 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)
577
578 Archive       = $(AR) $(AR.Flags)
579 LArchive      = $(LLVMToolDir)/llvm-ar rcsf
580 ifdef RANLIB
581 Ranlib        = $(RANLIB)
582 else
583 Ranlib        = ranlib
584 endif
585
586 #----------------------------------------------------------
587 # Get the list of source files and compute object file
588 # names from them.
589 #----------------------------------------------------------
590
591 ifndef SOURCES
592   Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
593              $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c))
594 else
595   Sources := $(SOURCES)
596 endif
597
598 ifdef BUILT_SOURCES
599 Sources += $(filter %.cpp %.c %.cc,$(BUILT_SOURCES))
600 endif
601
602 BaseNameSources := $(sort $(basename $(Sources)))
603
604 ObjectsO  := $(BaseNameSources:%=$(ObjDir)/%.o)
605 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
606
607 ###############################################################################
608 # DIRECTORIES: Handle recursive descent of directory structure
609 ###############################################################################
610
611 #---------------------------------------------------------
612 # Provide rules to make install dirs. This must be early
613 # in the file so they get built before dependencies
614 #---------------------------------------------------------
615
616 $(PROJ_bindir) $(PROJ_libdir) $(PROJ_includedir) $(PROJ_etcdir)::
617         $(Verb) $(MKDIR) $@
618
619 # To create other directories, as needed, and timestamp their creation
620 %/.dir:
621         $(Verb) $(MKDIR) $* > /dev/null
622         $(Verb) $(DATE) > $@
623
624 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
625 .PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
626
627 #---------------------------------------------------------
628 # Handle the DIRS options for sequential construction
629 #---------------------------------------------------------
630
631 SubDirs :=
632 ifdef DIRS
633 SubDirs += $(DIRS)
634
635 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
636 $(RecursiveTargets)::
637         $(Verb) for dir in $(DIRS); do \
638           if [ ! -f $$dir/Makefile ]; then \
639             $(MKDIR) $$dir; \
640             $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
641           fi; \
642           ($(MAKE) -C $$dir $@ ) || exit 1; \
643         done
644 else
645 $(RecursiveTargets)::
646         $(Verb) for dir in $(DIRS); do \
647           ($(MAKE) -C $$dir $@ ) || exit 1; \
648         done
649 endif
650
651 endif
652
653 #---------------------------------------------------------
654 # Handle the EXPERIMENTAL_DIRS options ensuring success
655 # after each directory is built.
656 #---------------------------------------------------------
657 ifdef EXPERIMENTAL_DIRS
658 $(RecursiveTargets)::
659         $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
660           if [ ! -f $$dir/Makefile ]; then \
661             $(MKDIR) $$dir; \
662             $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
663           fi; \
664           ($(MAKE) -C $$dir $@ ) || exit 0; \
665         done
666 endif
667
668 #-----------------------------------------------------------
669 # Handle the OPTIONAL_PARALLEL_DIRS options for optional parallel construction
670 #-----------------------------------------------------------
671 ifdef OPTIONAL_PARALLEL_DIRS
672   PARALLEL_DIRS += $(foreach T,$(OPTIONAL_PARALLEL_DIRS),$(shell test -d $(PROJ_SRC_DIR)/$(T) && echo "$(T)"))
673 endif
674
675 #-----------------------------------------------------------
676 # Handle the PARALLEL_DIRS options for parallel construction
677 #-----------------------------------------------------------
678 ifdef PARALLEL_DIRS
679
680 SubDirs += $(PARALLEL_DIRS)
681
682 # Unfortunately, this list must be maintained if new recursive targets are added
683 all      :: $(addsuffix /.makeall      ,$(PARALLEL_DIRS))
684 clean    :: $(addsuffix /.makeclean    ,$(PARALLEL_DIRS))
685 clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
686 install  :: $(addsuffix /.makeinstall  ,$(PARALLEL_DIRS))
687 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
688 install-bytecode  :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
689
690 ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
691
692 $(ParallelTargets) :
693         $(Verb) if [ ! -f $(@D)/Makefile ]; then \
694           $(MKDIR) $(@D); \
695           $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
696         fi; \
697         $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
698 endif
699
700 #---------------------------------------------------------
701 # Handle the OPTIONAL_DIRS options for directores that may
702 # or may not exist.
703 #---------------------------------------------------------
704 ifdef OPTIONAL_DIRS
705
706 SubDirs += $(OPTIONAL_DIRS)
707
708 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
709 $(RecursiveTargets)::
710         $(Verb) for dir in $(OPTIONAL_DIRS); do \
711           if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
712             if [ ! -f $$dir/Makefile ]; then \
713               $(MKDIR) $$dir; \
714               $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
715             fi; \
716             ($(MAKE) -C$$dir $@ ) || exit 1; \
717           fi \
718         done
719 else
720 $(RecursiveTargets)::
721         $(Verb) for dir in $(OPTIONAL_DIRS); do \
722           ($(MAKE) -C$$dir $@ ) || exit 1; \
723         done
724 endif
725 endif
726
727 #---------------------------------------------------------
728 # Handle the CONFIG_FILES options
729 #---------------------------------------------------------
730 ifdef CONFIG_FILES
731
732 ifdef NO_INSTALL
733 install-local::
734         $(Echo) Install circumvented with NO_INSTALL
735 uninstall-local::
736         $(Echo) UnInstall circumvented with NO_INSTALL
737 else
738 install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
739         $(Echo) Installing Configuration Files To $(PROJ_etcdir)
740         $(Verb)for file in $(CONFIG_FILES); do \
741           if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
742             $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
743           elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
744             $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
745           else \
746             $(ECHO) Error: cannot find config file $${file}. ; \
747           fi \
748         done
749
750 uninstall-local::
751         $(Echo) Uninstalling Configuration Files From $(PROJ_etcdir)
752         $(Verb)for file in $(CONFIG_FILES); do \
753           $(RM) -f $(PROJ_etcdir)/$${file} ; \
754         done
755 endif
756
757 endif
758
759 ###############################################################################
760 # Set up variables for building libararies
761 ###############################################################################
762
763 #---------------------------------------------------------
764 # Define various command line options pertaining to the
765 # libraries needed when linking. There are "Proj" libs
766 # (defined by the user's project) and "LLVM" libs (defined
767 # by the LLVM project).
768 #---------------------------------------------------------
769
770 ifdef USEDLIBS
771 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
772 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o,  $(ProjLibsOptions))
773 ProjUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
774 ProjLibsPaths   := $(addprefix $(LibDir)/,$(ProjUsedLibs))
775 endif
776
777 ifdef LLVMLIBS
778 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
779 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
780 LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
781 LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
782 endif
783
784 ifndef IS_CLEANING_TARGET
785 ifdef LINK_COMPONENTS
786
787 # If LLVM_CONFIG doesn't exist, build it.  This can happen if you do a make
788 # clean in tools, then do a make in tools (instead of at the top level).
789 $(LLVM_CONFIG):
790         @echo "*** llvm-config doesn't exist - rebuilding it."
791         @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
792
793 $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
794
795 LLVMLibsOptions += $(shell $(LLVM_CONFIG) --libs     $(LINK_COMPONENTS))
796 LLVMLibsPaths   += $(LLVM_CONFIG) \
797                   $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS))
798 endif
799 endif
800
801 ###############################################################################
802 # Library Build Rules: Four ways to build a library
803 ###############################################################################
804
805 #---------------------------------------------------------
806 # Bytecode Module Targets:
807 #   If the user set MODULE_NAME then they want to build a
808 #   bytecode module from the sources. We compile all the
809 #   sources and link it together into a single bytecode
810 #   module.
811 #---------------------------------------------------------
812
813 ifdef MODULE_NAME
814 ifeq ($(strip $(LLVMGCC)),)
815 $(warning Modules require llvm-gcc but no llvm-gcc is available ****)
816 else
817
818 Module     := $(LibDir)/$(MODULE_NAME).bc
819 LinkModule := $(LLVMLD) -L$(CFERuntimeLibDir) -r
820
821
822 ifdef EXPORTED_SYMBOL_FILE
823 LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
824 endif
825
826 $(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
827         $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
828         $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
829
830 all-local:: $(Module)
831
832 clean-local::
833 ifneq ($(strip $(Module)),)
834         -$(Verb) $(RM) -f $(Module)
835 endif
836
837 ifdef BYTECODE_DESTINATION
838 ModuleDestDir := $(BYTECODE_DESTINATION)
839 else
840 ModuleDestDir := $(PROJ_libdir)
841 endif
842
843 ifdef NO_INSTALL
844 install-local::
845         $(Echo) Install circumvented with NO_INSTALL
846 uninstall-local::
847         $(Echo) Uninstall circumvented with NO_INSTALL
848 else
849 DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
850
851 install-module:: $(DestModule)
852 install-local:: $(DestModule)
853
854 $(DestModule): $(ModuleDestDir) $(Module)
855         $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
856         $(Verb) $(DataInstall) $(Module) $(DestModule)
857
858 uninstall-local::
859         $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
860         -$(Verb) $(RM) -f $(DestModule)
861 endif
862
863 endif
864 endif
865
866 # if we're building a library ...
867 ifdef LIBRARYNAME
868
869 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
870 LIBRARYNAME := $(strip $(LIBRARYNAME))
871 ifdef LOADABLE_MODULE
872 LibName.A  := $(LibDir)/$(LIBRARYNAME).a
873 LibName.SO := $(LibDir)/$(LIBRARYNAME)$(SHLIBEXT)
874 else
875 LibName.A  := $(LibDir)/lib$(LIBRARYNAME).a
876 LibName.SO := $(LibDir)/lib$(LIBRARYNAME)$(SHLIBEXT)
877 endif
878 LibName.O  := $(LibDir)/$(LIBRARYNAME).o
879 LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
880
881 #---------------------------------------------------------
882 # Shared Library Targets:
883 #   If the user asked for a shared library to be built
884 #   with the SHARED_LIBRARY variable, then we provide
885 #   targets for building them.
886 #---------------------------------------------------------
887 ifdef SHARED_LIBRARY
888
889 all-local:: $(LibName.SO)
890
891 ifdef LINK_LIBS_IN_SHARED
892 ifdef LOADABLE_MODULE
893 SharedLibKindMessage := "Loadable Module"
894 else
895 SharedLibKindMessage := "Shared Library"
896 endif
897 $(LibName.SO): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths) $(LibDir)/.dir
898         $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
899           $(LIBRARYNAME)$(SHLIBEXT)
900         $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO) \
901           $(ProjLibsOptions) $(LLVMLibsOptions)
902 else
903 $(LibName.SO): $(ObjectsO) $(LibDir)/.dir
904         $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
905         $(Verb) $(Link) $(SharedLinkOptions) -o $@ $(ObjectsO)
906 endif
907
908 clean-local::
909 ifneq ($(strip $(LibName.SO)),)
910         -$(Verb) $(RM) -f $(LibName.SO)
911 endif
912
913 ifdef NO_INSTALL
914 install-local::
915         $(Echo) Install circumvented with NO_INSTALL
916 uninstall-local::
917         $(Echo) Uninstall circumvented with NO_INSTALL
918 else
919 DestSharedLib = $(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
920
921 install-local:: $(DestSharedLib)
922
923 $(DestSharedLib): $(LibName.SO) $(PROJ_libdir)
924         $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
925         $(Verb) $(INSTALL) $(LibName.SO) $(DestSharedLib)
926
927 uninstall-local::
928         $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
929         -$(Verb) $(RM) -f $(PROJ_libdir)/lib$(LIBRARYNAME).*
930 endif
931 endif
932
933 #---------------------------------------------------------
934 # Bytecode Library Targets:
935 #   If the user asked for a bytecode library to be built
936 #   with the BYTECODE_LIBRARY variable, then we provide
937 #   targets for building them.
938 #---------------------------------------------------------
939 ifdef BYTECODE_LIBRARY
940 ifeq ($(strip $(LLVMGCC)),)
941 $(warning Bytecode libraries require llvm-gcc which could not be found ****)
942 else
943
944 all-local:: $(LibName.BCA)
945
946 ifdef EXPORTED_SYMBOL_FILE
947 BCLinkLib = $(LLVMLD) -L$(CFERuntimeLibDir) \
948                      -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
949
950 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLD) \
951                 $(LLVMToolDir)/llvm-ar
952         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
953           "(internalize)"
954         $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
955         $(Verb) $(RM) -f $@
956         $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
957 else
958 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
959                 $(LLVMToolDir)/llvm-ar
960         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
961         $(Verb) $(RM) -f $@
962         $(Verb) $(LArchive) $@ $(ObjectsBC)
963
964 endif
965
966 clean-local::
967 ifneq ($(strip $(LibName.BCA)),)
968         -$(Verb) $(RM) -f $(LibName.BCA)
969 endif
970
971 ifdef BYTECODE_DESTINATION
972 BytecodeDestDir := $(BYTECODE_DESTINATION)
973 else
974 BytecodeDestDir := $(PROJ_libdir)
975 endif
976
977 DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
978
979 install-bytecode-local:: $(DestBytecodeLib)
980
981 ifdef NO_INSTALL
982 install-local::
983         $(Echo) Install circumvented with NO_INSTALL
984 uninstall-local::
985         $(Echo) Uninstall circumvented with NO_INSTALL
986 else
987 install-local:: $(DestBytecodeLib)
988
989 $(DestBytecodeLib): $(LibName.BCA) $(BytecodeDestDir)
990         $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
991         $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
992
993 uninstall-local::
994         $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
995         -$(Verb) $(RM) -f $(DestBytecodeLib)
996 endif
997 endif
998 endif
999
1000 #---------------------------------------------------------
1001 # ReLinked Library Targets:
1002 #   If the user explicitly requests a relinked library with
1003 #   BUILD_RELINKED, provide it.  Otherwise, if they specify
1004 #   neither of BUILD_ARCHIVE or DONT_BUILD_RELINKED, give
1005 #   them one.
1006 #---------------------------------------------------------
1007 ifndef BUILD_ARCHIVE
1008 ifndef DONT_BUILD_RELINKED
1009 BUILD_RELINKED = 1
1010 endif
1011 endif
1012
1013 ifdef BUILD_RELINKED
1014
1015 all-local:: $(LibName.O)
1016
1017 $(LibName.O): $(ObjectsO) $(LibDir)/.dir
1018         $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
1019         $(Verb) $(Relink) -Wl,-r -nodefaultlibs -nostdlib -nostartfiles -o $@ $(ObjectsO)
1020
1021 clean-local::
1022 ifneq ($(strip $(LibName.O)),)
1023         -$(Verb) $(RM) -f $(LibName.O)
1024 endif
1025
1026 ifdef NO_INSTALL
1027 install-local::
1028         $(Echo) Install circumvented with NO_INSTALL
1029 uninstall-local::
1030         $(Echo) Uninstall circumvented with NO_INSTALL
1031 else
1032 DestRelinkedLib = $(PROJ_libdir)/$(LIBRARYNAME).o
1033
1034 install-local:: $(DestRelinkedLib)
1035
1036 $(DestRelinkedLib): $(LibName.O) $(PROJ_libdir)
1037         $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
1038         $(Verb) $(INSTALL) $(LibName.O) $(DestRelinkedLib)
1039
1040 uninstall-local::
1041         $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
1042         -$(Verb) $(RM) -f $(DestRelinkedLib)
1043 endif
1044 endif
1045
1046 #---------------------------------------------------------
1047 # Archive Library Targets:
1048 #   If the user wanted a regular archive library built,
1049 #   then we provide targets for building them.
1050 #---------------------------------------------------------
1051 ifdef BUILD_ARCHIVE
1052
1053 all-local:: $(LibName.A)
1054
1055 $(LibName.A): $(ObjectsO) $(LibDir)/.dir
1056         $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
1057         -$(Verb) $(RM) -f $@
1058         $(Verb) $(Archive) $@ $(ObjectsO)
1059         $(Verb) $(Ranlib) $@
1060
1061 clean-local::
1062 ifneq ($(strip $(LibName.A)),)
1063         -$(Verb) $(RM) -f $(LibName.A)
1064 endif
1065
1066 ifdef NO_INSTALL
1067 install-local::
1068         $(Echo) Install circumvented with NO_INSTALL
1069 uninstall-local::
1070         $(Echo) Uninstall circumvented with NO_INSTALL
1071 else
1072 DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
1073
1074 install-local:: $(DestArchiveLib)
1075
1076 $(DestArchiveLib): $(LibName.A) $(PROJ_libdir)
1077         $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
1078         $(Verb) $(MKDIR) $(PROJ_libdir)
1079         $(Verb) $(INSTALL) $(LibName.A) $(DestArchiveLib)
1080
1081 uninstall-local::
1082         $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
1083         -$(Verb) $(RM) -f $(DestArchiveLib)
1084 endif
1085 endif
1086
1087 # endif LIBRARYNAME
1088 endif
1089
1090 ###############################################################################
1091 # Tool Build Rules: Build executable tool based on TOOLNAME option
1092 ###############################################################################
1093
1094 ifdef TOOLNAME
1095
1096 #---------------------------------------------------------
1097 # Set up variables for building a tool.
1098 #---------------------------------------------------------
1099 ifdef EXAMPLE_TOOL
1100 ToolBuildPath   := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
1101 else
1102 ToolBuildPath   := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
1103 endif
1104
1105 #---------------------------------------------------------
1106 # Prune Exports
1107 #---------------------------------------------------------
1108
1109 # If the tool opts in with TOOL_NO_EXPORTS, optimize startup time of the app by
1110 # not exporting all of the weak symbols from the binary.  This reduces dyld
1111 # startup time by 4x on darwin in some cases.
1112 ifdef TOOL_NO_EXPORTS
1113 ifeq ($(OS),Darwin)
1114 LD.Flags += -Wl,-exported_symbol -Wl,_main
1115 endif
1116
1117 ifeq ($(OS), $(filter $(OS), Linux NetBSD FreeBSD))
1118 LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map
1119 endif
1120 endif
1121
1122
1123 #---------------------------------------------------------
1124 # Provide targets for building the tools
1125 #---------------------------------------------------------
1126 all-local:: $(ToolBuildPath)
1127
1128 clean-local::
1129 ifneq ($(strip $(ToolBuildPath)),)
1130         -$(Verb) $(RM) -f $(ToolBuildPath)
1131 endif
1132
1133 ifdef EXAMPLE_TOOL
1134 $(ToolBuildPath): $(ExmplDir)/.dir
1135 else
1136 $(ToolBuildPath): $(ToolDir)/.dir
1137 endif
1138
1139 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
1140         $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
1141         $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
1142         $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
1143         $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
1144           $(StripWarnMsg)
1145
1146 ifdef NO_INSTALL
1147 install-local::
1148         $(Echo) Install circumvented with NO_INSTALL
1149 uninstall-local::
1150         $(Echo) Uninstall circumvented with NO_INSTALL
1151 else
1152 DestTool = $(PROJ_bindir)/$(TOOLNAME)
1153
1154 install-local:: $(DestTool)
1155
1156 $(DestTool): $(ToolBuildPath) $(PROJ_bindir)
1157         $(Echo) Installing $(BuildMode) $(DestTool)
1158         $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
1159
1160 uninstall-local::
1161         $(Echo) Uninstalling $(BuildMode) $(DestTool)
1162         -$(Verb) $(RM) -f $(DestTool)
1163 endif
1164 endif
1165
1166 ###############################################################################
1167 # Object Build Rules: Build object files based on sources
1168 ###############################################################################
1169
1170 # FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
1171 ifeq ($(OS),HP-UX)
1172   DISABLE_AUTO_DEPENDENCIES=1
1173 endif
1174
1175 # Provide rule sets for when dependency generation is enabled
1176 ifndef DISABLE_AUTO_DEPENDENCIES
1177
1178 #---------------------------------------------------------
1179 # Create .o files in the ObjDir directory from the .cpp and .c files...
1180 #---------------------------------------------------------
1181
1182 DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
1183          -MT "$(ObjDir)/$*.o" -MT "$(ObjDir)/$*.d"
1184
1185 # If the build succeeded, move the dependency file over.  If it failed, put an
1186 # empty file there.
1187 DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
1188                   else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
1189
1190 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1191         $(Echo) "Compiling $*.cpp for $(BuildMode) build " $(PIC_FLAG)
1192         $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1193                 $(DEPEND_MOVEFILE)
1194
1195 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1196         $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1197         $(Verb) if $(Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1198                 $(DEPEND_MOVEFILE)
1199
1200 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1201         $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1202         $(Verb) if $(Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1203                 $(DEPEND_MOVEFILE)
1204
1205 #---------------------------------------------------------
1206 # Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1207 #---------------------------------------------------------
1208
1209 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1210         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1211         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1212                               $< -o $@ -S -emit-llvm ; \
1213         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1214         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1215         $(call UPGRADE_MSG,$@)
1216         $(call UPGRADE_LL,$@)
1217
1218 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1219         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1220         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1221                               $< -o $@ -S -emit-llvm ; \
1222         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1223         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1224         $(call UPGRADE_MSG,$@)
1225         $(call UPGRADE_LL,$@)
1226
1227 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
1228         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1229         $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" \
1230                             $< -o $@ -S -emit-llvm ; \
1231         then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
1232         else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
1233         $(call UPGRADE_MSG,$@)
1234         $(call UPGRADE_LL,$@)
1235
1236 # Provide alternate rule sets if dependencies are disabled
1237 else
1238
1239 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1240         $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
1241         $(Compile.CXX) $< -o $@
1242
1243 $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1244         $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1245         $(Compile.CXX) $< -o $@
1246
1247 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1248         $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1249         $(Compile.C) $< -o $@
1250
1251 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1252         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1253         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1254         $(call UPGRADE_MSG,$@)
1255         $(call UPGRADE_LL,$@)
1256
1257 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1258         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1259         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1260         $(call UPGRADE_MSG,$@)
1261         $(call UPGRADE_LL,$@)
1262
1263 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
1264         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1265         $(BCCompile.C) $< -o $@ -S -emit-llvm
1266         $(call UPGRADE_MSG,@)
1267         $(call UPGRADE_LL,@)
1268
1269 endif
1270
1271
1272 ## Rules for building preprocessed (.i/.ii) outputs.
1273 $(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1274         $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1275         $(Verb) $(Preprocess.CXX) $< -o $@
1276
1277 $(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1278         $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1279         $(Verb) $(Preprocess.CXX) $< -o $@
1280
1281 $(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1282         $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1283         $(Verb) $(Preprocess.C) $< -o $@
1284
1285
1286 $(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1287         $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
1288         $(Compile.CXX) $< -o $@ -S
1289
1290 $(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1291         $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
1292         $(Compile.CXX) $< -o $@ -S
1293
1294 $(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1295         $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
1296         $(Compile.C) $< -o $@ -S
1297
1298
1299 # make the C and C++ compilers strip debug info out of bytecode libraries.
1300 ifdef DEBUG_RUNTIME
1301 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
1302         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1303         $(Verb) $(LLVMAS) $< -o - | $(LOPT) -std-compile-opts -o $@ -f
1304 else
1305 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
1306         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1307         $(Verb) $(LLVMAS) $< -o - | \
1308            $(LOPT) -std-compile-opts -strip-debug -o $@ -f
1309 endif
1310
1311
1312 #---------------------------------------------------------
1313 # Provide rule to build .bc files from .ll sources,
1314 # regardless of dependencies
1315 #---------------------------------------------------------
1316 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1317         $(Echo) "Compiling $*.ll for $(BuildMode) build"
1318         $(Verb) $(LLVMAS) $< -f -o $@
1319
1320 ###############################################################################
1321 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
1322 ###############################################################################
1323
1324 ifdef TARGET
1325 TABLEGEN_INC_FILES_COMMON = 1
1326 endif
1327
1328 ifdef LLVMC_BUILD_AUTOGENERATED_INC
1329 TABLEGEN_INC_FILES_COMMON = 1
1330 endif
1331
1332 ifdef TABLEGEN_INC_FILES_COMMON
1333
1334 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1335 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1336 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
1337
1338 # All of these files depend on tblgen and the .td files.
1339 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1340
1341 # INCFiles rule: All of the tblgen generated files are emitted to
1342 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc.  This allows
1343 # us to only "touch" the real file if the contents of it change.  IOW, if
1344 # tblgen is modified, all of the .inc.tmp files are regenerated, but no
1345 # dependencies of the .inc files are, unless the contents of the .inc file
1346 # changes.
1347 $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1348         $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1349
1350 endif # TABLEGEN_INC_FILES_COMMON
1351
1352 ifdef TARGET
1353
1354 TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1355            $(LLVM_SRC_ROOT)/include/llvm/Target/Target.td \
1356            $(LLVM_SRC_ROOT)/include/llvm/Target/TargetCallingConv.td \
1357            $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSchedule.td \
1358            $(LLVM_SRC_ROOT)/include/llvm/Target/TargetSelectionDAG.td \
1359            $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1360            $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1361
1362 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1363 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
1364         $(Echo) "Building $(<F) register names with tblgen"
1365         $(Verb) $(TableGen) -gen-register-enums -o $(call SYSPATH, $@) $<
1366
1367 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1368 $(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
1369         $(Echo) "Building $(<F) register information header with tblgen"
1370         $(Verb) $(TableGen) -gen-register-desc-header -o $(call SYSPATH, $@) $<
1371
1372 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1373 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1374         $(Echo) "Building $(<F) register info implementation with tblgen"
1375         $(Verb) $(TableGen) -gen-register-desc -o $(call SYSPATH, $@) $<
1376
1377 $(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1378 $(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1379         $(Echo) "Building $(<F) instruction names with tblgen"
1380         $(Verb) $(TableGen) -gen-instr-enums -o $(call SYSPATH, $@) $<
1381
1382 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1383 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1384         $(Echo) "Building $(<F) instruction information with tblgen"
1385         $(Verb) $(TableGen) -gen-instr-desc -o $(call SYSPATH, $@) $<
1386
1387 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1388 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1389         $(Echo) "Building $(<F) assembly writer with tblgen"
1390         $(Verb) $(TableGen) -gen-asm-writer -o $(call SYSPATH, $@) $<
1391
1392 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1393 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1394         $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1395         $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $(call SYSPATH, $@) $<
1396
1397 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1398 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1399         $(Echo) "Building $(<F) code emitter with tblgen"
1400         $(Verb) $(TableGen) -gen-emitter -o $(call SYSPATH, $@) $<
1401
1402 $(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1403 $(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
1404         $(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
1405         $(Verb) $(TableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
1406
1407 $(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
1408 $(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir
1409         $(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
1410         $(Verb) $(TableGen) -gen-fast-isel -o $(call SYSPATH, $@) $<
1411
1412 $(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1413 $(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1414         $(Echo) "Building $(<F) subtarget information with tblgen"
1415         $(Verb) $(TableGen) -gen-subtarget -o $(call SYSPATH, $@) $<
1416
1417 $(TARGET:%=$(ObjDir)/%GenCallingConv.inc.tmp): \
1418 $(ObjDir)/%GenCallingConv.inc.tmp : %.td $(ObjDir)/.dir
1419         $(Echo) "Building $(<F) calling convention information with tblgen"
1420         $(Verb) $(TableGen) -gen-callingconv -o $(call SYSPATH, $@) $<
1421
1422 $(TARGET:%=$(ObjDir)/%GenIntrinsics.inc.tmp): \
1423 $(ObjDir)/%GenIntrinsics.inc.tmp : Intrinsics%.td $(ObjDir)/.dir
1424         $(Echo) "Building $(<F) calling convention information with tblgen"
1425         $(Verb) $(TableGen) -gen-tgt-intrinsic -o $(call SYSPATH, $@) $<
1426
1427 clean-local::
1428         -$(Verb) $(RM) -f $(INCFiles)
1429
1430 endif # TARGET
1431
1432 ifdef LLVMC_BUILD_AUTOGENERATED_INC
1433
1434 LLVMCPluginSrc := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td))
1435
1436 TDFiles := $(LLVMCPluginSrc) \
1437         $(strip $(wildcard $(LLVM_SRC_ROOT)/include/llvm/CompilerDriver/*.td))
1438
1439 $(ObjDir)/AutoGenerated.inc.tmp: $(LLVMCPluginSrc) $(ObjDir)/.dir \
1440                                 $(TBLGEN) $(TD_COMMON)
1441         $(Echo) "Building LLVMC configuration library with tblgen"
1442         $(Verb) $(TableGen) -gen-llvmc -o $(call SYSPATH, $@) $<
1443
1444 endif # LLVMC_BUILD_AUTOGENERATED_INC
1445
1446
1447 ###############################################################################
1448 # OTHER RULES: Other rules needed
1449 ###############################################################################
1450
1451 # To create postscript files from dot files...
1452 ifneq ($(DOT),false)
1453 %.ps: %.dot
1454         $(DOT) -Tps < $< > $@
1455 else
1456 %.ps: %.dot
1457         $(Echo) "Cannot build $@: The program dot is not installed"
1458 endif
1459
1460 # This rules ensures that header files that are removed still have a rule for
1461 # which they can be "generated."  This allows make to ignore them and
1462 # reproduce the dependency lists.
1463 %.h:: ;
1464 %.hpp:: ;
1465
1466 # Define clean-local to clean the current directory. Note that this uses a
1467 # very conservative approach ensuring that empty variables do not cause
1468 # errors or disastrous removal.
1469 clean-local::
1470 ifneq ($(strip $(ObjRootDir)),)
1471         -$(Verb) $(RM) -rf $(ObjRootDir)
1472 endif
1473         -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1474 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1475         -$(Verb) $(RM) -f *$(SHLIBEXT)
1476 endif
1477
1478 clean-all-local::
1479         -$(Verb) $(RM) -rf Debug Release Profile
1480
1481
1482 ###############################################################################
1483 # DEPENDENCIES: Include the dependency files if we should
1484 ###############################################################################
1485 ifndef DISABLE_AUTO_DEPENDENCIES
1486
1487 # If its not one of the cleaning targets
1488 ifndef IS_CLEANING_TARGET
1489
1490 # Get the list of dependency files
1491 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1492 DependFiles := $(DependFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1493
1494 -include $(DependFiles) ""
1495
1496 endif
1497
1498 endif
1499
1500 ###############################################################################
1501 # CHECK: Running the test suite
1502 ###############################################################################
1503
1504 check::
1505         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1506           if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1507             $(EchoCmd) Running test suite ; \
1508             $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1509               TESTSUITE=$(TESTSUITE) ; \
1510           else \
1511             $(EchoCmd) No Makefile in test directory ; \
1512           fi ; \
1513         else \
1514           $(EchoCmd) No test directory ; \
1515         fi
1516
1517 ###############################################################################
1518 # UNITTESTS: Running the unittests test suite
1519 ###############################################################################
1520
1521 unittests::
1522         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/unittests" ; then \
1523           if test -f "$(PROJ_OBJ_ROOT)/unittests/Makefile" ; then \
1524             $(EchoCmd) Running unittests test suite ; \
1525             $(MAKE) -C $(PROJ_OBJ_ROOT)/unittests ; \
1526           else \
1527             $(EchoCmd) No Makefile in unittests directory ; \
1528           fi ; \
1529         else \
1530           $(EchoCmd) No unittests directory ; \
1531         fi
1532
1533 ###############################################################################
1534 # DISTRIBUTION: Handle construction of a distribution tarball
1535 ###############################################################################
1536
1537 #------------------------------------------------------------------------
1538 # Define distribution related variables
1539 #------------------------------------------------------------------------
1540 DistName    := $(PROJECT_NAME)-$(PROJ_VERSION)
1541 DistDir     := $(PROJ_OBJ_ROOT)/$(DistName)
1542 TopDistDir  := $(PROJ_OBJ_ROOT)/$(DistName)
1543 DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1544 DistZip     := $(PROJ_OBJ_ROOT)/$(DistName).zip
1545 DistTarBZ2  := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1546 DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1547                ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1548                Makefile.config.in configure autoconf
1549 DistOther   := $(notdir $(wildcard \
1550                $(PROJ_SRC_DIR)/*.h \
1551                $(PROJ_SRC_DIR)/*.td \
1552                $(PROJ_SRC_DIR)/*.def \
1553                $(PROJ_SRC_DIR)/*.ll \
1554                $(PROJ_SRC_DIR)/*.in))
1555 DistSubDirs := $(SubDirs)
1556 DistSources  = $(Sources) $(EXTRA_DIST)
1557 DistFiles    = $(DistAlways) $(DistSources) $(DistOther)
1558
1559 #------------------------------------------------------------------------
1560 # We MUST build distribution with OBJ_DIR != SRC_DIR
1561 #------------------------------------------------------------------------
1562 ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1563 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1564         $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1565
1566 else
1567
1568 #------------------------------------------------------------------------
1569 # Prevent attempt to run dist targets from anywhere but the top level
1570 #------------------------------------------------------------------------
1571 ifneq ($(LEVEL),.)
1572 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1573         $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
1574 else
1575
1576 #------------------------------------------------------------------------
1577 # Provide the top level targets
1578 #------------------------------------------------------------------------
1579
1580 dist-gzip:: $(DistTarGZip)
1581
1582 $(DistTarGZip) : $(TopDistDir)/.makedistdir
1583         $(Echo) Packing gzipped distribution tar file.
1584         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1585           $(GZIP) -c > "$(DistTarGZip)"
1586
1587 dist-bzip2:: $(DistTarBZ2)
1588
1589 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
1590         $(Echo) Packing bzipped distribution tar file.
1591         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1592           $(BZIP2) -c >$(DistTarBZ2)
1593
1594 dist-zip:: $(DistZip)
1595
1596 $(DistZip) : $(TopDistDir)/.makedistdir
1597         $(Echo) Packing zipped distribution file.
1598         $(Verb) rm -f $(DistZip)
1599         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1600
1601 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
1602         $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1603
1604 DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
1605
1606 dist-check:: $(DistTarGZip)
1607         $(Echo) Checking distribution tar file.
1608         $(Verb) if test -d $(DistCheckDir) ; then \
1609           $(RM) -rf $(DistCheckDir) ; \
1610         fi
1611         $(Verb) $(MKDIR) $(DistCheckDir)
1612         $(Verb) cd $(DistCheckDir) && \
1613           $(MKDIR) $(DistCheckDir)/build && \
1614           $(MKDIR) $(DistCheckDir)/install && \
1615           gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1616           cd build && \
1617           ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1618             --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
1619           $(MAKE) all && \
1620           $(MAKE) check && \
1621           $(MAKE) unittests && \
1622           $(MAKE) install && \
1623           $(MAKE) uninstall && \
1624           $(MAKE) dist-clean && \
1625           $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1626
1627 dist-clean::
1628         $(Echo) Cleaning distribution files
1629         -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1630           $(DistCheckDir)
1631
1632 endif
1633
1634 #------------------------------------------------------------------------
1635 # Provide the recursive distdir target for building the distribution directory
1636 #------------------------------------------------------------------------
1637 distdir: $(DistDir)/.makedistdir
1638 $(DistDir)/.makedistdir: $(DistSources)
1639         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1640           if test -d "$(DistDir)" ; then \
1641             find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
1642               exit 1 ; \
1643           fi ; \
1644           $(EchoCmd) Removing old $(DistDir) ; \
1645           $(RM) -rf $(DistDir); \
1646           $(EchoCmd) Making 'all' to verify build ; \
1647           $(MAKE) ENABLE_OPTIMIZED=1 all ; \
1648         fi
1649         $(Echo) Building Distribution Directory $(DistDir)
1650         $(Verb) $(MKDIR) $(DistDir)
1651         $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1652         srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
1653         for file in $(DistFiles) ; do \
1654           case "$$file" in \
1655             $(PROJ_SRC_DIR)/*) \
1656               file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1657               ;; \
1658             $(PROJ_SRC_ROOT)/*) \
1659               file=`echo "$$file" | \
1660                 sed "s#^$$srcrootstrip/##"` \
1661               ;; \
1662           esac; \
1663           if test -f "$(PROJ_SRC_DIR)/$$file" || \
1664              test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1665             from_dir="$(PROJ_SRC_DIR)" ; \
1666           elif test -f "$$file" || test -d "$$file" ; then \
1667             from_dir=. ; \
1668           fi ; \
1669           to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1670           if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1671             to_dir="$(DistDir)/$$dir"; \
1672             $(MKDIR) "$$to_dir" ; \
1673           else \
1674             to_dir="$(DistDir)"; \
1675           fi; \
1676           mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1677           if test -n "$$mid_dir" ; then \
1678             $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1679           fi ; \
1680           if test -d "$$from_dir/$$file"; then \
1681             if test -d "$(PROJ_SRC_DIR)/$$file" && \
1682                test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
1683                cd $(PROJ_SRC_DIR) ; \
1684                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1685                  ( cd $$to_dir ; $(TAR) xf - ) ; \
1686                cd $(PROJ_OBJ_DIR) ; \
1687             else \
1688                cd $$from_dir ; \
1689                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1690                  ( cd $$to_dir ; $(TAR) xf - ) ; \
1691                cd $(PROJ_OBJ_DIR) ; \
1692             fi; \
1693           elif test -f "$$from_dir/$$file" ; then \
1694             $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1695           elif test -L "$$from_dir/$$file" ; then \
1696             $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1697           elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1698             $(EchoCmd) "===== WARNING: Distribution Source " \
1699               "$$from_dir/$$file Not Found!" ; \
1700           elif test "$(Verb)" != '@' ; then \
1701             $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1702           fi; \
1703         done
1704         $(Verb) for subdir in $(DistSubDirs) ; do \
1705           if test "$$subdir" \!= "." ; then \
1706             new_distdir="$(DistDir)/$$subdir" ; \
1707             test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1708             ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
1709               DistDir="$$new_distdir" distdir ) || exit 1; \
1710           fi; \
1711         done
1712         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1713           $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
1714           $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
1715                                   -name .svn \) -print` ;\
1716           $(MAKE) dist-hook ; \
1717           $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1718             -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1719             -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1720             -o ! -type d ! -perm -444 -exec \
1721               $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1722             || chmod -R a+r $(DistDir) ; \
1723         fi
1724
1725 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1726 # defined by user.
1727 dist-hook::
1728
1729 endif
1730
1731 ###############################################################################
1732 # TOP LEVEL - targets only to apply at the top level directory
1733 ###############################################################################
1734
1735 ifeq ($(LEVEL),.)
1736
1737 #------------------------------------------------------------------------
1738 # Install support for the project's include files:
1739 #------------------------------------------------------------------------
1740 ifdef NO_INSTALL
1741 install-local::
1742         $(Echo) Install circumvented with NO_INSTALL
1743 uninstall-local::
1744         $(Echo) Uninstall circumvented with NO_INSTALL
1745 else
1746 install-local::
1747         $(Echo) Installing include files
1748         $(Verb) $(MKDIR) $(PROJ_includedir)
1749         $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
1750           cd $(PROJ_SRC_ROOT)/include && \
1751           for  hdr in `find . -type f '!' '(' -name '*~' \
1752               -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS | \
1753               grep -v .svn` ; do \
1754             instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1755             if test \! -d "$$instdir" ; then \
1756               $(EchoCmd) Making install directory $$instdir ; \
1757               $(MKDIR) $$instdir ;\
1758             fi ; \
1759             $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1760           done ; \
1761         fi
1762 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
1763         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
1764           cd $(PROJ_OBJ_ROOT)/include && \
1765           for hdr in `find . -type f -print | grep -v CVS` ; do \
1766             $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1767           done ; \
1768         fi
1769 endif
1770
1771 uninstall-local::
1772         $(Echo) Uninstalling include files
1773         $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1774           cd $(PROJ_SRC_ROOT)/include && \
1775             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1776               '!' '(' -name '*~' -o -name '.#*' \
1777         -o -name '*.in' ')' -print ')' | \
1778         grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
1779           cd $(PROJ_SRC_ROOT)/include && \
1780             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
1781       -print ')' | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
1782         fi
1783 endif
1784 endif
1785
1786 check-line-length:
1787         @echo searching for overlength lines in files: $(Sources)
1788         @echo
1789         @echo
1790         egrep -n '.{81}' $(Sources) /dev/null
1791
1792 check-for-tabs:
1793         @echo searching for tabs in files: $(Sources)
1794         @echo
1795         @echo
1796         egrep -n '      ' $(Sources) /dev/null
1797
1798 check-footprint:
1799         @ls -l $(LibDir) | awk '\
1800           BEGIN { sum = 0; } \
1801                 { sum += $$5; } \
1802           END   { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
1803         @ls -l $(ToolDir) | awk '\
1804           BEGIN { sum = 0; } \
1805                 { sum += $$5; } \
1806           END   { printf("Programs:  %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
1807 #------------------------------------------------------------------------
1808 # Print out the directories used for building
1809 #------------------------------------------------------------------------
1810 printvars::
1811         $(Echo) "BuildMode    : " '$(BuildMode)'
1812         $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1813         $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1814         $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1815         $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1816         $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1817         $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1818         $(Echo) "PROJ_prefix  : " '$(PROJ_prefix)'
1819         $(Echo) "PROJ_bindir  : " '$(PROJ_bindir)'
1820         $(Echo) "PROJ_libdir  : " '$(PROJ_libdir)'
1821         $(Echo) "PROJ_etcdir  : " '$(PROJ_etcdir)'
1822         $(Echo) "PROJ_includedir  : " '$(PROJ_includedir)'
1823         $(Echo) "UserTargets  : " '$(UserTargets)'
1824         $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1825         $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1826         $(Echo) "ObjDir       : " '$(ObjDir)'
1827         $(Echo) "LibDir       : " '$(LibDir)'
1828         $(Echo) "ToolDir      : " '$(ToolDir)'
1829         $(Echo) "ExmplDir     : " '$(ExmplDir)'
1830         $(Echo) "Sources      : " '$(Sources)'
1831         $(Echo) "TDFiles      : " '$(TDFiles)'
1832         $(Echo) "INCFiles     : " '$(INCFiles)'
1833         $(Echo) "INCTMPFiles  : " '$(INCTMPFiles)'
1834         $(Echo) "PreConditions: " '$(PreConditions)'
1835         $(Echo) "Compile.CXX  : " '$(Compile.CXX)'
1836         $(Echo) "Compile.C    : " '$(Compile.C)'
1837         $(Echo) "Archive      : " '$(Archive)'
1838         $(Echo) "YaccFiles    : " '$(YaccFiles)'
1839         $(Echo) "LexFiles     : " '$(LexFiles)'
1840         $(Echo) "Module       : " '$(Module)'
1841         $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
1842         $(Echo) "SubDirs      : " '$(SubDirs)'
1843         $(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
1844         $(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'
1845
1846 ###
1847 # Debugging
1848
1849 # General debugging rule, use 'make dbg-print-XXX' to print the
1850 # definition, value and origin of XXX.
1851 make-print-%:
1852         $(error PRINT: $(value $*) = "$($*)" (from $(origin $*)))