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