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