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