Avoid use of -fomit-frame-pointer on FreeBSD platforms. It causes thrown
[oota-llvm.git] / Makefile.rules
1 #===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
2 #
3 #                     The LLVM Compiler Infrastructure
4 #
5 # This file was developed by the LLVM research group and is distributed under
6 # the University of Illinois Open Source 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 tags 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=$(BUILD_SRC_DIR)
39
40 #--------------------------------------------------------------------
41 # Reset the list of suffixes we know how to build
42 #--------------------------------------------------------------------
43 .SUFFIXES:
44 .SUFFIXES: .c .cpp .h .hpp .y .l .lo .o .a .bc .td .ps .dot 
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 $(BUILD_SRC_DIR)/Makefile*))
65 ObjMakefiles       := $(subst $(BUILD_SRC_DIR),$(BUILD_OBJ_DIR),$(SrcMakefiles))
66 ConfigureScript    := $(BUILD_SRC_ROOT)/configure
67 ConfigStatusScript := $(BUILD_OBJ_ROOT)/config.status
68 LConfigStatusScript:= $(LLVM_OBJ_ROOT)/config.status
69 MakefileConfigIn   := $(LLVM_SRC_ROOT)/Makefile.config.in
70 MakefileConfig     := $(LLVM_OBJ_ROOT)/Makefile.config
71 PreConditions      := $(ConfigStatusScript) $(MakefileConfig) $(ObjMakefiles)
72
73 preconditions : $(PreConditions)
74
75 #------------------------------------------------------------------------
76 # Make sure the BUILT_SOURCES are built first
77 #------------------------------------------------------------------------
78 $(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
79
80 clean-local::
81 ifneq ($(strip $(BUILT_SOURCES)),)
82         -$(Verb) $(RM) -f $(BUILT_SOURCES)
83 endif
84
85 ifneq ($(BUILD_OBJ_ROOT),$(BUILD_SRC_ROOT))
86 spotless:
87         $(Verb) if test -x config.status ; then \
88           $(EchoCmd) Wiping out $(BUILD_OBJ_ROOT) ; \
89           $(MKDIR) .spotless.save ; \
90           $(MV) config.status .spotless.save ; \
91           $(MV) mklib  .spotless.save ; \
92           $(MV) projects  .spotless.save ; \
93           $(RM) -rf * ; \
94           $(MV) .spotless.save/config.status . ; \
95           $(MV) .spotless.save/mklib . ; \
96           $(MV) .spotless.save/projects . ; \
97           $(RM) -rf .spotless.save ; \
98           $(EchoCmd) Rebuilding configuration of $(BUILD_OBJ_ROOT) ; \
99           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
100           $(ConfigStatusScript) ; \
101         else \
102           $(EchoCmd) "make spotless" can only be run from $(BUILD_OBJ_ROOT); \
103         fi
104 endif
105
106 $(BUILT_SOURCES) : $(ObjMakefiles)
107
108 #------------------------------------------------------------------------
109 # Make sure we're not using a stale configuration
110 #------------------------------------------------------------------------
111 reconfigure:
112         $(Echo) Reconfiguring $(BUILD_OBJ_ROOT)
113         $(Verb) cd $(BUILD_OBJ_ROOT) && \
114           if test -w $(BUILD_OBJ_ROOT)/config.cache ; then \
115             $(RM) $(BUILD_OBJ_ROOT)/config.cache ; \
116           fi ; \
117           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
118           $(ConfigStatusScript)
119
120 .PRECIOUS: $(ConfigStatusScript)
121 $(ConfigStatusScript): $(ConfigureScript)
122         $(Echo) Reconfiguring with $<
123         $(Verb) cd $(BUILD_OBJ_ROOT) && \
124           if test -w $(BUILD_OBJ_ROOT)/config.cache ; then \
125             $(RM) $(BUILD_OBJ_ROOT)/config.cache ; \
126           fi ; \
127           $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
128           $(ConfigStatusScript)
129
130 #------------------------------------------------------------------------
131 # Make sure the configuration makefile is up to date
132 #------------------------------------------------------------------------
133 $(MakefileConfig): $(MakefileConfigIn) $(LConfigStatusScript)
134         $(Echo) Regenerating $@
135         $(Verb) cd $(LLVM_OBJ_ROOT) ; $(LConfigStatusScript) Makefile.config
136
137 #------------------------------------------------------------------------
138 # If the Makefile in the source tree has been updated, copy it over into the
139 # build tree. But, only do this if the source and object makefiles differ
140 #------------------------------------------------------------------------
141 ifneq ($(BUILD_OBJ_DIR),$(BUILD_SRC_DIR))
142
143 Makefile: $(BUILD_SRC_DIR)/Makefile
144         $(Echo) "Updating Makefile"
145         $(Verb) $(MKDIR) $(@D)
146         $(Verb) $(CP) -f $< $@
147
148 # Copy the Makefile.* files unless we're in the root directory which avoids
149 # the copying of Makefile.config.in or other things that should be explicitly
150 # taken care of.
151 $(BUILD_OBJ_DIR)/Makefile% : $(BUILD_SRC_DIR)/Makefile%
152         @case '$?' in \
153           *Makefile.rules) ;; \
154           *.in) ;; \
155           *) $(Echo) "Updating $(@F)" ; \
156              $(MKDIR) $(@D) ; \
157              $(CP) -f $< $@ ;; \
158         esac
159          
160 endif
161
162 #------------------------------------------------------------------------
163 # Set up the basic dependencies
164 #------------------------------------------------------------------------
165 $(UserTargets):: $(PreConditions)
166
167 all:: all-local
168 clean:: clean-local 
169 clean-all:: clean-local clean-all-local
170 install:: install-local
171 uninstall:: uninstall-local
172 install-local:: all-local 
173 install-bytecode:: install-bytecode-local
174
175 ###############################################################################
176 # VARIABLES: Set up various variables based on configuration data
177 ###############################################################################
178
179 #--------------------------------------------------------------------
180 # Variables derived from configuration we are building
181 #--------------------------------------------------------------------
182
183
184 ifdef ENABLE_PROFILING
185   BuildMode := Profile
186   CXX.Flags := -O3 -DNDEBUG -felide-constructors -finline-functions -pg
187   C.Flags   := -O3 -DNDEBUG -pg
188   LD.Flags  := -O3 -DNDEBUG -pg 
189 else
190   ifdef ENABLE_OPTIMIZED
191     BuildMode := Release
192     # Don't use -fomit-frame-pointer on FreeBSD
193     ifneq ($(OS),FreeBSD)
194       OmitFramePointer := -fomit-frame-pointer
195     endif
196     CXX.Flags  := -O3 -DNDEBUG -finline-functions -felide-constructors \
197                   $(OmitFramePointer)
198     C.Flags    := -O3 -DNDEBUG $(OmitFramePointer)
199     LD.Flags   := -O3 -DNDEBUG 
200   else
201     BuildMode := Debug
202     CXX.Flags := -g -D_DEBUG
203     C.Flags   := -g -D_DEBUG
204     LD.Flags  := -g -D_DEBUG 
205     KEEP_SYMBOLS := 1
206   endif
207 endif
208
209 CXX.Flags += $(CXXFLAGS)
210 C.Flags   += $(CFLAGS)
211 CPP.Flags += $(CPPFLAGS)
212 LD.Flags  += $(LDFLAGS)
213 AR.Flags  := cru
214 LibTool.Flags := --tag=CXX
215
216 #--------------------------------------------------------------------
217 # Directory locations
218 #--------------------------------------------------------------------
219 ObjDir      := $(BUILD_OBJ_DIR)/$(BuildMode)
220 LibDir      := $(BUILD_OBJ_ROOT)/$(BuildMode)/lib
221 ToolDir     := $(BUILD_OBJ_ROOT)/$(BuildMode)/bin
222 ExmplDir    := $(BUILD_OBJ_ROOT)/$(BuildMode)/examples
223 LLVMLibDir  := $(LLVM_OBJ_ROOT)/$(BuildMode)/lib
224 LLVMToolDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
225 LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(BuildMode)/examples
226 CFERuntimeLibDir := $(LLVMGCCDIR)/lib
227
228 #--------------------------------------------------------------------
229 # Full Paths To Compiled Tools and Utilities
230 #--------------------------------------------------------------------
231 EchoCmd  := $(ECHO) llvm[$(MAKELEVEL)]:
232 Echo     := @$(EchoCmd)
233 ifndef LIBTOOL
234 LIBTOOL  := $(LLVM_OBJ_ROOT)/mklib
235 endif
236 ifndef LLVMAS
237 LLVMAS   := $(LLVMToolDir)/llvm-as$(EXEEXT)
238 endif
239 ifndef BURG
240 BURG     := $(LLVMToolDir)/burg$(EXEEXT)
241 endif
242 ifndef TBLGEN
243 TBLGEN   := $(LLVMToolDir)/tblgen$(EXEEXT)
244 endif
245 ifndef GCCAS
246 GCCAS    := $(LLVMToolDir)/gccas$(EXEEXT)
247 endif
248 ifndef GCCLD
249 GCCLD    := $(LLVMToolDir)/gccld$(EXEEXT)
250 endif
251 ifndef LDIS
252 LLVMDIS  := $(LLVMToolDir)/llvm-dis$(EXEEXT)
253 endif
254 ifndef LLI
255 LLI      := $(LLVMToolDir)/lli$(EXEEXT)
256 endif
257 ifndef LOPT
258 LOPT     := $(LLVMToolDir)/opt$(EXEEXT)
259 endif
260 LLVMGCCWITHPATH  := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGCC)
261 LLVMGXXWITHPATH  := PATH="$(LLVMToolDir):$(PATH)" $(LLVMGXX)
262
263 #--------------------------------------------------------------------
264 # Adjust to user's request
265 #--------------------------------------------------------------------
266
267 # Adjust LIBTOOL flags for shared libraries, or not.
268 ifndef SHARED_LIBRARY
269   LibTool.Flags += --tag=disable-shared
270 else
271   LD.Flags += -rpath $(LibDir)
272 endif
273
274 ifdef TOOL_VERBOSE
275   C.Flags += -v
276   CXX.Flags += -v
277   LD.Flags += -v
278   VERBOSE := 1
279 endif
280
281 # Adjust settings for verbose mode
282 ifndef VERBOSE
283   Verb := @
284   LibTool.Flags += --silent
285   AR.Flags += >/dev/null 2>/dev/null
286   ConfigureScriptFLAGS += >$(BUILD_OBJ_DIR)/configure.out 2>&1
287 else
288   ConfigureScriptFLAGS := 
289 endif
290
291 # By default, strip symbol information from executable
292 ifndef KEEP_SYMBOLS
293   Strip := $(PLATFORMSTRIPOPTS)
294   StripWarnMsg := "(without symbols)"
295 endif
296
297 # Adjust linker flags for building an executable
298 ifdef TOOLNAME
299 ifdef EXAMPLE_TOOL
300   LD.Flags += -rpath $(ExmplDir) -export-dynamic
301 else
302   LD.Flags += -rpath $(ToolDir) -export-dynamic
303 endif
304 endif
305
306 #----------------------------------------------------------
307 # Options To Invoke Tools
308 #----------------------------------------------------------
309
310 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
311
312 LD.Flags  += -L$(LibDir) -L$(LLVMLibDir)
313 CPP.Flags += -I$(BUILD_OBJ_DIR) \
314             -I$(BUILD_SRC_DIR) \
315             -I$(BUILD_SRC_ROOT)/include \
316             -I$(BUILD_OBJ_ROOT)/include \
317             -I$(LLVM_OBJ_ROOT)/include \
318             -I$(LLVM_SRC_ROOT)/include \
319             -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
320
321 Compile.C     = $(CC) $(CPP.Flags) $(CompileCommonOpts) -c $(C.Flags)
322 LTCompile.C   = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.C)
323 BCCompile.C   = $(LLVMGCCWITHPATH) $(CPP.Flags) $(CompileCommonOpts) \
324                 $(C.Flags) -c
325 Compile.CXX   = $(CXX) $(CPP.Flags) $(CompileCommonOpts) $(CXX.Flags) -c
326 LTCompile.CXX = $(LIBTOOL) $(LibTool.Flags) --mode=compile $(Compile.CXX)
327 BCCompile.CXX = $(LLVMGXXWITHPATH) $(CPP.Flags) $(CompileCommonOpts) \
328                 $(CXX.Flags) -c
329 Link          = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
330                 $(CompileCommonOpts) $(LD.Flags) $(Strip)
331 Relink        = $(LIBTOOL) $(LibTool.Flags) --mode=link $(CXX) $(CPP.Flags) \
332                 $(CompileCommonOpts)
333 LTInstall     = $(LIBTOOL) $(LibTool.Flags) --mode=install $(INSTALL)
334 Burg          = $(BURG) -I $(BUILD_SRC_DIR)
335 TableGen      = $(TBLGEN) -I $(BUILD_SRC_DIR)
336 Archive       = $(AR) $(AR.Flags)
337 LArchive      = $(LLVMToolDir)/llvm-ar rcsf
338 ifdef RANLIB
339 Ranlib        = $(RANLIB)
340 else
341 Ranlib        = ranlib
342 endif
343
344 #----------------------------------------------------------
345 # Get the list of source files and compute object file 
346 # names from them. 
347 #----------------------------------------------------------
348 ifdef FAKE_SOURCES
349   Sources :=
350   FakeSources := $(FAKE_SOURCES)
351   ifdef BUILT_SOURCES
352   FakeSources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
353   endif
354   BaseNameSources := $(sort $(basename $(FakeSources)))
355   ObjectsO  := $(BaseNameSources:%=$(ObjDir)/%.o)
356   ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
357   ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
358 else
359   ifndef SOURCES
360     Sources := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
361                $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
362                $(BUILD_SRC_DIR)/*.l))
363   else
364     Sources := $(SOURCES)
365   endif 
366
367   ifdef BUILT_SOURCES
368   Sources += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
369   endif
370
371   BaseNameSources := $(sort $(basename $(Sources)))
372   ObjectsO  := $(BaseNameSources:%=$(ObjDir)/%.o)
373   ObjectsLO := $(BaseNameSources:%=$(ObjDir)/%.lo)
374   ObjectsBC := $(BaseNameSources:%=$(ObjDir)/%.bc)
375 endif
376
377 ###############################################################################
378 # DIRECTORIES: Handle recursive descent of directory structure
379 ###############################################################################
380
381 #---------------------------------------------------------
382 # Provide rules to make install dirs. This must be early
383 # in the file so they get built before dependencies
384 #---------------------------------------------------------
385
386 $(bindir):
387         $(Verb) $(MKDIR) $(bindir)
388
389 $(libdir):
390         $(Verb) $(MKDIR) $(libdir)
391
392 $(includedir):
393         $(Verb) $(MKDIR) $(includedir)
394
395 $(sysconfdir):
396         $(Verb) $(MKDIR) $(sysconfdir)
397
398 # To create other directories, as needed, and timestamp their creation
399 %/.dir:
400         $(Verb) $(MKDIR) $* > /dev/null
401         $(Verb) $(DATE) > $@
402
403 .PRECIOUS: $(ObjDir)/.dir $(LibDir)/.dir $(ToolDir)/.dir $(ExmplDir)/.dir
404 .PRECIOUS: $(LLVMLibDir)/.dir $(LLVMToolDir)/.dir $(LLVMExmplDir)/.dir
405
406 #---------------------------------------------------------
407 # Handle the DIRS options for sequential construction
408 #---------------------------------------------------------
409
410 SubDirs := 
411 ifdef DIRS
412 SubDirs += $(DIRS)
413 $(RecursiveTargets)::
414         $(Verb) for dir in $(DIRS); do \
415           if [ ! -f $$dir/Makefile ]; then \
416             $(MKDIR) $$dir; \
417             $(CP) $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
418           fi; \
419           if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
420             ($(MAKE) -C $$dir $@ ) || exit 1; \
421           fi ; \
422         done
423 endif
424
425 #---------------------------------------------------------
426 # Handle the EXPERIMENTAL_DIRS options ensuring success
427 # after each directory is built.
428 #---------------------------------------------------------
429 ifdef EXPERIMENTAL_DIRS
430 $(RecursiveTargets)::
431         $(Verb) for dir in $(EXPERIMENTAL_DIRS); do \
432           if [ ! -f $$dir/Makefile ]; then \
433             $(MKDIR) $$dir; \
434             $(CP) $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
435           fi; \
436           if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
437             ($(MAKE) -C $$dir $@ ) || exit 0; \
438           fi ; \
439         done
440 endif
441
442 #---------------------------------------------------------
443 # Handle the PARALLEL_DIRS options for parallel construction
444 #---------------------------------------------------------
445 ifdef PARALLEL_DIRS
446
447 SubDirs += $(PARALLEL_DIRS)
448
449 # Unfortunately, this list must be maintained if new recursive targets are added
450 all      :: $(addsuffix /.makeall      ,$(PARALLEL_DIRS))
451 clean    :: $(addsuffix /.makeclean    ,$(PARALLEL_DIRS))
452 clean-all:: $(addsuffix /.makeclean-all,$(PARALLEL_DIRS))
453 install  :: $(addsuffix /.makeinstall  ,$(PARALLEL_DIRS))
454 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
455 install-bytecode  :: $(addsuffix /.makeinstall-bytecode,$(PARALLEL_DIRS))
456
457 ParallelTargets := $(foreach T,$(RecursiveTargets),%/.make$(T))
458
459 $(ParallelTargets) :
460         $(Verb) if [ ! -f $(@D)/Makefile ]; then \
461           $(MKDIR) $(@D); \
462           $(CP) $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
463         fi; \
464         if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
465           $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) ; \
466         fi
467 endif
468
469 #---------------------------------------------------------
470 # Handle the OPTIONAL_DIRS options for directores that may
471 # or may not exist.
472 #---------------------------------------------------------
473 ifdef OPTIONAL_DIRS
474
475 SubDirs += $(OPTIONAL_DIRS)
476
477 $(RecursiveTargets)::
478         $(Verb) for dir in $(OPTIONAL_DIRS); do \
479           if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
480             if [ ! -f $$dir/Makefile ]; then \
481               $(MKDIR) $$dir; \
482               $(CP) $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
483             fi; \
484             if [ ! -f $$dir/LLVM_DO_NOT_BUILD ]; then \
485               ($(MAKE) -C$$dir $@ ) || exit 1; \
486             fi ; \
487           fi \
488         done
489 endif
490
491 #---------------------------------------------------------
492 # Handle the CONFIG_FILES options
493 #---------------------------------------------------------
494 ifdef CONFIG_FILES
495
496 install-local:: $(sysconfdir) $(CONFIG_FILES)
497         $(Echo) Installing Configuration Files To $(sysconfdir)
498         $(Verb)for file in $(CONFIG_FILES); do \
499           if test -f $(BUILD_OBJ_DIR)/$${file} ; then \
500             $(INSTALL) $(BUILD_OBJ_DIR)/$${file} $(sysconfdir) ; \
501           elif test -f $(BUILD_SRC_DIR)/$${file} ; then \
502             $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
503           else \
504             $(ECHO) Error: cannot find config file $${file}. ; \
505           fi \
506         done
507
508 uninstall-local::
509         $(Echo) Uninstalling Configuration Files From $(sysconfdir)
510         $(Verb)for file in $(CONFIG_FILES); do \
511           $(RM) -f $(sysconfdir)/$${file} ; \
512         done
513
514 endif
515
516 ###############################################################################
517 # Library Build Rules: Four ways to build a library
518 ###############################################################################
519
520 #---------------------------------------------------------
521 # Bytecode Module Targets:
522 #   If the user set MODULE_NAME then they want to build a
523 #   bytecode module from the sources. We compile all the
524 #   sources and link it together into a single bytecode
525 #   module.
526 #---------------------------------------------------------
527
528 ifdef MODULE_NAME
529
530 Module     := $(LibDir)/$(MODULE_NAME).bc
531 LinkModule := $(LLVMGCCWITHPATH) -shared -nostdlib
532
533 ifdef EXPORTED_SYMBOL_FILE
534 LinkMOdule += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
535 endif
536
537 $(Module): $(BUILT_SOURCES) $(ObjectsBC) $(LibDir)/.dir $(GCCLD)
538         $(Echo) Building $(BuildMOde) Bytecode Module $(notdir $@)
539         $(Verb) $(LinkModule) -o $@ $(ObjectsBC)
540
541 all-local:: $(Module)
542
543 clean-local::
544 ifneq ($(strip $(Module)),)
545         -$(Verb) $(RM) -f $(Module)
546 endif
547
548 ifdef BYTECODE_DESTINATION
549 ModuleDestDir := $(BYTECODE_DESTINATION)
550 else
551 ModuleDestDir := $(libdir)
552 endif
553
554 DestModule := $(ModuleDestDir)/$(MODULE_NAME).bc
555
556 install-module:: $(DestModule)
557 install-local:: $(DestModule)
558
559 $(DestModule): $(ModuleDestDir) $(Module) 
560         $(Echo) Installing $(BuildMode) Bytecode Module $(DestModule)
561         $(Verb) $(INSTALL) $(Module) $@
562
563 uninstall-local::
564         $(Echo) Uninstalling $(BuildMode) Bytecode Module $(DestModule)
565         -$(Verb) $(RM) -f $(DestModule)
566
567 endif
568
569 # if we're building a library ...
570 ifdef LIBRARYNAME
571
572 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
573 LIBRARYNAME := $(strip $(LIBRARYNAME))
574 LibName.LA := $(LibDir)/lib$(LIBRARYNAME).la
575 LibName.A  := $(LibDir)/lib$(LIBRARYNAME).a
576 LibName.O  := $(LibDir)/$(LIBRARYNAME).o
577 LibName.BCA:= $(LibDir)/lib$(LIBRARYNAME).bca
578
579 #---------------------------------------------------------
580 # Shared Library Targets:
581 #   If the user asked for a shared library to be built
582 #   with the SHARED_LIBRARY variable, then we provide
583 #   targets for building them.
584 #---------------------------------------------------------
585 ifdef SHARED_LIBRARY
586
587 all-local:: $(LibName.LA)
588
589 $(LibName.LA): $(ObjectsLO) $(LibDir)/.dir
590         $(Echo) Linking $(BuildMode) Shared Library $(LIBRARYNAME)$(SHLIBEXT)
591         $(Verb) $(Link) -o $@ $(ObjectsLO)
592         $(Verb) $(LTInstall) $@ $(LibDir)
593
594 clean-local::
595 ifneq ($(strip $(LibName.LA)),)
596         -$(Verb) $(RM) -f $(LibName.LA)
597 endif
598
599 DestSharedLib = $(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
600
601 install-local:: $(DestSharedLib)
602
603 $(DestSharedLib): $(libdir) $(LibName.LA)
604         $(Echo) Installing $(BuildMode) Shared Library $(DestSharedLib)
605         $(Verb) $(LTInstall) $(LibName.LA) $(DestSharedLib)
606         $(Verb) $(LIBTOOL) --finish $(libdir)
607
608 uninstall-local:: 
609         $(Echo) Uninstalling $(BuildMode) Shared Library $(DestSharedLib)
610         -$(Verb) $(RM) -f $(libdir)/lib$(LIBRARYNAME).*
611
612 endif
613
614 #---------------------------------------------------------
615 # Bytecode Library Targets:
616 #   If the user asked for a bytecode library to be built
617 #   with the BYTECODE_LIBRARY variable, then we provide 
618 #   targets for building them.
619 #---------------------------------------------------------
620 ifdef BYTECODE_LIBRARY
621
622 # make the C and C++ compilers strip debug info out of bytecode libraries.
623 BCCompile.C += -Wa,-strip-debug
624 BCCompile.CXX += -Wa,-strip-debug
625
626 all-local:: $(LibName.BCA)
627
628 ifdef EXPORTED_SYMBOL_FILE
629 BCLinkLib = $(LLVMGCCWITHPATH) -shared -nostdlib -Xlinker \
630             -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
631
632 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir $(GCCLD) \
633                 $(LLVMToolDir)/llvm-ar
634         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@) \
635           "(internalize)"
636         $(Verb) $(BCLinkLib) -o $(ObjDir)/$(LIBRARYNAME).o $(ObjectsBC)
637         $(Verb) $(RM) -f $@
638         $(Verb) $(LArchive) $@ $(ObjDir)/$(LIBRARYNAME).o
639 else
640 $(LibName.BCA): $(ObjectsBC) $(LibDir)/.dir \
641                 $(LLVMToolDir)/llvm-ar
642         $(Echo) Building $(BuildMode) Bytecode Archive $(notdir $@)
643         $(Verb) $(RM) -f $@
644         $(Verb) $(LArchive) $@ $(ObjectsBC)
645
646 endif
647
648 clean-local::
649 ifneq ($(strip $(LibName.BCA)),)
650         -$(Verb) $(RM) -f $(LibName.BCA)
651 endif
652
653 ifdef BYTECODE_DESTINATION
654 BytecodeDestDir := $(BYTECODE_DESTINATION)
655 else
656 BytecodeDestDir := $(libdir)
657 endif
658
659 DestBytecodeLib = $(BytecodeDestDir)/lib$(LIBRARYNAME).a
660
661 install-bytecode-local:: $(DestBytecodeLib)
662
663 install-local:: $(DestBytecodeLib)
664
665 $(DestBytecodeLib): $(BytecodeDestDir) $(LibName.BCA) 
666         $(Echo) Installing $(BuildMode) Bytecode Archive $(DestBytecodeLib)
667         $(Verb) $(INSTALL) $(LibName.BCA) $@
668
669 uninstall-local::
670         $(Echo) Uninstalling $(BuildMode) Bytecode Archive $(DestBytecodeLib)
671         -$(Verb) $(RM) -f $(DestBytecodeLib)
672
673 endif
674
675 #---------------------------------------------------------
676 # ReLinked Library Targets:
677 #   If the user didn't explicitly forbid building a 
678 #   relinked then we provide targets for building them.
679 #---------------------------------------------------------
680 ifndef DONT_BUILD_RELINKED
681
682 all-local:: $(LibName.O)
683
684 $(LibName.O): $(ObjectsO) $(LibDir)/.dir
685         $(Echo) Linking $(BuildMode) Object Library $(notdir $@)
686         $(Verb) $(Relink) -o $@ $(ObjectsO)
687
688 clean-local::
689 ifneq ($(strip $(LibName.O)),)
690         -$(Verb) $(RM) -f $(LibName.O)
691 endif
692
693 DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
694
695 install-local:: $(DestRelinkedLib)
696
697 $(DestRelinkedLib): $(libdir) $(LibName.O)
698         $(Echo) Installing $(BuildMode) Object Library $(DestRelinkedLib)
699         $(Verb) $(LTInstall) $(LibName.O) $(DestRelinkedLib)
700
701 uninstall-local::
702         $(Echo) Uninstalling $(BuildMode) Object Library $(DestRelinkedLib)
703         -$(Verb) $(RM) -f $(DestRelinkedLib)
704
705 endif
706
707 #---------------------------------------------------------
708 # Archive Library Targets:
709 #   If the user wanted a regular archive library built, 
710 #   then we provide targets for building them.
711 #---------------------------------------------------------
712 ifdef BUILD_ARCHIVE
713
714 all-local:: $(LibName.A)
715
716 $(LibName.A): $(ObjectsO) $(LibDir)/.dir
717         $(Echo) Building $(BuildMode) Archive Library $(notdir $@)
718         -$(Verb) $(RM) -f $@
719         $(Verb) $(Archive) $@ $(ObjectsO)
720         $(Verb) $(Ranlib) $@
721
722 clean-local::
723 ifneq ($(strip $(LibName.A)),)
724         -$(Verb) $(RM) -f $(LibName.A)
725 endif
726
727 DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
728
729 install-local:: $(DestArchiveLib)
730
731 $(DestArchiveLib): $(libdir) $(LibName.A)
732         $(Echo) Installing $(BuildMode) Archive Library $(DestArchiveLib)
733         $(Verb) $(MKDIR) $(libdir)
734         $(Verb) $(LTInstall) $(LibName.A) $(DestArchiveLib)
735
736 uninstall-local::
737         $(Echo) Uninstalling $(BuildMode) Archive Library $(DestArchiveLib)
738         -$(Verb) $(RM) -f $(DestArchiveLib)
739
740 endif
741
742 # endif LIBRARYNAME
743 endif 
744
745 ###############################################################################
746 # Tool Build Rules: Build executable tool based on TOOLNAME option
747 ###############################################################################
748
749 ifdef TOOLNAME
750
751 #---------------------------------------------------------
752 # Handle the special "JIT" value for LLVM_LIBS which is a
753 # shorthand for a bunch of libraries that get the correct
754 # JIT support for a tool that runs JIT.
755 #---------------------------------------------------------
756 ifeq ($(LLVMLIBS),JIT)
757
758 # Make sure we can get our own symbols in the tool
759 Link += -dlopen self
760
761 # Generic JIT libraries
762 JIT_LIBS := LLVMInterpreter LLVMJIT LLVMCodeGen LLVMExecutionEngine
763
764 # You can enable the X86 JIT on a non-X86 host by setting the flag
765 # ENABLE_X86_JIT on the make command line. If not, it will still be
766 # enabled automagically on an X86 host.
767 ifeq ($(ARCH), x86)
768   ENABLE_X86_JIT = 1
769 endif
770
771 # What the X86 JIT requires
772 ifdef ENABLE_X86_JIT
773   JIT_LIBS  += LLVMX86
774 endif
775
776 # You can enable the SparcV9 JIT on a non-SparcV9 host by setting the flag
777 # ENABLE_SPARCV9_JIT on the make command line. If not, it will still be
778 # enabled automagically on an SparcV9 host.
779 ifeq ($(ARCH), Sparc)
780   ENABLE_SPARCV9_JIT = 1
781 endif
782
783 # What the Sparc JIT requires
784 ifdef ENABLE_SPARCV9_JIT
785   JIT_LIBS += LLVMSparcV9 LLVMSparcV9ModuloSched LLVMSparcV9InstrSched \
786               LLVMSparcV9LiveVar LLVMInstrumentation.a LLVMProfilePaths \
787               LLVMBCWriter LLVMTransforms.a LLVMipo.a LLVMipa.a \
788               LLVMDataStructure.a LLVMSparcV9RegAlloc
789 endif
790
791 # You can enable the PowerPC JIT on a non-PowerPC host by setting the flag
792 # ENABLE_PPC_JIT on the make command line. If not, it will still be
793 # enabled automagically on an PowerPC host.
794 ifeq ($(ARCH), PowerPC)
795   ENABLE_PPC_JIT = 1
796 endif
797
798 # What the PowerPC JIT requires
799 ifdef ENABLE_PPC_JIT
800   JIT_LIBS  += LLVMPowerPC
801 endif
802
803 LLVMLIBS := $(JIT_LIBS) LLVMScalarOpts LLVMAnalysis.a LLVMTransformUtils.a \
804              LLVMBCReader LLVMCore LLVMSupport.a LLVMTarget.a LLVMbzip2 \
805              LLVMSystem.a $(PLATFORMLIBDL)
806 endif
807
808 #---------------------------------------------------------
809 # Set up variables for building a tool.
810 #---------------------------------------------------------
811 ifdef EXAMPLE_TOOL
812 ToolBuildPath   := $(ExmplDir)/$(TOOLNAME)$(EXEEXT)
813 else
814 ToolBuildPath   := $(ToolDir)/$(TOOLNAME)$(EXEEXT)
815 endif
816 ProjLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
817 ProjLibsOptions := $(patsubst %.o, $(LibDir)/%.o,  $(ProjLibsOptions))
818 LLVMLibsOptions := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
819 LLVMLibsOptions := $(patsubst %.o, $(LLVMLibDir)/%.o, $(LLVMLibsOptions))
820 ProjUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
821 LLVMUsedLibs    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
822 ProjLibsPaths   := $(addprefix $(LibDir)/,$(ProjUsedLibs))
823 LLVMLibsPaths   := $(addprefix $(LLVMLibDir)/,$(LLVMUsedLibs))
824
825 #---------------------------------------------------------
826 # Tell make that we need to rebuild subdirectories before 
827 # we can link the tool. This affects things like LLI which 
828 # has library subdirectories.
829 #---------------------------------------------------------
830 $(ToolBuildPath): $(addsuffix /.makeall, $(PARALLEL_DIRS))
831
832 #---------------------------------------------------------
833 # Provide targets for building the tools
834 #---------------------------------------------------------
835 all-local:: $(ToolBuildPath)
836
837 clean-local::
838 ifneq ($(strip $(ToolBuildPath)),)
839         -$(Verb) $(RM) -f $(ToolBuildPath)
840 endif
841
842 ifdef EXAMPLE_TOOL
843 $(ToolBuildPath): $(ExmplDir)/.dir
844 else
845 $(ToolBuildPath): $(ToolDir)/.dir
846 endif
847
848 $(ToolBuildPath): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
849         $(Echo) Linking $(BuildMode) executable $(TOOLNAME) $(StripWarnMsg)
850         $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
851           $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB)
852         $(Echo) ======= Finished Linking $(BuildMode) Executable $(TOOLNAME) $(StripWarnMsg) 
853
854 DestTool = $(bindir)/$(TOOLNAME)
855
856 install-local:: $(DestTool)
857
858 $(DestTool): $(bindir) $(ToolBuildPath)
859         $(Echo) Installing $(BuildMode) $(DestTool)
860         $(Verb) $(INSTALL) $(ToolBuildPath) $(DestTool)
861
862 uninstall-local::
863         $(Echo) Uninstalling $(BuildMode) $(DestTool)
864         -$(Verb) $(RM) -f $(DestTool)
865
866 endif
867
868 ###############################################################################
869 # Object Build Rules: Build object files based on sources 
870 ###############################################################################
871
872 # Provide rule sets for when dependency generation is enabled
873 ifndef DISABLE_AUTO_DEPENDENCIES
874
875 #---------------------------------------------------------
876 # Create .lo files in the ObjDir directory from the .cpp and .c files...
877 #---------------------------------------------------------
878 ifdef SHARED_LIBRARY
879
880 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
881         $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
882         $(Verb) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACXXd $< -o $@ ; \
883         then $(MV) -f "$(ObjDir)/$*.LACXXd" "$(ObjDir)/$*.d"; \
884         else $(RM) -f "$(ObjDir)/$*.LACXXd"; exit 1; fi
885
886 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
887         $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
888         $(Verb) if $(LTCompile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.LACd $< -o $@ ; \
889         then $(MV) -f "$(ObjDir)/$*.LACd" "$(ObjDir)/$*.d"; \
890         else $(RM) -f "$(ObjDir)/$*.LACd"; exit 1; fi
891
892 #---------------------------------------------------------
893 # Create .o files in the ObjDir directory from the .cpp and .c files...
894 #---------------------------------------------------------
895 else
896
897 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
898         $(Echo) "Compiling $*.cpp for $(BuildMode) build"
899         $(Verb) if $(Compile.CXX) -MD -MT $@ -MP -MF $(ObjDir)/$*.CXXd $< -o $@ ; \
900         then $(MV) -f "$(ObjDir)/$*.CXXd" "$(ObjDir)/$*.d"; \
901         else $(RM) -f "$(ObjDir)/$*.CXXd"; exit 1; fi
902
903 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
904         $(Echo) "Compiling $*.c for $(BuildMode) build"
905         $(Verb) if $(Compile.C) -MD -MT $@ -MP -MF $(ObjDir)/$*.Cd $< -o $@ ; \
906         then $(MV) -f "$(ObjDir)/$*.Cd" "$(ObjDir)/$*.d"; \
907         else $(RM) -f "$(ObjDir)/$*.Cd"; exit 1; fi
908
909 endif
910
911 #---------------------------------------------------------
912 # Create .bc files in the ObjDir directory from .cpp and .c files...
913 #---------------------------------------------------------
914 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
915         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
916         $(Verb) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCXXd" $< -o $@ ; \
917         then $(MV) -f "$(ObjDir)/$*.BCCXXd" "$(ObjDir)/$*.d"; \
918         else $(RM) -f "$(ObjDir)/$*.BCCXXd"; exit 1; fi
919
920 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
921         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
922         $(Verb) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(ObjDir)/$*.BCCd" $< -o $@ ; \
923         then $(MV) -f "$(ObjDir)/$*.BCCd" "$(ObjDir)/$*.d"; \
924         else $(RM) -f "$(ObjDir)/$*.BCCd"; exit 1; fi
925
926 # Provide alternate rule sets if dependencies are disabled
927 else
928
929 ifdef SHARED_LIBRARY
930
931 $(ObjDir)/%.lo $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
932         $(Echo) "Compiling $*.cpp for $(BuildMode) build (PIC)"
933         $(LTCompile.CXX) $< -o $@ 
934
935 $(ObjDir)/%.lo $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
936         $(Echo) "Compiling $*.c for $(BuildMode) build (PIC)"
937         $(LTCompile.C) $< -o $@ 
938
939 else
940
941 $(ObjDir)/%.o: %.cpp $(ObjDir)/.dir $(BUILT_SOURCES)
942         $(Echo) "Compiling $*.cpp for $(BuildMode) build"
943         $(Compile.CXX) $< -o $@ 
944
945 $(ObjDir)/%.o: %.c $(ObjDir)/.dir $(BUILT_SOURCES)
946         $(Echo) "Compiling $*.c for $(BuildMode) build"
947         $(Compile.C) $< -o $@ 
948 endif
949
950 $(ObjDir)/%.bc: %.cpp $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
951         $(Echo) "Compiling $*.cpp for $(BuildMode) build (bytecode)"
952         $(BCCompile.CXX) $< -o $@ 
953
954 $(ObjDir)/%.bc: %.c $(ObjDir)/.dir $(GCCAS) $(BUILT_SOURCES)
955         $(Echo) "Compiling $*.c for $(BuildMode) build (bytecode)"
956         $(BCCompile.C) $< -o $@
957
958 endif
959
960 #---------------------------------------------------------
961 # Provide rule to build .bc files from .ll sources,
962 # regardless of dependencies
963 #---------------------------------------------------------
964 $(ObjDir)/%.bc: %.ll $(ObjDir)/.dir $(LLVMAS)
965         $(Echo) "Compiling $*.ll for $(BuildMode) build"
966         $(Verb) $(LLVMAS) $< -f -o $@
967
968 ###############################################################################
969 # TABLEGEN: Provide rules for running tblgen to produce *.inc files
970 ###############################################################################
971
972 ifdef TARGET
973
974 TDFiles := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
975 INCFiles := $(filter %.inc,$(BUILT_SOURCES))
976 INCTMPFiles := $(INCFiles:%=$(ObjDir)/%.tmp)
977 .PRECIOUS: $(INCTMPFiles) $(INCFiles)
978
979 # All of these files depend on tblgen and the .td files.
980 $(INCTMPFiles) : $(TBLGEN) $(TDFiles)
981
982 # INCFiles rule: All of the tblgen generated files are emitted to 
983 # $(ObjDir)/%.inc.tmp, instead of emitting them directly to %.inc.  This allows
984 # us to only "touch" the real file if the contents of it change.  IOW, if
985 # tblgen is modified, all of the .inc.tmp files are regereated, but no
986 # dependencies of the .inc files are, unless the contents of the .inc file
987 # changes.
988 $(INCFiles) : %.inc : $(ObjDir)/%.inc.tmp
989         $(Verb) $(CMP) -s $@ $< || $(CP) $< $@
990
991 $(TARGET:%=$(ObjDir)/%GenRegisterNames.inc.tmp): \
992 $(ObjDir)/%GenRegisterNames.inc.tmp : %.td $(ObjDir)/.dir
993         $(Echo) "Building $(<F) register names with tblgen"
994         $(Verb) $(TableGen) -gen-register-enums -o $@ $<
995
996 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.h.inc.tmp): \
997 $(ObjDir)/%GenRegisterInfo.h.inc.tmp : %.td $(ObjDir)/.dir
998         $(Echo) "Building $(<F) register information header with tblgen"
999         $(Verb) $(TableGen) -gen-register-desc-header -o $@ $<
1000
1001 $(TARGET:%=$(ObjDir)/%GenRegisterInfo.inc.tmp): \
1002 $(ObjDir)/%GenRegisterInfo.inc.tmp : %.td $(ObjDir)/.dir
1003         $(Echo) "Building $(<F) register info implementation with tblgen"
1004         $(Verb) $(TableGen) -gen-register-desc -o $@ $<
1005
1006 $(TARGET:%=$(ObjDir)/%GenInstrNames.inc.tmp): \
1007 $(ObjDir)/%GenInstrNames.inc.tmp : %.td $(ObjDir)/.dir
1008         $(Echo) "Building $(<F) instruction names with tblgen"
1009         $(Verb) $(TableGen) -gen-instr-enums -o $@ $<
1010
1011 $(TARGET:%=$(ObjDir)/%GenInstrInfo.inc.tmp): \
1012 $(ObjDir)/%GenInstrInfo.inc.tmp : %.td $(ObjDir)/.dir
1013         $(Echo) "Building $(<F) instruction information with tblgen"
1014         $(Verb) $(TableGen) -gen-instr-desc -o $@ $<
1015
1016 $(TARGET:%=$(ObjDir)/%GenAsmWriter.inc.tmp): \
1017 $(ObjDir)/%GenAsmWriter.inc.tmp : %.td $(ObjDir)/.dir
1018         $(Echo) "Building $(<F) assembly writer with tblgen"
1019         $(Verb) $(TableGen) -gen-asm-writer -o $@ $<
1020
1021 $(TARGET:%=$(ObjDir)/%GenAsmWriter1.inc.tmp): \
1022 $(ObjDir)/%GenAsmWriter1.inc.tmp : %.td $(ObjDir)/.dir
1023         $(Echo) "Building $(<F) assembly writer #1 with tblgen"
1024         $(Verb) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $< 
1025
1026 $(TARGET:%=$(ObjDir)/%GenCodeEmitter.inc.tmp): \
1027 $(ObjDir)/%GenCodeEmitter.inc.tmp: %.td $(ObjDir)/.dir
1028         $(Echo) "Building $(<F) code emitter with tblgen"
1029         $(Verb) $(TableGen) -gen-emitter -o $@ $<
1030
1031 clean-local::
1032         -$(Verb) $(RM) -f $(INCFiles)
1033
1034 endif
1035
1036 ###############################################################################
1037 # LEX AND YACC: Provide rules for generating sources with lex and yacc
1038 ###############################################################################
1039
1040 #---------------------------------------------------------
1041 # Provide rules for generating a .cpp source file from 
1042 # (f)lex input sources. 
1043 #---------------------------------------------------------
1044
1045 LexFiles  := $(filter %.l,$(Sources))
1046
1047 ifneq ($(LexFiles),)
1048
1049 LexOutput := $(strip $(patsubst %.l,%.cpp,$(LexFiles)))
1050
1051 .PRECIOUS: $(LexOutput)
1052
1053 # Note the extra sed filtering here, used to cut down on the warnings emited 
1054 # by GCC.  The last line is a gross hack to work around flex aparently not 
1055 # being able to resize the buffer on a large token input.  Currently, for 
1056 # uninitialized string buffers in LLVM we can generate very long tokens, so 
1057 # this is a hack around it.
1058 # FIXME.  (f.e. char Buffer[10000] )
1059 %.cpp: %.l
1060         $(Echo) Flexing $*.l
1061         $(Verb) $(FLEX) -t $< | \
1062         $(SED) 's/void yyunput/inline void yyunput/' | \
1063         $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
1064         $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
1065           > $@
1066
1067 clean-local::
1068         -$(Verb) $(RM) -f $(LexOutput)
1069         $(Verb) $(RM) -f $(LexOutput)
1070
1071 endif
1072
1073 #---------------------------------------------------------
1074 # Provide rules for generating a .cpp and .h source files 
1075 # from yacc (bison) input sources.
1076 #---------------------------------------------------------
1077
1078 YaccFiles  := $(filter %.y,$(Sources))
1079 ifneq ($(YaccFiles),)
1080 YaccOutput := $(addprefix $(patsubst %.y,%,$(YaccFiles)),.h .cpp .output)
1081
1082 .PRECIOUS: $(YaccOutput)
1083
1084 # Cancel built-in rules for yacc
1085 %.c: %.y 
1086 %.cpp: %.y
1087 %.h: %.y
1088
1089 # Rule for building the bison parsers...
1090 %.cpp %.h : %.y
1091         $(Echo) "Bisoning $*.y"
1092         $(Verb) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c  $<
1093         $(Verb) $(MV) -f $*.tab.c $*.cpp
1094         $(Verb) $(MV) -f $*.tab.h $*.h
1095
1096 clean-local::
1097         -$(Verb) $(RM) -f $(YaccOutput)
1098         $(Verb) $(RM) -f $(YaccOutput)
1099 endif
1100
1101 ###############################################################################
1102 # OTHER RULES: Other rules needed
1103 ###############################################################################
1104
1105 # To create postscript files from dot files...
1106 ifneq ($(DOT),false)
1107 %.ps: %.dot
1108         $(DOT) -Tps < $< > $@
1109 else
1110 %.ps: %.dot
1111         $(Echo) "Cannot build $@: The program dot is not installed"
1112 endif
1113
1114 # This rules ensures that header files that are removed still have a rule for
1115 # which they can be "generated."  This allows make to ignore them and
1116 # reproduce the dependency lists.
1117 %.h:: ;
1118
1119 # Define clean-local to clean the current directory. Note that this uses a
1120 # very conservative approach ensuring that empty variables do not cause 
1121 # errors or disastrous removal.
1122 clean-local::
1123 ifneq ($(strip $(ObjDir)),)
1124         -$(Verb) $(RM) -rf $(ObjDir)
1125 endif
1126         -$(Verb) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
1127 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
1128         -$(Verb) $(RM) -f *$(SHLIBEXT)
1129 endif
1130
1131 clean-all-local::
1132         -$(Verb) $(RM) -rf Debug Release Profile
1133
1134 # Build tags database for Emacs/Xemacs:
1135 tags:: TAGS CTAGS
1136
1137 TAGS: 
1138         find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
1139           $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
1140           $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
1141           $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
1142         -name '*.cpp' -o -name '*.h' | \
1143         $(ETAGS) $(ETAGSFLAGS) -
1144
1145 CTAGS:
1146         find $(BUILD_SRC_ROOT)/include $(BUILD_SRC_ROOT)/lib \
1147           $(BUILD_SRC_ROOT)/tools $(BUILD_SRC_ROOT)/examples \
1148           $(BUILD_OBJ_ROOT)/include $(BUILD_OBJ_ROOT)/lib \
1149           $(BUILD_OBJ_ROOT)/tools $(BUILD_OBJ_ROOT)/examples \
1150           \( -name '*.cpp' -o -name '*.h' \) -print | \
1151           ctags -ImtT -o $(BUILD_OBJ_ROOT)/CTAGS -L -
1152
1153
1154 ###############################################################################
1155 # DEPENDENCIES: Include the dependency files if we should
1156 ###############################################################################
1157 ifndef DISABLE_AUTO_DEPENDENCIES
1158
1159 # If its not one of the cleaning targets
1160 ifneq ($strip($(filter-out clean clean-local dist-clean,$(MAKECMDGOALS))),)
1161
1162 # Get the list of dependency files
1163 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(Sources)))
1164 DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(BuildMode)/%.d,$(DependFiles))
1165
1166 -include /dev/null $(DependFiles)
1167
1168 endif
1169
1170 endif 
1171
1172 ###############################################################################
1173 # CHECK: Running the test suite
1174 ###############################################################################
1175
1176 check::
1177         $(Verb) if test -d "$(BUILD_OBJ_ROOT)/test" ; then \
1178           if test -f "$(BUILD_OBJ_ROOT)/test/Makefile" ; then \
1179             $(EchoCmd) Running test suite ; \
1180             $(MAKE) -C $(BUILD_OBJ_ROOT)/test check-local \
1181               TESTSUITE=$(TESTSUITE) ; \
1182           else \
1183             $(EchoCmd) No Makefile in test directory ; \
1184           fi ; \
1185         else \
1186           $(EchoCmd) No test directory ; \
1187         fi
1188
1189 ###############################################################################
1190 # DISTRIBUTION: Handle construction of a distribution tarball
1191 ###############################################################################
1192
1193 #------------------------------------------------------------------------
1194 # Define distribution related variables
1195 #------------------------------------------------------------------------
1196 DistName    := $(LLVM_TARBALL_NAME)
1197 DistDir     := $(BUILD_OBJ_ROOT)/$(DistName)
1198 TopDistDir  := $(BUILD_OBJ_ROOT)/$(DistName)
1199 DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
1200 DistZip     := $(BUILD_OBJ_ROOT)/$(DistName).zip
1201 DistTarBZ2  := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
1202 DistAlways  := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
1203                ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
1204                Makefile.config.in configure autoconf
1205 DistOther   := $(notdir $(wildcard \
1206                $(BUILD_SRC_DIR)/*.h \
1207                $(BUILD_SRC_DIR)/*.td \
1208                $(BUILD_SRC_DIR)/*.def \
1209                $(BUILD_SRC_DIR)/*.ll \
1210                $(BUILD_SRC_DIR)/*.in))
1211 DistSubDirs := $(SubDirs)
1212 DistSources  = $(Sources) $(EXTRA_DIST)
1213 DistFiles    = $(DistAlways) $(DistSources) $(DistOther)
1214
1215 #------------------------------------------------------------------------
1216 # We MUST build distribution with OBJ_DIR != SRC_DIR
1217 #------------------------------------------------------------------------
1218 ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
1219 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1220         $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
1221
1222 else
1223
1224 #------------------------------------------------------------------------
1225 # Prevent catastrophic remove
1226 #------------------------------------------------------------------------
1227 ifeq ($(LLVM_TARBALL_NAME),)
1228 $(error LLVM_TARBALL_NAME is empty.  Please rerun configure)
1229 endif
1230
1231 #------------------------------------------------------------------------
1232 # Prevent attempt to run dist targets from anywhere but the top level
1233 #------------------------------------------------------------------------
1234 ifneq ($(LEVEL),.)
1235
1236 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
1237         $(Echo) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
1238
1239 else
1240
1241 #------------------------------------------------------------------------
1242 # Provide the top level targets
1243 #------------------------------------------------------------------------
1244
1245 dist-gzip:: $(DistTarGZip)
1246
1247 $(DistTarGZip) : $(TopDistDir)/.makedistdir
1248         $(Echo) Packing gzipped distribution tar file.
1249         $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | \
1250           $(GZIP) -c > "$(DistTarGZip)"
1251
1252 dist-bzip2:: $(DistTarBZ2)
1253
1254 $(DistTarBZ2) : $(TopDistDir)/.makedistdir
1255         $(Echo) Packing bzipped distribution tar file.
1256         $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - $(DistName) | \
1257           $(BZIP2) -c >$(DistTarBZ2)
1258
1259 dist-zip:: $(DistZip)
1260
1261 $(DistZip) : $(TopDistDir)/.makedistdir
1262         $(Echo) Packing zipped distribution file.
1263         $(Verb) rm -f $(DistZip)
1264         $(Verb) cd $(BUILD_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
1265
1266 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip) 
1267         $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
1268
1269 DistCheckDir := $(LLVM_OBJ_ROOT)/_distcheckdir
1270
1271 dist-check:: $(DistTarGZip)
1272         $(Echo) Checking distribution tar file.
1273         $(Verb) if test -d $(DistCheckDir) ; then \
1274           $(RM) -rf $(DistCheckDir) ; \
1275         fi
1276         $(Verb) $(MKDIR) $(DistCheckDir)
1277         $(Verb) cd $(DistCheckDir) && \
1278           $(MKDIR) $(DistCheckDir)/build && \
1279           $(MKDIR) $(DistCheckDir)/install && \
1280           gunzip -c $(DistTarGZip) | $(TAR) xf - && \
1281           cd build && \
1282           ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
1283             --srcdir=../$(DistName) && \
1284           $(MAKE) all && \
1285           $(MAKE) check && \
1286           $(MAKE) install && \
1287           $(MAKE) uninstall && \
1288           $(MAKE) dist && \
1289           $(MAKE) clean && \
1290           $(MAKE) dist-clean && \
1291           $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
1292
1293 dist-clean::
1294         $(Echo) Cleaning distribution files
1295         -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) \
1296           $(DistCheckDir)
1297
1298 endif
1299
1300 #------------------------------------------------------------------------
1301 # Provide the recursive distdir target for building the distribution directory
1302 #------------------------------------------------------------------------
1303 distdir: $(DistDir)/.makedistdir
1304 $(DistDir)/.makedistdir: $(DistSources)
1305         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1306           if test -d "$(DistDir)" ; then \
1307             find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';'  || \
1308               exit 1 ; \
1309           fi ; \
1310           $(EchoCmd) Removing old $(DistDir) ; \
1311           $(RM) -rf $(DistDir); \
1312           $(EchoCmd) Making 'all' to verify build ; \
1313           $(MAKE) all ; \
1314         fi
1315         $(Echo) Building Distribution Directory $(DistDir)
1316         $(Verb) $(MKDIR) $(DistDir) 
1317         $(Verb) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
1318         srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
1319         for file in $(DistFiles) ; do \
1320           case "$$file" in \
1321             $(BUILD_SRC_DIR)/*) \
1322               file=`echo "$$file" | sed "s#^$$srcdirstrip/##"` \
1323               ;; \
1324             $(BUILD_SRC_ROOT)/*) \
1325               file=`echo "$$file" | \
1326                 sed "s#^$$srcrootstrip/##"` \
1327               ;; \
1328           esac; \
1329           if test -f "$(BUILD_SRC_DIR)/$$file" || \
1330              test -d "$(BUILD_SRC_DIR)/$$file" ; then \
1331             from_dir="$(BUILD_SRC_DIR)" ; \
1332           elif test -f "$$file" || test -d "$$file" ; then \
1333             from_dir=. ; \
1334           fi ; \
1335           to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'` ; \
1336           if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
1337             to_dir="$(DistDir)/$$dir"; \
1338             $(MKDIR) "$$to_dir" ; \
1339           else \
1340             to_dir="$(DistDir)"; \
1341           fi; \
1342           mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1343           if test -n "$$mid_dir" ; then \
1344             $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1345           fi ; \
1346           if test -d "$$from_dir/$$file"; then \
1347             if test -d "$(BUILD_SRC_DIR)/$$file" && \
1348                test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
1349               $(CP) -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
1350             fi; \
1351             $(CP) -pR $$from_dir/$$file $$to_dir || exit 1; \
1352           elif test -f "$$from_dir/$$file" ; then \
1353             $(CP) -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1354           elif test -L "$$from_dir/$$file" ; then \
1355             $(CP) -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1356           elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1357             $(EchoCmd) "===== WARNING: Distribution Source " \
1358               "$$from_dir/$$file Not Found!" ; \
1359           elif test "$(Verb)" != '@' ; then \
1360             $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
1361           fi; \
1362         done
1363         $(Verb) for subdir in $(DistSubDirs) ; do \
1364           if test "$$subdir" \!= "." ; then \
1365             new_distdir="$(DistDir)/$$subdir" ; \
1366             test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1367             ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || \
1368             exit 1; \
1369           fi; \
1370         done
1371         $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
1372           $(EchoCmd) Eliminating CVS directories from distribution ; \
1373           $(RM) -rf `find $(TopDistDir) -type d -name CVS -print` ;\
1374           $(MAKE) dist-hook ; \
1375           $(FIND) $(TopDistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; \
1376             -o ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; \
1377             -o ! -type d ! -perm -400 -exec chmod a+r {} \; \
1378             -o ! -type d ! -perm -444 -exec \
1379               $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1380             || chmod -R a+r $(DistDir) ; \
1381         fi
1382
1383 # This is invoked by distdir target, define it as a no-op to avoid errors if not
1384 # defined by user.
1385 dist-hook::
1386
1387 endif
1388
1389 ###############################################################################
1390 # TOP LEVEL - targets only to apply at the top level directory
1391 ###############################################################################
1392
1393 ifeq ($(LEVEL),.)
1394
1395 #------------------------------------------------------------------------
1396 # Install support for the project's include files:
1397 #------------------------------------------------------------------------
1398 install-local::
1399         $(Echo) Installing include files
1400         $(Verb) $(MKDIR) $(includedir)
1401         $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1402           cd $(BUILD_SRC_ROOT)/include && \
1403             find . -path '*/Internal' -prune -o '(' -type f \
1404               '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1405               -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
1406         fi
1407
1408 uninstall-local::
1409         $(Echo) Uninstalling include files
1410         $(Verb) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1411           cd $(BUILD_SRC_ROOT)/include && \
1412             $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1413               '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1414               -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
1415         fi 
1416
1417 endif
1418
1419 #------------------------------------------------------------------------
1420 # Print out the directories used for building
1421 #------------------------------------------------------------------------
1422 printvars::
1423         $(Echo) "BuildMode      : " '$(BuildMode)'
1424         $(Echo) "BUILD_SRC_ROOT : " '$(BUILD_SRC_ROOT)'
1425         $(Echo) "BUILD_SRC_DIR  : " '$(BUILD_SRC_DIR)'
1426         $(Echo) "BUILD_OBJ_ROOT : " '$(BUILD_OBJ_ROOT)'
1427         $(Echo) "BUILD_OBJ_DIR  : " '$(BUILD_OBJ_DIR)'
1428         $(Echo) "LLVM_SRC_ROOT  : " '$(LLVM_SRC_ROOT)'
1429         $(Echo) "LLVM_OBJ_ROOT  : " '$(LLVM_OBJ_ROOT)'
1430         $(Echo) "libdir         : " '$(libdir)'
1431         $(Echo) "bindir         : " '$(bindir)'
1432         $(Echo) "sysconfdir     : " '$(sysconfdir)'
1433         $(Echo) "UserTargets    : " '$(UserTargets)'
1434         $(Echo) "ObjMakefiles   : " '$(ObjMakefiles)'
1435         $(Echo) "SrcMakefiles   : " '$(SrcMakefiles)'
1436         $(Echo) "ObjDir         : " '$(ObjDir)'
1437         $(Echo) "LibDir         : " '$(LibDir)'
1438         $(Echo) "ToolDir        : " '$(ToolDir)'
1439         $(Echo) "ExmplDir       : " '$(ExmplDir)'
1440         $(Echo) "Sources        : " '$(Sources)'
1441         $(Echo) "TDFiles        : " '$(TDFiles)'
1442         $(Echo) "INCFiles       : " '$(INCFiles)'
1443         $(Echo) "INCTMPFiles    : " '$(INCTMPFiles)'
1444         $(Echo) "Compile.CXX    : " '$(Compile.CXX)'
1445         $(Echo) "Compile.C      : " '$(Compile.C)'
1446         $(Echo) "Archive        : " '$(Archive)'
1447         $(Echo) "YaccFiles      : " '$(YaccFiles)'
1448         $(Echo) "LexFiles       : " '$(LexFiles)'
1449         $(Echo) "Module         : " '$(Module)'