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