Removed the utils/Makefile file from being copied to the object root tree.
[oota-llvm.git] / Makefile.rules
1 #===-- Makefile.common - Common make rules for LLVM -------*- makefile -*--====
2 #
3 # This file is included by all of the LLVM makefiles.  This file defines common
4 # rules to do things like compile a .cpp file or generate dependency info.
5 # These are platform dependent, so this is the file used to specify these
6 # system dependent operations.
7 #
8 # The following functionality can be set by setting incoming variables.
9 # The variable $(LEVEL) *must* be set:
10 #
11 # 1. LEVEL - The level of the current subdirectory from the top of the 
12 #    MagicStats view.  This level should be expressed as a path, for 
13 #    example, ../.. for two levels deep.
14 #
15 # 2. DIRS - A list of subdirectories to be built.  Fake targets are set up
16 #    so that each of the targets "all", "install", and "clean" each build
17 #    the subdirectories before the local target.  DIRS are guaranteed to be
18 #    built in order.
19 #
20 # 3. PARALLEL_DIRS - A list of subdirectories to be built, but that may be
21 #    built in any order.  All DIRS are built in order before PARALLEL_DIRS are
22 #    built, which are then built in any order.
23 #
24 # 4. Source - If specified, this sets the source code filenames.  If this
25 #    is not set, it defaults to be all of the .cpp, .c, .y, and .l files 
26 #    in the current directory.  Also, if you want to build files in addition
27 #    to the local files, you can use the ExtraSource variable
28 #
29 # 5. SourceDir - If specified, this specifies a directory that the source files
30 #    are in, if they are not in the current directory.  This should include a
31 #    trailing / character.
32 #
33 # 6. LLVM_SRC_ROOT - If specified, points to the top of the LLVM source tree.
34 #
35 # 8. BUILD_SRC_DIR - The directory which contains the current set of Makefiles
36 #    and usually the source code too (unless SourceDir is set).
37 #
38 # 9. BUILD_SRC_ROOT - The root directory of the source code being compiled.
39 #
40 # 10. BUILD_OBJ_DIR - The directory where object code should be placed.
41 #
42 # 11. BUILD_OBJ_ROOT - The root directory for where object code should be
43 #     placed.
44 #
45 # For building,
46 #       LLVM, LLVM_SRC_ROOT = BUILD_SRC_ROOT
47 #
48 #===-----------------------------------------------------------------------====
49
50 #
51 # Set the VPATH so that we can find source files.
52 #
53 VPATH=$(SourceDir)
54
55 ###########################################################################
56 # Default Targets:
57 #       The following targets are the standard top level targets for
58 #       building.
59 ###########################################################################
60
61 ifdef SHARED_LIBRARY
62 # if SHARED_LIBRARY is specified, the default is to build the dynamic lib
63 all:: dynamic
64 endif
65
66 ifdef BYTECODE_LIBRARY
67 # if BYTECODE_LIBRARY is specified, the default is to build the bytecode lib
68 all:: bytecodelib
69 install:: bytecodelib-install
70 endif
71
72 # Default Rule:  Make sure it's also a :: rule
73 all ::
74
75 # Default for install is to at least build everything...
76 install ::
77
78 # Default rule for test.  It ensures everything has a test rule
79 test::
80
81 # Default rule for building only bytecode.
82 bytecode::
83
84 # Print out the directories used for building
85 prdirs::
86         @echo "Build Source Root: " $(BUILD_SRC_ROOT)
87         @echo "Build Source Dir : " $(BUILD_SRC_DIR)
88         @echo "Build Object Root: " $(BUILD_OBJ_ROOT)
89         @echo "Build Object Dir : " $(BUILD_OBJ_DIR)
90         @echo "LLVM  Source Root: " $(LLVM_SRC_ROOT)
91         @echo "LLVM  Object Root: " $(LLVM_OBJ_ROOT)
92
93 ###########################################################################
94 # Suffixes and implicit rules:
95 #       Empty out the list of suffixes, generate a list that is only
96 #       used by this Makefile, and cancel useless implicit rules.   This
97 #       will hopefully speed up compilation a little bit.
98 ###########################################################################
99 .SUFFIXES:
100 .SUFFIXES: .c .cpp .h .hpp .y .l
101 .SUFFIXES: .lo .o .a .so .bc .td
102 .SUFFIXES: .ps .dot .d
103
104 #
105 # Mark all of these targets as phony.  This will hopefully speed up builds
106 # slightly since GNU Make will not try to find implicit rules for targets
107 # which are marked as Phony.
108 #
109 .PHONY: all dynamic bytecodelib bytecodelib-install
110 .PHONY: clean distclean install test bytecode prdirs
111
112 ###########################################################################
113 # Miscellaneous paths and commands:
114 #       This section defines various configuration macros, such as where
115 #       to find burg, tblgen, and libtool.
116 ###########################################################################
117
118 #--------------------------------------------------------------------
119 # Variables derived from configuration options... 
120 #--------------------------------------------------------------------
121
122 #BinInstDir=/usr/local/bin
123 #LibInstDir=/usr/local/lib/xxx
124 #DocInstDir=/usr/doc/xxx
125
126 BURG_OPTS = -I
127
128 ifdef ENABLE_PROFILING
129   ENABLE_OPTIMIZED = 1
130   CONFIGURATION := Profile
131 else
132   ifdef ENABLE_OPTIMIZED
133     CONFIGURATION := Release
134   else
135     CONFIGURATION := Debug
136   endif
137 endif
138
139 #
140 # Enable this for profiling support with 'gprof'
141 # This automatically enables optimized builds.
142 #
143 ifdef ENABLE_PROFILING
144   PROFILE = -pg
145 endif
146
147 ###########################################################################
148 # Library Locations:
149 #       These variables describe various library locations:
150 #
151 #       DEST* = Location of where libraries that are built will be placed.
152 #       LLVM* = Location of LLVM libraries used for linking.
153 #       PROJ* = Location of previously built libraries used for linking.
154 ###########################################################################
155
156 # Libraries that are being built
157 DESTLIBDEBUG    := $(BUILD_OBJ_ROOT)/lib/Debug
158 DESTLIBRELEASE  := $(BUILD_OBJ_ROOT)/lib/Release
159 DESTLIBPROFILE  := $(BUILD_OBJ_ROOT)/lib/Profile
160 DESTLIBBYTECODE := $(BUILD_OBJ_ROOT)/lib/BytecodeLibs
161 DESTLIBCURRENT  := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
162
163 # LLVM libraries used for linking
164 LLVMLIBDEBUGSOURCE    := $(LLVM_OBJ_ROOT)/lib/Debug
165 LLVMLIBRELEASESOURCE  := $(LLVM_OBJ_ROOT)/lib/Release
166 LLVMLIBPROFILESOURCE  := $(LLVM_OBJ_ROOT)/lib/Profile
167 LLVMLIBCURRENTSOURCE  := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
168
169 # Libraries that were built that will now be used for linking
170 PROJLIBDEBUGSOURCE    := $(BUILD_OBJ_ROOT)/lib/Debug
171 PROJLIBRELEASESOURCE  := $(BUILD_OBJ_ROOT)/lib/Release
172 PROJLIBPROFILESOURCE  := $(BUILD_OBJ_ROOT)/lib/Profile
173 PROJLIBCURRENTSOURCE  := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
174
175 ###########################################################################
176 # Tool Locations
177 #       These variables describe various tool locations:
178 #
179 #       DEST* = Location of where tools that are built will be placed.
180 #       LLVM* = Location of LLVM tools used for building.
181 #       PROJ* = Location of previously built tools used for linking.
182 ###########################################################################
183
184 DESTTOOLDEBUG   := $(BUILD_OBJ_ROOT)/tools/Debug
185 DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
186 DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
187 DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
188
189 LLVMTOOLDEBUG   := $(LLVM_OBJ_ROOT)/tools/Debug
190 LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
191 LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
192 LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
193
194 PROJTOOLDEBUG   := $(BUILD_OBJ_ROOT)/tools/Debug
195 PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
196 PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
197 PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
198
199 #
200 # Libtool is found in the current directory.
201 #
202 LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
203
204 #
205 # If we're not building a shared library, use the disable-shared tag with
206 # libtool.  This will disable the building of objects for shared libraries and
207 # only generate static library objects.
208 #
209 # For dynamic libraries, we'll take the performance hit for now, since we
210 # almost never build them.
211 #
212 # This should speed up compilation and require no modifications to future
213 # versions of libtool.
214 #
215 ifndef SHARED_LIBRARY
216 LIBTOOL += --tag=disable-shared
217 endif
218
219 #
220 # Verbosity levels
221 #
222 ifndef VERBOSE
223 VERB := @
224 LIBTOOL += --silent
225 endif
226
227 ###########################################################################
228 # Miscellaneous paths and commands (part deux):
229 #       This section defines various configuration macros, such as where
230 #       to find burg, tblgen, and libtool.
231 ###########################################################################
232
233 #--------------------------------------------------------------------------
234 # Utilities used while building the LLVM tree, which live in the utils dir
235 #
236 BURG    := $(LLVMTOOLCURRENT)/burg
237 RunBurg := $(BURG) $(BURG_OPTS)
238 TBLGEN  := $(LLVMTOOLCURRENT)/tblgen
239
240 #--------------------------------------------------------------------------
241 # The LLVM GCC front-end in C and C++ flavors
242 #
243 LLVMGCC := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/gcc
244 LCC1    := $(LLVMGCCDIR)/libexec/gcc/$(LLVMGCCARCH)/cc1
245 LLVMGXX := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/g++
246 LCC1XX  := $(LLVMGCCDIR)/libexec/gcc/$(LLVMGCCARCH)/cc1plus
247
248 #--------------------------------------------------------------------------
249 # Some of the compiled LLVM tools which are used for compilation of runtime
250 # libraries.
251 #
252 LLVMAS  := $(LLVMTOOLCURRENT)/llvm-as
253
254
255 ###########################################################################
256 # Compile Time Flags
257 ###########################################################################
258
259 #
260 # Include both the project headers and the LLVM headers for compilation and
261 # dependency computation.
262 #
263 # BUILD_OBJ_DIR          : Files local to the particular object directory
264 #                          (locallly generated header files).
265 # BUILD_SRC_DIR          : Files local to the particular source directory.
266 # BUILD_SRC_ROOT/include : Files global to the project.
267 # LLVM_OBJ_ROOT/include  : config.h files generated by autoconf
268 # LEVEL/include          : config.h files for the project
269 # LLVM_SRC_ROOT/include  : Files global to LLVM.
270 #
271 CPPFLAGS += -I$(BUILD_OBJ_DIR) -I$(BUILD_SRC_DIR) -I$(LLVM_OBJ_ROOT)/include \
272             -I$(BUILD_SRC_ROOT)/include -I$(LEVEL)/include \
273             -I$(LLVM_SRC_ROOT)/include
274
275 # By default, strip symbol information from executable
276 ifndef KEEP_SYMBOLS
277 STRIP = $(PLATFORMSTRIPOPTS)
278 STRIP_WARN_MSG = "(without symbols)"
279 endif
280
281 # Allow gnu extensions...
282 CPPFLAGS += -D_GNU_SOURCE
283
284 CompileWarnings  := -Wall -W  -Wwrite-strings -Wno-unused
285 CompileCommonOpts := $(CompileWarnings) -fshort-enums
286 CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions
287
288 #
289 # Compile commands with libtool.
290 #
291 Compile  := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
292 CompileC  := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(CompileCommonOpts)
293
294 # Compile a cpp file, don't link...
295 CompileG := $(Compile) -g  -D_DEBUG
296 CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
297 CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
298
299 # Compile a c file, don't link...
300 CompileCG := $(CompileC) -g  -D_DEBUG
301 CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
302 CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
303
304 ###########################################################################
305 # Link Time Options
306 ###########################################################################
307
308 #
309 # Link final executable
310 #       (Note that we always link with the C++ compiler).
311 #
312 Link     := $(LIBTOOL) --mode=link $(CXX)
313
314 # link both projlib and llvmlib libraries
315 LinkG    := $(Link) -g -L$(PROJLIBDEBUGSOURCE)  -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
316 LinkO    := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
317 LinkP    := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
318
319 # Create one .o file from a bunch of .o files...
320 Relink := ${LIBTOOL} --mode=link $(CXX)
321
322 #
323 # Configure where the item being compiled should go.
324 #
325 ifdef SHARED_LIBRARY
326 Link += -rpath $(DESTLIBCURRENT)
327 endif
328
329 ifdef TOOLNAME
330 Link += -rpath $(DESTTOOLCURRENT)
331 endif
332
333 # Create dependency file from CPP file, send to stdout.
334 Depend   := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS) 
335 DependC  := $(CC)  -MM -I$(LEVEL)/include $(CPPFLAGS) 
336
337 # Archive a bunch of .o files into a .a file...
338 AR       = ${AR_PATH} cq 
339
340 #----------------------------------------------------------
341
342 # Source includes all of the cpp files, and objects are derived from the
343 # source files...
344 # The local Makefile can list other Source files via ExtraSource = ...
345
346 ifndef Source
347 Source  := $(notdir $(ExtraSource) $(wildcard $(SourceDir)/*.cpp \
348                     $(SourceDir)/*.c $(SourceDir)/*.y $(SourceDir)/*.l))
349 endif
350
351 #
352 # Libtool Objects
353 #
354 Srcs := $(sort $(basename $(Source)))
355 Objs := $(addsuffix .lo, $(Srcs))
356 ObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(Objs))
357 ObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(Objs))
358 ObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(Objs))
359 ObjectsBC := $(addprefix $(BUILD_OBJ_DIR)/BytecodeObj/,$(addsuffix .bc, $(Srcs)))
360
361 #
362 # The real objects underlying the libtool objects
363 #
364 RObjs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(basename $(Source)))))
365 RObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(RObjs))
366 RObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(RObjs))
367 RObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(RObjs))
368
369 #---------------------------------------------------------
370 # Handle the DIRS and PARALLEL_DIRS options
371 #---------------------------------------------------------
372
373 ifdef DIRS
374 all install clean test bytecode ::
375         $(VERB) for dir in ${DIRS}; do \
376                 (cd $$dir; $(MAKE) $@) || exit 1; \
377         done
378 endif
379
380 # Handle PARALLEL_DIRS
381 ifdef PARALLEL_DIRS
382 all      :: $(addsuffix /.makeall     , $(PARALLEL_DIRS))
383 install  :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
384 clean    :: $(addsuffix /.makeclean   , $(PARALLEL_DIRS))
385 test     :: $(addsuffix /.maketest    , $(PARALLEL_DIRS))
386 bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
387
388 %/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode:
389         $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
390 endif
391
392 # Handle directories that may or may not exist
393 ifdef OPTIONAL_DIRS
394 all install clean test bytecode ::
395         $(VERB) for dir in ${OPTIONAL_DIRS}; do \
396                 if [ -d $$dir ]; \
397                 then\
398                         (cd $$dir; $(MAKE) $@) || exit 1; \
399                 fi \
400         done
401 endif
402
403 ###########################################################################
404 # Library Build Rules:
405 #
406 #---------------------------------------------------------
407 # Handle the LIBRARYNAME option - used when building libs...
408 #---------------------------------------------------------
409 #
410 #  When libraries are built, they are allowed to optionally define the
411 #  DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
412 #  from being built for the library. This .o files may then be linked to by a
413 #  tool if the tool does not need (or want) the semantics a .a file provides
414 #  (linking in only object files that are "needed").  If a library is never to
415 #  be used in this way, it is better to define DONT_BUILD_RELINKED, and define
416 #  BUILD_ARCHIVE instead.
417 #
418 #  Some libraries must be built as .a files (libscalar for example) because if
419 #  it's built as a .o file, then all of the constituent .o files in it will be
420 #  linked into tools (for example gccas) even if they only use one of the parts
421 #  of it.  For this reason, sometimes it's useful to use libraries as .a files.
422 ###########################################################################
423
424 ifdef LIBRARYNAME
425
426 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
427 LIBRARYNAME := $(strip $(LIBRARYNAME))
428
429 LIBNAME_O    := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
430 LIBNAME_P    := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
431 LIBNAME_G    := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
432 LIBNAME_AO   := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
433 LIBNAME_AP   := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
434 LIBNAME_AG   := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
435 LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
436 LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
437 LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
438 LIBNAME_BC   := $(DESTLIBBYTECODE)/lib$(LIBRARYNAME).bc
439
440 #--------------------------------------------------------------------
441 # Library Targets
442 #       Modify the top level targets to build the desired libraries.
443 #--------------------------------------------------------------------
444
445 # dynamic target builds a shared object version of the library...
446 dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
447 bytecodelib:: $(LIBNAME_BC)
448 bytecodelib-install:: $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc
449
450 $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc: $(LIBNAME_BC)
451         @echo ======= Installing $(LIBRARYNAME) bytecode library =======
452         cp $< $@
453
454 # Does the library want a .o version built?
455 ifndef DONT_BUILD_RELINKED
456 all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
457 endif
458
459 # Does the library want an archive version built?
460 ifdef BUILD_ARCHIVE
461 all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
462 endif
463
464 #--------------------------------------------------------------------
465 # Rules for building libraries
466 #--------------------------------------------------------------------
467
468 LinkBCLib := $(LLVMGCC) -shared
469 ifdef EXPORTED_SYMBOL_LIST
470 LinkBCLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
471 else
472   ifdef EXPORTED_SYMBOL_FILE
473 LinkBCLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
474   else
475 LinkBCLib += -Xlinker -disable-internalize
476   endif
477 endif
478
479
480 # Rule for building bytecode libraries.
481 $(LIBNAME_BC): $(ObjectsBC) $(LibSubDirs) $(DESTLIBBYTECODE)/.dir
482         @echo ======= Linking $(LIBRARYNAME) bytecode library =======
483         $(VERB) $(LinkBCLib) -o $@ $(ObjectsBC) $(LibSubDirs) $(LibLinkOpts)
484 #
485 # Rules for building dynamically linked libraries.
486 #
487 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
488         @echo ======= Linking $(LIBRARYNAME) dynamic release library =======
489         $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
490         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
491
492 $(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
493         @echo ======= Linking $(LIBRARYNAME) dynamic profile library =======
494         $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
495         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
496
497 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
498         @echo ======= Linking $(LIBRARYNAME) dynamic debug library =======
499         $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
500         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
501
502 #
503 # Rules for building static archive libraries.
504 #
505 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
506         @echo ======= Linking $(LIBRARYNAME) archive release library =======
507         @$(RM) -f $@
508         $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
509
510 $(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
511         @echo ======= Linking $(LIBRARYNAME) archive profile library =======
512         @$(RM) -f $@
513         $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
514
515 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
516         @echo ======= Linking $(LIBRARYNAME) archive debug library =======
517         @$(RM) -f $@
518         $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
519
520
521 #
522 # Rules for building .o libraries.
523 #
524 #       JTC:
525 #       Note that for this special case, we specify the actual object files
526 #       instead of their libtool counterparts.  This is because libtool
527 #       doesn't want to generate a reloadable object file unless it is given
528 #       .o files explicitly.
529 #
530 #       Note that we're making an assumption here: If we build a .lo file,
531 #       it's corresponding .o file will be placed in the same directory.
532 #
533 #       I think that is safe.
534 #
535 $(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
536         @echo "Linking $@"
537         $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
538
539 $(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
540         @echo "Linking $@"
541         $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
542
543 $(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
544         @echo "Linking $@"
545         $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
546
547 endif
548
549 #------------------------------------------------------------------------
550 # Create a TAGS database for emacs
551 #------------------------------------------------------------------------
552
553 ifdef ETAGS
554 ifeq ($(LEVEL), .)
555 SRCDIRS := $(wildcard $(SourceDir)/include $(SourceDir)/lib $(SourceDir)/tools)
556
557 tags:
558         $(ETAGS) -l c++ `find $(SRCDIRS) -name '*.cpp' -o -name '*.h'`
559 all:: tags
560 endif
561 else
562 tags:
563         ${ECHO} "Cannot build $@: The program etags is not installed"
564 endif
565
566 #------------------------------------------------------------------------
567 # Handle the TOOLNAME option - used when building tool executables...
568 #------------------------------------------------------------------------
569 #
570 # The TOOLNAME option should be used with a USEDLIBS variable that tells the
571 # libraries (and the order of the libs) that should be linked to the
572 # tool. USEDLIBS should contain a list of library names (some with .a extension)
573 # that are automatically linked in as .o files unless the .a suffix is added.
574 #
575 ifdef TOOLNAME
576
577 # TOOLEXENAME* - These compute the output filenames to generate...
578 TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
579 TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
580 TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
581 TOOLEXENAMES  := $(DESTTOOLCURRENT)/$(TOOLNAME)
582
583 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
584 PROJ_LIBS_OPTIONS   := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
585 PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o,  $(PROJ_LIBS_OPTIONS))
586 PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
587 PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
588
589 LLVM_LIBS_OPTIONS   := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
590 LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o,  $(LLVM_LIBS_OPTIONS))
591 LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
592 LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
593
594 LIB_OPTS_G :=  $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
595 LIB_OPTS_O :=  $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
596 LIB_OPTS_P :=  $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
597
598 # USED_LIB_PATHS - Compute the path of the libraries used so that tools are
599 # rebuilt if libraries change.  This has to make sure to handle .a/.so and .o
600 # files separately.
601 #
602 STATICUSEDLIBS   := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
603 USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
604 USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
605 USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
606
607 #
608 # Libtool link options:
609 #       Ensure that all binaries have their symbols exported so that they can
610 #       by dlsym'ed.
611 #
612 LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
613
614
615
616
617
618 # Tell make that we need to rebuild subdirectories before we can link the tool.
619 # This affects things like LLI which has library subdirectories.
620 $(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
621         $(addsuffix /.makeall, $(PARALLEL_DIRS))
622
623 all::   $(TOOLEXENAMES)
624
625 clean::
626         $(VERB) $(RM) -f $(TOOLEXENAMES)
627
628 $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
629         @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
630         $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
631
632 $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
633         @echo ======= Linking $(TOOLNAME) release executable =======
634         $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
635
636 $(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
637         @echo ======= Linking $(TOOLNAME) profile executable =======
638         $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
639
640 endif
641
642
643
644 #---------------------------------------------------------
645 .PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir $(BUILD_OBJ_DIR)/BytecodeObj/.dir
646 .PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
647
648 # Create .lo files in the ObjectFiles directory from the .cpp and .c files...
649 $(BUILD_OBJ_DIR)/Release/%.lo: %.cpp $(BUILD_OBJ_DIR)/Release/.dir
650         @echo "Compiling $<"
651         $(VERB) $(CompileO) $< -o $@
652
653 $(BUILD_OBJ_DIR)/Release/%.lo: %.c $(BUILD_OBJ_DIR)/Release/.dir
654         @echo "Compiling $<"
655         $(VERB) $(CompileCO) $< -o $@
656
657 $(BUILD_OBJ_DIR)/Profile/%.lo: %.cpp $(BUILD_OBJ_DIR)/Profile/.dir
658         @echo "Compiling $<"
659         $(VERB) $(CompileP) $< -o $@
660
661 $(BUILD_OBJ_DIR)/Profile/%.lo: %.c $(BUILD_OBJ_DIR)/Profile/.dir
662         @echo "Compiling $<"
663         $(VERB) $(CompileCP) $< -o $@
664
665 $(BUILD_OBJ_DIR)/Debug/%.lo: %.cpp $(BUILD_OBJ_DIR)/Debug/.dir
666         @echo "Compiling $<"
667         $(VERB) $(CompileG) $< -o $@
668
669 $(BUILD_OBJ_DIR)/Debug/%.lo: %.c $(BUILD_OBJ_DIR)/Debug/.dir 
670         @echo "Compiling $<"
671         $(VERB) $(CompileCG) $< -o $@
672
673 $(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.cpp $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LCC1XX)
674         @echo "Compiling $< to bytecode"
675         $(VERB) $(LLVMGXX) $(CompileWarnings) $(CPPFLAGS) -c $< -o $@
676
677 $(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.c $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LCC1)
678         @echo "Compiling $< to bytecode"
679         $(VERB) $(LLVMGCC) $(CompileWarnings) $(CPPFLAGS) -c $< -o $@
680
681 $(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.ll $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LLVMAS)
682         @echo "Compiling $< to bytecode"
683         $(VERB) $(LLVMAS) $< -f -o $@
684
685
686 #
687 # Rules for building lex/yacc files
688 #
689 LEX_FILES   = $(filter %.l, $(Source))
690 LEX_OUTPUT  = $(LEX_FILES:%.l=%.cpp)
691 YACC_FILES  = $(filter %.y, $(Source))
692 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
693 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
694
695 # Create a .cpp source file from a flex input file... this uses sed to cut down
696 # on the warnings emited by GCC...
697 #
698 # The last line is a gross hack to work around flex aparently not being able to
699 # resize the buffer on a large token input.  Currently, for uninitialized string
700 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
701 # FIXME.  (f.e. char Buffer[10000] )
702 #
703 %.cpp: %.l
704         @echo Flexing $<
705         $(VERB) $(FLEX) -t $< | \
706           $(SED) '/^find_rule/d' | \
707           $(SED) 's/void yyunput/inline void yyunput/' | \
708           $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
709           $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
710               > $@.tmp
711         $(VERB) cmp -s $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
712         @# remove the output of flex if it didn't get moved over...
713         @rm -f $@.tmp
714
715 # Rule for building the bison parsers...
716 %.c: %.y     # Cancel built-in rules for yacc
717 %.h: %.y     # Cancel built-in rules for yacc
718 %.cpp %.h : %.y
719         @echo Bisoning $<
720         $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c  $<
721         $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
722         $(VERB) cmp -s $*.tab.h $*.h   > /dev/null || ${MV} -f $*.tab.h $*.h
723         @# If the files were not updated, don't leave them lying around...
724         @rm -f $*.tab.c $*.tab.h
725
726 # To create the directories...
727 %/.dir:
728         $(VERB) ${MKDIR} $* > /dev/null
729         @$(DATE) > $@
730
731 # To create postscript files from dot files...
732 ifdef DOT
733 %.ps: %.dot
734         ${DOT} -Tps < $< > $@
735 else
736 %.ps: %.dot
737         ${ECHO} "Cannot build $@: The program dot is not installed"
738 endif
739
740 #
741 # This rules ensures that header files that are removed still have a rule for
742 # which they can be "generated."  This allows make to ignore them and
743 # reproduce the dependency lists.
744 #
745 %.h:: ;
746
747 # 'make clean' nukes the tree
748 clean::
749         $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
750         $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
751         $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/BytecodeObj
752         $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
753         $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
754
755 ###########################################################################
756 # C/C++ Dependencies
757 #       Define variables and rules that generate header file dependencies
758 #       from C/C++ source files.
759 ###########################################################################
760
761 ifndef DISABLE_AUTO_DEPENDENCIES
762
763 # If dependencies were generated for the file that included this file,
764 # include the dependencies now...
765 #
766 SourceBaseNames := $(basename $(Source))
767 SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
768
769 # Create dependencies for the *.cpp files...
770 $(BUILD_OBJ_DIR)/Depend/%.d: %.cpp $(BUILD_OBJ_DIR)/Depend/.dir
771         $(VERB) $(Depend) $< | $(SED) 's|\.o|\.lo|' | $(SED) 's|$*\.lo *|$(BUILD_OBJ_DIR)/Release/& $(BUILD_OBJ_DIR)/Profile/& $(BUILD_OBJ_DIR)/Debug/& $(BUILD_OBJ_DIR)/Depend/$(@F)|g' > $@
772
773 # Create dependencies for the *.c files...
774 $(BUILD_OBJ_DIR)/Depend/%.d: %.c $(BUILD_OBJ_DIR)/Depend/.dir
775         $(VERB) $(DependC) -o $@ $< | $(SED) 's|\.o|\.lo|' | $(SED) 's|$*\.lo *|$(BUILD_OBJ_DIR)/Release/& $(BUILD_OBJ_DIR)/Profile/& $(BUILD_OBJ_DIR)/Debug/& $(BUILD_OBJ_DIR)/Depend/$(@F)|g' > $@
776
777 #
778 # Include dependencies generated from C/C++ source files, but not if we
779 # are cleaning (this example taken from the GNU Make Manual).
780 #
781 ifneq ($(MAKECMDGOALS),clean)
782 ifneq ($(MAKECMDGOALS),distclean)
783 -include /dev/null $(SourceDepend)
784 endif
785 endif
786
787 endif  # ifndef DISABLE_AUTO_DEPENDENCIES