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 tags
31 USER_TARGETS := $(RECURSIVE_TARGETS) $(LOCAL_TARGETS) $(TOPLEV_TARGETS)
32 INTERNAL_TARGETS := preconditions \
33 install-config-dir install-shared-library install-bytecode-library \
34 install-archive-library install-relinked-library install-tool \
35 uninstall-config-dir uninstall-shared-library uninstall-bytecode-library \
36 uninstall-archive-library uninstall-relinked-library uninstall-tool
38 #--------------------------------------------------------------------
39 # Mark all of these targets as phony to avoid implicit rule search
40 #--------------------------------------------------------------------
41 .PHONY: $(USER_TARGETS) $(INTERNAL_TARGETS)
43 #--------------------------------------------------------------------
44 # Make sure all the user-target rules are double colon rules and that
45 # the preconditions are run first.
46 #--------------------------------------------------------------------
48 $(USER_TARGETS) :: preconditions
53 install :: install-local
54 uninstall :: uninstall-local
55 check-local :: all-local
56 install-local :: all-local
58 ###############################################################################
59 # SUFFIXES: Reset the list of suffixes we know how to build
60 ###############################################################################
62 .SUFFIXES: .c .cpp .h .hpp .y .l .lo .o .a $(SHLIBEXT) .bc .td .ps .dot $(SUFFIXES)
64 ###############################################################################
65 # VARIABLES: Set up various variables based on configuration data
66 ###############################################################################
68 #--------------------------------------------------------------------
69 # Variables derived from configuration we are building
70 #--------------------------------------------------------------------
72 ifdef ENABLE_PROFILING
73 CONFIGURATION := Profile
74 CXXFLAGS += -O3 -DNDEBUG -felide-constructors -finline-functions -pg
75 CFLAGS += -O3 -DNDEBUG -pg
76 LDFLAGS += -O3 -DNDEBUG -pg
78 ifdef ENABLE_OPTIMIZED
79 CONFIGURATION := Release
80 CXXFLAGS += -O3 -DNDEBUG -finline-functions -felide-constructors -fomit-frame-pointer
81 CFLAGS += -O3 -DNDEBUG -fomit-frame-pointer
82 LDFLAGS += -O3 -DNDEBUG
84 CONFIGURATION := Debug
85 CXXFLAGS += -g -D_DEBUG
87 LDFLAGS += -g -D_DEBUG
94 #--------------------------------------------------------------------
96 #--------------------------------------------------------------------
97 OBJDIR := $(BUILD_OBJ_DIR)/$(CONFIGURATION)
98 LIBDIR := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
99 TOOLDIR := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
100 LLVMLIBDIR := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
101 LLVMTOOLDIR := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
103 #--------------------------------------------------------------------
104 # Full Paths To Compiled Tools and Utilities
105 #--------------------------------------------------------------------
106 LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
107 LLVMAS := $(LLVMTOOLDIR)/llvm-as$(EXEEXT)
108 BURG := $(LLVMTOOLDIR)/burg$(EXEEXT)
109 TBLGEN := $(LLVMTOOLDIR)/tblgen$(EXEEXT)
110 GCCLD := $(LLVMTOOLDIR)/gccld$(EXEEXT)
111 LLVMGCC := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/gcc
112 LLVMGXX := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/g++
114 # Need a better way to compute this.
115 LLVMGCCLIBDIR := $(dir $(shell $(LLVMGCC) -print-file-name=libgcc.a))/
117 #--------------------------------------------------------------------
118 # Adjust to user's request
119 #--------------------------------------------------------------------
121 # Adjust LIBTOOL options for shared libraries, or not.
122 ifndef SHARED_LIBRARY
123 LIBTOOL += --tag=disable-shared
125 LDFLAGS += -rpath $(LIBDIR)
128 # Adjust settings for verbose mode
132 AR += >/dev/null 2>/dev/null
133 CONFIGUREFLAGS += >$(BUILD_OBJ_DIR)/configure.out 2>&1
138 # By default, strip symbol information from executable
140 STRIP = $(PLATFORMSTRIPOPTS)
141 STRIP_WARN_MSG = "(without symbols)"
144 # Adjust linker flags for building an executable
146 LDFLAGS += -rpath $(TOOLDIR) -export-dynamic $(TOOLLINKOPTS)
149 # Use TOOLLINKOPTSB to pass options to the linker like library search
151 # Note that this is different from TOOLLINKOPTS, these options
152 # are passed to the linker *before* the USEDLIBS options are passed.
153 # e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
155 LDFLAGS += $(TOOLLINKOPTSB)
158 #----------------------------------------------------------
159 # Options To Invoke Tools
160 #----------------------------------------------------------
162 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
164 LDFLAGS += -L$(LIBDIR) -L$(LLVMLIBDIR)
165 CPPFLAGS += -I$(BUILD_OBJ_DIR) \
167 -I$(BUILD_SRC_ROOT)/include \
168 -I$(BUILD_OBJ_ROOT)/include \
169 -I$(LLVM_OBJ_ROOT)/include \
170 -I$(LLVM_SRC_ROOT)/include \
171 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
173 Compile.C = $(CC) $(CPPFLAGS) $(CompileCommonOpts) -c $(CFLAGS)
174 Compile.CXX = $(CXX) $(CPPFLAGS) $(CompileCommonOpts) $(CXXFLAGS) -c
175 LTCompile.C = $(LIBTOOL) --mode=compile $(Compile.C)
176 LTCompile.CXX = $(LIBTOOL) --tag=CXX --mode=compile $(Compile.CXX)
177 BCCompile.CXX = $(LLVMGXX) $(CPPFLAGS) $(CompileCommonOpts) $(CXXFLAGS) -c
178 BCCompile.C = $(LLVMGCC) $(CPPFLAGS) $(CompileCommonOpts) $(CFLAGS) -c
179 Link = $(LIBTOOL) --tag=CXX --mode=link $(CXX) $(CPPFLAGS) \
180 $(CompileCommonOpts) $(LDFLAGS) $(STRIP)
181 Relink = $(LIBTOOL) --tag=CXX --mode=link $(CXX)
182 BCLinkLib = $(LLVMGCC) -shared -nostdlib
183 Burg = $(BURG) -I $(BUILD_SRC_DIR)
184 TableGen = $(TBLGEN) -I $(BUILD_SRC_DIR)
185 Archive = $(AR) $(ARFLAGS)
192 #----------------------------------------------------------
193 # Get the list of source files
194 #----------------------------------------------------------
196 SOURCES := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
197 $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
198 $(BUILD_SRC_DIR)/*.l))
202 SOURCES += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
205 #----------------------------------------------------------
206 # Types of objects that can be built from sources
207 #----------------------------------------------------------
208 BASENAME_SOURCES := $(sort $(basename $(SOURCES)))
209 ObjectsO := $(BASENAME_SOURCES:%=$(OBJDIR)/%.o)
210 ObjectsLO := $(BASENAME_SOURCES:%=$(OBJDIR)/%.lo)
211 ObjectsBC := $(BASENAME_SOURCES:%=$(OBJDIR)/%.bc)
214 ###############################################################################
215 # DIRECTORIES: Handle recursive descent of directory structure
216 ###############################################################################
218 #---------------------------------------------------------
219 # Handle the DIRS options for sequential construction
220 #---------------------------------------------------------
225 $(RECURSIVE_TARGETS)::
226 $(VERB) for dir in $(DIRS); do \
227 if [ ! -f $$dir/Makefile ]; then \
229 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
231 ($(MAKE) -C $$dir $@ ) || exit 1; \
235 #---------------------------------------------------------
236 # Handle the EXPERIMENTAL_DIRS options ensuring success
237 # after each directory is built.
238 #---------------------------------------------------------
239 ifdef EXPERIMENTAL_DIRS
240 $(RECURSIVE_TARGETS)::
241 $(VERB) for dir in $(EXPERIMENTAL_DIRS); do \
242 if [ ! -f $$dir/Makefile ]; then \
244 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
246 ($(MAKE) -C $$dir $@ ) || exit 0; \
250 #---------------------------------------------------------
251 # Handle the PARALLEL_DIRS options for parallel construction
252 #---------------------------------------------------------
255 SUBDIRS += $(PARALLEL_DIRS)
256 # Unfortunately, this list must be maintained if new
257 # recursive targets are added.
258 all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
259 clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
260 check :: $(addsuffix /.makecheck , $(PARALLEL_DIRS))
261 install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
262 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
264 Parallel_Targets := $(foreach T,$(RECURSIVE_TARGETS),%/.make$(T))
266 $(Parallel_Targets) :
267 $(VERB) if [ ! -f $(@D)/Makefile ]; then \
269 cp $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
271 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
274 #---------------------------------------------------------
275 # Handle the OPTIONAL_DIRS options for directores that may
277 #---------------------------------------------------------
280 SUBDIRS += $(OPTIONAL_DIRS)
282 $(RECURSIVE_TARGETS)::
283 $(VERB) for dir in $(OPTIONAL_DIRS); do \
284 if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
285 if [ ! -f $$dir/Makefile ]; then \
287 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
289 ($(MAKE) -C$$dir $@ ) || exit 1; \
294 #---------------------------------------------------------
295 # Handle the CONFIG_FILES options
296 #---------------------------------------------------------
299 install-local:: install-config-dir
301 install-config-dir: $(sysconfdir) $(CONFIG_FILES)
302 $(VERB)$(ECHO) Installing Configuration Files To $(sysconfdir)
303 $(VERB)for file in $(CONFIG_FILES); do \
304 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
307 uninstall-local:: uninstall-config-dir
309 uninstall-config-dir:
310 $(VERB)$(ECHO) Uninstalling Configuration Files From $(sysconfdir)
311 $(VERB)for file in $(CONFIG_FILES); do \
312 $(RM) -f $(sysconfdir)/$${file} ; \
316 $(MKDIR) $(sysconfdir)
320 ###############################################################################
321 # Library Build Rules: Four ways to build a library
322 ###############################################################################
325 # if we're building a library ...
328 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
329 LIBRARYNAME := $(strip $(LIBRARYNAME))
330 LIBNAME_LA := $(LIBDIR)/lib$(LIBRARYNAME).la
331 LIBNAME_A := $(LIBDIR)/lib$(LIBRARYNAME).a
332 LIBNAME_O := $(LIBDIR)/$(LIBRARYNAME).o
333 LIBNAME_BC := $(LIBDIR)/lib$(LIBRARYNAME).bc
335 #---------------------------------------------------------
336 # Shared Library Targets:
337 # If the user asked for a shared library to be built
338 # with the SHARED_LIBRARY variable, then we provide
339 # targets for building them.
340 #---------------------------------------------------------
343 all-local:: $(LIBNAME_LA)
345 $(LIBNAME_LA): $(BUILT_SOURCES) $(ObjectsLO) $(LIBDIR)/.dir
346 @$(ECHO) Linking shared library $(notdir $@)
347 $(VERB) $(Link) -o $@ $(ObjectsLO)
348 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $@ $(LIBDIR)
351 ifneq ($(strip $(LIBNAME_LA)),)
352 $(VERB) $(RM) -f $(LIBNAME_LA)
355 DestSharedLib = $(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
356 install-local:: install-shared-library
358 install-shared-library: $(DestSharedLib)
360 $(DestSharedLib): $(LIBNAME_LA)
361 @$(ECHO) Installing shared library $(DestSharedLib)
362 $(VERB) $(MKDIR) $(libdir)
363 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_LA) $(DestSharedLib)
364 $(VERB) $(LIBTOOL) --finish $(libdir)
366 uninstall-local:: uninstall-shared-library
368 uninstall-shared-library:
369 @$(ECHO) Uninstalling shared library $(DestSharedLib)
370 $(VERB) $(RM) -f $(DestSharedLib)
374 #---------------------------------------------------------
375 # Bytecode Library Targets:
376 # If the user asked for a bytecode library to be built
377 # with the BYTECODE_LIBRARY variable, then we provide
378 # targets for building them.
379 #---------------------------------------------------------
380 ifdef BYTECODE_LIBRARY
382 ifdef EXPORTED_SYMBOL_LIST
383 BCLinkLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
385 ifdef EXPORTED_SYMBOL_FILE
386 BCLinkLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
388 BCLinkLib += -Xlinker -disable-internalize
392 all-local:: $(LIBNAME_BC)
394 $(LIBNAME_BC): $(BUILT_SOURCES) $(ObjectsBC) $(LIBDIR)/.dir
395 @$(ECHO) Linking bytecode library $(notdir $@)
396 $(VERB) $(BCLinkLib) -o $@ $(ObjectsBC)
399 ifneq ($(strip $(LIBNAME_BC)),)
400 $(VERB) $(RM) -f $(LIBNAME_BC)
403 DestBytecodeLib = $(bytecode_libdir)/lib$(LIBRARYNAME).bc
404 install-local:: install-bytecode-library
406 install-bytecode-library: $(DestBytecodeLib)
408 $(DestBytecodeLib): $(LIBNAME_BC) $(bytecode_libdir)
409 @$(ECHO) Installing bytecode library $(DestBytecodeLib)
410 $(VERB) $(INSTALL) $< $@
412 uninstall-local:: uninstall-bytecode-library
414 uninstall-bytecode-library:
415 @$(ECHO) Uninstalling bytecode library $(DestBytecodeLib)
416 $(VERB) $(RM) -f $(DestBytecodeLib)
420 # Does the library want a .o version built?
421 ifndef DONT_BUILD_RELINKED
422 all-local:: $(LIBNAME_O)
424 $(LIBNAME_O): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
425 @$(ECHO) Linking object library $(notdir $@)
426 $(VERB) $(Relink) -o $@ $(ObjectsO)
429 ifneq ($(strip $(LIBNAME_O)),)
430 $(VERB) $(RM) -f $(LIBNAME_O)
433 DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
435 install-local:: install-relinked-library
437 install-relinked-library: $(DestRelinkedLib)
439 $(DestRelinkedLib): $(LIBNAME_O)
440 @$(ECHO) Installing object library $(DestRelinkedLib)
441 $(VERB) $(MKDIR) $(libdir)
442 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_O) $(DestRelinkedLib)
444 uninstall-local:: uninstall-relinked-library
446 uninstall-relinked-library:
447 @$(ECHO) Uninstalling object library $(DestRelinkedLib)
448 $(VERB) $(RM) -f $(DestRelinkedLib)
452 # Does the library want an archive version built?
454 all-local:: $(LIBNAME_A)
456 $(LIBNAME_A): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
457 @$(ECHO) Building archive library $(notdir $@)
459 $(VERB) $(Archive) $@ $(ObjectsO)
463 ifneq ($(strip $(LIBNAME_A)),)
464 $(VERB) $(RM) -f $(LIBNAME_A)
467 DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
469 install-local:: install-archive-library
471 install-archive-library: $(DestArchiveLib)
473 $(DestArchiveLib): $(LIBNAME_A)
474 @$(ECHO) Installing archive library $(DestArchiveLib)
475 $(VERB) $(MKDIR) $(libdir)
476 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_A) $(DestArchiveLib)
478 uninstall-local:: uninstall-archive-library
480 uninstall-archive-library:
481 @$(ECHO) Uninstalling archive library $(DestArchiveLib)
482 $(VERB) $(RM) -f $(DestArchiveLib)
489 ###############################################################################
490 # Tool Build Rules: Build executable tool based on TOOLNAME option
491 ###############################################################################
495 #---------------------------------------------------------
496 # TOOLLINKOPTSB to pass options to the linker like library search path etc
497 # Note that this is different from TOOLLINKOPTS, these options
498 # are passed to the linker *before* the USEDLIBS options are passed.
499 # e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
500 #---------------------------------------------------------
502 Link += $(TOOLLINKOPTSB)
505 # TOOLEXENAME - This is the output filenames to generate
506 TOOLEXENAME := $(TOOLDIR)/$(TOOLNAME)
508 # LIBS_OPTIONS - Compute the options lines that add -llib1 -llib2, etc.
509 PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
510 PROJ_LIBS_OPTIONS := $(patsubst %.o, $(LIBDIR)/%.o, $(PROJ_LIBS_OPTIONS))
511 LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
512 LLVM_LIBS_OPTIONS := $(patsubst %.o, $(LLVMLIBDIR)/%.o, $(LLVM_LIBS_OPTIONS))
514 # USED_LIBS/LIBS_PATHS - Compute dependent library file paths
515 PROJ_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
516 LLVM_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
517 PROJ_LIBS_PATHS := $(addprefix $(LIBDIR)/,$(PROJ_USED_LIBS))
518 LLVM_LIBS_PATHS := $(addprefix $(LLVMLIBDIR)/,$(LLVM_USED_LIBS))
520 # Concatenate all the optoins
521 LINK_OPTS := $(TOOLLINKOPTS) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS)
523 # Handle compression libraries automatically
524 ifeq ($(HAVE_BZIP2),1)
527 ifeq ($(HAVE_ZLIB),1)
531 # Tell make that we need to rebuild subdirectories before we can link the tool.
532 # This affects things like LLI which has library subdirectories.
533 $(TOOLEXENAME): $(addsuffix /.makeall, $(PARALLEL_DIRS))
535 all-local:: $(TOOLEXENAME)
538 ifneq ($(strip $(TOOLEXENAME)),)
539 $(VERB) $(RM) -f $(TOOLEXENAME)
542 $(TOOLEXENAME): $(BUILT_SOURCES) $(ObjectsO) $(PROJ_LIBS_PATHS) $(LLVM_LIBS_PATHS) $(TOOLDIR)/.dir
543 @$(ECHO) Linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
544 $(VERB) $(Link) -o $@ $(ObjectsO) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS) $(LIBS)
545 @$(ECHO) ======= Finished linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
547 install-local:: install-tool
549 DestTool = $(bindir)/$(TOOLNAME)
551 install-tool: $(DestTool)
553 $(DestTool): $(TOOLEXENAME)
554 @$(ECHO) Installing $(DestTool)
555 $(VERB) $(INSTALL) $(TOOLEXENAME) $(bindir)
557 uninstall-local:: uninstall-tool
560 @$(ECHO) Uninstalling $(DestTool)
561 $(VERB) $(RM) -f $(DestTool)
565 ifndef DISABLE_AUTO_DEPENDENCIES
567 # Create .lo files in the OBJDIR directory from the .cpp and .c files...
570 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
571 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
572 $(VERB) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(OBJDIR)/$*.LACXXd $< -o $@ ; \
573 then $(MV) -f "$(OBJDIR)/$*.LACXXd" "$(OBJDIR)/$*.d"; \
574 else $(RM) -f "$(OBJDIR)/$*.LACXXd"; exit 1; fi
576 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
577 @$(ECHO) "Compiling $(CONFIGURATION) $*.c For Shared Library"
578 $(VERB) if $(LTCompile.C) -MD -MT $@ -MP -MF $(OBJDIR)/$*.LACd $< -o $@ ; \
579 then $(MV) -f "$(OBJDIR)/$*.LACd" "$(OBJDIR)/$*.d"; \
580 else $(RM) -f "$(OBJDIR)/$*.LACd"; exit 1; fi
584 $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
585 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
586 $(VERB) if $(Compile.CXX) -MD -MT $@ -MP -MF $(OBJDIR)/$*.CXXd $< -o $@ ; \
587 then $(MV) -f "$(OBJDIR)/$*.CXXd" "$(OBJDIR)/$*.d"; \
588 else $(RM) -f "$(OBJDIR)/$*.CXXd"; exit 1; fi
590 $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
591 @$(ECHO) "Compiling $(CONFIGURATION) $*.c For Archive"
592 $(VERB) if $(Compile.C) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Cd $< -o $@ ; \
593 then $(MV) -f "$(OBJDIR)/$*.Cd" "$(OBJDIR)/$*.d"; \
594 else $(RM) -f "$(OBJDIR)/$*.Cd"; exit 1; fi
598 # Create .bc files in the OBJDIR directory from .cpp and .c files...
599 $(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
600 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp to bytecode"
601 $(VERB) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.BCCXXd" $< -o $@ ; \
602 then $(MV) -f "$(OBJDIR)/$*.BCCXXd" "$(OBJDIR)/$*.d"; \
603 else $(RM) -f "$(OBJDIR)/$*.BCCXXd"; exit 1; fi
605 $(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
606 @$(ECHO) "Compiling $(CONFIGURATION) $*.c to bytecode"
607 $(VERB) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.BCCd" $< -o $@ ; \
608 then $(MV) -f "$(OBJDIR)/$*.BCCd" "$(OBJDIR)/$*.d"; \
609 else $(RM) -f "$(OBJDIR)/$*.BCCd"; exit 1; fi
615 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
616 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
617 $(LTCompile.CXX) $< -o $@
619 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
620 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Shared Library"
621 $(LTCompile.C) $< -o $@
625 $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
626 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
627 $(Compile.CXX) $< -o $@
629 $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
630 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp For Archive"
631 $(Compile.C) $< -o $@
634 # Create .bc files in the OBJDIR directory from .cpp and .c files...
635 $(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
636 @$(ECHO) "Compiling $(CONFIGURATION) $*.cpp To Bytecode"
637 $(BCCompileCPP) $< -o $@
639 $(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
640 @$(ECHO) "Compiling $(CONFIGURATION) $*.c To Bytecode"
641 $(BCCompileC) $< -o $@
645 $(OBJDIR)/%.bc: %.ll $(OBJDIR)/.dir $(LLVMAS)
646 @$(ECHO) "Compiling $*.ll To Bytecode"
647 $(VERB) $(LLVMAS) $< -f -o $@
651 TDFILES := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
653 $(BUILT_SOURCES): $(TDFILES)
655 %GenRegisterNames.inc : %.td
656 @echo "Building $(<F) register names with tblgen"
657 $(VERB) $(TableGen) -gen-register-enums -o $@ $<
659 %GenRegisterInfo.h.inc : %.td
660 @echo "Building $(<F) register information header with tblgen"
661 $(VERB) $(TableGen) -gen-register-desc-header -o $@ $<
663 %GenRegisterInfo.inc : %.td
664 @echo "Building $(<F) register info implementation with tblgen"
665 $(VERB) $(TableGen) -gen-register-desc -o $@ $<
667 %GenInstrNames.inc : %.td
668 @echo "Building $(<F) instruction names with tblgen"
669 $(VERB) $(TableGen) -gen-instr-enums -o $@ $<
671 %GenInstrInfo.inc : %.td
672 @echo "Building $(<F) instruction information with tblgen"
673 $(VERB) $(TableGen) -gen-instr-desc -o $@ $<
675 %GenAsmWriter.inc : %.td
676 @echo "Building $(<F) assembly writer with tblgen"
677 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
679 %GenATTAsmWriter.inc : %.td
680 @echo "Building $(<F) AT&T assembly writer with tblgen"
681 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
683 %GenIntelAsmWriter.inc : %.td
684 @echo "Building $(<F) Intel assembly writer with tblgen"
685 $(VERB) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
687 %GenInstrSelector.inc: %.td
688 @echo "Building $(<F) instruction selector with tblgen"
689 $(VERB) $(TableGen) -gen-instr-selector -o $@ $<
691 %GenCodeEmitter.inc:: %.td
692 @echo "Building $(<F) code emitter with tblgen"
693 $(VERB) $(TableGen) -gen-emitter -o $@ $<
701 # Rules for building lex/yacc files
703 LEX_FILES = $(filter %.l, $(SOURCES))
704 LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
705 YACC_FILES = $(filter %.y, $(SOURCES))
706 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
707 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
709 # Create a .cpp source file from a flex input file... this uses sed to cut down
710 # on the warnings emited by GCC...
712 # The last line is a gross hack to work around flex aparently not being able to
713 # resize the buffer on a large token input. Currently, for uninitialized string
714 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
715 # FIXME. (f.e. char Buffer[10000] )
719 $(VERB) $(FLEX) -t $< | \
720 $(SED) '/^find_rule/d' | \
721 $(SED) 's/void yyunput/inline void yyunput/' | \
722 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
723 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
725 $(VERB) cmp -s $@ $@.tmp > /dev/null || $(MV) -f $@.tmp $@
726 @# remove the output of flex if it didn't get moved over...
729 # Rule for building the bison parsers...
730 %.c: %.y # Cancel built-in rules for yacc
731 %.h: %.y # Cancel built-in rules for yacc
733 @$(ECHO) "Bisoning $*.y"
734 $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
735 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || $(MV) -f $*.tab.c $*.cpp
736 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || $(MV) -f $*.tab.h $*.h
737 @# If the files were not updated, don't leave them lying around...
738 @rm -f $*.tab.c $*.tab.h
740 # To create the directories...
742 $(VERB) $(MKDIR) $* > /dev/null
745 .PRECIOUS: $(OBJDIR)/.dir $(LIBDIR)/.dir $(TOOLDIR)/.dir $(LLVMLIBDIR)/.dir
746 .PRECIOUS: $(LLVMTOOLDIR)/.dir
748 # To create postscript files from dot files...
751 $(DOT) -Tps < $< > $@
754 $(ECHO) "Cannot build $@: The program dot is not installed"
758 # This rules ensures that header files that are removed still have a rule for
759 # which they can be "generated." This allows make to ignore them and
760 # reproduce the dependency lists.
764 # 'make clean' nukes the tree
766 ifneq ($(strip $(OBJDIR)),)
767 $(VERB) $(RM) -rf $(OBJDIR)
769 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
770 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
771 $(VERB) $(RM) -f *$(SHLIBEXT)
773 ifneq ($(strip $(LEX_OUTPUT)),)
774 $(VERB) $(RM) -f $(LEX_OUTPUT)
776 ifneq ($(strip $(YACC_OUTPUT)),)
777 $(VERB) $(RM) -f $(YACC_OUTPUT)
780 ###############################################################################
781 # DEPENDENCIES: Include the dependency files if we should
782 ###############################################################################
783 ifndef DISABLE_AUTO_DEPENDENCIES
785 # If its not one of the cleaning targets
786 ifneq ($strip($(filter-out clean clean-local dist-clean, $(MAKECMDGOALS))),)
788 # Get the list of dependency files
789 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(SOURCES)))
790 DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(CONFIGURATION)/%.d,$(DependFiles))
792 -include /dev/null $(DependFiles)
796 endif # ifndef DISABLE_AUTO_DEPENDENCIES
798 ################################################################################
799 # PRECONDITIONS - that which must be built/checked first
800 ################################################################################
802 OBJMKFILE := $(BUILD_OBJ_DIR)/Makefile
803 SRCMKFILE := $(BUILD_SRC_DIR)/Makefile
804 CONFIGURE := $(LLVM_SRC_ROOT)/configure
805 CONFIG_STATUS := $(LLVM_OBJ_ROOT)/config.status
806 MAKE_CONFIG_IN := $(LLVM_SRC_ROOT)/Makefile.config.in
807 MAKE_CONFIG := $(LLVM_OBJ_ROOT)/Makefile.config
809 #------------------------------------------------------------------------
810 # List of the preconditions
811 #------------------------------------------------------------------------
813 preconditions: $(CONFIG_STATUS) $(MAKE_CONFIG) $(OBJMKFILE)
815 $(filter-out clean clean-local,USER_TARGETS):: $(BUILT_SOURCES)
818 ifneq ($(strip $(BUILT_SOURCES)),)
819 $(VERB) $(RM) -f $(BUILT_SOURCES)
822 #------------------------------------------------------------------------
823 # Make sure we're not using a stale configuration
824 #------------------------------------------------------------------------
825 .PRECIOUS: $(CONFIG_STATUS)
826 $(CONFIG_STATUS): $(CONFIGURE)
827 @$(ECHO) Reconfiguring with $<
828 $(VERB) $(CONFIG_STATUS) --recheck $(CONFIGUREFLAGS)
830 #------------------------------------------------------------------------
831 # Make sure the configuration makefile is up to date
832 #------------------------------------------------------------------------
833 $(MAKE_CONFIG): $(MAKE_CONFIG_IN) $(CONFIG_STATUS)
834 @$(ECHO) Regenerating $@
835 $(VERB) cd $(LLVM_OBJ_ROOT) ; $(CONFIG_STATUS) Makefile.config
837 #------------------------------------------------------------------------
838 # If the Makefile in the source tree has been updated, copy it over into the
839 # build tree. But, only do this if the source and object makefiles differ
840 #------------------------------------------------------------------------
841 ifneq ($(OBJMKFILE),$(SRCMKFILE))
842 .PRECIOUS: $(OBJMKFILE)
843 $(OBJMKFILE): $(SRCMKFILE)
844 @$(ECHO) "Updating Makefile from: $(dir $<)"
845 $(VERB) $(MKDIR) $(@D)
849 ###############################################################################
850 # Handle construction of a distribution tarball
851 ###############################################################################
853 .PHONY: dist dist-chck dist-clean distdir dist-gzip dist-bzip2 dist-zip
855 ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
857 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
858 @$(ECHO) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
862 ifeq ($(LLVM_TARBALL_NAME),)
863 $(error LLVM_TARBALL_NAME is empty. Please rerun configure)
868 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
869 @$(ECHO) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
875 DistTopCheck := check
878 @$(ECHO) Packing gzipped distribution tar file.
879 $(VERB) $(TAR) chf - "$(TopDistDir)" | gzip -c > "$(DistTarGZip)"
882 @$(ECHO) Packing bzipped distribution tar file.
883 $(VERB) $(TAR) chf - $(DistName) | $(BZIP2) -c >$(DistTarBZ2)
886 @$(ECHO) Packing zipped distribution file.
887 $(VERB) rm -f $(DistZip)
888 $(VERB) $(ZIP) -rq $(DistZip) $(DistName)
891 @$(ECHO) Packing gzipped distribution tar file.
892 $(VERB) $(TAR) chf - $(DistName) | $(GZIP) -c >$(DistTarGZip)
893 @$(ECHO) Packing bzipped distribution tar file.
894 $(VERB) $(TAR) chf - $(DistName) | $(BZIP2) -c >$(DistTarBZ2)
895 @$(ECHO) Packing zipped distribution file.
896 $(VERB) rm -f $(DistZip)
897 $(VERB) $(ZIP) -rq $(DistZip) $(DistName)
898 @$(ECHO) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
903 @$(ECHO) Cleaning distribution files
904 $(VERB) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName)
908 DistName := $(LLVM_TARBALL_NAME)
909 DistDir := $(BUILD_OBJ_ROOT)/$(DistName)
910 TopDistDir := $(DistDir)
911 DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
912 DistZip := $(BUILD_OBJ_ROOT)/$(DistName).zip
913 DistTarBZ2 := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
914 DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
915 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
917 DistSources := $(filter-out projects,$(SOURCES) $(EXTRA_DIST))
918 DistSubDirs := $(filter-out projects,$(SUBDIRS))
919 DistFiles := $(DistAlways) $(DistSources)
920 RmDistDir := { test ! -d $(DistDir) || { \
921 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' \
922 && rm -rf $(DistDir); }; }
924 distdir : $(DistTopCheck) $(DistSources)
925 @$(ECHO) Building Distribution Directory $(DistDir)
927 $(VERB) $(MKDIR) $(DistDir)
928 $(VERB) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
929 srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
930 for file in $(DistFiles) ; do \
932 $(BUILD_SRC_DIR)/*) file=`echo "$$file" | sed "s#^$$srcdirstrip/##"`;; \
933 $(BUILD_SRC_ROOT)/*) file=`echo "$$file" | sed "s#^$srcrootstrip/#$(BUILD_OBJ_ROOT)/#"`;; \
935 if test -f "$$file" || test -d "$$file" ; then \
938 from_dir=$(BUILD_SRC_DIR); \
940 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'`; \
941 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
942 to_dir="$(DistDir)/$$dir"; \
943 $(MKDIR) "$$to_dir" ; \
945 to_dir="$(DistDir)"; \
947 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
948 if test -n "$$mid_dir" ; then \
949 $(MKDIR) "$$to_dir/$$mid_dir" ; \
951 if test -d "$$from_dir/$$file"; then \
952 if test -d "$(BUILD_SRC_DIR)/$$file" && \
953 test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
954 cp -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
956 cp -pR $$from_dir/$$file $$to_dir || exit 1; \
957 elif test -f "$$from_dir/$$file" ; then \
958 cp -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
959 elif test -L "$$from_dir/$$file" ; then \
960 cp -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
961 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
962 $(ECHO) "===== WARNING: Distribution Source $$from_dir/$$file Not Found!" ; \
963 elif test "$(VERB)" != '@' ; then \
964 $(ECHO) "Skipping non-existent $$from_dir/$$file" ; \
967 $(VERB) for subdir in $(SUBDIRS) ; do \
968 if test "$$subdir" \!= "." ; then \
969 test -d "$(DistDir)/$$subdir" || $(MKDIR) "$(DistDir)/$$subdir" || exit 1; \
970 new_distdir="$(DistDir)/$$subdir" ; \
971 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || exit 1; \
974 $(VERB) $(MAKE) DistDir="$(DistDir)" dist-hook
975 -$(VERB) find $(DistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
976 ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
977 ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
978 ! -type d ! -perm -444 -exec $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
979 || chmod -R a+r $(DistDir)
986 ###############################################################################
987 # TOP LEVEL - targets only to apply at the top level directory
988 ###############################################################################
992 #------------------------------------------------------------------------
993 # Install support for project's include files:
994 #------------------------------------------------------------------------
996 @$(ECHO) Installing include files
997 $(VERB) $(MKDIR) $(includedir)
998 $(VERB) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
999 cd $(BUILD_SRC_ROOT)/include && \
1000 find . -path '*/Internal' -prune -o '(' -type f \
1001 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1002 -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
1006 @$(ECHO) Uninstalling include files
1007 $(VERB) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1008 cd $(BUILD_SRC_ROOT)/include && \
1009 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1010 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1011 -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
1014 #------------------------------------------------------------------------
1015 # Build tags database for Emacs/Xemacs:
1016 #------------------------------------------------------------------------
1020 find include lib tools examples -name '*.cpp' -o -name '*.h' | $(ETAGS) $(ETAGSFLAGS) -
1024 ###############################################################################
1025 # MISCELLANEOUS - utility targets
1026 ###############################################################################
1028 #------------------------------------------------------------------------
1029 # Print out the directories used for building
1031 @$(ECHO) "BUILD_SRC_ROOT: " $(BUILD_SRC_ROOT)
1032 @$(ECHO) "BUILD_SRC_DIR : " $(BUILD_SRC_DIR)
1033 @$(ECHO) "BUILD_OBJ_ROOT: " $(BUILD_OBJ_ROOT)
1034 @$(ECHO) "BUILD_OBJ_DIR : " $(BUILD_OBJ_DIR)
1035 @$(ECHO) "LLVM_SRC_ROOT : " $(LLVM_SRC_ROOT)
1036 @$(ECHO) "LLVM_OBJ_ROOT : " $(LLVM_OBJ_ROOT)
1037 @$(ECHO) "CONFIGURATION : " $(CONFIGURATION)
1038 @$(ECHO) "OBJDIR: " $(OBJDIR)
1039 @$(ECHO) "LIBDIR: " $(LIBDIR)
1040 @$(ECHO) "TOOLDIR: " $(TOOLDIR)
1041 @$(ECHO) "TDFILES:" '$(TDFILES)'
1042 @$(ECHO) "Compile.CXX: " '$(Compile.CXX)'
1043 @$(ECHO) "Compile.C: " '$(Compile.C)'
1045 # This frivolous target provided for Resistor who requested that the makefiles
1046 # be hardened and that he get a "pony" after the makefiles (accidentally)
1047 # deleted his unix kernel.
1050 http://search.cpan.org/src/ASAVIGE/Acme-EyeDrops-1.40/lib/Acme/EyeDrops/pony2.eye \
1051 -O /tmp/resistor.pony
1052 @cat /tmp/resistor.pony