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