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