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