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