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