]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - opencl/llvm.git/blob - Makefile.common
Implement BYTECODE_LIBRARY support
[opencl/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 #===-----------------------------------------------------------------------====
53 #
54 # Configuration file to set paths specific to local installation of LLVM
55
56 include $(LEVEL)/Makefile.config
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 ###########################################################################
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
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
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))
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
107 # Set the root of the object directory.
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
118 # Set the LLVM source directory.
119 # It is typically the root directory of what we're compiling now.
121 ifndef LLVM_SRC_ROOT
122 LLVM_SRC_ROOT := $(BUILD_SRC_ROOT)
123 endif
126 # Set the LLVM object directory.
128 ifndef LLVM_OBJ_ROOT
129 LLVM_OBJ_ROOT := $(BUILD_OBJ_ROOT)
130 endif
132 ###########################################################################
133 # Default Targets:
134 #       The following targets are the standard top level targets for
135 #       building.
136 ###########################################################################
138 ifdef SHARED_LIBRARY
139 # if SHARED_LIBRARY is specified, the default is to build the dynamic lib
140 all:: dynamic
141 endif
143 ifdef BYTECODE_LIBRARY
144 # if BYTECODE_LIBRARY is specified, the default is to build the bytecode lib
145 all:: bytecodelib
146 install:: bytecodelib-install
147 endif
149 # Default Rule:  Make sure it's also a :: rule
150 all ::
152 # Default for install is to at least build everything...
153 install ::
155 # Default rule for test.  It ensures everything has a test rule
156 test::
158 # Default rule for building only bytecode.
159 bytecode::
161 # Print out the directories used for building
162 prdirs::
163         echo "Home Offset      : " $(HOME_OBJ_ROOT);
164         echo "Build Source Root: " $(BUILD_SRC_ROOT);
165         echo "Build Source Dir : " $(BUILD_SRC_DIR);
166         echo "Build Object Root: " $(BUILD_OBJ_ROOT);
167         echo "Build Object Dir : " $(BUILD_OBJ_DIR);
168         echo "LLVM  Source Root: " $(LLVM_SRC_ROOT);
169         echo "LLVM  Object Root: " $(LLVM_OBJ_ROOT);
172 # Mark all of these targets as phony.  This will hopefully speed up builds
173 # slightly since GNU Make will not try to find implicit rules for targets
174 # which are marked as Phony.
176 .PHONY: all dynamic bytecodelib bytecodelib-install
177 .PHONY: clean distclean install test bytecode prdirs
179 ###########################################################################
180 # Miscellaneous paths and commands:
181 #       This section defines various configuration macros, such as where
182 #       to find burg, tblgen, and libtool.
183 ###########################################################################
185 #--------------------------------------------------------------------
186 # Variables derived from configuration options... 
187 #--------------------------------------------------------------------
189 #BinInstDir=/usr/local/bin
190 #LibInstDir=/usr/local/lib/xxx
191 #DocInstDir=/usr/doc/xxx
193 BURG_OPTS = -I
195 ifdef ENABLE_PROFILING
196   ENABLE_OPTIMIZED = 1
197   CONFIGURATION := Profile
198 else
199   ifdef ENABLE_OPTIMIZED
200     CONFIGURATION := Release
201   else
202     CONFIGURATION := Debug
203   endif
204 endif
207 # Enable this for profiling support with 'gprof'
208 # This automatically enables optimized builds.
210 ifdef ENABLE_PROFILING
211   PROFILE = -pg
212 endif
215 # Suffixes for library compilation rules
217 .SUFFIXES: .so
219 ###########################################################################
220 # Library Locations:
221 #       These variables describe various library locations:
223 #       DEST* = Location of where libraries that are built will be placed.
224 #       LLVM* = Location of LLVM libraries used for linking.
225 #       PROJ* = Location of previously built libraries used for linking.
226 ###########################################################################
228 # Libraries that are being built
229 DESTLIBDEBUG    := $(BUILD_OBJ_ROOT)/lib/Debug
230 DESTLIBRELEASE  := $(BUILD_OBJ_ROOT)/lib/Release
231 DESTLIBPROFILE  := $(BUILD_OBJ_ROOT)/lib/Profile
232 DESTLIBBYTECODE := $(BUILD_OBJ_ROOT)/lib/Bytecode
233 DESTLIBCURRENT  := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
235 # LLVM libraries used for linking
236 LLVMLIBDEBUGSOURCE    := $(LLVM_OBJ_ROOT)/lib/Debug
237 LLVMLIBRELEASESOURCE  := $(LLVM_OBJ_ROOT)/lib/Release
238 LLVMLIBPROFILESOURCE  := $(LLVM_OBJ_ROOT)/lib/Profile
239 LLVMLIBCURRENTSOURCE  := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
241 # Libraries that were built that will now be used for linking
242 PROJLIBDEBUGSOURCE    := $(BUILD_OBJ_ROOT)/lib/Debug
243 PROJLIBRELEASESOURCE  := $(BUILD_OBJ_ROOT)/lib/Release
244 PROJLIBPROFILESOURCE  := $(BUILD_OBJ_ROOT)/lib/Profile
245 PROJLIBCURRENTSOURCE  := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
247 ###########################################################################
248 # Tool Locations
249 #       These variables describe various tool locations:
251 #       DEST* = Location of where tools that are built will be placed.
252 #       LLVM* = Location of LLVM tools used for building.
253 #       PROJ* = Location of previously built tools used for linking.
254 ###########################################################################
256 DESTTOOLDEBUG   := $(BUILD_OBJ_ROOT)/tools/Debug
257 DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
258 DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
259 DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
261 LLVMTOOLDEBUG   := $(LLVM_OBJ_ROOT)/tools/Debug
262 LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release
263 LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile
264 LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
266 PROJTOOLDEBUG   := $(BUILD_OBJ_ROOT)/tools/Debug
267 PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release
268 PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile
269 PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
272 # Libtool is found in the current directory.
274 LIBTOOL := $(LLVM_SRC_ROOT)/mklib
277 # If we're not building a shared library, use the disable-shared tag with
278 # libtool.  This will disable the building of objects for shared libraries and
279 # only generate static library objects.
281 # For dynamic libraries, we'll take the performance hit for now, since we
282 # almost never build them.
284 # This should speed up compilation and require no modifications to future
285 # versions of libtool.
287 ifndef SHARED_LIBRARY
288 LIBTOOL += --tag=disable-shared
289 endif
292 # Verbosity levels
294 ifndef VERBOSE
295 VERB := @
296 LIBTOOL += --silent
297 endif
299 ###########################################################################
300 # Miscellaneous paths and commands (part deux):
301 #       This section defines various configuration macros, such as where
302 #       to find burg, tblgen, and libtool.
303 ###########################################################################
305 #--------------------------------------------------------------------------
306 # Utilities used while building the LLVM tree, which live in the utils dir
308 BURG    := $(LLVMTOOLCURRENT)/burg
309 RunBurg := $(BURG) $(BURG_OPTS)
310 TBLGEN  := $(LLVMTOOLCURRENT)/tblgen
312 #--------------------------------------------------------------------------
313 # The LLVM GCC front-end in C and C++ flavors
315 LLVMGCC := $(LLVMGCCDIR)/bin/gcc
316 LCC1    := $(LLVMGCCDIR)/lib/gcc-lib/$(LLVMGCCARCH)/cc1
317 LLVMGXX := $(LLVMGCCDIR)/bin/g++
318 LCC1XX  := $(LLVMGCCDIR)/lib/gcc-lib/$(LLVMGCCARCH)/cc1plus
320 #--------------------------------------------------------------------------
321 # Some of the compiled LLVM tools which are used for compilation of runtime
322 # libraries.
324 LLVMAS  := $(LLVMTOOLCURRENT)/as
327 ###########################################################################
328 # Compile Time Flags
329 ###########################################################################
332 # Include both the project headers and the LLVM headers for compilation and
333 # dependency computation.
335 CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include
337 # By default, strip symbol information from executable
338 ifndef KEEP_SYMBOLS
339 STRIP = $(PLATFORMSTRIPOPTS)
340 STRIP_WARN_MSG = "(without symbols)"
341 endif
343 # Allow gnu extensions...
344 CPPFLAGS += -D_GNU_SOURCE
346 CompileCommonOpts := -Wall -W  -Wwrite-strings -Wno-unused -I$(LEVEL)/include
347 CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums
350 # Compile commands with libtool.
352 Compile  := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
353 CompileC  := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts)
355 # Compile a cpp file, don't link...
356 CompileG := $(Compile) -g  -D_DEBUG
357 CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
358 CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
360 # Compile a c file, don't link...
361 CompileCG := $(CompileC) -g  -D_DEBUG
362 CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
363 CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
365 ###########################################################################
366 # Link Time Options
367 ###########################################################################
370 # Link final executable
371 #       (Note that we always link with the C++ compiler).
373 Link     := $(LIBTOOL) --mode=link $(CXX)
375 # link both projlib and llvmlib libraries
376 LinkG    := $(Link) -g -L$(PROJLIBDEBUGSOURCE)  -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
377 LinkO    := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
378 LinkP    := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
380 # Create one .o file from a bunch of .o files...
381 Relink := ${LIBTOOL} --mode=link $(CXX)
382 ifndef SHARED_LIBRARY
383 Relink += -only-static
384 endif
387 # Configure where the item being compiled should go.
389 ifdef SHARED_LIBRARY
390 Link += -rpath $(DESTLIBCURRENT)
391 endif
393 ifdef TOOLNAME
394 Link += -rpath $(DESTTOOLCURRENT)
395 endif
397 # Create dependancy file from CPP file, send to stdout.
398 Depend   := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS) 
399 DependC  := $(CC)  -MM -I$(LEVEL)/include $(CPPFLAGS) 
401 # Archive a bunch of .o files into a .a file...
402 AR       = ${AR_PATH} cq 
404 #----------------------------------------------------------
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
415 # Libtool Objects
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)))
425 # The real objects underlying the libtool objects
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))
432 #---------------------------------------------------------
433 # Handle the DIRS and PARALLEL_DIRS options
434 #---------------------------------------------------------
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
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))
451 %/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode:
452         $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@)
453 endif
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
466 ###########################################################################
467 # Library Build Rules:
469 #---------------------------------------------------------
470 # Handle the LIBRARYNAME option - used when building libs...
471 #---------------------------------------------------------
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.
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 ###########################################################################
487 ifdef LIBRARYNAME
489 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
490 LIBRARYNAME := $(strip $(LIBRARYNAME))
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
503 #--------------------------------------------------------------------
504 # Library Targets
505 #       Modify the top level targets to build the desired libraries.
506 #--------------------------------------------------------------------
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
513 $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc: $(LIBNAME_BC)
514         @echo ======= Installing $(LIBRARYNAME) bytecode library =======
515         cp $< $@
517 # Does the library want a .o version built?
518 ifndef DONT_BUILD_RELINKED
519 all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o
520 endif
522 # Does the library want an archive version built?
523 ifdef BUILD_ARCHIVE
524 all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
525 endif
527 #--------------------------------------------------------------------
528 # Rules for building libraries
529 #--------------------------------------------------------------------
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
539 # Rule for building bytecode libraries.
540 $(LIBNAME_BC): $(ObjectsBC) $(LibSubDirs)
541         @echo ======= Linking $(LIBRARYNAME) bytecode library =======
542         $(VERB) $(LinkBCLib) -o $@ $(ObjectsBC) $(LibSubDirs) $(LibLinkOpts)
544 # Rules for building dynamically linked libraries.
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);
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);
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);
562 # Rules for building static archive libraries.
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
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
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
581 # Rules for building .o libraries.
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.
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.
592 #       I think that is safe.
594 $(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
595         @echo "Linking $@"
596         $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
598 $(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
599         @echo "Linking $@"
600         $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
602 $(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
603         @echo "Linking $@"
604         $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
606 endif
608 #------------------------------------------------------------------------
609 # Create a TAGS database for emacs
610 #------------------------------------------------------------------------
612 ifdef ETAGS
613 ifeq ($(LEVEL), .)
614 tags:
615         $(ETAGS) -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
616 all:: tags
617 endif
618 else
619 tags:
620         ${ECHO} "Cannot build $@: The program etags is not installed"
621 endif
623 #------------------------------------------------------------------------
624 # Handle the TOOLNAME option - used when building tool executables...
625 #------------------------------------------------------------------------
627 # The TOOLNAME option should be used with a USEDLIBS variable that tells the
628 # libraries (and the order of the libs) that should be linked to the
629 # tool. USEDLIBS should contain a list of library names (some with .a extension)
630 # that are automatically linked in as .o files unless the .a suffix is added.
632 ifdef TOOLNAME
634 # TOOLEXENAME* - These compute the output filenames to generate...
635 TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
636 TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
637 TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
638 TOOLEXENAMES  := $(DESTTOOLCURRENT)/$(TOOLNAME)
640 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
641 PROJ_LIBS_OPTIONS   := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
642 PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o,  $(PROJ_LIBS_OPTIONS))
643 PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
644 PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
646 LLVM_LIBS_OPTIONS   := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
647 LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o,  $(LLVM_LIBS_OPTIONS))
648 LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
649 LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
651 LIB_OPTS_G :=  $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
652 LIB_OPTS_O :=  $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
653 LIB_OPTS_P :=  $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
655 # USED_LIB_PATHS - Compute the path of the libraries used so that tools are
656 # rebuilt if libraries change.  This has to make sure to handle .a/.so and .o
657 # files separately.
659 STATICUSEDLIBS   := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
660 USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
661 USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
662 USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
663 #LINK_OPTS        := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS)
666 # Libtool link options:
667 #       Ensure that all binaries have their symbols exported so that they can
668 #       by dlsym'ed.
670 LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
676 # Tell make that we need to rebuild subdirectories before we can link the tool.
677 # This affects things like LLI which has library subdirectories.
678 $(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
679         $(addsuffix /.makeall, $(PARALLEL_DIRS))
681 all::   $(TOOLEXENAMES)
683 clean::
684         $(VERB) $(RM) -f $(TOOLEXENAMES)
686 $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
687         @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
688         $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
690 $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
691         @echo ======= Linking $(TOOLNAME) release executable =======
692         $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
694 $(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
695         @echo ======= Linking $(TOOLNAME) profile executable =======
696         $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
698 endif
702 #---------------------------------------------------------
703 .PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir $(BUILD_OBJ_DIR)/Bytecode/.dir
704 .PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
706 # Create .lo files in the ObjectFiles directory from the .cpp and .c files...
707 $(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir
708         @echo "Compiling $<"
709         $(VERB) $(CompileO) $< -o $@
711 $(BUILD_OBJ_DIR)/Release/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir
712         @echo "Compiling $<"
713         $(VERB) $(CompileCO) $< -o $@
715 $(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir
716         @echo "Compiling $<"
717         $(VERB) $(CompileP) $< -o $@
719 $(BUILD_OBJ_DIR)/Profile/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir
720         @echo "Compiling $<"
721         $(VERB) $(CompileCP) $< -o $@
723 $(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir
724         @echo "Compiling $<"
725         $(VERB) $(CompileG) $< -o $@
727 $(BUILD_OBJ_DIR)/Debug/%.lo: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir 
728         @echo "Compiling $<"
729         $(VERB) $(CompileCG) $< -o $@
731 $(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1XX)
732         @echo "Compiling $< to bytecode"
733         $(VERB) $(LLVMGXX) $(CPPFLAGS) -c $< -o $@
735 $(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1)
736         @echo "Compiling $< to bytecode"
737         $(VERB) $(LLVMGCC) $(CPPFLAGS) -c $< -o $@
739 $(BUILD_OBJ_DIR)/Bytecode/%.bc: $(SourceDir)%.ll $(BUILD_OBJ_DIR)/Bytecode/.dir $(LCC1)
740         @echo "Compiling $< to bytecode"
741         $(VERB) $(LLVMAS) $< -f -o $@
745 # Rules for building lex/yacc files
747 LEX_FILES   = $(filter %.l, $(Source))
748 LEX_OUTPUT  = $(LEX_FILES:%.l=%.cpp)
749 YACC_FILES  = $(filter %.y, $(Source))
750 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
751 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
753 # Create a .cpp source file from a flex input file... this uses sed to cut down
754 # on the warnings emited by GCC...
756 # The last line is a gross hack to work around flex aparently not being able to
757 # resize the buffer on a large token input.  Currently, for uninitialized string
758 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
759 # FIXME.  (f.e. char Buffer[10000]; )
761 %.cpp: %.l
762         @echo Flex\'ing $<...
763         $(VERB) $(FLEX) -t $< | \
764           $(SED) '/^find_rule/d' | \
765           $(SED) 's/void yyunput/inline void yyunput/' | \
766           $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
767           $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
768               > $@.tmp
769         $(VERB) cmp -s $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
770         @# remove the output of flex if it didn't get moved over...
771         @rm -f $@.tmp
773 # Rule for building the bison parsers...
774 %.c: %.y     # Cancel built-in rules for yacc
775 %.h: %.y     # Cancel built-in rules for yacc
776 %.cpp %.h : %.y
777         @echo Bison\'ing $<...
778         $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y
779         $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
780         $(VERB) cmp -s $*.tab.h $*.h   > /dev/null || ${MV} -f $*.tab.h $*.h
781         @# If the files were not updated, don't leave them lying around...
782         @rm -f $*.tab.c $*.tab.h
784 # To create the directories...
785 %/.dir:
786         $(VERB) ${MKDIR} $* > /dev/null
787         @$(DATE) > $@
789 # To create postscript files from dot files...
790 ifdef DOT
791 %.ps: %.dot
792         ${DOT} -Tps < $< > $@
793 else
794 %.ps: %.dot
795         ${ECHO} "Cannot build $@: The program dot is not installed"
796 endif
798 # 'make clean' nukes the tree
799 clean::
800         $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
801         $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
802         $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Bytecode
803         $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
804         $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
806 ###########################################################################
807 # C/C++ Dependencies
808 #       Define variables and rules that generate header file dependencies
809 #       from C/C++ source files.
810 ###########################################################################
812 # If dependencies were generated for the file that included this file,
813 # include the dependancies now...
815 SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source))))
816 SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
818 # Create dependencies for the *.cpp files...
819 #$(SourceDepend): \x
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' > $@
823 # Create dependencies for the *.c files...
824 #$(SourceDepend): \x
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' > $@
829 # Include dependencies generated from C/C++ source files, but not if we
830 # are cleaning (this example taken from the GNU Make Manual).
832 ifneq ($(MAKECMDGOALS),clean)
833 ifneq ($(MAKECMDGOALS),distclean)
834 ifneq ($(SourceDepend),)
835 -include $(SourceDepend)
836 endif
837 endif
838 endif