* Actually ignore build errors in optional directories
[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 BUILT_SOURCES variable
35 #
36 # 6. LLVM_SRC_ROOT - If specified, points to the top of the LLVM source tree.
37 #
38 # 8. BUILD_SRC_DIR - The directory which contains the current set of Makefiles
39 #    and usually the source code too (unless SourceDir is set).
40 #
41 # 9. BUILD_SRC_ROOT - The root directory of the source code being compiled.
42 #
43 # 10. BUILD_OBJ_DIR - The directory where object code should be placed.
44 #
45 # 11. BUILD_OBJ_ROOT - The root directory for where object code should be
46 #     placed.
47 #
48 # For building,
49 #       LLVM, LLVM_SRC_ROOT = BUILD_SRC_ROOT
50 #
51 #===-----------------------------------------------------------------------====
52
53 #
54 # Set the VPATH so that we can find source files.
55 #
56 VPATH=$(BUILD_SRC_DIR)
57
58 ###########################################################################
59 # Default Targets:
60 #       The following targets are the standard top level targets for
61 #       building.
62 ###########################################################################
63
64
65 # Ensure all preconditions are met
66 all:: preconditions
67
68 # Make sure all the user-target rules are double colon rules
69 all :: preconditions
70 clean:: preconditions
71 install :: preconditions
72 uninstall :: preconditions
73 check:: preconditions
74 dist:: preconditions
75 distcheck:: preconditions
76 distclean:: preconditions
77
78
79 ###########################################################################
80 # Suffixes and implicit rules:
81 #       Empty out the list of suffixes, generate a list that is only
82 #       used by this Makefile, and cancel useless implicit rules.   This
83 #       will hopefully speed up compilation a little bit.
84 ###########################################################################
85 .SUFFIXES:
86 .SUFFIXES: .c .cpp .h .hpp .y .l
87 .SUFFIXES: .lo .o .a $(SHLIBEXT) .bc .td
88 .SUFFIXES: .ps .dot .d
89
90 #
91 # Mark all of these targets as phony.  This will hopefully speed up builds
92 # slightly since GNU Make will not try to find implicit rules for targets
93 # which are marked as Phony.
94 #
95 ALL_TARGETS= all dynamic bytecodelib install-bytecode-library clean distclean install test bytecode prdirs
96 .PHONY: $(ALL_TARGETS) preconditions
97
98 ###########################################################################
99 # Miscellaneous paths and commands:
100 #       This section defines various configuration macros, such as where
101 #       to find burg, tblgen, and libtool.
102 ###########################################################################
103
104 #--------------------------------------------------------------------
105 # Variables derived from configuration options... 
106 #--------------------------------------------------------------------
107
108 ifdef ENABLE_PROFILING
109   CONFIGURATION := Profile
110   CXXFLAGS += -O3 -DNDEBUG -felide-constructors -finline-functions -pg
111   CFLAGS   += -O3 -DNDEBUG -pg
112   LDFLAGS  += -O3 -DNDEBUG -pg 
113 else
114   ifdef ENABLE_OPTIMIZED
115     CONFIGURATION := Release
116     CXXFLAGS  += -O3 -DNDEBUG -finline-functions -felide-constructors -fomit-frame-pointer
117     CFLAGS    += -O3 -DNDEBUG -fomit-frame-pointer
118     LDFLAGS   += -O3 -DNDEBUG 
119   else
120     CONFIGURATION := Debug
121     CXXFLAGS += -g -D_DEBUG 
122     CFLAGS   += -g -D_DEBUG
123     LDFLAGS  += -g -D_DEBUG 
124     KEEP_SYMBOLS := 1
125   endif
126 endif
127
128 ARFLAGS := cru
129 #------------------------------------------------------------------------------
130 # Directory locations
131 OBJDIR      := $(BUILD_OBJ_DIR)/$(CONFIGURATION)
132 LIBDIR      := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
133 TOOLDIR     := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
134 LLVMLIBDIR  := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
135 LLVMTOOLDIR := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
136
137 #------------------------------------------------------------------------------
138 # Full Paths To Compiled Tools and Utilities
139 LIBTOOL  := $(LLVM_OBJ_ROOT)/mklib
140 LLVMAS   := $(LLVMTOOLDIR)/llvm-as$(EXEEXT)
141 BURG     := $(LLVMTOOLDIR)/burg$(EXEEXT)
142 TBLGEN   := $(LLVMTOOLDIR)/tblgen$(EXEEXT)
143 GCCLD    := $(LLVMTOOLDIR)/gccld$(EXEEXT)
144 LLVMGCC  := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/gcc
145 LLVMGXX  := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/g++
146
147 # Need a better way to compute this.
148 LLVMGCCLIBDIR := $(dir $(shell $(LLVMGCC) -print-file-name=libgcc.a))/
149
150 #------------------------------------------------------------------------------
151 # Adjust to user's request
152
153 ifndef SHARED_LIBRARY
154   LIBTOOL += --tag=disable-shared
155 else
156   LDFLAGS += -rpath $(LIBDIR)
157 endif
158
159 #
160 # Verbosity levels
161 #
162 ifndef VERBOSE
163   VERB := @
164   LIBTOOL += --silent
165   AR += >/dev/null 2>/dev/null
166 endif
167
168 # By default, strip symbol information from executable
169 ifndef KEEP_SYMBOLS
170   STRIP = $(PLATFORMSTRIPOPTS)
171   STRIP_WARN_MSG = "(without symbols)"
172 endif
173
174 ifdef TOOLNAME
175   LDFLAGS += -rpath $(TOOLDIR) -export-dynamic $(TOOLLINKOPTS)
176 endif
177
178 # TOOLLINKOPTSB to pass options to the linker like library search path etc
179 # Note that this is different from TOOLLINKOPTS, these options
180 # are passed to the linker *before* the USEDLIBS options are passed.
181 # e.g. usage TOOLLINKOPTSB =  -L/home/xxx/lib
182 ifdef TOOLLINKOPTSB
183 LDFLAGS += $(TOOLLINKOPTSB)
184 endif
185
186 LDFLAGS += -L$(LIBDIR) -L$(LLVMLIBDIR)
187
188 #------------------------------------------------------------------------------
189 # Options To Invoke Tools
190
191 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
192
193 CPPFLAGS += -I$(BUILD_OBJ_DIR) \
194             -I$(BUILD_SRC_DIR) \
195             -I$(BUILD_SRC_ROOT)/include \
196             -I$(BUILD_OBJ_ROOT)/include \
197             -I$(LLVM_OBJ_ROOT)/include \
198             -I$(LLVM_SRC_ROOT)/include \
199             -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
200
201 CXXCompile   := $(CXX) $(CPPFLAGS) $(CompileCommonOpts) $(CXXFLAGS) -c
202 LTCXXCompile := $(LIBTOOL) --tag=CXX --mode=compile $(CXXCompile)
203 CCompile     := $(CC) $(CPPFLAGS) $(CompileCommonOpts) -c $(CFLAGS)
204 LTCCompile   := $(LIBTOOL) --mode=compile $(CCompile)
205 BCCXXCompile := $(LLVMGXX) $(CPPFLAGS) $(CompileCommonOpts) $(CXXFLAGS) -c
206 BCCCompile   := $(LLVMGCC) $(CPPFLAGS) $(CompileCommonOpts) $(CFLAGS) -c
207 Link         := $(LIBTOOL) --tag=CXX --mode=link $(CXX) $(CPPFLAGS) $(CompileCommonOpts) $(LDFLAGS) $(STRIP)
208 Relink       := $(LIBTOOL) --tag=CXX --mode=link $(CXX)
209 BCLinkLib    := $(LLVMGCC) -shared -nostdlib
210 Burg         := $(BURG) -I $(BUILD_SRC_DIR)
211 TableGen     := $(TBLGEN) -I $(BUILD_SRC_DIR)
212 Archive      := $(AR) $(ARFLAGS)
213 ifdef RANLIB
214 Ranlib       := $(RANLIB)
215 else
216 Ranlib       := ranlib
217 endif
218
219 #----------------------------------------------------------
220 # Source includes all of the cpp files, and objects are derived from the
221 # source files...
222 # The local Makefile can list other Source files via BUILT_SOURCES = ...
223
224 ifndef Source
225
226 Source  := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
227                     $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
228                     $(BUILD_SRC_DIR)/*.l))
229 endif
230
231 ifdef BUILT_SOURCES
232 Source += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
233 endif
234
235 #
236 # Libtool Objects
237 #
238 Srcs := $(sort $(basename $(Source)))
239 ObjectsO  := $(Srcs:%=$(OBJDIR)/%.o)
240 ObjectsLO := $(Srcs:%=$(OBJDIR)/%.lo)
241 ObjectsBC := $(Srcs:%=$(OBJDIR)/%.bc)
242
243 #---------------------------------------------------------
244 # Handle the DIRS and PARALLEL_DIRS options
245 #---------------------------------------------------------
246
247 ifdef DIRS
248 $(ALL_TARGETS)::
249         $(VERB) for dir in $(DIRS); do \
250           if [ ! -f $$dir/Makefile ]; then \
251             $(MKDIR) $$dir; \
252             cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
253           fi; \
254           ($(MAKE) -C $$dir $@ $(MFLAGS)) || exit 1; \
255         done
256 endif
257
258 # Handle PARALLEL_DIRS
259 ifdef PARALLEL_DIRS
260 all      :: $(addsuffix /.makeall     , $(PARALLEL_DIRS))
261 install  :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
262 clean    :: $(addsuffix /.makeclean   , $(PARALLEL_DIRS))
263 test     :: $(addsuffix /.maketest    , $(PARALLEL_DIRS))
264 bytecode :: $(addsuffix /.makebytecode, $(PARALLEL_DIRS))
265 stripped-bytecode :: $(addsuffix /.makestripped-bytecode, $(PARALLEL_DIRS))
266 install-bytecode :: $(addsuffix /.makeinstall-bytecode, $(PARALLEL_DIRS))
267
268 %/.makeall %/.makeinstall %/.makeclean %/.maketest %/.makebytecode %/.makestripped-bytecode %/.makeinstall-bytecode:
269         $(VERB) if [ ! -f $(@D)/Makefile ]; then \
270           $(MKDIR) $(@D); \
271           cp $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
272         fi; \
273         $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) $(MFLAGS)
274 endif
275
276 # Handle directories that may or may not exist
277 ifdef OPTIONAL_DIRS
278 $(ALL_TARGETS)::
279         $(VERB) for dir in $(OPTIONAL_DIRS); do \
280           if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
281             if [ ! -f $$dir/Makefile ]; then \
282               $(MKDIR) $$dir; \
283               cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
284             fi; \
285             ($(MAKE) -C$$dir $@ $(MFLAGS)) || exit 0; \
286           fi \
287         done
288 endif
289
290 #---------------------------------------------------------
291 # Handle the CONFIG_FILES options
292 #---------------------------------------------------------
293 ifdef CONFIG_FILES
294 install:: install-config-files
295
296 $(sysconfdir):
297         $(MKDIR) $(sysconfdir)
298
299 install-config-files: $(sysconfdir) $(CONFIG_FILES)
300         $(VERB)$(ECHO) Installing Configuration Files To $(sysconfdir)
301         $(VERB)for file in $(CONFIG_FILES); do \
302                 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
303         done
304 endif
305
306 ###########################################################################
307 # Library Build Rules:
308 #
309 #---------------------------------------------------------
310 # Handle the LIBRARYNAME option - used when building libs...
311 #---------------------------------------------------------
312 #
313 #  When libraries are built, they are allowed to optionally define the
314 #  DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file
315 #  from being built for the library. This .o files may then be linked to by a
316 #  tool if the tool does not need (or want) the semantics a .a file provides
317 #  (linking in only object files that are "needed").  If a library is never to
318 #  be used in this way, it is better to define DONT_BUILD_RELINKED, and define
319 #  BUILD_ARCHIVE instead.
320 #
321 #  Some libraries must be built as .a files (libscalar for example) because if
322 #  it's built as a .o file, then all of the constituent .o files in it will be
323 #  linked into tools (for example gccas) even if they only use one of the parts
324 #  of it.  For this reason, sometimes it's useful to use libraries as .a files.
325 ###########################################################################
326
327 # Install rule for making bytecode library directory if it does not exist.
328 # Trigger this by making libraries that need to be installed here depend on it.
329 $(DESTDIR)$(bytecode_libdir):
330         $(MKDIR) $@
331
332 ifdef LIBRARYNAME
333
334 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
335 LIBRARYNAME := $(strip $(LIBRARYNAME))
336 LIBNAME_LA := $(LIBDIR)/lib$(LIBRARYNAME).la
337 LIBNAME_A  := $(LIBDIR)/lib$(LIBRARYNAME).a
338 LIBNAME_O  := $(LIBDIR)/$(LIBRARYNAME).o
339 LIBNAME_BC := $(LIBDIR)/lib$(LIBRARYNAME).bc
340
341 #-------------------------------------------------------------------------------
342 # Shared Library Targets
343 #       Modify the top level targets to build the desired libraries.
344 #-------------------------------------------------------------------------------
345
346 # Does the library want a shared library version built?
347 ifdef SHARED_LIBRARY
348
349 all:: $(LIBNAME_LA)
350
351 $(LIBNAME_LA): $(BUILT_SOURCES) $(ObjectsLO) $(LIBDIR)/.dir
352         @$(ECHO) Linking shared library $(notdir $@)
353         $(VERB) $(Link) -o $@ $(ObjectsLO)
354         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $@ $(LIBDIR)
355         @$(ECHO) Finished linking shared library $(LIBRARYNAME).la 
356 clean::
357         $(VERB) $(RM) -f $(LIBNAME_LA)
358
359 install:: $(DESTDIR)$(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
360
361 $(DESTDIR)/lib/lib$(LIBRARYNAME)$(SHLIBEXT): $(LIBNAME_LA)
362         @$(ECHO) Installing shared library $(notdir $@)
363         $(VERB) $(MKDIR) $(DESTDIR)
364         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_LA) $(DESTDIR)$(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
365         $(VERB) $(LIBTOOL) --finish $(DESTDIR)$(libdir)
366 endif
367
368 # Does the library want a bytecode version built?
369 ifdef BYTECODE_LIBRARY
370
371 ifdef EXPORTED_SYMBOL_LIST
372   BCLinkLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
373 else
374   ifdef EXPORTED_SYMBOL_FILE
375     BCLinkLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
376   else
377     BCLinkLib += -Xlinker -disable-internalize
378   endif
379 endif
380
381 all:: $(LIBNAME_BC)
382
383 $(LIBNAME_BC): $(BUILT_SOURCES) $(ObjectsBC) $(LIBDIR)/.dir
384         @$(ECHO) Linking bytecode library $(notdir $@)
385         $(VERB) $(BCLinkLib) -o $@ $(ObjectsBC)
386
387 clean::
388         $(VERB) $(RM) -f $(LIBNAME_BC)
389
390 install:: $(DESTDIR)$(bytecode_libdir)/lib$(LIBRARYNAME).bc
391
392 $(DESTDIR)$(bytecode_libdir)/lib$(LIBRARYNAME).bc: $(LIBNAME_BC) $(DESTDIR)$(bytecode_libdir)
393         @$(ECHO) Installing bytecode library $(notdir $@)
394         $(VERB)$(INSTALL) $< $@
395
396 endif
397
398 # Does the library want a .o version built?
399 ifndef DONT_BUILD_RELINKED
400 all:: $(LIBNAME_O)
401
402 $(LIBNAME_O): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
403         @$(ECHO) Linking object $(notdir $@)
404         $(VERB) $(Relink) -o $@ $(ObjectsO)
405
406 install:: $(DESTDIR)$(libdir)/$(LIBRARYNAME).o
407
408 $(DESTDIR)$(libdir)/$(LIBRARYNAME).o: $(LIBNAME_O)
409         @$(ECHO) Installing object library $(notdir $@)
410         $(VERB) $(MKDIR) $(DESTDIR)$(libdir)
411         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_O) $(DESTDIR)$(libdir)/$(LIBRARYNAME).o
412
413 clean::
414         $(VERB) $(RM) -f $(LIBNAME_O)
415
416 endif
417
418 # Does the library want an archive version built?
419 ifdef BUILD_ARCHIVE
420 all:: $(LIBNAME_A)
421
422 $(LIBNAME_A): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
423         @$(ECHO) Linking archive $(notdir $@) library
424         $(VERB)$(RM) -f $@
425         $(VERB) $(Archive) $@ $(ObjectsO)
426         $(VERB) $(Ranlib) $@
427
428 clean::
429         $(VERB) $(RM) -f $(LIBNAME_A)
430
431 install:: $(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a
432
433 $(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a: $(LIBNAME_A)
434         $(MKDIR) $(DESTDIR)$(libdir)
435         $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_A) $(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a
436 endif
437
438 # if LIBRARYNAME
439 endif 
440
441 #------------------------------------------------------------------------
442 # Handle the TOOLNAME option - used when building tool executables...
443 #------------------------------------------------------------------------
444 #
445 # The TOOLNAME option should be used with a USEDLIBS variable that tells the
446 # libraries (and the order of the libs) that should be linked to the
447 # tool. USEDLIBS should contain a list of library names (some with .a extension)
448 # that are automatically linked in as .o files unless the .a suffix is added.
449 #
450 ifdef TOOLNAME
451
452 # TOOLLINKOPTSB to pass options to the linker like library search path etc
453 # Note that this is different from TOOLLINKOPTS, these options
454 # are passed to the linker *before* the USEDLIBS options are passed.
455 # e.g. usage TOOLLINKOPTSB =  -L/home/xxx/lib
456 ifdef TOOLLINKOPTSB
457 Link    += $(TOOLLINKOPTSB) 
458 endif
459
460 # TOOLEXENAME* - These compute the output filenames to generate...
461 TOOLEXENAME := $(TOOLDIR)/$(TOOLNAME)
462
463 # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
464 PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
465 PROJ_LIBS_OPTIONS := $(patsubst %.o, $(LIBDIR)/%.o,  $(PROJ_LIBS_OPTIONS))
466 LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
467 LLVM_LIBS_OPTIONS := $(patsubst %.o, $(LLVMLIBDIR)/%.o, $(LLVM_LIBS_OPTIONS))
468
469 PROJ_USED_LIBS    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
470 LLVM_USED_LIBS    := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
471 PROJ_LIBS_PATHS   := $(addprefix $(LIBDIR)/,$(PROJ_USED_LIBS))
472 LLVM_LIBS_PATHS   := $(addprefix $(LLVMLIBDIR)/,$(LLVM_USED_LIBS))
473
474 LINK_OPTS := $(TOOLLINKOPTS) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS)
475
476 #
477 # Libtool link options:
478 #       Ensure that all binaries have their symbols exported so that they can
479 #       by dlsym'ed.
480 #
481
482 # Handle compression libraries automatically
483 ifeq ($(HAVE_BZIP2),1)
484 LIBS += -lbz2
485 endif
486 ifeq ($(HAVE_ZLIB),1)
487 LIBS += -lz
488 endif
489
490 # Tell make that we need to rebuild subdirectories before we can link the tool.
491 # This affects things like LLI which has library subdirectories.
492 $(LIBS): $(addsuffix /.makeall, $(PARALLEL_DIRS))
493
494 all::   $(TOOLEXENAME)
495
496 clean::
497         $(VERB) $(RM) -f $(TOOLEXENAME)
498
499 $(TOOLEXENAME): $(BUILT_SOURCES) $(ObjectsO) $(PROJ_LIBS_PATHS) $(LLVM_LIBS_PATHS) $(TOOLDIR)/.dir
500         @$(ECHO) Linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
501         $(VERB) $(Link) -o $@ $(ObjectsO) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS) $(LIBS)
502         @$(ECHO) ======= Finished linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG) 
503
504 install:: $(TOOLEXENAME)
505         @$(ECHO) Installing $(TOOLNAME)
506         $(VERB) $(INSTALL) $(TOOLEXENAME) $(DESTDIR)/bin
507 endif
508
509 ifndef DISABLE_AUTO_DEPENDENCIES
510
511 # Create .lo files in the OBJDIR directory from the .cpp and .c files...
512 $(OBJDIR)/%.lo: %.cpp $(OBJDIR)/.dir
513         @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
514         $(VERB) if $(LTCXXCompile) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Td $< -o $@ ; \
515         then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
516
517 $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
518         @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
519         $(VERB) if $(CXXCompile) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Td $< -o $@ ; \
520         then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
521
522 $(OBJDIR)/%.lo: %.c $(OBJDIR)/.dir 
523         @$(ECHO) "Compiling $(CONFIGURATION) $*.c For Shared Library"
524         $(VERB) if $(LTCCompile) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Td $< -o $@ ; \
525         then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
526
527 $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
528         @$(ECHO) "Compiling $(CONFIGURATION) $*.c For Archive"
529         $(VERB) if $(CCompile) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Td $< -o $@ ; \
530         then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
531
532 # Create .bc files in the OBJDIR directory from .cpp and .c files...
533 $(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
534         @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp to bytecode"
535         $(VERB) if $(BCCXXCompile) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.Td" $< -o $@ ; \
536         then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Td"; exit 1; fi
537
538 $(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
539         @$(ECHO) "Compiling $(CONFIGURATION) $*.c to bytecode"
540         $(VERB) if $(BCCCompile) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.Td" $< -o $@ ; \
541         then mv -f "$(OBJDIR)/$*.Td" "$(OBJDIR)/$*.d"; else rm -f "$(OBJDIR)/$*.Tpo"; exit 1; fi
542
543 else
544
545 $(OBJDIR)/%.lo: %.cpp $(OBJDIR)/.dir 
546         @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
547         $(LTCXXCompile) $< -o $@ 
548
549 $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
550         @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
551         $(CXXCompile) $< -o $@ 
552
553 $(OBJDIR)/%.lo: %.c $(OBJDIR)/.dir 
554         @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
555         $(LTCCompile) $< -o $@ 
556
557 $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
558         @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
559         $(CCompile) $< -o $@ 
560
561 # Create .bc files in the OBJDIR directory from .cpp and .c files...
562 $(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
563         @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp To Bytecode"
564         $(BCCompileCPP) $< -o $@ 
565
566 $(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
567         @$(ECHO) "Compiling $(CONFIGURATION) $*.c To Bytecode"
568         $(BCCompileC) $< -o $@
569
570 endif
571
572 $(OBJDIR)/%.bc: %.ll $(OBJDIR)/.dir $(LLVMAS)
573         @$(ECHO) "Compiling $*.ll To Bytecode"
574         $(VERB) $(LLVMAS) $< -f -o $@
575
576 ifdef TARGET
577
578 TDFILES := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
579
580 $(BUILT_SOURCES): $(TDFILES) 
581
582 %GenRegisterNames.inc : %.td
583         @echo "Building $(<F) register names with tblgen"
584         $(VERB) $(TableGen) -gen-register-enums -o $@ $<
585
586 %GenRegisterInfo.h.inc : %.td
587         @echo "Building $(<F) register information header with tblgen"
588         $(VERB) $(TableGen) -gen-register-desc-header -o $@ $<
589
590 %GenRegisterInfo.inc : %.td
591         @echo "Building $(<F) register info implementation with tblgen"
592         $(VERB) $(TableGen) -gen-register-desc -o $@ $<
593
594 %GenInstrNames.inc : %.td
595         @echo "Building $(<F) instruction names with tblgen"
596         $(VERB) $(TableGen) -gen-instr-enums -o $@ $<
597
598 %GenInstrInfo.inc : %.td
599         @echo "Building $(<F) instruction information with tblgen"
600         $(VERB) $(TableGen) -gen-instr-desc -o $@ $<
601
602 %GenAsmWriter.inc : %.td
603         @echo "Building $(<F) assembly writer with tblgen"
604         $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
605
606 %GenATTAsmWriter.inc : %.td
607         @echo "Building $(<F) AT&T assembly writer with tblgen"
608         $(VERB) $(TableGen) -gen-asm-writer -o $@ $< 
609
610 %GenIntelAsmWriter.inc : %.td
611         @echo "Building $(<F) Intel assembly writer with tblgen"
612         $(VERB) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $< 
613
614 %GenInstrSelector.inc: %.td
615         @echo "Building $(<F) instruction selector with tblgen"
616         $(VERB) $(TableGen) -gen-instr-selector -o $@ $< 
617
618 %GenCodeEmitter.inc:: %.td
619         @echo "Building $(<F) code emitter with tblgen"
620         $(VERB) $(TableGen) -gen-emitter -o $@ $<
621
622 clean::
623         $(VERB) rm -f *.inc
624
625 endif
626
627 #
628 # Rules for building lex/yacc files
629 #
630 LEX_FILES   = $(filter %.l, $(Source))
631 LEX_OUTPUT  = $(LEX_FILES:%.l=%.cpp)
632 YACC_FILES  = $(filter %.y, $(Source))
633 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
634 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
635
636 # Create a .cpp source file from a flex input file... this uses sed to cut down
637 # on the warnings emited by GCC...
638 #
639 # The last line is a gross hack to work around flex aparently not being able to
640 # resize the buffer on a large token input.  Currently, for uninitialized string
641 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
642 # FIXME.  (f.e. char Buffer[10000] )
643 #
644 %.cpp: %.l
645         @$(ECHO) Flexing $<
646         $(VERB) $(FLEX) -t $< | \
647         $(SED) '/^find_rule/d' | \
648         $(SED) 's/void yyunput/inline void yyunput/' | \
649         $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
650         $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
651           > $@.tmp
652         $(VERB) cmp -s $@ $@.tmp > /dev/null || $(MV) -f $@.tmp $@
653         @# remove the output of flex if it didn't get moved over...
654         @rm -f $@.tmp
655
656 # Rule for building the bison parsers...
657 %.c: %.y     # Cancel built-in rules for yacc
658 %.h: %.y     # Cancel built-in rules for yacc
659 %.cpp %.h : %.y
660         @$(ECHO) "Bisoning $*.y"
661         $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c  $<
662         $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || $(MV) -f $*.tab.c $*.cpp
663         $(VERB) cmp -s $*.tab.h $*.h   > /dev/null || $(MV) -f $*.tab.h $*.h
664         @# If the files were not updated, don't leave them lying around...
665         @rm -f $*.tab.c $*.tab.h
666
667 # To create the directories...
668 %/.dir:
669         $(VERB) $(MKDIR) $* > /dev/null
670         @$(DATE) > $@
671
672 .PRECIOUS: $(OBJDIR)/.dir $(LIBDIR)/.dir $(TOOLDIR)/.dir $(LLVMLIBDIR)/.dir
673 .PRECIOUS: $(LLVMTOOLDIR)/.dir
674
675 # To create postscript files from dot files...
676 ifneq ($(DOT),false)
677 %.ps: %.dot
678         $(DOT) -Tps < $< > $@
679 else
680 %.ps: %.dot
681         $(ECHO) "Cannot build $@: The program dot is not installed"
682 endif
683
684 #
685 # This rules ensures that header files that are removed still have a rule for
686 # which they can be "generated."  This allows make to ignore them and
687 # reproduce the dependency lists.
688 #
689 %.h:: ;
690
691 # 'make clean' nukes the tree
692 clean::
693         $(VERB) $(RM) -rf $(OBJDIR)
694         $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
695 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
696         $(VERB) $(RM) -f *$(SHLIBEXT)
697 endif
698         $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
699
700 ###########################################################################
701 # C/C++ Dependencies
702 #       Define variables and rules that generate header file dependencies
703 #       from C/C++ source files.
704 ###########################################################################
705
706 ifndef DISABLE_AUTO_DEPENDENCIES
707
708 # If dependencies were generated for the file that included this file,
709 # include the dependencies now...
710 #
711
712 SourceBaseNames := $(basename $(Source))
713 SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/$(CONFIGURATION)/%.d)
714
715 #
716 # Include dependencies generated from C/C++ source files, but not if we
717 # are cleaning (this example taken from the GNU Make Manual).
718 #
719 ifneq ($(MAKECMDGOALS),clean)
720 ifneq ($(MAKECMDGOALS),distclean)
721 -include /dev/null $(SourceDepend)
722 endif
723 endif
724
725 endif  # ifndef DISABLE_AUTO_DEPENDENCIES
726
727 ###############################################################################
728 # PRECONDITIONS - that which must be built/checked first
729 ###############################################################################
730
731 OBJMKFILE := $(BUILD_OBJ_DIR)/Makefile
732 SRCMKFILE := $(BUILD_SRC_DIR)/Makefile
733 CONFIGURE := $(LLVM_SRC_ROOT)/configure
734 CONFIG_STATUS := $(LLVM_OBJ_ROOT)/config.status
735 MAKE_CONFIG_IN := $(LLVM_SRC_ROOT)/Makefile.config.in
736 MAKE_CONFIG := $(LLVM_OBJ_ROOT)/Makefile.config
737
738 #------------------------------------------------------------------------
739 # List of the preconditions
740 preconditions: $(CONFIG_STATUS) $(MAKE_CONFIG) $(OBJMKFILE) 
741
742 all dist distcheck install:: $(BUILT_SOURCES)
743
744 clean::
745         $(VERB) $(RM) -f $(BUILT_SOURCES)
746
747 #------------------------------------------------------------------------
748 # Make sure we're not using a stale configuration
749 .PRECIOUS: $(CONFIG_STATUS)
750 $(CONFIG_STATUS): $(CONFIGURE)
751         @$(ECHO) Reconfiguring with $@
752         $(VERB) $(CONFIG_STATUS) --recheck
753
754 #------------------------------------------------------------------------
755 # Make sure the configuration makefile is up to date
756 $(MAKE_CONFIG): $(MAKE_CONFIG_IN)
757         @$(ECHO) Regenerating $@
758         $(VERB) cd $(LLVM_OBJ_ROOT) ; $(CONFIG_STATUS) Makefile.config
759         $(VERB) $(MAKE) $(MFLAGS) $(MAKECMDGOALS)
760         @exit 0;
761
762 #------------------------------------------------------------------------
763 # If the Makefile in the source tree has been updated, copy it over into the
764 # build tree.
765 ifneq ($(OBJMKFILE),$(SRCMKFILE))
766 .PRECIOUS: $(OBJMKFILE)
767 $(OBJMKFILE): $(SRCMKFILE)
768         @$(ECHO) "Updating Makefile from : $(dir $<)"
769         $(VERB) $(MKDIR) $(@D)
770         $(VERB) cp -f $< $@
771         $(VERB) $(MAKE) $(MFLAGS) $(MAKECMDGOALS)
772         @exit 0;
773 endif
774
775 ###############################################################################
776 # MISCELLANEOUS - utility targets
777 ###############################################################################
778
779 #------------------------------------------------------------------------
780 # Print out the directories used for building
781 printvars:
782         @$(ECHO) "BUILD_SRC_ROOT: " $(BUILD_SRC_ROOT)
783         @$(ECHO) "BUILD_SRC_DIR : " $(BUILD_SRC_DIR)
784         @$(ECHO) "BUILD_OBJ_ROOT: " $(BUILD_OBJ_ROOT)
785         @$(ECHO) "BUILD_OBJ_DIR : " $(BUILD_OBJ_DIR)
786         @$(ECHO) "LLVM_SRC_ROOT : " $(LLVM_SRC_ROOT)
787         @$(ECHO) "LLVM_OBJ_ROOT : " $(LLVM_OBJ_ROOT)
788         @$(ECHO) "CONFIGURATION : " $(CONFIGURATION)
789         @$(ECHO) "OBJDIR: " $(OBJDIR)
790         @$(ECHO) "LIBDIR: " $(LIBDIR)
791         @$(ECHO) "TOOLDIR: " $(TOOLDIR)
792         @$(ECHO) "TDFILES:" '$(TDFILES)'
793         @$(ECHO) "CXXCompile: " '$(CXXCompile)'
794         @$(ECHO) "CCompile: " '$(CCompile)'