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