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