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