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