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