Point to the correct cc1/cc1plus binaries
[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 cleandeps 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 cleandeps 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 cleandeps:: $(addsuffix /.makecleandeps, $(PARALLEL_DIRS))
453 test     :: $(addsuffix /.maketest    , $(PARALLEL_DIRS))
454 bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
455
456 %/.makeall %/.makeinstall %/.makeclean %/.makecleandeps %/.maketest \
457     %/.makebytecode:
458         $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
459 endif
460
461 # Handle directories that may or may not exist
462 ifdef OPTIONAL_DIRS
463 all install clean cleandeps test bytecode ::
464         $(VERB) for dir in ${OPTIONAL_DIRS}; do \
465                 if [ -d $$dir ]; \
466                 then\
467                         (cd $$dir; $(MAKE) $@) || exit 1; \
468                 fi \
469         done
470 endif
471
472 ###########################################################################
473 # Library Build Rules:
474 #
475 #---------------------------------------------------------
476 # Handle the LIBRARYNAME option - used when building libs...
477 #---------------------------------------------------------
478 #
479 #  When libraries are built, they are allowed to optionally define the
480 #  DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
481 #  from being built for the library. This .o files may then be linked to by a
482 #  tool if the tool does not need (or want) the semantics a .a file provides
483 #  (linking in only object files that are "needed").  If a library is never to
484 #  be used in this way, it is better to define DONT_BUILD_RELINKED, and define
485 #  BUILD_ARCHIVE instead.
486 #
487 #  Some libraries must be built as .a files (libscalar for example) because if
488 #  it's built as a .o file, then all of the constituent .o files in it will be
489 #  linked into tools (for example gccas) even if they only use one of the parts
490 #  of it.  For this reason, sometimes it's useful to use libraries as .a files.
491 ###########################################################################
492
493 ifdef LIBRARYNAME
494
495 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
496 LIBRARYNAME := $(strip $(LIBRARYNAME))
497
498 LIBNAME_O    := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
499 LIBNAME_P    := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
500 LIBNAME_G    := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
501 LIBNAME_AO   := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
502 LIBNAME_AP   := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
503 LIBNAME_AG   := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
504 LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
505 LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
506 LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
507 LIBNAME_BC   := $(DESTLIBBYTECODE)/lib$(LIBRARYNAME).bc
508
509 #--------------------------------------------------------------------
510 # Library Targets
511 #       Modify the top level targets to build the desired libraries.
512 #--------------------------------------------------------------------
513
514 # dynamic target builds a shared object version of the library...
515 dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
516 bytecodelib:: $(LIBNAME_BC)
517 bytecodelib-install:: $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc
518
519 $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc: $(LIBNAME_BC)
520         @echo ======= Installing $(LIBRARYNAME) bytecode library =======
521         cp $< $@
522
523 # Does the library want a .o version built?
524 ifndef DONT_BUILD_RELINKED
525 all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
526 endif
527
528 # Does the library want an archive version built?
529 ifdef BUILD_ARCHIVE
530 all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
531 endif
532
533 #--------------------------------------------------------------------
534 # Rules for building libraries
535 #--------------------------------------------------------------------
536
537 LinkBCLib := $(LLVMGCC) -shared
538 ifdef EXPORTED_SYMBOL_LIST
539 LinkBCLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
540 else
541 LinkBCLib += -Xlinker -disable-internalize
542 endif
543
544
545 # Rule for building bytecode libraries.
546 $(LIBNAME_BC): $(ObjectsBC) $(LibSubDirs) $(DESTLIBBYTECODE)/.dir
547         @echo ======= Linking $(LIBRARYNAME) bytecode library =======
548         $(VERB) $(LinkBCLib) -o $@ $(ObjectsBC) $(LibSubDirs) $(LibLinkOpts)
549 #
550 # Rules for building dynamically linked libraries.
551 #
552 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
553         @echo ======= Linking $(LIBRARYNAME) dynamic release library =======
554         $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
555         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
556
557 $(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
558         @echo ======= Linking $(LIBRARYNAME) dynamic profile library =======
559         $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
560         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
561
562 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
563         @echo ======= Linking $(LIBRARYNAME) dynamic debug library =======
564         $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
565         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
566
567 #
568 # Rules for building static archive libraries.
569 #
570 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
571         @echo ======= Linking $(LIBRARYNAME) archive release library =======
572         @$(RM) -f $@
573         $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
574
575 $(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
576         @echo ======= Linking $(LIBRARYNAME) archive profile library =======
577         @$(RM) -f $@
578         $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
579
580 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
581         @echo ======= Linking $(LIBRARYNAME) archive debug library =======
582         @$(RM) -f $@
583         $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
584
585
586 #
587 # Rules for building .o libraries.
588 #
589 #       JTC:
590 #       Note that for this special case, we specify the actual object files
591 #       instead of their libtool counterparts.  This is because libtool
592 #       doesn't want to generate a reloadable object file unless it is given
593 #       .o files explicitly.
594 #
595 #       Note that we're making an assumption here: If we build a .lo file,
596 #       it's corresponding .o file will be placed in the same directory.
597 #
598 #       I think that is safe.
599 #
600 $(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
601         @echo "Linking $@"
602         $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
603
604 $(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
605         @echo "Linking $@"
606         $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
607
608 $(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
609         @echo "Linking $@"
610         $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
611
612 endif
613
614 #------------------------------------------------------------------------
615 # Create a TAGS database for emacs
616 #------------------------------------------------------------------------
617
618 ifdef ETAGS
619 ifeq ($(LEVEL), .)
620 tags:
621         $(ETAGS) -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
622 all:: tags
623 endif
624 else
625 tags:
626         ${ECHO} "Cannot build $@: The program etags is not installed"
627 endif
628
629 #------------------------------------------------------------------------
630 # Handle the TOOLNAME option - used when building tool executables...
631 #------------------------------------------------------------------------
632 #
633 # The TOOLNAME option should be used with a USEDLIBS variable that tells the
634 # libraries (and the order of the libs) that should be linked to the
635 # tool. USEDLIBS should contain a list of library names (some with .a extension)
636 # that are automatically linked in as .o files unless the .a suffix is added.
637 #
638 ifdef TOOLNAME
639
640 # TOOLEXENAME* - These compute the output filenames to generate...
641 TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
642 TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
643 TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
644 TOOLEXENAMES  := $(DESTTOOLCURRENT)/$(TOOLNAME)
645
646 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
647 PROJ_LIBS_OPTIONS   := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
648 PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o,  $(PROJ_LIBS_OPTIONS))
649 PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
650 PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
651
652 LLVM_LIBS_OPTIONS   := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
653 LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o,  $(LLVM_LIBS_OPTIONS))
654 LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
655 LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
656
657 LIB_OPTS_G :=  $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
658 LIB_OPTS_O :=  $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
659 LIB_OPTS_P :=  $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
660
661 # USED_LIB_PATHS - Compute the path of the libraries used so that tools are
662 # rebuilt if libraries change.  This has to make sure to handle .a/.so and .o
663 # files separately.
664 #
665 STATICUSEDLIBS   := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
666 USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
667 USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
668 USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
669
670 #
671 # Libtool link options:
672 #       Ensure that all binaries have their symbols exported so that they can
673 #       by dlsym'ed.
674 #
675 LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
676
677
678
679
680
681 # Tell make that we need to rebuild subdirectories before we can link the tool.
682 # This affects things like LLI which has library subdirectories.
683 $(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
684         $(addsuffix /.makeall, $(PARALLEL_DIRS))
685
686 all::   $(TOOLEXENAMES)
687
688 clean::
689         $(VERB) $(RM) -f $(TOOLEXENAMES)
690
691 $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
692         @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
693         $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
694
695 $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
696         @echo ======= Linking $(TOOLNAME) release executable =======
697         $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
698
699 $(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
700         @echo ======= Linking $(TOOLNAME) profile executable =======
701         $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
702
703 endif
704
705
706
707 #---------------------------------------------------------
708 .PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir $(BUILD_OBJ_DIR)/Bytecode/.dir
709 .PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
710
711 # Create .lo files in the ObjectFiles directory from the .cpp and .c files...
712 $(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
713         @echo "Compiling $<"
714         $(VERB) $(CompileO) $< -o $@
715
716 $(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
717         @echo "Compiling $<"
718         $(VERB) $(CompileCO) $< -o $@
719
720 $(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
721         @echo "Compiling $<"
722         $(VERB) $(CompileP) $< -o $@
723
724 $(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
725         @echo "Compiling $<"
726         $(VERB) $(CompileCP) $< -o $@
727
728 $(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
729         @echo "Compiling $<"
730         $(VERB) $(CompileG) $< -o $@
731
732 $(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir 
733         @echo "Compiling $<"
734         $(VERB) $(CompileCG) $< -o $@
735
736 $(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1XX)
737         @echo "Compiling $< to bytecode"
738         $(VERB) $(LLVMGXX) $(CPPFLAGS) -c $< -o $@
739
740 $(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1)
741         @echo "Compiling $< to bytecode"
742         $(VERB) $(LLVMGCC) $(CPPFLAGS) -c $< -o $@
743
744 $(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.ll $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1)
745         @echo "Compiling $< to bytecode"
746         $(VERB) $(LLVMAS) $< -f -o $@
747
748
749 #
750 # Rules for building lex/yacc files
751 #
752 LEX_FILES   = $(filter %.l, $(Source))
753 LEX_OUTPUT  = $(LEX_FILES:%.l=%.cpp)
754 YACC_FILES  = $(filter %.y, $(Source))
755 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
756 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
757
758 # Create a .cpp source file from a flex input file... this uses sed to cut down
759 # on the warnings emited by GCC...
760 #
761 # The last line is a gross hack to work around flex aparently not being able to
762 # resize the buffer on a large token input.  Currently, for uninitialized string
763 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
764 # FIXME.  (f.e. char Buffer[10000] )
765 #
766 %.cpp: %.l
767         @echo Flex\'ing $<...
768         $(VERB) $(FLEX) -t $< | \
769           $(SED) '/^find_rule/d' | \
770           $(SED) 's/void yyunput/inline void yyunput/' | \
771           $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
772           $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
773               > $@.tmp
774         $(VERB) cmp -s $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
775         @# remove the output of flex if it didn't get moved over...
776         @rm -f $@.tmp
777
778 # Rule for building the bison parsers...
779 %.c: %.y     # Cancel built-in rules for yacc
780 %.h: %.y     # Cancel built-in rules for yacc
781 %.cpp %.h : %.y
782         @echo Bison\'ing $<...
783         $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
784         $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
785         $(VERB) cmp -s $*.tab.h $*.h   > /dev/null || ${MV} -f $*.tab.h $*.h
786         @# If the files were not updated, don't leave them lying around...
787         @rm -f $*.tab.c $*.tab.h
788
789 # To create the directories...
790 %/.dir:
791         $(VERB) ${MKDIR} $* > /dev/null
792         @$(DATE) > $@
793
794 # To create postscript files from dot files...
795 ifdef DOT
796 %.ps: %.dot
797         ${DOT} -Tps < $< > $@
798 else
799 %.ps: %.dot
800         ${ECHO} "Cannot build $@: The program dot is not installed"
801 endif
802
803 # 'make clean' nukes the tree
804 clean::
805         $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
806         $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
807         $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Bytecode
808         $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
809         $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
810
811 ###########################################################################
812 # C/C++ Dependencies
813 #       Define variables and rules that generate header file dependencies
814 #       from C/C++ source files.
815 ###########################################################################
816
817 # If dependencies were generated for the file that included this file,
818 # include the dependancies now...
819 #
820 SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
821 SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
822
823 # Create dependencies for the *.cpp files...
824 #$(SourceDepend): \x
825 $(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Depend/.dir
826         $(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' > $@
827
828 # Create dependencies for the *.c files...
829 #$(SourceDepend): \x
830 $(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Depend/.dir
831         $(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' > $@
832
833 #
834 # Include dependencies generated from C/C++ source files, but not if we
835 # are cleaning (this example taken from the GNU Make Manual).
836 #
837 ifneq ($(MAKECMDGOALS),clean)
838 ifneq ($(MAKECMDGOALS),distclean)
839 ifneq ($(MAKECMDGOALS),cleandeps)
840 ifneq ($(SourceDepend),)
841 -include $(SourceDepend)
842 endif
843 endif
844 endif
845 endif
846
847 cleandeps::
848         $(VERB) rm -f $(SourceDepend)
849