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