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