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