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