1 #===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
3 # The LLVM Compiler Infrastructure
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.
8 #===------------------------------------------------------------------------===#
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.
13 #===-----------------------------------------------------------------------====
16 # Set the VPATH so that we can find source files.
18 VPATH=$(BUILD_SRC_DIR)
20 ###############################################################################
21 # TARGETS: Define standard targets that can be invoked
22 ###############################################################################
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\
30 TOPLEV_TARGETS := dist dist-check dist-clean
31 INTERNAL_TARGETS := preconditions
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)
38 #--------------------------------------------------------------------
39 # Make sure all the user-target rules are double colon rules and that
40 # the preconditions are run first.
41 #--------------------------------------------------------------------
46 install :: install-local
47 uninstall :: uninstall-local
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
57 dist-check:: preconditions
58 dist-clean:: preconditions
60 ###############################################################################
61 # SUFFIXES: Reset the list of suffixes we know how to build
62 ###############################################################################
64 .SUFFIXES: .c .cpp .h .hpp .y .l .lo .o .a $(SHLIBEXT) .bc .td .ps .dot $(SUFFIXES)
66 ###############################################################################
67 # VARIABLES: Set up various variables based on configuration data
68 ###############################################################################
70 #--------------------------------------------------------------------
71 # Variables derived from configuration we are building
72 #--------------------------------------------------------------------
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
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
86 CONFIGURATION := Debug
87 CXXFLAGS += -g -D_DEBUG
89 LDFLAGS += -g -D_DEBUG
96 #--------------------------------------------------------------------
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)
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++
116 # Need a better way to compute this.
117 LLVMGCCLIBDIR := $(dir $(shell $(LLVMGCC) -print-file-name=libgcc.a))/
119 #--------------------------------------------------------------------
120 # Adjust to user's request
121 #--------------------------------------------------------------------
123 # Adjust LIBTOOL options for shared libraries, or not.
124 ifndef SHARED_LIBRARY
125 LIBTOOL += --tag=disable-shared
127 LDFLAGS += -rpath $(LIBDIR)
130 # Adjust settings for verbose mode
134 AR += >/dev/null 2>/dev/null
137 # By default, strip symbol information from executable
139 STRIP = $(PLATFORMSTRIPOPTS)
140 STRIP_WARN_MSG = "(without symbols)"
143 # Adjust linker flags for building an executable
145 LDFLAGS += -rpath $(TOOLDIR) -export-dynamic $(TOOLLINKOPTS)
148 # Use TOOLLINKOPTSB to pass options to the linker like library search
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
154 LDFLAGS += $(TOOLLINKOPTSB)
157 #----------------------------------------------------------
158 # Options To Invoke Tools
159 #----------------------------------------------------------
161 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
163 LDFLAGS += -L$(LIBDIR) -L$(LLVMLIBDIR)
164 CPPFLAGS += -I$(BUILD_OBJ_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
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)
191 #----------------------------------------------------------
192 # Get the list of source files
193 #----------------------------------------------------------
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))
201 SOURCES += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
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)
213 ###############################################################################
214 # DIRECTORIES: Handle recursive descent of directory structure
215 ###############################################################################
217 #---------------------------------------------------------
218 # Handle the DIRS options for sequential construction
219 #---------------------------------------------------------
222 $(RECURSIVE_TARGETS)::
223 $(VERB) for dir in $(DIRS); do \
224 if [ ! -f $$dir/Makefile ]; then \
226 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
228 ($(MAKE) -C $$dir $@ $(MFLAGS)) || exit 1; \
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 \
241 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
243 $(MAKE) -C $$dir $@ $(MFLAGS) || exit 0; \
247 #---------------------------------------------------------
248 # Handle the PARALLEL_DIRS options for parallel construction
249 #---------------------------------------------------------
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))
260 Parallel_Targets := $(foreach T,$(RECURSIVE_TARGETS),%/.make$(T))
262 $(Parallel_Targets) :
263 $(VERB) if [ ! -f $(@D)/Makefile ]; then \
265 cp $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
267 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) $(MFLAGS)
270 #---------------------------------------------------------
271 # Handle the OPTIONAL_DIRS options for directores that may
273 #---------------------------------------------------------
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 \
280 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
282 ($(MAKE) -C$$dir $@ $(MFLAGS)) || exit 1; \
287 #---------------------------------------------------------
288 # Handle the CONFIG_FILES options
289 #---------------------------------------------------------
292 .PHONY: install-config-dir
294 install:: install-config-dir
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) ; \
303 $(MKDIR) $(sysconfdir)
307 ###############################################################################
308 # Library Build Rules: Four ways to build a library
309 ###############################################################################
312 # if we're building a library ...
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
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 #---------------------------------------------------------
330 all-local:: $(LIBNAME_LA)
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)
338 $(VERB) $(RM) -f $(LIBNAME_LA)
340 install-local:: $(DESTDIR)$(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
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)
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
357 ifdef EXPORTED_SYMBOL_LIST
358 BCLinkLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
360 ifdef EXPORTED_SYMBOL_FILE
361 BCLinkLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
363 BCLinkLib += -Xlinker -disable-internalize
367 all-local:: $(LIBNAME_BC)
369 $(LIBNAME_BC): $(BUILT_SOURCES) $(ObjectsBC) $(LIBDIR)/.dir
370 @$(ECHO) Linking bytecode library $(notdir $@)
371 $(VERB) $(BCLinkLib) -o $@ $(ObjectsBC)
374 $(VERB) $(RM) -f $(LIBNAME_BC)
376 install-local:: $(DESTDIR)$(bytecode_libdir)/lib$(LIBRARYNAME).bc
378 $(DESTDIR)$(bytecode_libdir)/lib$(LIBRARYNAME).bc: $(LIBNAME_BC) $(DESTDIR)$(bytecode_libdir)
379 @$(ECHO) Installing bytecode library $(notdir $@)
380 $(VERB)$(INSTALL) $< $@
384 # Does the library want a .o version built?
385 ifndef DONT_BUILD_RELINKED
386 all-local:: $(LIBNAME_O)
388 $(LIBNAME_O): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
389 @$(ECHO) Linking object library $(notdir $@)
390 $(VERB) $(Relink) -o $@ $(ObjectsO)
392 install-local:: $(DESTDIR)$(libdir)/$(LIBRARYNAME).o
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
400 $(VERB) $(RM) -f $(LIBNAME_O)
404 # Does the library want an archive version built?
406 all-local:: $(LIBNAME_A)
408 $(LIBNAME_A): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
409 @$(ECHO) Building archive library $(notdir $@)
411 $(VERB) $(Archive) $@ $(ObjectsO)
415 $(VERB) $(RM) -f $(LIBNAME_A)
417 install-local:: $(DESTDIR)$(libdir)/lib$(LIBRARYNAME).a
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
428 #------------------------------------------------------------------------
429 # Handle the TOOLNAME option - used when building tool executables...
430 #------------------------------------------------------------------------
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.
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
444 Link += $(TOOLLINKOPTSB)
447 # TOOLEXENAME* - These compute the output filenames to generate...
448 TOOLEXENAME := $(TOOLDIR)/$(TOOLNAME)
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))
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))
461 LINK_OPTS := $(TOOLLINKOPTS) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS)
464 # Libtool link options:
465 # Ensure that all binaries have their symbols exported so that they can
469 # Handle compression libraries automatically
470 ifeq ($(HAVE_BZIP2),1)
473 ifeq ($(HAVE_ZLIB),1)
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))
481 all-local:: $(TOOLEXENAME)
484 $(VERB) $(RM) -f $(TOOLEXENAME)
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)
491 install-local:: $(TOOLEXENAME)
492 @$(ECHO) Installing $(TOOLNAME)
493 $(VERB) $(INSTALL) $(TOOLEXENAME) $(DESTDIR)/bin
496 ifndef DISABLE_AUTO_DEPENDENCIES
498 # Create .lo files in the OBJDIR directory from the .cpp and .c files...
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
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
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
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
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
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
546 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
547 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
548 $(LTCompile.CXX) $< -o $@
550 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
551 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
552 $(LTCompile.C) $< -o $@
556 $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
557 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
558 $(Compile.CXX) $< -o $@
560 $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
561 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
562 $(Compile.C) $< -o $@
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 $@
570 $(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
571 @$(ECHO) "Compiling $(CONFIGURATION) $*.c To Bytecode"
572 $(BCCompileC) $< -o $@
576 $(OBJDIR)/%.bc: %.ll $(OBJDIR)/.dir $(LLVMAS)
577 @$(ECHO) "Compiling $*.ll To Bytecode"
578 $(VERB) $(LLVMAS) $< -f -o $@
582 TDFILES := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
584 $(BUILT_SOURCES): $(TDFILES)
586 %GenRegisterNames.inc : %.td
587 @echo "Building $(<F) register names with tblgen"
588 $(VERB) $(TableGen) -gen-register-enums -o $@ $<
590 %GenRegisterInfo.h.inc : %.td
591 @echo "Building $(<F) register information header with tblgen"
592 $(VERB) $(TableGen) -gen-register-desc-header -o $@ $<
594 %GenRegisterInfo.inc : %.td
595 @echo "Building $(<F) register info implementation with tblgen"
596 $(VERB) $(TableGen) -gen-register-desc -o $@ $<
598 %GenInstrNames.inc : %.td
599 @echo "Building $(<F) instruction names with tblgen"
600 $(VERB) $(TableGen) -gen-instr-enums -o $@ $<
602 %GenInstrInfo.inc : %.td
603 @echo "Building $(<F) instruction information with tblgen"
604 $(VERB) $(TableGen) -gen-instr-desc -o $@ $<
606 %GenAsmWriter.inc : %.td
607 @echo "Building $(<F) assembly writer with tblgen"
608 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
610 %GenATTAsmWriter.inc : %.td
611 @echo "Building $(<F) AT&T assembly writer with tblgen"
612 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
614 %GenIntelAsmWriter.inc : %.td
615 @echo "Building $(<F) Intel assembly writer with tblgen"
616 $(VERB) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
618 %GenInstrSelector.inc: %.td
619 @echo "Building $(<F) instruction selector with tblgen"
620 $(VERB) $(TableGen) -gen-instr-selector -o $@ $<
622 %GenCodeEmitter.inc:: %.td
623 @echo "Building $(<F) code emitter with tblgen"
624 $(VERB) $(TableGen) -gen-emitter -o $@ $<
632 # Rules for building lex/yacc files
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)
640 # Create a .cpp source file from a flex input file... this uses sed to cut down
641 # on the warnings emited by GCC...
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] )
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)/' \
656 $(VERB) cmp -s $@ $@.tmp > /dev/null || $(MV) -f $@.tmp $@
657 @# remove the output of flex if it didn't get moved over...
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
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
671 # To create the directories...
673 $(VERB) $(MKDIR) $* > /dev/null
676 .PRECIOUS: $(OBJDIR)/.dir $(LIBDIR)/.dir $(TOOLDIR)/.dir $(LLVMLIBDIR)/.dir
677 .PRECIOUS: $(LLVMTOOLDIR)/.dir
679 # To create postscript files from dot files...
682 $(DOT) -Tps < $< > $@
685 $(ECHO) "Cannot build $@: The program dot is not installed"
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.
695 # 'make clean' nukes the tree
697 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
698 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
699 $(VERB) $(RM) -f *$(SHLIBEXT)
701 $(VERB) $(RM) -f $(LEX_OUTPUT) $(YACC_OUTPUT)
703 ###############################################################################
704 # DEPENDENCIES: Include the dependency files if we should
705 ###############################################################################
706 ifndef DISABLE_AUTO_DEPENDENCIES
708 # If its not one of the cleaning targets
709 ifneq ($strip($(filter-out clean clean-local dist-clean, $(MAKECMDGOALS))),)
711 # Get the list of dependency files
712 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(SOURCES)))
713 DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(CONFIGURATION)/%.d,$(DependFiles))
715 -include /dev/null $(DependFiles)
719 endif # ifndef DISABLE_AUTO_DEPENDENCIES
721 ################################################################################
722 # PRECONDITIONS - that which must be built/checked first
723 ################################################################################
725 OBJMKFILE := $(BUILD_OBJ_DIR)/Makefile
726 SRCMKFILE := $(BUILD_SRC_DIR)/Makefile
727 CONFIGURE := $(LLVM_SRC_ROOT)/configure
728 CONFIG_STATUS := $(LLVM_OBJ_ROOT)/config.status
729 MAKE_CONFIG_IN := $(LLVM_SRC_ROOT)/Makefile.config.in
730 MAKE_CONFIG := $(LLVM_OBJ_ROOT)/Makefile.config
732 #------------------------------------------------------------------------
733 # List of the preconditions
734 #------------------------------------------------------------------------
735 preconditions: $(CONFIG_STATUS) $(MAKE_CONFIG) $(OBJMKFILE)
737 all all-local check check-local dist dist-check install:: $(BUILT_SOURCES)
740 $(VERB) $(RM) -f $(BUILT_SOURCES)
742 #------------------------------------------------------------------------
743 # Make sure we're not using a stale configuration
744 #------------------------------------------------------------------------
745 .PRECIOUS: $(CONFIG_STATUS)
746 $(CONFIG_STATUS): $(CONFIGURE)
747 @$(ECHO) Reconfiguring with $@
748 $(VERB) $(CONFIG_STATUS) --recheck
750 #------------------------------------------------------------------------
751 # Make sure the configuration makefile is up to date
752 #------------------------------------------------------------------------
753 $(MAKE_CONFIG): $(MAKE_CONFIG_IN)
754 @$(ECHO) Regenerating $@
755 $(VERB) cd $(LLVM_OBJ_ROOT) ; $(CONFIG_STATUS) Makefile.config
756 $(VERB) $(MAKE) $(MFLAGS) $(MAKECMDGOALS)
759 #------------------------------------------------------------------------
760 # If the Makefile in the source tree has been updated, copy it over into the
761 # build tree. But, only do this if the source and object makefiles differ
762 #------------------------------------------------------------------------
763 ifneq ($(OBJMKFILE),$(SRCMKFILE))
764 .PRECIOUS: $(OBJMKFILE)
765 $(OBJMKFILE): $(SRCMKFILE)
766 @$(ECHO) "Updating Makefile from : $(dir $<)"
767 $(VERB) $(MKDIR) $(@D)
769 $(VERB) $(MAKE) $(MFLAGS) $(MAKECMDGOALS)
773 ###############################################################################
774 # MISCELLANEOUS - utility targets
775 ###############################################################################
777 #------------------------------------------------------------------------
778 # Print out the directories used for building
780 @$(ECHO) "BUILD_SRC_ROOT: " $(BUILD_SRC_ROOT)
781 @$(ECHO) "BUILD_SRC_DIR : " $(BUILD_SRC_DIR)
782 @$(ECHO) "BUILD_OBJ_ROOT: " $(BUILD_OBJ_ROOT)
783 @$(ECHO) "BUILD_OBJ_DIR : " $(BUILD_OBJ_DIR)
784 @$(ECHO) "LLVM_SRC_ROOT : " $(LLVM_SRC_ROOT)
785 @$(ECHO) "LLVM_OBJ_ROOT : " $(LLVM_OBJ_ROOT)
786 @$(ECHO) "CONFIGURATION : " $(CONFIGURATION)
787 @$(ECHO) "OBJDIR: " $(OBJDIR)
788 @$(ECHO) "LIBDIR: " $(LIBDIR)
789 @$(ECHO) "TOOLDIR: " $(TOOLDIR)
790 @$(ECHO) "TDFILES:" '$(TDFILES)'
791 @$(ECHO) "Compile.CXX: " '$(Compile.CXX)'
792 @$(ECHO) "Compile.C: " '$(Compile.C)'