Initial checkin of the new "fast" instruction selection support. See
[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 LocalTargets     := all-local clean-local clean-all-local check-local \
24                     install-local printvars uninstall-local \
25                     install-bytecode-local
26 TopLevelTargets  := check dist dist-check dist-clean dist-gzip dist-bzip2 \
27                     dist-zip
28 UserTargets      := $(RecursiveTargets) $(LocalTargets) $(TopLevelTargets)
29 InternalTargets  := preconditions distdir dist-hook
30
31 ################################################################################
32 # INITIALIZATION: Basic things the makefile needs
33 ################################################################################
34
35 #--------------------------------------------------------------------
36 # Set the VPATH so that we can find source files.
37 #--------------------------------------------------------------------
38 VPATH=$(PROJ_SRC_DIR)
39
40 #--------------------------------------------------------------------
41 # Reset the list of suffixes we know how to build.
42 #--------------------------------------------------------------------
43 .SUFFIXES:
44 .SUFFIXES: .c .cpp .cc .h .hpp .y .l .lo .o .a .bc .td .ps .dot .ll
45 .SUFFIXES: $(SHLIBEXT) $(SUFFIXES)
46
47 #--------------------------------------------------------------------
48 # Mark all of these targets as phony to avoid implicit rule search
49 #--------------------------------------------------------------------
50 .PHONY: $(UserTargets) $(InternalTargets)
51
52 #--------------------------------------------------------------------
53 # Make sure all the user-target rules are double colon rules and 
54 # they are defined first.
55 #--------------------------------------------------------------------
56
57 $(UserTargets)::
58
59 ################################################################################
60 # PRECONDITIONS: that which must be built/checked first
61 ################################################################################
62
63 SrcMakefiles       := $(filter %Makefile %Makefile.tests,\
64                       $(wildcard $(PROJ_SRC_DIR)/Makefile*))
65 ObjMakefiles       := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
66 ConfigureScript    := $(PROJ_SRC_ROOT)/configure
67 ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
68 MakefileConfigIn   := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
69 MakefileCommonIn   := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
70 MakefileConfig     := $(PROJ_OBJ_ROOT)/Makefile.config
71 MakefileCommon     := $(PROJ_OBJ_ROOT)/Makefile.common
72 PreConditions      := $(ConfigStatusScript) $(ObjMakefiles)
73 ifneq ($(MakefileCommonIn),)
74 PreConditions      += $(MakefileCommon)
75 endif
76
77 ifneq ($(MakefileConfigIn),)
78 PreConditions      += $(MakefileConfig)
79 endif
80
81 preconditions: $(PreConditions)
82
83 #------------------------------------------------------------------------
84 # Make sure the BUILT_SOURCES are built first
85 #------------------------------------------------------------------------
86 $(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
87
88 clean-all-local::
89 ifneq ($(strip $(BUILT_SOURCES)),)
90         -$(Verb) $(RM) -f $(BUILT_SOURCES)
91 endif
92
93 ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
94 spotless:
95         $(Verb) if test -x config.status ; then \
96           $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
97           $(MKDIR) .spotless.save ; \
98           $(MV) config.status .spotless.save ; \
99           $(MV) mklib  .spotless.save ; \
100           $(MV) projects  .spotless.save ; \
101           $(RM) -rf * ; \
102           $(MV) .spotless.save/config.status . ; \
103           $(MV) .spotless.save/mklib . ; \
104           $(MV) .spotless.save/projects . ; \
105           $(RM) -rf .spotless.save ; \
106           $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
107           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
108           $(ConfigStatusScript) ; \
109         else \
110           $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
111         fi
112 else
113 spotless:
114         $(EchoCmd) "spotless target not supported for objdir == srcdir"
115 endif
116
117 $(BUILT_SOURCES) : $(ObjMakefiles)
118
119 #------------------------------------------------------------------------
120 # Make sure we're not using a stale configuration
121 #------------------------------------------------------------------------
122 reconfigure:
123         $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
124         $(Verb) cd $(PROJ_OBJ_ROOT) && \
125           if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
126             $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
127           fi ; \
128           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
129           $(ConfigStatusScript)
130
131 .PRECIOUS: $(ConfigStatusScript)
132 $(ConfigStatusScript): $(ConfigureScript)
133         $(Echo) Reconfiguring with $<
134         $(Verb) cd $(PROJ_OBJ_ROOT) && \
135           if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
136             $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
137           fi ; \
138           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
139           $(ConfigStatusScript)
140
141 #------------------------------------------------------------------------
142 # Make sure the configuration makefile is up to date
143 #------------------------------------------------------------------------
144 ifneq ($(MakefileConfigIn),)
145 $(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
146         $(Echo) Regenerating $@
147         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
148 endif
149
150 ifneq ($(MakefileCommonIn),)
151 $(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
152         $(Echo) Regenerating $@
153         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
154 endif
155
156 #------------------------------------------------------------------------
157 # If the Makefile in the source tree has been updated, copy it over into the
158 # build tree. But, only do this if the source and object makefiles differ
159 #------------------------------------------------------------------------
160 ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
161
162 Makefile: $(PROJ_SRC_DIR)/Makefile $(ExtraMakefiles)
163         $(Echo) "Updating Makefile"
164         $(Verb) $(MKDIR) $(@D)
165         $(Verb) $(CP) -f $< $@
166
167 # Copy the Makefile.* files unless we're in the root directory which avoids
168 # the copying of Makefile.config.in or other things that should be explicitly
169 # taken care of.
170 $(PROJ_OBJ_DIR)/Makefile% : $(PROJ_SRC_DIR)/Makefile%
171         @case '$?' in \
172           *Makefile.rules) ;; \
173           *.in) ;; \
174           *) $(EchoCmd) "Updating $(@F)" ; \
175              $(MKDIR) $(@D) ; \
176              $(CP) -f $< $@ ;; \
177         esac
178
179 endif
180
181 #------------------------------------------------------------------------
182 # Set up the basic dependencies
183 #------------------------------------------------------------------------
184 $(UserTargets):: $(PreConditions)
185
186 all:: all-local
187 clean:: clean-local 
188 clean-all:: clean-local clean-all-local
189 install:: install-local
190 uninstall:: uninstall-local
191 install-local:: all-local 
192 install-bytecode:: install-bytecode-local
193
194 ###############################################################################
195 # VARIABLES: Set up various variables based on configuration data
196 ###############################################################################
197
198 #--------------------------------------------------------------------
199 # Variables derived from configuration we are building
200 #--------------------------------------------------------------------
201
202 CPP.Defines :=
203 # OPTIMIZE_OPTION - The optimization level option we want to build LLVM with
204 # this can be overridden on the make command line.
205 ifneq ($(OS),MingW)
206   OPTIMIZE_OPTION := -O3
207 else
208   OPTIMIZE_OPTION := -O2
209 endif
210
211 ifdef ENABLE_PROFILING
212   BuildMode := Profile
213   CXX.Flags += $(OPTIMIZE_OPTION) -pg -g
214   C.Flags   += $(OPTIMIZE_OPTION) -pg -g
215   LD.Flags  += $(OPTIMIZE_OPTION) -pg -g
216   KEEP_SYMBOLS := 1
217 else
218   ifeq ($(ENABLE_OPTIMIZED),1)
219     BuildMode := Release
220     # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
221     ifneq ($(OS),FreeBSD)
222     ifneq ($(OS),Darwin)
223       OmitFramePointer := -fomit-frame-pointer
224     endif
225     endif
226
227     # Darwin requires -fstrict-aliasing to be explicitly enabled.
228     ifeq ($(OS),Darwin)
229       EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
230     endif
231
232     CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
233     C.Flags   += $(OPTIMIZE_OPTION) $(OmitFramePointer)
234     LD.Flags  += $(OPTIMIZE_OPTION)
235   else
236     BuildMode := Debug
237     CXX.Flags += -g
238     C.Flags   += -g
239     LD.Flags  += -g
240     KEEP_SYMBOLS := 1
241   endif
242 endif
243
244 # IF REQUIRES_EH=1 is specified then don't disable exceptions
245 ifndef REQUIRES_EH
246   CXX.Flags += -fno-exceptions
247 endif
248
249 # IF REQUIRES_RTTI=1 is specified then don't disable run-time type id
250 ifndef REQUIRES_RTTI
251 #  CXX.Flags += -fno-rtti
252 endif
253
254 # If DISABLE_ASSERTIONS=1 is specified (make command line or configured),
255 # then disable assertions by defining the appropriate preprocessor symbols.
256 ifdef DISABLE_ASSERTIONS
257   BuildMode := $(BuildMode)-Asserts
258   CPP.Defines += -DNDEBUG
259 else
260   CPP.Defines += -D_DEBUG
261 endif
262
263 # If ENABLE_EXPENSIVE_CHECKS=1 is specified (make command line or 
264 # configured), then enable expensive checks by defining the 
265 # appropriate preprocessor symbols.
266 ifdef ENABLE_EXPENSIVE_CHECKS
267   BuildMode := $(BuildMode)+Checks
268   CPP.Defines += -D_GLIBCXX_DEBUG
269 endif
270
271 ifeq ($(ENABLE_PIC),1)
272   CXX.Flags += -fPIC
273   C.Flags   += -fPIC
274 endif
275
276 CXX.Flags     += $(CXXFLAGS) -Woverloaded-virtual
277 C.Flags       += $(CFLAGS)
278 CPP.Defines   += $(CPPFLAGS)
279 CPP.BaseFlags += $(CPP.Defines)
280 LD.Flags      += $(LDFLAGS)
281 AR.Flags      := cru
282 LibTool.Flags := --tag=CXX
283
284 # Make Floating point IEEE compliant on Alpha.
285 ifeq ($(ARCH),Alpha)
286   CXX.Flags     += -mieee
287   CPP.BaseFlags += -mieee
288 ifeq ($(ENABLE_PIC),0)
289   CXX.Flags     += -fPIC
290   CPP.BaseFlags += -fPIC
291 endif
292 endif
293
294 ifeq ($(ARCH),Alpha)
295   LD.Flags += -Wl,--no-relax
296 endif
297
298 #--------------------------------------------------------------------
299 # Directory locations
300 #--------------------------------------------------------------------
301 ObjDir      := $(PROJ_OBJ_DIR)/$(BuildMode)
302 LibDir      := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib
303 ToolDir     := $(PROJ_OBJ_ROOT)/$(BuildMode)/bin
304 ExmplDir    := $(PROJ_OBJ_ROOT)/$(BuildMode)/examples
305 LLVMLibDir  := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
306 LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
307 LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
308 CFERuntimeLibDir := $(LLVMGCCDIR)/lib
309
310 #--------------------------------------------------------------------
311 # Full Paths To Compiled Tools and Utilities
312 #--------------------------------------------------------------------
313 EchoCmd  = $(ECHO) llvm[$(MAKELEVEL)]:
314 Echo     = @$(EchoCmd)
315 ifndef LIBTOOL
316 LIBTOOL  := $(LLVM_OBJ_ROOT)/mklib
317 endif
318 ifndef LLVMAS
319 LLVMAS   := $(LLVMToolDir)/llvm-as$(EXEEXT)
320 endif
321 ifndef TBLGEN
322   ifeq ($(LLVM_CROSS_COMPILING),1)
323     TBLGEN   := $(LLVMToolDir)/tblgen$(BUILD_EXEEXT)
324   else
325     TBLGEN   := $(LLVMToolDir)/tblgen$(EXEEXT)
326   endif
327 endif
328 LLVM_CONFIG := $(LLVMToolDir)/llvm-config 
329 ifndef LLVMLD
330 LLVMLD    := $(LLVMToolDir)/llvm-ld$(EXEEXT)
331 endif
332 ifndef LLVMDIS
333 LLVMDIS  := $(LLVMToolDir)/llvm-dis$(EXEEXT)
334 endif
335 ifndef LLI
336 LLI      := $(LLVMToolDir)/lli$(EXEEXT)
337 endif
338 ifndef LLC
339 LLC      := $(LLVMToolDir)/llc$(EXEEXT)
340 endif
341 ifndef LOPT
342 LOPT     := $(LLVMToolDir)/opt$(EXEEXT)
343 endif
344 ifndef LBUGPOINT
345 LBUGPOINT := $(LLVMToolDir)/bugpoint$(EXEEXT)
346 endif
347 ifndef LUPGRADE
348 LUPGRADE := $(LLVMToolDir)/llvm-upgrade$(EXEEXT)
349 endif
350 ifeq ($(LLVMGCC_MAJVERS),3)
351 UPGRADE_MSG = $(Echo) "Upgrading $(1) assembly to latest."
352 UPGRADE_LL  = $(Verb)$(LUPGRADE) $(1) -o $(1).up.tmp -f ; $(MV) $(1).up.tmp $(1)
353 LLVMGCCWITHPATH  := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGCC)
354 LLVMGXXWITHPATH  := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGXX)
355 else
356 UPGRADE_MSG =
357 UPGRADE_LL  =
358 LLVMGCCWITHPATH  := $(LLVMGCC)
359 LLVMGXXWITHPATH  := $(LLVMGXX)
360 endif
361
362 #--------------------------------------------------------------------
363 # Adjust to user's request
364 #--------------------------------------------------------------------
365
366 # Adjust LD.Flags and Libtool.Flags depending on the kind of library that is
367 # to be built. Note that if LOADABLE_MODULE is specified then the resulting
368 # shared library can be opened with dlopen. Also, LOADABLE_MODULE implies 
369 # several other things so we force them to be defined/on.
370 ifdef LOADABLE_MODULE
371   SHARED_LIBRARY := 1
372   DONT_BUILD_RELINKED := 1
373   LINK_LIBS_IN_SHARED := 1
374   LD.Flags += -module
375 endif
376
377 ifdef SHARED_LIBRARY
378   LD.Flags += -rpath $(LibDir)
379 else
380   LibTool.Flags += --tag=disable-shared
381 endif
382
383 ifdef TOOL_VERBOSE
384   C.Flags += -v
385   CXX.Flags += -v
386   LD.Flags += -v
387   VERBOSE := 1
388 endif
389
390 # Adjust settings for verbose mode
391 ifndef VERBOSE
392   Verb := @
393   LibTool.Flags += --silent
394   AR.Flags += >/dev/null 2>/dev/null
395   ConfigureScriptFLAGS += >$(PROJ_OBJ_DIR)/configure.out 2>&1
396 else
397   ConfigureScriptFLAGS := 
398 endif
399
400 # By default, strip symbol information from executable
401 ifndef KEEP_SYMBOLS
402   Strip := $(PLATFORMSTRIPOPTS)
403   StripWarnMsg := "(without symbols)"
404   Install.StripFlag += -s
405 endif
406
407 # Adjust linker flags for building an executable
408 ifdef TOOLNAME
409 ifdef EXAMPLE_TOOL
410   LD.Flags += -rpath $(ExmplDir) -export-dynamic
411 else
412   LD.Flags += -rpath $(ToolDir) -export-dynamic
413 endif
414 endif
415
416 #----------------------------------------------------------
417 # Options To Invoke Tools
418 #----------------------------------------------------------
419
420 CompileCommonOpts := -pedantic -Wall -W -Wwrite-strings -Wno-long-long \
421                      -Wunused -Wno-unused-parameter $(EXTRA_OPTIONS)
422
423 ifeq ($(OS),HP-UX)
424   CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
425 endif
426
427 # If we are building a universal binary on Mac OS/X, pass extra options.  This
428 # is useful to people that want to link the LLVM libraries into their universal
429 # apps.
430 #
431 # The following can be optionally specified:
432 #   UNIVERSAL_SDK_PATH variable can be specified as a path to the SDK to use.
433 #      For Mac OS/X 10.4 Intel machines, the traditional one is:
434 #      UNIVERSAL_SDK_PATH=/Developer/SDKs/MacOSX10.4u.sdk/
435 #   UNIVERSAL_ARCH can be optionally specified to be a list of architectures
436 #      to build for, e.g. UNIVERSAL_ARCH="i386 ppc ppc64".  This defaults to
437 #      i386/ppc only.
438 ifdef UNIVERSAL
439   ifndef UNIVERSAL_ARCH
440     UNIVERSAL_ARCH := i386 ppc
441   endif
442   UNIVERSAL_ARCH_OPTIONS := $(UNIVERSAL_ARCH:%=-arch %)
443   CompileCommonOpts += $(UNIVERSAL_ARCH_OPTIONS)
444   Relink.Flags := $(UNIVERSAL_ARCH_OPTIONS:%=-XCClinker %)
445   ifdef UNIVERSAL_SDK_PATH
446     CompileCommonOpts += -isysroot $(UNIVERSAL_SDK_PATH)
447     Relink.Flags      += -XCClinker -isysroot -XCClinker $(UNIVERSAL_SDK_PATH)
448   endif
449
450   # Building universal cannot compute dependencies automatically.
451   DISABLE_AUTO_DEPENDENCIES=1
452 endif
453
454 ifeq ($(OS),SunOS)
455 CPP.BaseFlags += -include llvm/System/Solaris.h
456 endif
457
458 LD.Flags      += -L$(LibDir) -L$(LLVMLibDir) 
459 CPP.BaseFlags += -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
460 # All -I flags should go here, so that they don't confuse llvm-config.
461 CPP.Flags     += $(sort -I$(PROJ_OBJ_DIR) -I$(PROJ_SRC_DIR) \
462                  $(patsubst %,-I%/include,\
463                  $(PROJ_OBJ_ROOT) $(PROJ_SRC_ROOT) \
464                  $(LLVM_OBJ_ROOT) $(LLVM_SRC_ROOT))) \
465                  $(CPP.BaseFlags)
466
467 Compile.C     = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -c
468 LTCompile.C   = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
469 BCCompile.C   = $(LLVMGCCWITHPATH) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts)
470 Preprocess.C  = $(CC) $(CPP.Flags) $(C.Flags) $(CompileCommonOpts) -E
471
472 Compile.CXX   = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) -c
473 LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
474 BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CXX.Flags) \
475                 $(CompileCommonOpts)
476
477 Preprocess.CXX= $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -E
478 Link          = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
479                 $(LD.Flags) $(Strip)
480 LTLink        = $(LIBTOOL) $(LibTool.Flags) --mode=link $(Link)
481 Relink        = $(CXX) $(CPP.Flags) $(CXX.Flags) $(CompileCommonOpts) \
482                 $(Relink.Flags)
483 LTRelink      = $(LIBTOOL) $(LibTool.Flags) --mode=link $(Relink)
484 LTInstall     = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL) \
485                 $(Install.Flags)
486 ProgInstall   = $(INSTALL) $(Install.StripFlag) -m 0755 
487 ScriptInstall = $(INSTALL) -m 0755 
488 DataInstall   = $(INSTALL) -m 0644
489
490 # When compiling under Mingw/Cygwin, the tblgen tool expects Windows
491 # paths. In this case, the SYSPATH function (defined in
492 # Makefile.config) transforms Unix paths into Windows paths.
493 TableGen      = $(TBLGEN) -I $(call SYSPATH, $(PROJ_SRC_DIR)) \
494                 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/include) \
495                 -I $(call SYSPATH, $(PROJ_SRC_ROOT)/lib/Target)
496
497 Archive       = $(AR) $(AR.Flags)
498 LArchive      = $(LLVMToolDir)/llvm-ar rcsf
499 ifdef RANLIB
500 Ranlib        = $(RANLIB)
501 else
502 Ranlib        = ranlib
503 endif
504
505 #----------------------------------------------------------
506 # Get the list of source files and compute object file 
507 # names from them. 
508 #----------------------------------------------------------
509
510 ifndef SOURCES
511   Sources := $(notdir $(wildcard $(PROJ_SRC_DIR)/*.cpp \
512              $(PROJ_SRC_DIR)/*.cc $(PROJ_SRC_DIR)/*.c $(PROJ_SRC_DIR)/*.y \
513              $(PROJ_SRC_DIR)/*.l))
514 else
515   Sources := $(SOURCES)
516 endif 
517
518 ifdef BUILT_SOURCES
519 Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
520 endif
521
522 BaseNameSources := $(sort $(basename $(Sources)))
523
524 ObjectsO  := $(BaseNameSources:%=$(ObjDir)/%.o)
525 ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
526 ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
527
528 ###############################################################################
529 # DIRECTORIES: Handle recursive descent of directory structure
530 ###############################################################################
531
532 #---------------------------------------------------------
533 # Provide rules to make install dirs. This must be early
534 # in the file so they get built before dependencies
535 #---------------------------------------------------------
536
537 $(PROJ_bindir): $(PROJ_bindir)/.dir
538 $(PROJ_libdir): $(PROJ_libdir)/.dir
539 $(PROJ_includedir): $(PROJ_includedir)/.dir
540 $(PROJ_etcdir): $(PROJ_etcdir)/.dir
541
542 # To create other directories, as needed, and timestamp their creation
543 %/.dir:
544         $(Verb) $(MKDIR) $* > /dev/null
545         $(Verb) $(DATE) > $@
546
547 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
548 .PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
549
550 #---------------------------------------------------------
551 # Handle the DIRS options for sequential construction
552 #---------------------------------------------------------
553
554 SubDirs := 
555 ifdef DIRS
556 SubDirs += $(DIRS)
557
558 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
559 $(RecursiveTargets)::
560         $(Verb) for dir in $(DIRS); do \
561           if [ ! -f $$dir/Makefile ]; then \
562             $(MKDIR) $$dir; \
563             $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
564           fi; \
565           ($(MAKE) -C $$dir $@ ) || exit 1; \
566         done
567 else
568 $(RecursiveTargets)::
569         $(Verb) for dir in $(DIRS); do \
570           ($(MAKE) -C $$dir $@ ) || exit 1; \
571         done
572 endif
573
574 endif
575
576 #---------------------------------------------------------
577 # Handle the EXPERIMENTAL_DIRS options ensuring success
578 # after each directory is built.
579 #---------------------------------------------------------
580 ifdef EXPERIMENTAL_DIRS
581 $(RecursiveTargets)::
582         $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
583           if [ ! -f $$dir/Makefile ]; then \
584             $(MKDIR) $$dir; \
585             $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
586           fi; \
587           ($(MAKE) -C $$dir $@ ) || exit 0; \
588         done
589 endif
590
591 #-----------------------------------------------------------
592 # Handle the PARALLEL_DIRS options for parallel construction
593 #-----------------------------------------------------------
594 ifdef PARALLEL_DIRS
595
596 SubDirs += $(PARALLEL_DIRS)
597
598 # Unfortunately, this list must be maintained if new recursive targets are added
599 all      :: $(addsuffix /.makeall      ,$(PARALLEL_DIRS))
600 clean    :: $(addsuffix /.makeclean    ,$(PARALLEL_DIRS))
601 clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
602 install  :: $(addsuffix /.makeinstall  ,$(PARALLEL_DIRS))
603 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
604 install-bytecode  :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
605
606 ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
607
608 $(ParallelTargets) :
609         $(Verb) if [ ! -f $(@D)/Makefile ]; then \
610           $(MKDIR) $(@D); \
611           $(CP) $(PROJ_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
612         fi; \
613         $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
614 endif
615
616 #---------------------------------------------------------
617 # Handle the OPTIONAL_DIRS options for directores that may
618 # or may not exist.
619 #---------------------------------------------------------
620 ifdef OPTIONAL_DIRS
621
622 SubDirs += $(OPTIONAL_DIRS)
623
624 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
625 $(RecursiveTargets)::
626         $(Verb) for dir in $(OPTIONAL_DIRS); do \
627           if [ -d $(PROJ_SRC_DIR)/$$dir ]; then\
628             if [ ! -f $$dir/Makefile ]; then \
629               $(MKDIR) $$dir; \
630               $(CP) $(PROJ_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
631             fi; \
632             ($(MAKE) -C$$dir $@ ) || exit 1; \
633           fi \
634         done
635 else
636 $(RecursiveTargets)::
637         $(Verb) for dir in $(OPTIONAL_DIRS); do \
638           ($(MAKE) -C$$dir $@ ) || exit 1; \
639         done
640 endif
641 endif
642
643 #---------------------------------------------------------
644 # Handle the CONFIG_FILES options
645 #---------------------------------------------------------
646 ifdef CONFIG_FILES
647
648 ifdef NO_INSTALL
649 install-local::
650         $(Echo) Install circumvented with NO_INSTALL
651 uninstall-local::
652         $(Echo) UnInstall circumvented with NO_INSTALL
653 else
654 install-local:: $(PROJ_etcdir) $(CONFIG_FILES)
655         $(Echo) Installing Configuration Files To $(PROJ_etcdir)
656         $(Verb)for file in $(CONFIG_FILES); do \
657           if test -f $(PROJ_OBJ_DIR)/$${file} ; then \
658             $(DataInstall) $(PROJ_OBJ_DIR)/$${file} $(PROJ_etcdir) ; \
659           elif test -f $(PROJ_SRC_DIR)/$${file} ; then \
660             $(DataInstall) $(PROJ_SRC_DIR)/$${file} $(PROJ_etcdir) ; \
661           else \
662             $(ECHO) Error: cannot find config file $${file}. ; \
663           fi \
664         done
665
666 uninstall-local::
667         $(Echo) Uninstalling Configuration Files From $(PROJ_etcdir)
668         $(Verb)for file in $(CONFIG_FILES); do \
669           $(RM) -f $(PROJ_etcdir)/$${file} ; \
670         done
671 endif
672
673 endif
674
675 ###############################################################################
676 # Set up variables for building libararies
677 ###############################################################################
678
679 #---------------------------------------------------------
680 # Define various command line options pertaining to the
681 # libraries needed when linking. There are "Proj" libs 
682 # (defined by the user's project) and "LLVM" libs (defined 
683 # by the LLVM project).
684 #---------------------------------------------------------
685
686 ifdef USEDLIBS
687 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
688 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o,  $(ProjLibsOptions))
689 ProjUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
690 ProjLibsPaths   := $(addprefix $(LibDir)/,$(ProjUsedLibs))
691 endif
692
693 ifdef LLVMLIBS
694 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
695 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
696 LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
697 LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
698 endif
699
700 ifeq ($(strip $(filter clean clean-local dist-clean,$(MAKECMDGOALS))),)
701 ifdef LINK_COMPONENTS
702
703 # If LLVM_CONFIG doesn't exist, build it.  This can happen if you do a make
704 # clean in tools, then do a make in tools (instead of at the top level).
705 $(LLVM_CONFIG):
706         @echo "*** llvm-config doesn't exist - rebuilding it."
707         @$(MAKE) -C $(PROJ_OBJ_ROOT)/tools/llvm-config
708
709 $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT): $(LLVM_CONFIG)
710
711 ProjLibsOptions += $(shell $(LLVM_CONFIG) --libs     $(LINK_COMPONENTS))
712 ProjLibsPaths   += $(LLVM_CONFIG) \
713                   $(shell $(LLVM_CONFIG) --libfiles $(LINK_COMPONENTS))
714 endif
715 endif
716
717 ###############################################################################
718 # Library Build Rules: Four ways to build a library
719 ###############################################################################
720
721 #---------------------------------------------------------
722 # Bytecode Module Targets:
723 #   If the user set MODULE_NAME then they want to build a
724 #   bytecode module from the sources. We compile all the
725 #   sources and link it together into a single bytecode
726 #   module.
727 #---------------------------------------------------------
728
729 ifdef MODULE_NAME
730 ifeq ($(strip $(LLVMGCC)),)
731 $(warning Modules require llvm-gcc but no llvm-gcc is available ****)
732 else
733
734 Module     := $(LibDir)/$(MODULE_NAME).bc
735 LinkModule := $(LLVMLD) -L$(CFERuntimeLibDir) -r
736
737
738 ifdef EXPORTED_SYMBOL_FILE
739 LinkModule += -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
740 endif
741
742 $(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(LLVMLD)
743         $(Echo) Building $(BuildMode) Bytecode Module $(notdir $@)
744         $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
745
746 all-local:: $(Module)
747
748 clean-local::
749 ifneq ($(strip $(Module)),)
750         -$(Verb) $(RM) -f $(Module)
751 endif
752
753 ifdef BYTECODE_DESTINATION
754 ModuleDestDir := $(BYTECODE_DESTINATION)
755 else
756 ModuleDestDir := $(PROJ_libdir)
757 endif
758
759 ifdef NO_INSTALL
760 install-local::
761         $(Echo) Install circumvented with NO_INSTALL
762 uninstall-local::
763         $(Echo) Uninstall circumvented with NO_INSTALL
764 else
765 DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
766
767 install-module:: $(DestModule)
768 install-local:: $(DestModule)
769
770 $(DestModule): $(ModuleDestDir) $(Module) 
771         $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
772         $(Verb) $(DataInstall) $(Module) $(DestModule)
773
774 uninstall-local::
775         $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
776         -$(Verb) $(RM) -f $(DestModule)
777 endif
778
779 endif
780 endif
781
782 # if we're building a library ...
783 ifdef LIBRARYNAME
784
785 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
786 LIBRARYNAME := $(strip $(LIBRARYNAME))
787 ifdef LOADABLE_MODULE
788 LibName.LA := $(LibDir)/$(LIBRARYNAME).la
789 else
790 LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
791 endif
792 LibName.A  := $(LibDir)/lib$(LIBRARYNAME).a
793 LibName.O  := $(LibDir)/$(LIBRARYNAME).o
794 LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
795
796 #---------------------------------------------------------
797 # Shared Library Targets:
798 #   If the user asked for a shared library to be built
799 #   with the SHARED_LIBRARY variable, then we provide
800 #   targets for building them.
801 #---------------------------------------------------------
802 ifdef SHARED_LIBRARY
803
804 all-local:: $(LibName.LA)
805
806 ifdef LINK_LIBS_IN_SHARED
807 ifdef LOADABLE_MODULE
808 SharedLibKindMessage := "Loadable Module"
809 else
810 SharedLibKindMessage := "Shared Library"
811 endif
812 $(LibName.LA): $(ObjectsLO) $(ProjLibsPaths) $(LLVMLibsPaths) $(LibDir)/.dir
813         $(Echo) Linking $(BuildMode) $(SharedLibKindMessage) \
814           $(LIBRARYNAME)$(SHLIBEXT)
815         $(Verb) $(LTLink) -o $@ $(ObjectsLO) $(ProjLibsOptions) \
816           $(LLVMLibsOptions)
817         $(Verb) $(LTInstall) $@ $(LibDir)
818 else
819 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
820         $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
821         $(Verb) $(LTLink) -o $@ $(ObjectsLO)
822         $(Verb) $(LTInstall) $@ $(LibDir)
823 endif
824
825 clean-local::
826 ifneq ($(strip $(LibName.LA)),)
827         -$(Verb) $(RM) -f $(LibName.LA)
828 endif
829
830 ifdef NO_INSTALL
831 install-local::
832         $(Echo) Install circumvented with NO_INSTALL
833 uninstall-local::
834         $(Echo) Uninstall circumvented with NO_INSTALL
835 else
836 DestSharedLib = $(PROJ_libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
837
838 install-local:: $(DestSharedLib)
839
840 $(DestSharedLib): $(PROJ_libdir) $(LibName.LA)
841         $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
842         $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
843         $(Verb) $(LIBTOOL) --finish $(PROJ_libdir)
844
845 uninstall-local:: 
846         $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
847         -$(Verb) $(RM) -f $(PROJ_libdir)/lib$(LIBRARYNAME).*
848 endif
849 endif
850
851 #---------------------------------------------------------
852 # Bytecode Library Targets:
853 #   If the user asked for a bytecode library to be built
854 #   with the BYTECODE_LIBRARY variable, then we provide 
855 #   targets for building them.
856 #---------------------------------------------------------
857 ifdef BYTECODE_LIBRARY
858 ifeq ($(strip $(LLVMGCC)),)
859 $(warning Bytecode libraries require llvm-gcc which could not be found ****)
860 else
861
862 all-local:: $(LibName.BCA)
863
864 ifdef EXPORTED_SYMBOL_FILE
865 BCLinkLib = $(LLVMLD) -L$(CFERuntimeLibDir) \
866                      -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
867
868 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(LLVMLD) \
869                 $(LLVMToolDir)/llvm-ar
870         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
871           "(internalize)"
872         $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
873         $(Verb) $(RM) -f $@
874         $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
875 else
876 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
877                 $(LLVMToolDir)/llvm-ar
878         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
879         $(Verb) $(RM) -f $@
880         $(Verb) $(LArchive) $@ $(ObjectsBC)
881
882 endif
883
884 clean-local::
885 ifneq ($(strip $(LibName.BCA)),)
886         -$(Verb) $(RM) -f $(LibName.BCA)
887 endif
888
889 ifdef BYTECODE_DESTINATION
890 BytecodeDestDir := $(BYTECODE_DESTINATION)
891 else
892 BytecodeDestDir := $(PROJ_libdir)
893 endif
894
895 DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
896
897 install-bytecode-local:: $(DestBytecodeLib)
898
899 ifdef NO_INSTALL
900 install-local::
901         $(Echo) Install circumvented with NO_INSTALL
902 uninstall-local::
903         $(Echo) Uninstall circumvented with NO_INSTALL
904 else
905 install-local:: $(DestBytecodeLib)
906
907 $(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA) 
908         $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
909         $(Verb) $(DataInstall) $(LibName.BCA) $(DestBytecodeLib)
910
911 uninstall-local::
912         $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
913         -$(Verb) $(RM) -f $(DestBytecodeLib)
914 endif
915 endif
916 endif
917
918 #---------------------------------------------------------
919 # ReLinked Library Targets:
920 #   If the user explicitly requests a relinked library with
921 #   BUILD_RELINKED, provide it.  Otherwise, if they specify
922 #   neither of BUILD_ARCHIVE or DONT_BUILD_RELINKED, give
923 #   them one.
924 #---------------------------------------------------------
925 ifndef BUILD_ARCHIVE
926 ifndef DONT_BUILD_RELINKED
927 BUILD_RELINKED = 1
928 endif
929 endif
930
931 ifdef BUILD_RELINKED
932
933 all-local:: $(LibName.O)
934
935 $(LibName.O): $(ObjectsO) $(LibDir)/.dir
936         $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
937         $(Verb) $(LTRelink) -o $@ $(ObjectsO)
938
939 clean-local::
940 ifneq ($(strip $(LibName.O)),)
941         -$(Verb) $(RM) -f $(LibName.O)
942 endif
943
944 ifdef NO_INSTALL
945 install-local::
946         $(Echo) Install circumvented with NO_INSTALL
947 uninstall-local::
948         $(Echo) Uninstall circumvented with NO_INSTALL
949 else
950 DestRelinkedLib = $(PROJ_libdir)/$(LIBRARYNAME).o
951
952 install-local:: $(DestRelinkedLib)
953
954 $(DestRelinkedLib): $(PROJ_libdir) $(LibName.O)
955         $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
956         $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
957
958 uninstall-local::
959         $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
960         -$(Verb) $(RM) -f $(DestRelinkedLib)
961 endif
962 endif
963
964 #---------------------------------------------------------
965 # Archive Library Targets:
966 #   If the user wanted a regular archive library built, 
967 #   then we provide targets for building them.
968 #---------------------------------------------------------
969 ifdef BUILD_ARCHIVE
970
971 all-local:: $(LibName.A)
972
973 $(LibName.A): $(ObjectsO) $(LibDir)/.dir
974         $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
975         -$(Verb) $(RM) -f $@
976         $(Verb) $(Archive) $@ $(ObjectsO)
977         $(Verb) $(Ranlib) $@
978
979 clean-local::
980 ifneq ($(strip $(LibName.A)),)
981         -$(Verb) $(RM) -f $(LibName.A)
982 endif
983
984 ifdef NO_INSTALL
985 install-local::
986         $(Echo) Install circumvented with NO_INSTALL
987 uninstall-local::
988         $(Echo) Uninstall circumvented with NO_INSTALL
989 else
990 DestArchiveLib := $(PROJ_libdir)/lib$(LIBRARYNAME).a
991
992 install-local:: $(DestArchiveLib)
993
994 $(DestArchiveLib): $(PROJ_libdir) $(LibName.A)
995         $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
996         $(Verb) $(MKDIR) $(PROJ_libdir)
997         $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
998
999 uninstall-local::
1000         $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
1001         -$(Verb) $(RM) -f $(DestArchiveLib)
1002 endif
1003 endif
1004
1005 # endif LIBRARYNAME
1006 endif 
1007
1008 ###############################################################################
1009 # Tool Build Rules: Build executable tool based on TOOLNAME option
1010 ###############################################################################
1011
1012 ifdef TOOLNAME
1013
1014 #---------------------------------------------------------
1015 # Set up variables for building a tool.
1016 #---------------------------------------------------------
1017 ifdef EXAMPLE_TOOL
1018 ToolBuildPath   := $(ExmplDir)/$(strip $(TOOLNAME))$(EXEEXT)
1019 else
1020 ToolBuildPath   := $(ToolDir)/$(strip $(TOOLNAME))$(EXEEXT)
1021 endif
1022
1023 #---------------------------------------------------------
1024 # Provide targets for building the tools
1025 #---------------------------------------------------------
1026 all-local:: $(ToolBuildPath)
1027
1028 clean-local::
1029 ifneq ($(strip $(ToolBuildPath)),)
1030         -$(Verb) $(RM) -f $(ToolBuildPath)
1031 endif
1032
1033 ifdef EXAMPLE_TOOL
1034 $(ToolBuildPath): $(ExmplDir)/.dir
1035 else
1036 $(ToolBuildPath): $(ToolDir)/.dir
1037 endif
1038
1039 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
1040         $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
1041         $(Verb) $(LTLink) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
1042         $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
1043         $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) \
1044           $(StripWarnMsg) 
1045
1046 ifdef NO_INSTALL
1047 install-local::
1048         $(Echo) Install circumvented with NO_INSTALL
1049 uninstall-local::
1050         $(Echo) Uninstall circumvented with NO_INSTALL
1051 else
1052 DestTool = $(PROJ_bindir)/$(TOOLNAME)
1053
1054 install-local:: $(DestTool)
1055
1056 $(DestTool): $(PROJ_bindir) $(ToolBuildPath)
1057         $(Echo) Installing $(BuildMode) $(DestTool)
1058         $(Verb) $(ProgInstall) $(ToolBuildPath) $(DestTool)
1059
1060 uninstall-local::
1061         $(Echo) Uninstalling $(BuildMode) $(DestTool)
1062         -$(Verb) $(RM) -f $(DestTool)
1063 endif
1064 endif
1065
1066 ###############################################################################
1067 # Object Build Rules: Build object files based on sources 
1068 ###############################################################################
1069
1070 # FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
1071 ifeq ($(OS),HP-UX)
1072   DISABLE_AUTO_DEPENDENCIES=1
1073 endif
1074
1075 ifdef SHARED_LIBRARY
1076 PIC_FLAG = "(PIC)"
1077 MAYBE_PIC_Compile.CXX = $(LTCompile.CXX)
1078 MAYBE_PIC_Compile.C = $(LTCompile.C)
1079 else
1080 MAYBE_PIC_Compile.CXX = $(Compile.CXX)
1081 MAYBE_PIC_Compile.C = $(Compile.C)
1082 endif
1083
1084 # Provide rule sets for when dependency generation is enabled
1085 ifndef DISABLE_AUTO_DEPENDENCIES
1086
1087 #---------------------------------------------------------
1088 # Create .lo files in the ObjDir directory from the .cpp and .c files...
1089 #---------------------------------------------------------
1090
1091 DEPEND_OPTIONS = -MMD -MP -MF "$(ObjDir)/$*.d.tmp" \
1092          -MT "$(ObjDir)/$*.lo" -MT "$(ObjDir)/$*.o" -MT "$(ObjDir)/$*.d"
1093
1094 # If the build succeeded, move the dependency file over.  If it failed, put an
1095 # empty file there.
1096 DEPEND_MOVEFILE = then $(MV) -f "$(ObjDir)/$*.d.tmp" "$(ObjDir)/$*.d"; \
1097                   else $(RM) "$(ObjDir)/$*.d.tmp"; exit 1; fi
1098
1099 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1100         $(Echo) "Compiling $*.cpp for $(BuildMode) build " $(PIC_FLAG)
1101         $(Verb) if $(MAYBE_PIC_Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1102                 $(DEPEND_MOVEFILE)
1103
1104 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1105         $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1106         $(Verb) if $(MAYBE_PIC_Compile.CXX) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1107                 $(DEPEND_MOVEFILE)
1108
1109 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1110         $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1111         $(Verb) if $(MAYBE_PIC_Compile.C) $(DEPEND_OPTIONS) $< -o $(ObjDir)/$*.o ; \
1112                 $(DEPEND_MOVEFILE)
1113
1114 #---------------------------------------------------------
1115 # Create .bc files in the ObjDir directory from .cpp .cc and .c files...
1116 #---------------------------------------------------------
1117
1118 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1119         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1120         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1121                               $< -o $@ -S -emit-llvm ; \
1122         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1123         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1124         $(call UPGRADE_MSG,$@) 
1125         $(call UPGRADE_LL,$@)
1126
1127 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1128         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1129         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" \
1130                               $< -o $@ -S -emit-llvm ; \
1131         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
1132         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
1133         $(call UPGRADE_MSG,$@) 
1134         $(call UPGRADE_LL,$@)
1135
1136 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
1137         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1138         $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" \
1139                             $< -o $@ -S -emit-llvm ; \
1140         then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
1141         else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
1142         $(call UPGRADE_MSG,$@) 
1143         $(call UPGRADE_LL,$@)
1144
1145 # Provide alternate rule sets if dependencies are disabled
1146 else
1147
1148 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1149         $(Echo) "Compiling $*.cpp for $(BuildMode) build" $(PIC_FLAG)
1150         $(MAYBE_PIC_Compile.CXX) $< -o $@ 
1151
1152 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1153         $(Echo) "Compiling $*.cc for $(BuildMode) build" $(PIC_FLAG)
1154         $(MAYBE_PIC_Compile.CXX) $< -o $@ 
1155
1156 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1157         $(Echo) "Compiling $*.c for $(BuildMode) build" $(PIC_FLAG)
1158         $(MAYBE_PIC_Compile.C) $< -o $@ 
1159
1160 $(ObjDir)/%.ll: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1161         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
1162         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1163         $(call UPGRADE_MSG,$@) 
1164         $(call UPGRADE_LL,$@)
1165
1166 $(ObjDir)/%.ll: %.cc $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGXX)
1167         $(Echo) "Compiling $*.cc for $(BuildMode) build (bytecode)"
1168         $(BCCompile.CXX) $< -o $@ -S -emit-llvm
1169         $(call UPGRADE_MSG,$@) 
1170         $(call UPGRADE_LL,$@)
1171
1172 $(ObjDir)/%.ll: %.c $(ObjDir)/.dir $(BUILT_SOURCES) $(LLVMGCC)
1173         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
1174         $(BCCompile.C) $< -o $@ -S -emit-llvm
1175         $(call UPGRADE_MSG,@) 
1176         $(call UPGRADE_LL,@)
1177
1178 endif
1179
1180
1181 ## Rules for building preprocessed (.i/.ii) outputs.
1182 $(BuildMode)/%.ii: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1183         $(Echo) "Compiling $*.cpp for $(BuildMode) build to .ii file"
1184         $(Verb) $(Preprocess.CXX) $< -o $@
1185
1186 $(BuildMode)/%.ii: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1187         $(Echo) "Compiling $*.cc for $(BuildMode) build to .ii file"
1188         $(Verb) $(Preprocess.CXX) $< -o $@
1189
1190 $(BuildMode)/%.i: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1191         $(Echo) "Compiling $*.c for $(BuildMode) build to .i file"
1192         $(Verb) $(Preprocess.C) $< -o $@
1193
1194
1195 $(ObjDir)/%.s: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
1196         $(Echo) "Compiling $*.cpp to asm for $(BuildMode) build" $(PIC_FLAG)
1197         $(MAYBE_PIC_Compile.CXX) $< -o $@ -S
1198
1199 $(ObjDir)/%.s: %.cc $(ObjDir)/.dir $(BUILT_SOURCES)
1200         $(Echo) "Compiling $*.cc to asm for $(BuildMode) build" $(PIC_FLAG)
1201         $(MAYBE_PIC_Compile.CXX) $< -o $@ -S
1202
1203 $(ObjDir)/%.s: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
1204         $(Echo) "Compiling $*.c to asm for $(BuildMode) build" $(PIC_FLAG)
1205         $(MAYBE_PIC_Compile.C) $< -o $@ -S
1206
1207
1208 # make the C and C++ compilers strip debug info out of bytecode libraries.
1209 ifdef DEBUG_RUNTIME
1210 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
1211         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1212         $(Verb) $(LLVMAS) $< -o - | $(LOPT) -std-compile-opts -o $@ -f
1213 else
1214 $(ObjectsBC): $(ObjDir)/%.bc: $(ObjDir)/%.ll $(LLVMAS) $(LOPT)
1215         $(Echo) "Compiling $*.ll to $*.bc for $(BuildMode) build (bytecode)"
1216         $(Verb) $(LLVMAS) $< -o - | \
1217            $(LOPT) -std-compile-opts -strip-debug -o $@ -f
1218 endif
1219
1220
1221 #---------------------------------------------------------
1222 # Provide rule to build .bc files from .ll sources,
1223 # regardless of dependencies
1224 #---------------------------------------------------------
1225 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
1226         $(Echo) "Compiling $*.ll for $(BuildMode) build"
1227         $(Verb) $(LLVMAS) $< -f -o $@
1228
1229 ###############################################################################
1230 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
1231 ###############################################################################
1232
1233 ifdef TARGET
1234
1235 TDFiles := $(strip $(wildcard $(PROJ_SRC_DIR)/*.td) \
1236            $(LLVM_SRC_ROOT)/lib/Target/Target.td \
1237            $(LLVM_SRC_ROOT)/lib/Target/TargetCallingConv.td \
1238            $(LLVM_SRC_ROOT)/lib/Target/TargetSelectionDAG.td \
1239            $(LLVM_SRC_ROOT)/include/llvm/CodeGen/ValueTypes.td) \
1240            $(wildcard $(LLVM_SRC_ROOT)/include/llvm/Intrinsics*.td)
1241 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
1242 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
1243 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
1244
1245 # All of these files depend on tblgen and the .td files.
1246 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
1247
1248 # INCFiles rule: All of the tblgen generated files are emitted to 
1249 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc.  This allows
1250 # us to only "touch" the real file if the contents of it change.  IOW, if
1251 # tblgen is modified, all of the .inc.tmp files are regereated, but no
1252 # dependencies of the .inc files are, unless the contents of the .inc file
1253 # changes.
1254 $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
1255         $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
1256
1257 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
1258 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
1259         $(Echo) "Building $(<F) register names with tblgen"
1260         $(Verb) $(TableGen) -gen-register-enums -o $(call SYSPATH, $@) $<
1261
1262 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
1263 $(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
1264         $(Echo) "Building $(<F) register information header with tblgen"
1265         $(Verb) $(TableGen) -gen-register-desc-header -o $(call SYSPATH, $@) $<
1266
1267 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1268 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1269         $(Echo) "Building $(<F) register info implementation with tblgen"
1270         $(Verb) $(TableGen) -gen-register-desc -o $(call SYSPATH, $@) $<
1271
1272 $(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1273 $(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1274         $(Echo) "Building $(<F) instruction names with tblgen"
1275         $(Verb) $(TableGen) -gen-instr-enums -o $(call SYSPATH, $@) $<
1276
1277 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1278 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1279         $(Echo) "Building $(<F) instruction information with tblgen"
1280         $(Verb) $(TableGen) -gen-instr-desc -o $(call SYSPATH, $@) $<
1281
1282 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1283 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1284         $(Echo) "Building $(<F) assembly writer with tblgen"
1285         $(Verb) $(TableGen) -gen-asm-writer -o $(call SYSPATH, $@) $<
1286
1287 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1288 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1289         $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1290         $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $(call SYSPATH, $@) $< 
1291
1292 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1293 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1294         $(Echo) "Building $(<F) code emitter with tblgen"
1295         $(Verb) $(TableGen) -gen-emitter -o $(call SYSPATH, $@) $<
1296
1297 $(TARGET:%=$(ObjDir)/%GenDAGISel.inc.tmp): \
1298 $(ObjDir)/%GenDAGISel.inc.tmp : %.td $(ObjDir)/.dir
1299         $(Echo) "Building $(<F) DAG instruction selector implementation with tblgen"
1300         $(Verb) $(TableGen) -gen-dag-isel -o $(call SYSPATH, $@) $<
1301
1302 $(TARGET:%=$(ObjDir)/%GenFastISel.inc.tmp): \
1303 $(ObjDir)/%GenFastISel.inc.tmp : %.td $(ObjDir)/.dir
1304         $(Echo) "Building $(<F) \"fast\" instruction selector implementation with tblgen"
1305         $(Verb) $(TableGen) -gen-fast-isel -o $(call SYSPATH, $@) $<
1306
1307 $(TARGET:%=$(ObjDir)/%GenSubtarget.inc.tmp): \
1308 $(ObjDir)/%GenSubtarget.inc.tmp : %.td $(ObjDir)/.dir
1309         $(Echo) "Building $(<F) subtarget information with tblgen"
1310         $(Verb) $(TableGen) -gen-subtarget -o $(call SYSPATH, $@) $<
1311
1312 $(TARGET:%=$(ObjDir)/%GenCallingConv.inc.tmp): \
1313 $(ObjDir)/%GenCallingConv.inc.tmp : %.td $(ObjDir)/.dir
1314         $(Echo) "Building $(<F) calling convention information with tblgen"
1315         $(Verb) $(TableGen) -gen-callingconv -o $(call SYSPATH, $@) $<
1316
1317 clean-local::
1318         -$(Verb) $(RM) -f $(INCFiles)
1319
1320 endif
1321
1322 ###############################################################################
1323 # LEX AND YACC: Provide rules for generating sources with lex and yacc
1324 ###############################################################################
1325
1326 #---------------------------------------------------------
1327 # Provide rules for generating a .cpp source file from 
1328 # (f)lex input sources. 
1329 #---------------------------------------------------------
1330
1331 LexFiles  := $(filter %.l,$(Sources))
1332
1333 ifneq ($(LexFiles),)
1334
1335 # Cancel built-in rules for lex
1336 %.c: %.l
1337 %.cpp: %.l
1338
1339 all:: $(LexFiles:%.l=$(PROJ_SRC_DIR)/%.cpp.cvs)
1340
1341 # Note the extra sed filtering here, used to cut down on the warnings emited 
1342 # by GCC.  The last line is a gross hack to work around flex aparently not 
1343 # being able to resize the buffer on a large token input.  Currently, for 
1344 # uninitialized string buffers in LLVM we can generate very long tokens, so 
1345 # this is a hack around it.
1346 # FIXME.  (f.e. char Buffer[10000] )
1347 $(PROJ_SRC_DIR)/%.cpp: $(PROJ_SRC_DIR)/%.l
1348         $(Echo) Flexing $*.l
1349         $(Verb) $(FLEX) -t $(PROJ_SRC_DIR)/$*.l | \
1350         $(SED) 's/void yyunput/inline void yyunput/' | \
1351         $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1352         $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
1353           > $(PROJ_SRC_DIR)/$*.cpp
1354
1355 # IFF the .l file has changed since it was last checked into SVN, copy the .l
1356 # file to .l.cvs and the generated .cpp file to .cpp.cvs.  We use this mechanism
1357 # so that people without flex can build LLVM by copying the .cvs files to the 
1358 # source location and building them.
1359 $(LexFiles:%.l=$(PROJ_SRC_DIR)/%.cpp.cvs): \
1360 $(PROJ_SRC_DIR)/%.cpp.cvs: $(PROJ_SRC_DIR)/%.cpp
1361         $(Verb) $(CMP) -s $(PROJ_SRC_DIR)/$*.l $(PROJ_SRC_DIR)/$*.l.cvs || \
1362       ($(CP) $< $@; $(CP) $(PROJ_SRC_DIR)/$*.l $(PROJ_SRC_DIR)/$*.l.cvs)
1363
1364 $(LexFiles:%.l=$(ObjDir)/%.o) : \
1365 $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
1366
1367 clean-local::
1368         -$(Verb) $(RM) -f $(LexOutput)
1369
1370 endif
1371
1372 #---------------------------------------------------------
1373 # Provide rules for generating a .cpp and .h source files 
1374 # from yacc (bison) input sources.
1375 #---------------------------------------------------------
1376
1377 YaccFiles  := $(filter %.y,$(Sources))
1378 ifneq ($(YaccFiles),)
1379
1380 .PRECIOUS: $(YaccOutput)
1381
1382 all:: $(YaccFiles:%.y=$(PROJ_SRC_DIR)/%.cpp.cvs)
1383
1384 # Cancel built-in rules for yacc
1385 %.c: %.y 
1386 %.cpp: %.y
1387 %.h: %.y
1388
1389 # Rule for building the bison based parsers...
1390 ifneq ($(BISON),)
1391 $(PROJ_SRC_DIR)/%.cpp $(PROJ_SRC_DIR)/%.h : $(PROJ_SRC_DIR)/%.y
1392         $(Echo) "Bisoning $*.y"
1393         $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
1394         $(Verb) $(MV) -f $*.tab.c $(PROJ_SRC_DIR)/$*.cpp
1395         $(Verb) $(MV) -f $*.tab.h $(PROJ_SRC_DIR)/$*.h
1396
1397 # IFF the .y file has changed since it was last checked into SVN, copy the .y
1398 # file to .y.cvs and the generated .cpp/.h file to .cpp.cvs/.h.cvs.  We use this
1399 # mechanism so that people without flex can build LLVM by copying the .cvs files
1400 # to the source location and building them.
1401 $(YaccFiles:%.y=$(PROJ_SRC_DIR)/%.cpp.cvs): \
1402 $(PROJ_SRC_DIR)/%.cpp.cvs: $(PROJ_SRC_DIR)/%.cpp
1403         $(Verb) $(CMP) -s $(PROJ_SRC_DIR)/$*.y $(PROJ_SRC_DIR)/$*.y.cvs || \
1404       ($(CP) $< $@; \
1405        $(CP) $(PROJ_SRC_DIR)/$*.y $(PROJ_SRC_DIR)/$*.y.cvs; \
1406        $(CP) $(PROJ_SRC_DIR)/$*.h $(PROJ_SRC_DIR)/$*.h.cvs)
1407
1408 else
1409 $(PROJ_SRC_DIR)/%.cpp : $(PROJ_SRC_DIR)/%.cpp.cvs
1410         $(Echo) "Bison of $*.y SKIPPED, bison not found -- copying .cpp.cvs"
1411         $(Verb)$(CP) $(PROJ_SRC_DIR)/$*.cpp.cvs $(PROJ_SRC_DIR)/$*.cpp
1412
1413 $(PROJ_SRC_DIR)/%.h : $(PROJ_SRC_DIR)/%.h.cvs
1414         $(Echo) "Bison of $*.y SKIPPED, bison not found -- copying .h.cvs"
1415         $(Verb)$(CP) $(PROJ_SRC_DIR)/$*.h.cvs $(PROJ_SRC_DIR)/$*.h
1416 endif
1417
1418
1419 $(YaccFiles:%.y=$(ObjDir)/%.o): $(ObjDir)/%.o : $(PROJ_SRC_DIR)/%.cpp
1420
1421 YaccOutput := $(YaccFiles:%.y=%.output)
1422
1423 clean-local::
1424         -$(Verb) $(RM) -f $(YaccOutput)
1425 endif
1426
1427 ###############################################################################
1428 # OTHER RULES: Other rules needed
1429 ###############################################################################
1430
1431 # To create postscript files from dot files...
1432 ifneq ($(DOT),false)
1433 %.ps: %.dot
1434         $(DOT) -Tps < $< > $@
1435 else
1436 %.ps: %.dot
1437         $(Echo) "Cannot build $@: The program dot is not installed"
1438 endif
1439
1440 # This rules ensures that header files that are removed still have a rule for
1441 # which they can be "generated."  This allows make to ignore them and
1442 # reproduce the dependency lists.
1443 %.h:: ;
1444 %.hpp:: ;
1445
1446 # Define clean-local to clean the current directory. Note that this uses a
1447 # very conservative approach ensuring that empty variables do not cause 
1448 # errors or disastrous removal.
1449 clean-local::
1450 ifneq ($(strip $(ObjDir)),)
1451         -$(Verb) $(RM) -rf $(ObjDir)
1452 endif
1453         -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1454 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1455         -$(Verb) $(RM) -f *$(SHLIBEXT)
1456 endif
1457
1458 clean-all-local::
1459         -$(Verb) $(RM) -rf Debug Release Profile
1460
1461
1462 ###############################################################################
1463 # DEPENDENCIES: Include the dependency files if we should
1464 ###############################################################################
1465 ifndef DISABLE_AUTO_DEPENDENCIES
1466
1467 # If its not one of the cleaning targets
1468 ifneq ($(strip $(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
1469
1470 # Get the list of dependency files
1471 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1472 DependFiles := $(DependFiles:%=$(PROJ_OBJ_DIR)/$(BuildMode)/%.d)
1473
1474 -include $(DependFiles) ""
1475
1476 endif
1477
1478 endif 
1479
1480 ###############################################################################
1481 # CHECK: Running the test suite
1482 ###############################################################################
1483
1484 check::
1485         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/test" ; then \
1486           if test -f "$(PROJ_OBJ_ROOT)/test/Makefile" ; then \
1487             $(EchoCmd) Running test suite ; \
1488             $(MAKE) -C $(PROJ_OBJ_ROOT)/test check-local \
1489               TESTSUITE=$(TESTSUITE) ; \
1490           else \
1491             $(EchoCmd) No Makefile in test directory ; \
1492           fi ; \
1493         else \
1494           $(EchoCmd) No test directory ; \
1495         fi
1496
1497 ###############################################################################
1498 # DISTRIBUTION: Handle construction of a distribution tarball
1499 ###############################################################################
1500
1501 #------------------------------------------------------------------------
1502 # Define distribution related variables
1503 #------------------------------------------------------------------------
1504 DistName    := $(PROJECT_NAME)-$(PROJ_VERSION)
1505 DistDir     := $(PROJ_OBJ_ROOT)/$(DistName)
1506 TopDistDir  := $(PROJ_OBJ_ROOT)/$(DistName)
1507 DistTarGZip := $(PROJ_OBJ_ROOT)/$(DistName).tar.gz
1508 DistZip     := $(PROJ_OBJ_ROOT)/$(DistName).zip
1509 DistTarBZ2  := $(PROJ_OBJ_ROOT)/$(DistName).tar.bz2
1510 DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1511                ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1512                Makefile.config.in configure autoconf
1513 DistOther   := $(notdir $(wildcard \
1514                $(PROJ_SRC_DIR)/*.h \
1515                $(PROJ_SRC_DIR)/*.td \
1516                $(PROJ_SRC_DIR)/*.def \
1517                $(PROJ_SRC_DIR)/*.ll \
1518                $(PROJ_SRC_DIR)/*.in))
1519 DistSubDirs := $(SubDirs)
1520 DistSources  = $(Sources) $(EXTRA_DIST)
1521 DistFiles    = $(DistAlways) $(DistSources) $(DistOther)
1522
1523 #------------------------------------------------------------------------
1524 # We MUST build distribution with OBJ_DIR != SRC_DIR
1525 #------------------------------------------------------------------------
1526 ifeq ($(PROJ_SRC_DIR),$(PROJ_OBJ_DIR))
1527 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1528         $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1529
1530 else
1531
1532 #------------------------------------------------------------------------
1533 # Prevent attempt to run dist targets from anywhere but the top level
1534 #------------------------------------------------------------------------
1535 ifneq ($(LEVEL),.)
1536 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1537         $(Echo) ERROR: You must run $@ from $(PROJ_OBJ_ROOT)
1538 else
1539
1540 #------------------------------------------------------------------------
1541 # Provide the top level targets
1542 #------------------------------------------------------------------------
1543
1544 dist-gzip:: $(DistTarGZip)
1545
1546 $(DistTarGZip) : $(TopDistDir)/.makedistdir
1547         $(Echo) Packing gzipped distribution tar file.
1548         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1549           $(GZIP) -c > "$(DistTarGZip)"
1550
1551 dist-bzip2:: $(DistTarBZ2)
1552
1553 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
1554         $(Echo) Packing bzipped distribution tar file.
1555         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1556           $(BZIP2) -c >$(DistTarBZ2)
1557
1558 dist-zip:: $(DistZip)
1559
1560 $(DistZip) : $(TopDistDir)/.makedistdir
1561         $(Echo) Packing zipped distribution file.
1562         $(Verb) rm -f $(DistZip)
1563         $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1564
1565 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip) 
1566         $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1567
1568 DistCheckDir := $(PROJ_OBJ_ROOT)/_distcheckdir
1569
1570 dist-check:: $(DistTarGZip)
1571         $(Echo) Checking distribution tar file.
1572         $(Verb) if test -d $(DistCheckDir) ; then \
1573           $(RM) -rf $(DistCheckDir) ; \
1574         fi
1575         $(Verb) $(MKDIR) $(DistCheckDir)
1576         $(Verb) cd $(DistCheckDir) && \
1577           $(MKDIR) $(DistCheckDir)/build && \
1578           $(MKDIR) $(DistCheckDir)/install && \
1579           gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1580           cd build && \
1581           ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1582             --srcdir=../$(DistName) $(DIST_CHECK_CONFIG_OPTIONS) && \
1583           $(MAKE) all && \
1584           $(MAKE) check && \
1585           $(MAKE) install && \
1586           $(MAKE) uninstall && \
1587           $(MAKE) dist-clean && \
1588           $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1589
1590 dist-clean::
1591         $(Echo) Cleaning distribution files
1592         -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1593           $(DistCheckDir)
1594
1595 endif
1596
1597 #------------------------------------------------------------------------
1598 # Provide the recursive distdir target for building the distribution directory
1599 #------------------------------------------------------------------------
1600 distdir: $(DistDir)/.makedistdir
1601 $(DistDir)/.makedistdir: $(DistSources)
1602         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1603           if test -d "$(DistDir)" ; then \
1604             find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
1605               exit 1 ; \
1606           fi ; \
1607           $(EchoCmd) Removing old $(DistDir) ; \
1608           $(RM) -rf $(DistDir); \
1609           $(EchoCmd) Making 'all' to verify build ; \
1610           $(MAKE) ENABLE_OPTIMIZED=1 all ; \
1611         fi
1612         $(Echo) Building Distribution Directory $(DistDir)
1613         $(Verb) $(MKDIR) $(DistDir) 
1614         $(Verb) srcdirstrip=`echo "$(PROJ_SRC_DIR)" | sed 's|.|.|g'`; \
1615         srcrootstrip=`echo "$(PROJ_SRC_ROOT)" | sed 's|.|.|g'`; \
1616         for file in $(DistFiles) ; do \
1617           case "$$file" in \
1618             $(PROJ_SRC_DIR)/*) \
1619               file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1620               ;; \
1621             $(PROJ_SRC_ROOT)/*) \
1622               file=`echo "$$file" | \
1623                 sed "s#^$$srcrootstrip/##"` \
1624               ;; \
1625           esac; \
1626           if test -f "$(PROJ_SRC_DIR)/$$file" || \
1627              test -d "$(PROJ_SRC_DIR)/$$file" ; then \
1628             from_dir="$(PROJ_SRC_DIR)" ; \
1629           elif test -f "$$file" || test -d "$$file" ; then \
1630             from_dir=. ; \
1631           fi ; \
1632           to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1633           if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1634             to_dir="$(DistDir)/$$dir"; \
1635             $(MKDIR) "$$to_dir" ; \
1636           else \
1637             to_dir="$(DistDir)"; \
1638           fi; \
1639           mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1640           if test -n "$$mid_dir" ; then \
1641             $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1642           fi ; \
1643           if test -d "$$from_dir/$$file"; then \
1644             if test -d "$(PROJ_SRC_DIR)/$$file" && \
1645                test "$$from_dir" != "$(PROJ_SRC_DIR)" ; then \
1646                cd $(PROJ_SRC_DIR) ; \
1647                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1648                  ( cd $$to_dir ; $(TAR) xf - ) ; \
1649                cd $(PROJ_OBJ_DIR) ; \
1650             else \
1651                cd $$from_dir ; \
1652                $(TAR) cf - $$file --exclude .svn --exclude CVS | \
1653                  ( cd $$to_dir ; $(TAR) xf - ) ; \
1654                cd $(PROJ_OBJ_DIR) ; \
1655             fi; \
1656           elif test -f "$$from_dir/$$file" ; then \
1657             $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1658           elif test -L "$$from_dir/$$file" ; then \
1659             $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1660           elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1661             $(EchoCmd) "===== WARNING: Distribution Source " \
1662               "$$from_dir/$$file Not Found!" ; \
1663           elif test "$(Verb)" != '@' ; then \
1664             $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1665           fi; \
1666         done
1667         $(Verb) for subdir in $(DistSubDirs) ; do \
1668           if test "$$subdir" \!= "." ; then \
1669             new_distdir="$(DistDir)/$$subdir" ; \
1670             test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1671             ( cd $$subdir && $(MAKE) ENABLE_OPTIMIZED=1 \
1672               DistDir="$$new_distdir" distdir ) || exit 1; \
1673           fi; \
1674         done
1675         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1676           $(EchoCmd) Eliminating CVS/.svn directories from distribution ; \
1677           $(RM) -rf `find $(TopDistDir) -type d \( -name CVS -o \
1678                                   -name .svn \) -print` ;\
1679           $(MAKE) dist-hook ; \
1680           $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1681             -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1682             -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1683             -o ! -type d ! -perm -444 -exec \
1684               $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1685             || chmod -R a+r $(DistDir) ; \
1686         fi
1687
1688 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1689 # defined by user.
1690 dist-hook::
1691
1692 endif
1693
1694 ###############################################################################
1695 # TOP LEVEL - targets only to apply at the top level directory
1696 ###############################################################################
1697
1698 ifeq ($(LEVEL),.)
1699
1700 #------------------------------------------------------------------------
1701 # Install support for the project's include files:
1702 #------------------------------------------------------------------------
1703 ifdef NO_INSTALL
1704 install-local::
1705         $(Echo) Install circumvented with NO_INSTALL
1706 uninstall-local::
1707         $(Echo) Uninstall circumvented with NO_INSTALL
1708 else
1709 install-local::
1710         $(Echo) Installing include files
1711         $(Verb) $(MKDIR) $(PROJ_includedir)
1712         $(Verb) if test -d "$(PROJ_SRC_ROOT)/include" ; then \
1713           cd $(PROJ_SRC_ROOT)/include && \
1714           for  hdr in `find . -type f '!' '(' -name '*~' -o -name '.cvsignore' \
1715               -o -name '.#*' -o -name '*.in' ')' -print | grep -v CVS | \
1716               grep -v .svn` ; do \
1717             instdir=`dirname "$(PROJ_includedir)/$$hdr"` ; \
1718             if test \! -d "$$instdir" ; then \
1719               $(EchoCmd) Making install directory $$instdir ; \
1720               $(MKDIR) $$instdir ;\
1721             fi ; \
1722             $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1723           done ; \
1724         fi
1725 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
1726         $(Verb) if test -d "$(PROJ_OBJ_ROOT)/include" ; then \
1727           cd $(PROJ_OBJ_ROOT)/include && \
1728           for hdr in `find . -type f -print | grep -v CVS` ; do \
1729             $(DataInstall) $$hdr $(PROJ_includedir)/$$hdr ; \
1730           done ; \
1731         fi
1732 endif
1733
1734 uninstall-local::
1735         $(Echo) Uninstalling include files
1736         $(Verb) if [ -d "$(PROJ_SRC_ROOT)/include" ] ; then \
1737           cd $(PROJ_SRC_ROOT)/include && \
1738             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1739               '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' \
1740         -o -name '*.in' ')' -print ')' | \
1741         grep -v CVS | sed 's#^#$(PROJ_includedir)/#'` ; \
1742           cd $(PROJ_SRC_ROOT)/include && \
1743             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f -name '*.in' \
1744       -print ')' | sed 's#\.in$$##;s#^#$(PROJ_includedir)/#'` ; \
1745         fi
1746 endif
1747 endif
1748
1749 check-line-length:
1750         @echo searching for overlength lines in files: $(Sources)
1751         @echo
1752         @echo
1753         @egrep -n '.{81}' $(Sources) /dev/null
1754
1755 check-for-tabs:
1756         @echo searching for tabs in files: $(Sources)
1757         @echo
1758         @echo
1759         @egrep -n '     ' $(Sources) /dev/null
1760
1761 check-footprint:
1762         @ls -l $(LibDir) | awk '\
1763           BEGIN { sum = 0; } \
1764                 { sum += $$5; } \
1765           END   { printf("Libraries: %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
1766         @ls -l $(ToolDir) | awk '\
1767           BEGIN { sum = 0; } \
1768                 { sum += $$5; } \
1769           END   { printf("Programs:  %6.3f MBytes\n", sum/(1024.0*1024.0)); }'
1770 #------------------------------------------------------------------------
1771 # Print out the directories used for building
1772 #------------------------------------------------------------------------
1773 printvars::
1774         $(Echo) "BuildMode    : " '$(BuildMode)'
1775         $(Echo) "PROJ_SRC_ROOT: " '$(PROJ_SRC_ROOT)'
1776         $(Echo) "PROJ_SRC_DIR : " '$(PROJ_SRC_DIR)'
1777         $(Echo) "PROJ_OBJ_ROOT: " '$(PROJ_OBJ_ROOT)'
1778         $(Echo) "PROJ_OBJ_DIR : " '$(PROJ_OBJ_DIR)'
1779         $(Echo) "LLVM_SRC_ROOT: " '$(LLVM_SRC_ROOT)'
1780         $(Echo) "LLVM_OBJ_ROOT: " '$(LLVM_OBJ_ROOT)'
1781         $(Echo) "PROJ_prefix  : " '$(PROJ_prefix)'
1782         $(Echo) "PROJ_bindir  : " '$(PROJ_bindir)'
1783         $(Echo) "PROJ_libdir  : " '$(PROJ_libdir)'
1784         $(Echo) "PROJ_etcdir  : " '$(PROJ_etcdir)'
1785         $(Echo) "PROJ_includedir  : " '$(PROJ_includedir)'
1786         $(Echo) "UserTargets  : " '$(UserTargets)'
1787         $(Echo) "ObjMakefiles : " '$(ObjMakefiles)'
1788         $(Echo) "SrcMakefiles : " '$(SrcMakefiles)'
1789         $(Echo) "ObjDir       : " '$(ObjDir)'
1790         $(Echo) "LibDir       : " '$(LibDir)'
1791         $(Echo) "ToolDir      : " '$(ToolDir)'
1792         $(Echo) "ExmplDir     : " '$(ExmplDir)'
1793         $(Echo) "Sources      : " '$(Sources)'
1794         $(Echo) "TDFiles      : " '$(TDFiles)'
1795         $(Echo) "INCFiles     : " '$(INCFiles)'
1796         $(Echo) "INCTMPFiles  : " '$(INCTMPFiles)'
1797         $(Echo) "PreConditions: " '$(PreConditions)'
1798         $(Echo) "Compile.CXX  : " '$(Compile.CXX)'
1799         $(Echo) "Compile.C    : " '$(Compile.C)'
1800         $(Echo) "Archive      : " '$(Archive)'
1801         $(Echo) "YaccFiles    : " '$(YaccFiles)'
1802         $(Echo) "LexFiles     : " '$(LexFiles)'
1803         $(Echo) "Module       : " '$(Module)'
1804         $(Echo) "FilesToConfig: " '$(FilesToConfigPATH)'
1805         $(Echo) "SubDirs      : " '$(SubDirs)'
1806         $(Echo) "ProjLibsPaths: " '$(ProjLibsPaths)'
1807         $(Echo) "ProjLibsOptions: " '$(ProjLibsOptions)'