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