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