2390897c6b3cc7740eeab9477f94a279a38e2579
[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
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 .so .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 LCC1    := $(LLVMGCCDIR)/libexec/gcc/$(LLVMGCCARCH)/cc1
253 LLVMGXX := PATH=$(LLVMTOOLCURRENT):$(PATH) $(LLVMGCCDIR)/bin/g++
254 LCC1XX  := $(LLVMGCCDIR)/libexec/gcc/$(LLVMGCCARCH)/cc1plus
255
256 #--------------------------------------------------------------------------
257 # Some of the compiled LLVM tools which are used for compilation of runtime
258 # libraries.
259 #
260 LLVMAS  := $(LLVMTOOLCURRENT)/llvm-as
261
262
263 ###########################################################################
264 # Compile Time Flags
265 ###########################################################################
266
267 #
268 # Include both the project headers and the LLVM headers for compilation and
269 # dependency computation.
270 #
271 # BUILD_OBJ_DIR          : Files local to the particular object directory
272 #                          (locallly generated header files).
273 # BUILD_SRC_DIR          : Files local to the particular source directory.
274 # BUILD_SRC_ROOT/include : Files global to the project.
275 # LLVM_OBJ_ROOT/include  : config.h files generated by autoconf
276 # LEVEL/include          : config.h files for the project
277 # LLVM_SRC_ROOT/include  : Files global to LLVM.
278 #
279 CPPFLAGS += -I$(BUILD_OBJ_DIR) -I$(BUILD_SRC_DIR) -I$(LLVM_OBJ_ROOT)/include \
280             -I$(BUILD_SRC_ROOT)/include -I$(LEVEL)/include \
281             -I$(LLVM_SRC_ROOT)/include
282
283 # By default, strip symbol information from executable
284 ifndef KEEP_SYMBOLS
285 STRIP = $(PLATFORMSTRIPOPTS)
286 STRIP_WARN_MSG = "(without symbols)"
287 endif
288
289 # Allow GNU extensions:
290 CPPFLAGS += -D_GNU_SOURCE
291 # Pull in limit macros from stdint.h, even in C++:
292 CPPFLAGS += -D__STDC_LIMIT_MACROS
293
294 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
295 CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions
296
297 #
298 # Compile commands with libtool.
299 #
300 Compile  := $(LIBTOOL) --mode=compile $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts)
301 CompileC  := $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(CompileCommonOpts)
302
303 # Compile a cpp file, don't link...
304 CompileG := $(Compile) -g  -D_DEBUG
305 CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer
306 CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE)
307
308 # Compile a c file, don't link...
309 CompileCG := $(CompileC) -g  -D_DEBUG
310 CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer
311 CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE)
312
313 ###########################################################################
314 # Link Time Options
315 ###########################################################################
316
317 #
318 # Link final executable
319 #       (Note that we always link with the C++ compiler).
320 #
321 Link     := $(LIBTOOL) --mode=link $(CXX)
322
323 # link both projlib and llvmlib libraries
324 LinkG    := $(Link) -g -L$(PROJLIBDEBUGSOURCE)  -L$(LLVMLIBDEBUGSOURCE) $(STRIP)
325 LinkO    := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE)
326 LinkP    := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE)
327
328 # TOOLLINKOPTSB to pass options to the linker like library search path etc
329 # Note that this is different from TOOLLINKOPTS, these options
330 # are passed to the linker *before* the USEDLIBS options are passed.
331 # e.g. usage TOOLLINKOPTSB =  -L/home/xxx/lib
332 ifdef TOOLLINKOPTSB
333 LinkG    := $(LinkG) $(TOOLLINKOPTSB) 
334 LinkO    := $(LinkO) $(TOOLLINKOPTSB) 
335 LinkP    := $(LinkP) $(TOOLLINKOPTSB) 
336 endif
337
338 # Create one .o file from a bunch of .o files...
339 Relink := ${LIBTOOL} --mode=link $(CXX)
340
341 #
342 # Configure where the item being compiled should go.
343 #
344 ifdef SHARED_LIBRARY
345 Link += -rpath $(DESTLIBCURRENT)
346 endif
347
348 ifdef TOOLNAME
349 Link += -rpath $(DESTTOOLCURRENT)
350 endif
351
352 # Create dependency file from CPP file, send to stdout.
353 Depend   := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS) 
354 DependC  := $(CC)  -MM -I$(LEVEL)/include $(CPPFLAGS) 
355
356 # Archive a bunch of .o files into a .a file...
357 AR       = ${AR_PATH} cq 
358
359 #----------------------------------------------------------
360
361 # Source includes all of the cpp files, and objects are derived from the
362 # source files...
363 # The local Makefile can list other Source files via ExtraSource = ...
364
365 ifndef Source
366 Source  := $(notdir $(ExtraSource) $(wildcard $(SourceDir)/*.cpp \
367                     $(SourceDir)/*.cc $(SourceDir)/*.c $(SourceDir)/*.y \
368                     $(SourceDir)/*.l))
369 endif
370
371 #
372 # Libtool Objects
373 #
374 Srcs := $(sort $(basename $(Source)))
375 ObjectsO  := $(Srcs:%=$(BUILD_OBJ_DIR)/Release/%.lo)
376 ObjectsP  := $(Srcs:%=$(BUILD_OBJ_DIR)/Profile/%.lo)
377 ObjectsG  := $(Srcs:%=$(BUILD_OBJ_DIR)/Debug/%.lo)
378 ObjectsBC := $(Srcs:%=$(BUILD_OBJ_DIR)/BytecodeObj/%.bc)
379
380 #
381 # The real objects underlying the libtool objects
382 #
383 RObjs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(basename $(Source)))))
384 RObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(RObjs))
385 RObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(RObjs))
386 RObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(RObjs))
387
388 #---------------------------------------------------------
389 # Handle the DIRS and PARALLEL_DIRS options
390 #---------------------------------------------------------
391
392 ifdef DIRS
393 all install clean test bytecode stripped-bytecode::
394         $(VERB) for dir in ${DIRS}; do \
395                 if [ ! -f $$dir/Makefile ]; \
396                 then \
397                         $(MKDIR) $$dir; \
398                         cp $(SourceDir)/$$dir/Makefile $$dir/Makefile; \
399                 fi; \
400                 ($(MAKE) -C $$dir $@) || exit 1; \
401         done
402 endif
403
404 # Handle PARALLEL_DIRS
405 ifdef PARALLEL_DIRS
406 all      :: $(addsuffix /.makeall     , $(PARALLEL_DIRS))
407 install  :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
408 clean    :: $(addsuffix /.makeclean   , $(PARALLEL_DIRS))
409 test     :: $(addsuffix /.maketest    , $(PARALLEL_DIRS))
410 bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
411 stripped-bytecode :: $(addsuffix /.makestripped-bytecode, $(PARALLEL_DIRS))
412
413 %/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode %/.makestripped-bytecode:
414         $(VERB) if [ ! -f $(@D)/Makefile ]; \
415         then \
416                 $(MKDIR) $(@D); \
417                 cp $(SourceDir)/$(@D)/Makefile $(@D)/Makefile; \
418         fi; \
419         $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
420 endif
421
422 # Handle directories that may or may not exist
423 ifdef OPTIONAL_DIRS
424 all install clean test bytecode stripped-bytecode::
425         $(VERB) for dir in ${OPTIONAL_DIRS}; do \
426                 if [ -d $(SourceDir)/$$dir ]; \
427                 then\
428                         if [ ! -f $$dir/Makefile ]; \
429                         then \
430                                 $(MKDIR) $$dir; \
431                                 cp $(SourceDir)/$$dir/Makefile $$dir/Makefile; \
432                         fi; \
433                         ($(MAKE) -C$$dir $@) || exit 1; \
434                 fi \
435         done
436 endif
437
438 ###########################################################################
439 # Library Build Rules:
440 #
441 #---------------------------------------------------------
442 # Handle the LIBRARYNAME option - used when building libs...
443 #---------------------------------------------------------
444 #
445 #  When libraries are built, they are allowed to optionally define the
446 #  DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
447 #  from being built for the library. This .o files may then be linked to by a
448 #  tool if the tool does not need (or want) the semantics a .a file provides
449 #  (linking in only object files that are "needed").  If a library is never to
450 #  be used in this way, it is better to define DONT_BUILD_RELINKED, and define
451 #  BUILD_ARCHIVE instead.
452 #
453 #  Some libraries must be built as .a files (libscalar for example) because if
454 #  it's built as a .o file, then all of the constituent .o files in it will be
455 #  linked into tools (for example gccas) even if they only use one of the parts
456 #  of it.  For this reason, sometimes it's useful to use libraries as .a files.
457 ###########################################################################
458
459 ifdef LIBRARYNAME
460
461 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
462 LIBRARYNAME := $(strip $(LIBRARYNAME))
463
464 LIBNAME_O    := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so
465 LIBNAME_P    := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so
466 LIBNAME_G    := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so
467 LIBNAME_CUR  := $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so
468 LIBNAME_AO   := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a
469 LIBNAME_AP   := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a
470 LIBNAME_AG   := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a
471 LIBNAME_ACUR := $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a
472 LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o
473 LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o
474 LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o
475 LIBNAME_OBJCUR := $(DESTLIBCURRENT)/$(LIBRARYNAME).o
476 LIBNAME_BC   := $(DESTLIBBYTECODE)/lib$(LIBRARYNAME).bc
477
478
479 #--------------------------------------------------------------------
480 # Library Targets
481 #       Modify the top level targets to build the desired libraries.
482 #--------------------------------------------------------------------
483
484 # dynamic target builds a shared object version of the library...
485 dynamic:: $(LIBNAME_CUR)
486 bytecodelib:: $(LIBNAME_BC)
487 install-bytecode-library:: $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc
488
489 $(LLVMGCCDIR)/bytecode-libs/lib$(LIBRARYNAME).bc: $(LIBNAME_BC)
490         @${ECHO} ======= Installing $(LIBRARYNAME) bytecode library =======
491         cp $< $@
492
493 # Does the library want a .o version built?
494 ifndef DONT_BUILD_RELINKED
495 all:: $(LIBNAME_OBJCUR)
496 install:: install-single-object-library
497 endif
498
499 # Does the library want an archive version built?
500 ifdef BUILD_ARCHIVE
501 all:: $(LIBNAME_ACUR)
502 install:: install-archive-library
503 endif
504
505 #--------------------------------------------------------------------
506 # Rules for building libraries
507 #--------------------------------------------------------------------
508
509 LinkBCLib := $(LLVMGCC) -shared -nostdlib
510 ifdef EXPORTED_SYMBOL_LIST
511 LinkBCLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
512 else
513   ifdef EXPORTED_SYMBOL_FILE
514 LinkBCLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
515   else
516 LinkBCLib += -Xlinker -disable-internalize
517   endif
518 endif
519
520
521 # Rule for building bytecode libraries.
522 $(LIBNAME_BC): $(ObjectsBC) $(LibSubDirs) $(DESTLIBBYTECODE)/.dir
523         @${ECHO} Linking $(LIBRARYNAME) bytecode library
524         $(VERB) $(LinkBCLib) -o $@ $(ObjectsBC) $(LibSubDirs) $(LibLinkOpts)
525         @${ECHO} ======= Finished building $(LIBRARYNAME) bytecode library =======
526 #
527 # Rules for building dynamically linked libraries.
528 #
529 $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
530         @${ECHO} Linking $(LIBRARYNAME) dynamic release library
531         $(VERB) $(Link) -o $*.la $(ObjectsO) $(LibSubDirs) $(LibLinkOpts)
532         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
533         @${ECHO} ======= Finished building $(LIBRARYNAME) dynamic release library =======
534
535 $(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
536         @${ECHO} Linking $(LIBRARYNAME) dynamic profile library
537         $(VERB) $(Link) -o $*.la $(ObjectsP) $(LibSubDirs) $(LibLinkOpts)
538         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
539         @${ECHO} ======= Finished building $(LIBRARYNAME) dynamic profile library =======
540
541 $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
542         @${ECHO} Linking $(LIBRARYNAME) dynamic debug library
543         $(VERB) $(Link) -o $*.la $(ObjectsG) $(LibSubDirs) $(LibLinkOpts)
544         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $*.la $(DESTLIBCURRENT)
545         @${ECHO} ======= Finished building $(LIBRARYNAME) dynamic debug library =======
546
547 install-dynamic-library: $(LIBNAME_CUR)
548         $(MKDIR) $(libdir)
549         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_CUR) $(libdir)/lib$(LIBRARYNAME).so
550
551 #
552 # Rules for building static archive libraries.
553 #
554 $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
555         @${ECHO} Linking $(LIBRARYNAME) archive release library
556         @$(RM) -f $@
557         $(VERB) $(Link) -03 -o $@ $(ObjectsO) $(LibSubDirs) -static
558         @${ECHO} Finished building $(LIBRARYNAME) archive release library =======
559
560 $(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
561         @${ECHO} Linking $(LIBRARYNAME) archive profile library
562         @$(RM) -f $@
563         $(VERB) $(Link) -03 $(PROFILE) -o $@ $(ObjectsP) $(LibSubDirs) -static
564         @${ECHO} ======= Finished building $(LIBRARYNAME) archive profile library =======
565
566 $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
567         @${ECHO} Linking $(LIBRARYNAME) archive debug library
568         @$(RM) -f $@
569         $(VERB) $(Link) -g $(STRIP) -o $@ $(ObjectsG) $(LibSubDirs) -static
570         @${ECHO} ======= Finished building $(LIBRARYNAME) archive debug library =======
571
572 install-archive-library: $(LIBNAME_ACUR)
573         $(MKDIR) $(libdir)
574         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_ACUR) $(libdir)/lib$(LIBRARYNAME).a
575
576 #
577 # Rules for building .o libraries.
578 #
579 #       JTC:
580 #       Note that for this special case, we specify the actual object files
581 #       instead of their libtool counterparts.  This is because libtool
582 #       doesn't want to generate a reloadable object file unless it is given
583 #       .o files explicitly.
584 #
585 #       Note that we're making an assumption here: If we build a .lo file,
586 #       it's corresponding .o file will be placed in the same directory.
587 #
588 #       I think that is safe.
589 #
590 $(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir
591         @${ECHO} "Linking `basename $@`"
592         $(VERB) $(Relink) -o $@ $(RObjectsO) $(LibSubDirs)
593
594 $(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir
595         @${ECHO} "Linking `basename $@`"
596         $(VERB) $(Relink) -o $@ $(RObjectsP) $(LibSubDirs)
597
598 $(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir
599         @${ECHO} "Linking `basename $@`"
600         $(VERB) $(Relink) -o $@ $(RObjectsG) $(LibSubDirs)
601
602 install-single-object-library: $(LIBNAME_OBJCUR)
603         $(MKDIR) $(libdir)
604         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_OBJCUR) $(libdir)/$(LIBRARYNAME).o
605
606 endif
607
608 #------------------------------------------------------------------------
609 # Create a TAGS database for emacs
610 #------------------------------------------------------------------------
611
612 ifneq ($(ETAGS),false)
613 ifeq ($(LEVEL), .)
614 SRCDIRS := $(wildcard $(SourceDir)/include $(SourceDir)/lib $(SourceDir)/tools)
615
616 tags:
617         $(ETAGS) -l c++ `find $(SRCDIRS) -name '*.cpp' -o -name '*.h'`
618 all:: tags
619 endif
620 else
621 tags:
622         ${ECHO} "Cannot build $@: The program etags is not installed"
623 endif
624
625 #------------------------------------------------------------------------
626 # Handle the TOOLNAME option - used when building tool executables...
627 #------------------------------------------------------------------------
628 #
629 # The TOOLNAME option should be used with a USEDLIBS variable that tells the
630 # libraries (and the order of the libs) that should be linked to the
631 # tool. USEDLIBS should contain a list of library names (some with .a extension)
632 # that are automatically linked in as .o files unless the .a suffix is added.
633 #
634 ifdef TOOLNAME
635
636 # TOOLEXENAME* - These compute the output filenames to generate...
637 TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME)
638 TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME)
639 TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME)
640 TOOLEXENAMES  := $(DESTTOOLCURRENT)/$(TOOLNAME)
641
642 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
643 PROJ_LIBS_OPTIONS   := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
644 PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o,  $(PROJ_LIBS_OPTIONS))
645 PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
646 PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS))
647
648 LLVM_LIBS_OPTIONS   := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
649 LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o,  $(LLVM_LIBS_OPTIONS))
650 LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
651 LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS))
652
653 LIB_OPTS_G :=  $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G)
654 LIB_OPTS_O :=  $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_O)
655 LIB_OPTS_P :=  $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P)
656
657 # USED_LIB_PATHS - Compute the path of the libraries used so that tools are
658 # rebuilt if libraries change.  This has to make sure to handle .a/.so and .o
659 # files separately.
660 #
661 STATICUSEDLIBS   := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
662 USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS))
663 USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS))
664 USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS))
665
666 #
667 # Libtool link options:
668 #       Ensure that all binaries have their symbols exported so that they can
669 #       by dlsym'ed.
670 #
671 LINK_OPTS := -export-dynamic $(TOOLLINKOPTS)
672
673
674
675
676
677 # Tell make that we need to rebuild subdirectories before we can link the tool.
678 # This affects things like LLI which has library subdirectories.
679 $(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
680         $(addsuffix /.makeall, $(PARALLEL_DIRS))
681
682 all::   $(TOOLEXENAMES)
683
684 clean::
685         $(VERB) $(RM) -f $(TOOLEXENAMES)
686
687 $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir
688         @${ECHO} Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG)
689         $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) $(LIBS)
690         @${ECHO} ======= Finished building $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
691
692 $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir
693         @${ECHO} Linking $(TOOLNAME) release executable
694         $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) $(LIBS)
695         @${ECHO} ======= Finished building $(TOOLNAME) release executable =======
696
697 $(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir
698         @${ECHO} Linking $(TOOLNAME) profile executable
699         $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) $(LIBS)
700         @${ECHO} ======= Finished building $(TOOLNAME) profile executable =======
701
702 install:: $(TOOLEXENAMES)
703         $(MKDIR) $(bindir)
704         $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) -c -m 0755 $(TOOLEXENAMES) $(bindir)/$(TOOLNAME)
705
706 endif
707
708
709
710 #---------------------------------------------------------
711 .PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir $(BUILD_OBJ_DIR)/BytecodeObj/.dir
712 .PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir
713
714 # Create .lo files in the ObjectFiles directory from the .cpp and .c files...
715 $(BUILD_OBJ_DIR)/Release/%.lo: %.cpp $(BUILD_OBJ_DIR)/Release/.dir
716         @${ECHO} "Compiling `basename $<`"
717         $(VERB) $(CompileO) $< -o $@
718
719 $(BUILD_OBJ_DIR)/Release/%.lo: %.c $(BUILD_OBJ_DIR)/Release/.dir
720         @${ECHO} "Compiling `basename $<`"
721         $(VERB) $(CompileCO) $< -o $@
722
723 $(BUILD_OBJ_DIR)/Profile/%.lo: %.cpp $(BUILD_OBJ_DIR)/Profile/.dir
724         @${ECHO} "Compiling `basename $<`"
725         $(VERB) $(CompileP) $< -o $@
726
727 $(BUILD_OBJ_DIR)/Profile/%.lo: %.c $(BUILD_OBJ_DIR)/Profile/.dir
728         @${ECHO} "Compiling `basename $<`"
729         $(VERB) $(CompileCP) $< -o $@
730
731 $(BUILD_OBJ_DIR)/Debug/%.lo: %.cpp $(BUILD_OBJ_DIR)/Debug/.dir
732         @${ECHO} "Compiling `basename $<`"
733         $(VERB) $(CompileG) $< -o $@
734
735 $(BUILD_OBJ_DIR)/Debug/%.lo: %.c $(BUILD_OBJ_DIR)/Debug/.dir 
736         @${ECHO} "Compiling `basename $<`"
737         $(VERB) $(CompileCG) $< -o $@
738
739 $(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.cpp $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LCC1XX)
740         @${ECHO} "Compiling `basename $<` to bytecode"
741         $(VERB) $(LLVMGXX) $(CompileCommonOpts) $(CPPFLAGS) -c $< -o $@
742
743 $(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.c $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LCC1)
744         @${ECHO} "Compiling `basename $<` to bytecode"
745         $(VERB) $(LLVMGCC) $(CompileCommonOpts) $(CPPFLAGS) -c $< -o $@
746
747 $(BUILD_OBJ_DIR)/BytecodeObj/%.bc: %.ll $(BUILD_OBJ_DIR)/BytecodeObj/.dir $(LLVMAS)
748         @${ECHO} "Compiling `basename $<` to bytecode"
749         $(VERB) $(LLVMAS) $< -f -o $@
750
751
752 #
753 # Rules for building lex/yacc files
754 #
755 LEX_FILES   = $(filter %.l, $(Source))
756 LEX_OUTPUT  = $(LEX_FILES:%.l=%.cpp)
757 YACC_FILES  = $(filter %.y, $(Source))
758 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
759 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
760
761 # Create a .cpp source file from a flex input file... this uses sed to cut down
762 # on the warnings emited by GCC...
763 #
764 # The last line is a gross hack to work around flex aparently not being able to
765 # resize the buffer on a large token input.  Currently, for uninitialized string
766 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
767 # FIXME.  (f.e. char Buffer[10000] )
768 #
769 %.cpp: %.l
770         @${ECHO} Flexing $<
771         $(VERB) $(FLEX) -t $< | \
772           $(SED) '/^find_rule/d' | \
773           $(SED) 's/void yyunput/inline void yyunput/' | \
774           $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
775           $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
776               > $@.tmp
777         $(VERB) cmp -s $@ $@.tmp > /dev/null || ${MV} -f $@.tmp $@
778         @# remove the output of flex if it didn't get moved over...
779         @rm -f $@.tmp
780
781 # Rule for building the bison parsers...
782 %.c: %.y     # Cancel built-in rules for yacc
783 %.h: %.y     # Cancel built-in rules for yacc
784 %.cpp %.h : %.y
785         @${ECHO} "Bisoning `basename $<`"
786         $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c  $<
787         $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || ${MV} -f $*.tab.c $*.cpp
788         $(VERB) cmp -s $*.tab.h $*.h   > /dev/null || ${MV} -f $*.tab.h $*.h
789         @# If the files were not updated, don't leave them lying around...
790         @rm -f $*.tab.c $*.tab.h
791
792 # To create the directories...
793 %/.dir:
794         $(VERB) ${MKDIR} $* > /dev/null
795         @$(DATE) > $@
796
797 # To create postscript files from dot files...
798 ifneq ($(DOT),false)
799 %.ps: %.dot
800         ${DOT} -Tps < $< > $@
801 else
802 %.ps: %.dot
803         ${ECHO} "Cannot build $@: The program dot is not installed"
804 endif
805
806 #
807 # This rules ensures that header files that are removed still have a rule for
808 # which they can be "generated."  This allows make to ignore them and
809 # reproduce the dependency lists.
810 #
811 %.h:: ;
812
813 # 'make clean' nukes the tree
814 clean::
815         $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release
816         $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend
817         $(VERB) $(RM) -rf $(BUILD_OBJ_DIR)/BytecodeObj
818         $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc
819         $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
820
821 ###########################################################################
822 # C/C++ Dependencies
823 #       Define variables and rules that generate header file dependencies
824 #       from C/C++ source files.
825 ###########################################################################
826
827 ifndef DISABLE_AUTO_DEPENDENCIES
828
829 # If dependencies were generated for the file that included this file,
830 # include the dependencies now...
831 #
832 SourceBaseNames := $(basename $(Source))
833 SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d)
834
835 # Create dependencies for the *.cpp files...
836 $(BUILD_OBJ_DIR)/Depend/%.d: %.cpp $(BUILD_OBJ_DIR)/Depend/.dir
837         $(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' > $@
838
839 # Create dependencies for the *.c files...
840 $(BUILD_OBJ_DIR)/Depend/%.d: %.c $(BUILD_OBJ_DIR)/Depend/.dir
841         $(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' > $@
842
843 #
844 # Autoconf Dependencies.
845 #
846 $(LLVM_OBJ_ROOT)/config.status:: $(LLVM_SRC_ROOT)/configure
847         @${ECHO} "****************************************************************"
848         @${ECHO} "   You need to re-run $(LLVM_SRC_ROOT)/configure"
849         @${ECHO} "   in directory $(LLVM_OBJ_ROOT)"
850         @${ECHO} "****************************************************************"
851         $(VERB) exit 1
852
853 # If the Makefile in the source tree has been updated, copy it over into the
854 # build tree.
855 Makefile :: $(BUILD_SRC_DIR)/Makefile
856         @${ECHO} "===== Updating Makefile from source dir: `dirname $<` ====="
857         $(MKDIR) $(@D)
858         cp -f $< $@
859
860 #
861 # Include dependencies generated from C/C++ source files, but not if we
862 # are cleaning (this example taken from the GNU Make Manual).
863 #
864 ifneq ($(MAKECMDGOALS),clean)
865 ifneq ($(MAKECMDGOALS),distclean)
866 -include /dev/null $(SourceDepend)
867 endif
868 endif
869
870 endif  # ifndef DISABLE_AUTO_DEPENDENCIES