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