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