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 \
29 printvars uninstall-local
30 TOPLEV_TARGETS := dist dist-check dist-clean tags
31 USER_TARGETS := $(RECURSIVE_TARGETS) $(LOCAL_TARGETS) $(TOPLEV_TARGETS)
32 INTERNAL_TARGETS := preconditions
34 ###############################################################################
35 # INITIALIZATION: Basic things the makefile needs
36 ###############################################################################
38 #--------------------------------------------------------------------
39 # Reset the list of suffixes we know how to build
40 #--------------------------------------------------------------------
42 .SUFFIXES: .c .cpp .h .hpp .y .l .lo .o .a $(SHLIBEXT) .bc .td .ps .dot $(SUFFIXES)
44 #--------------------------------------------------------------------
45 # Mark all of these targets as phony to avoid implicit rule search
46 #--------------------------------------------------------------------
47 .PHONY: $(USER_TARGETS) $(INTERNAL_TARGETS)
49 #--------------------------------------------------------------------
50 # Make sure all the user-target rules are double colon rules and
51 # they are defined first.
52 #--------------------------------------------------------------------
56 ################################################################################
57 # PRECONDITIONS: that which must be built/checked first
58 ################################################################################
60 SRCMKFILES := $(filter %Makefile %Makefile.rules %Makefile.tests \
61 %Makefile.JIT,$(wildcard $(BUILD_SRC_DIR)/Makefile*))
62 OBJMKFILES := $(subst $(BUILD_SRC_DIR),$(BUILD_OBJ_DIR),$(SRCMKFILES))
63 CONFIGURE := $(LLVM_SRC_ROOT)/configure
64 CONFIG_STATUS := $(LLVM_OBJ_ROOT)/config.status
65 MAKE_CONFIG_IN:= $(LLVM_SRC_ROOT)/Makefile.config.in
66 MAKE_CONFIG := $(LLVM_OBJ_ROOT)/Makefile.config
67 PRECONDITIONS := $(CONFIG_STATUS) $(MAKE_CONFIG) $(OBJMKFILES)
69 preconditions : $(PRECONDITIONS)
71 #------------------------------------------------------------------------
72 # Make sure the BUILT_SOURCES are built first
73 #------------------------------------------------------------------------
74 $(filter-out clean clean-local,USER_TARGETS):: $(BUILT_SOURCES)
77 ifneq ($(strip $(BUILT_SOURCES)),)
78 $(VERB) $(RM) -f $(BUILT_SOURCES)
81 $(BUILT_SOURCES) : $(BUILD_OBJ_ROOT)/Makefile
83 #------------------------------------------------------------------------
84 # Make sure we're not using a stale configuration
85 #------------------------------------------------------------------------
86 .PRECIOUS: $(CONFIG_STATUS)
87 $(CONFIG_STATUS): $(CONFIGURE)
88 @$(ECHO) Reconfiguring with $<
89 $(VERB) $(CONFIG_STATUS) --recheck $(CONFIGUREFLAGS)
90 $(VERB) $(CONFIG_STATUS)
92 #------------------------------------------------------------------------
93 # Make sure the configuration makefile is up to date
94 #------------------------------------------------------------------------
95 $(MAKE_CONFIG): $(MAKE_CONFIG_IN) $(CONFIG_STATUS)
96 @$(ECHO) Regenerating $@
97 $(VERB) cd $(LLVM_OBJ_ROOT) ; $(CONFIG_STATUS) Makefile.config
99 #------------------------------------------------------------------------
100 # If the Makefile in the source tree has been updated, copy it over into the
101 # build tree. But, only do this if the source and object makefiles differ
102 #------------------------------------------------------------------------
103 ifneq ($(BUILD_OBJ_DIR),$(BUILD_SRC_DIR))
105 $(BUILD_OBJ_DIR)/Makefile : $(BUILD_SRC_DIR)/Makefile
106 @$(ECHO) "Updating Makefile"
107 $(VERB) $(MKDIR) $(@D)
110 # Copy the Makefile.* files unless we're in the root directory which avoids
111 # the copying of Makefile.config.in or other things that should be explicitly
113 $(BUILD_OBJ_DIR)/Makefile% : $(BUILD_SRC_DIR)/Makefile%
115 *Makefile.rules) ;; \
117 *) $(ECHO) "Updating $(@F)" ; \
124 #------------------------------------------------------------------------
125 # Set up the basic dependencies
126 #------------------------------------------------------------------------
127 $(USER_TARGETS):: $(PRECONDITIONS)
132 install:: install-local
133 uninstall:: uninstall-local
134 check-local:: all-local
135 install-local:: all-local
137 ###############################################################################
138 # VARIABLES: Set up various variables based on configuration data
139 ###############################################################################
141 #--------------------------------------------------------------------
142 # Variables derived from configuration we are building
143 #--------------------------------------------------------------------
145 ifdef ENABLE_PROFILING
146 CONFIGURATION := Profile
147 LLVMCXXFLAGS := -O3 -DNDEBUG -felide-constructors -finline-functions -pg
148 LLVMCFLAGS := -O3 -DNDEBUG -pg
149 LLVMLDFLAGS := -O3 -DNDEBUG -pg
151 ifdef ENABLE_OPTIMIZED
152 CONFIGURATION := Release
153 LLVMCXXFLAGS := -O3 -DNDEBUG -finline-functions -felide-constructors -fomit-frame-pointer
154 LLVMCFLAGS := -O3 -DNDEBUG -fomit-frame-pointer
155 LLVMLDFLAGS := -O3 -DNDEBUG
157 CONFIGURATION := Debug
158 LLVMCXXFLAGS := -g -D_DEBUG
159 LLVMCFLAGS := -g -D_DEBUG
160 LLVMLDFLAGS := -g -D_DEBUG
165 LLVMCXXFLAGS += $(CXXFLAGS)
166 LLVMCFLAGS += $(CFLAGS)
167 LLVMCPPFLAGS += $(CPPFLAGS)
168 LLVMLDFLAGS += $(LDFLAGS)
171 #--------------------------------------------------------------------
172 # Directory locations
173 #--------------------------------------------------------------------
174 OBJDIR := $(BUILD_OBJ_DIR)/$(CONFIGURATION)
175 LIBDIR := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
176 TOOLDIR := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
177 LLVMLIBDIR := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
178 LLVMTOOLDIR := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
180 #--------------------------------------------------------------------
181 # Full Paths To Compiled Tools and Utilities
182 #--------------------------------------------------------------------
183 LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
184 LLVMAS := $(LLVMTOOLDIR)/llvm-as$(EXEEXT)
185 BURG := $(LLVMTOOLDIR)/burg$(EXEEXT)
186 TBLGEN := $(LLVMTOOLDIR)/tblgen$(EXEEXT)
187 GCCLD := $(LLVMTOOLDIR)/gccld$(EXEEXT)
188 LLVMGCC := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/gcc
189 LLVMGXX := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/g++
191 # Need a better way to compute this.
192 LLVMGCCLIBDIR := $(dir $(shell $(LLVMGCC) -print-file-name=libgcc.a))/
194 #--------------------------------------------------------------------
195 # Adjust to user's request
196 #--------------------------------------------------------------------
198 # Adjust LIBTOOL options for shared libraries, or not.
199 ifndef SHARED_LIBRARY
200 LIBTOOL += --tag=disable-shared
202 LLVMLDFLAGS += -rpath $(LIBDIR)
205 # Adjust settings for verbose mode
209 AR += >/dev/null 2>/dev/null
210 CONFIGUREFLAGS += >$(BUILD_OBJ_DIR)/configure.out 2>&1
215 # By default, strip symbol information from executable
217 STRIP = $(PLATFORMSTRIPOPTS)
218 STRIP_WARN_MSG = "(without symbols)"
221 # Adjust linker flags for building an executable
223 LLVMLDFLAGS += -rpath $(TOOLDIR) -export-dynamic
226 #----------------------------------------------------------
227 # Options To Invoke Tools
228 #----------------------------------------------------------
230 CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
232 LLVMLDFLAGS += -L$(LIBDIR) -L$(LLVMLIBDIR)
233 LLVMCPPFLAGS += -I$(BUILD_OBJ_DIR) \
235 -I$(BUILD_SRC_ROOT)/include \
236 -I$(BUILD_OBJ_ROOT)/include \
237 -I$(LLVM_OBJ_ROOT)/include \
238 -I$(LLVM_SRC_ROOT)/include \
239 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
241 Compile.C = $(CC) $(LLVMCPPFLAGS) $(CompileCommonOpts) -c $(LLVMCFLAGS)
242 LTCompile.C = $(LIBTOOL) --mode=compile $(Compile.C)
243 BCCompile.C = $(LLVMGCC) $(LLVMCPPFLAGS) $(CompileCommonOpts) $(LLVMCFLAGS) -c
244 Compile.CXX = $(CXX) $(LLVMCPPFLAGS) $(CompileCommonOpts) $(LLVMCXXFLAGS) -c
245 LTCompile.CXX = $(LIBTOOL) --tag=CXX --mode=compile $(Compile.CXX)
246 BCCompile.CXX = $(LLVMGXX) $(LLVMCPPFLAGS) $(CompileCommonOpts) $(LLVMCXXFLAGS) -c
247 Link = $(LIBTOOL) --tag=CXX --mode=link $(CXX) $(LLVMCPPFLAGS) \
248 $(CompileCommonOpts) $(LLVMLDFLAGS) $(STRIP)
249 Relink = $(LIBTOOL) --tag=CXX --mode=link $(CXX) $(LLVMCPPFLAGS) \
251 BCLinkLib = $(LLVMGCC) -shared -nostdlib
252 Burg = $(BURG) -I $(BUILD_SRC_DIR)
253 TableGen = $(TBLGEN) -I $(BUILD_SRC_DIR)
254 Archive = $(AR) $(LLVMARFLAGS)
261 #----------------------------------------------------------
262 # Get the list of source files
263 #----------------------------------------------------------
265 SOURCES := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
266 $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
267 $(BUILD_SRC_DIR)/*.l))
271 SOURCES += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
274 #----------------------------------------------------------
275 # Types of objects that can be built from sources
276 #----------------------------------------------------------
277 BASENAME_SOURCES := $(sort $(basename $(SOURCES)))
278 ObjectsO := $(BASENAME_SOURCES:%=$(OBJDIR)/%.o)
279 ObjectsLO := $(BASENAME_SOURCES:%=$(OBJDIR)/%.lo)
280 ObjectsBC := $(BASENAME_SOURCES:%=$(OBJDIR)/%.bc)
283 ###############################################################################
284 # DIRECTORIES: Handle recursive descent of directory structure
285 ###############################################################################
287 #---------------------------------------------------------
288 # Provide rules to make install dirs. This must be early
289 # in the file so they get built before dependencies
290 #---------------------------------------------------------
293 $(VERB) $(MKDIR) $(bindir)
296 $(VERB) $(MKDIR) $(libdir)
299 $(VERB) $(MKDIR) $(bytecode_libdir)
302 $(VERB) $(MKDIR) $(sysconfdir)
305 #---------------------------------------------------------
306 # Handle the DIRS options for sequential construction
307 #---------------------------------------------------------
312 $(RECURSIVE_TARGETS)::
313 $(VERB) for dir in $(DIRS); do \
314 if [ ! -f $$dir/Makefile ]; then \
316 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
318 ($(MAKE) -C $$dir $@ ) || exit 1; \
322 #---------------------------------------------------------
323 # Handle the EXPERIMENTAL_DIRS options ensuring success
324 # after each directory is built.
325 #---------------------------------------------------------
326 ifdef EXPERIMENTAL_DIRS
327 $(RECURSIVE_TARGETS)::
328 $(VERB) for dir in $(EXPERIMENTAL_DIRS); do \
329 if [ ! -f $$dir/Makefile ]; then \
331 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
333 ($(MAKE) -C $$dir $@ ) || exit 0; \
337 #---------------------------------------------------------
338 # Handle the PARALLEL_DIRS options for parallel construction
339 #---------------------------------------------------------
342 SUBDIRS += $(PARALLEL_DIRS)
343 # Unfortunately, this list must be maintained if new
344 # recursive targets are added.
345 all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
346 clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
347 check :: $(addsuffix /.makecheck , $(PARALLEL_DIRS))
348 install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
349 uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
351 Parallel_Targets := $(foreach T,$(RECURSIVE_TARGETS),%/.make$(T))
353 $(Parallel_Targets) :
354 $(VERB) if [ ! -f $(@D)/Makefile ]; then \
356 cp $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
358 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
361 #---------------------------------------------------------
362 # Handle the OPTIONAL_DIRS options for directores that may
364 #---------------------------------------------------------
367 SUBDIRS += $(OPTIONAL_DIRS)
369 $(RECURSIVE_TARGETS)::
370 $(VERB) for dir in $(OPTIONAL_DIRS); do \
371 if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
372 if [ ! -f $$dir/Makefile ]; then \
374 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
376 ($(MAKE) -C$$dir $@ ) || exit 1; \
381 #---------------------------------------------------------
382 # Handle the CONFIG_FILES options
383 #---------------------------------------------------------
386 install-local:: $(sysconfdir) $(CONFIG_FILES)
387 $(VERB)$(ECHO) Installing Configuration Files To $(sysconfdir)
388 $(VERB)for file in $(CONFIG_FILES); do \
389 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
393 $(VERB)$(ECHO) Uninstalling Configuration Files From $(sysconfdir)
394 $(VERB)for file in $(CONFIG_FILES); do \
395 $(RM) -f $(sysconfdir)/$${file} ; \
400 ###############################################################################
401 # Library Build Rules: Four ways to build a library
402 ###############################################################################
405 # if we're building a library ...
408 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
409 LIBRARYNAME := $(strip $(LIBRARYNAME))
410 LIBNAME_LA := $(LIBDIR)/lib$(LIBRARYNAME).la
411 LIBNAME_A := $(LIBDIR)/lib$(LIBRARYNAME).a
412 LIBNAME_O := $(LIBDIR)/$(LIBRARYNAME).o
413 LIBNAME_BC := $(LIBDIR)/lib$(LIBRARYNAME).bc
415 #---------------------------------------------------------
416 # Shared Library Targets:
417 # If the user asked for a shared library to be built
418 # with the SHARED_LIBRARY variable, then we provide
419 # targets for building them.
420 #---------------------------------------------------------
423 all-local:: $(LIBNAME_LA)
425 $(LIBNAME_LA): $(BUILT_SOURCES) $(ObjectsLO) $(LIBDIR)/.dir
426 @$(ECHO) Linking $(CONFIGURATION) Shared Library $(notdir $@)
427 $(VERB) $(Link) -o $@ $(ObjectsLO)
428 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $@ $(LIBDIR)
431 ifneq ($(strip $(LIBNAME_LA)),)
432 $(VERB) $(RM) -f $(LIBNAME_LA)
435 DestSharedLib = $(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
437 install-local:: $(DestSharedLib)
439 $(DestSharedLib): $(libdir) $(LIBNAME_LA)
440 @$(ECHO) Installing $(CONFIGURATION) Shared Library $(DestSharedLib)
441 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_LA) $(DestSharedLib)
442 $(VERB) $(LIBTOOL) --finish $(libdir)
445 @$(ECHO) Uninstalling $(CONFIGURATION) Shared Library $(DestSharedLib)
446 $(VERB) $(RM) -f $(DestSharedLib)
450 #---------------------------------------------------------
451 # Bytecode Library Targets:
452 # If the user asked for a bytecode library to be built
453 # with the BYTECODE_LIBRARY variable, then we provide
454 # targets for building them.
455 #---------------------------------------------------------
456 ifdef BYTECODE_LIBRARY
458 ifdef EXPORTED_SYMBOL_LIST
459 BCLinkLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
461 ifdef EXPORTED_SYMBOL_FILE
462 BCLinkLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
464 BCLinkLib += -Xlinker -disable-internalize
468 all-local:: $(LIBNAME_BC)
470 $(LIBNAME_BC): $(BUILT_SOURCES) $(ObjectsBC) $(LIBDIR)/.dir
471 @$(ECHO) Linking $(CONFIGURATION) Bytecode Library $(notdir $@)
472 $(VERB) $(BCLinkLib) -o $@ $(ObjectsBC)
475 ifneq ($(strip $(LIBNAME_BC)),)
476 $(VERB) $(RM) -f $(LIBNAME_BC)
479 DestBytecodeLib = $(bytecode_libdir)/lib$(LIBRARYNAME).bc
481 install-local:: $(DestBytecodeLib)
483 $(DestBytecodeLib): $(bytecode_libdir) $(LIBNAME_BC)
484 @$(ECHO) Installing $(CONFIGURATION) Bytecode Library $(DestBytecodeLib)
485 $(VERB) $(INSTALL) $(LIBNAME_BC) $@
488 @$(ECHO) Uninstalling $(CONFIGURATION) Bytecode Library $(DestBytecodeLib)
489 $(VERB) $(RM) -f $(DestBytecodeLib)
493 # Does the library want a .o version built?
494 ifndef DONT_BUILD_RELINKED
495 all-local:: $(LIBNAME_O)
497 $(LIBNAME_O): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
498 @$(ECHO) Linking $(CONFIGURATION) Object Library $(notdir $@)
499 $(VERB) $(Relink) -o $@ $(ObjectsO)
502 ifneq ($(strip $(LIBNAME_O)),)
503 $(VERB) $(RM) -f $(LIBNAME_O)
506 DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
508 install-local:: $(DestRelinkedLib)
510 $(DestRelinkedLib): $(libdir) $(LIBNAME_O)
511 @$(ECHO) Installing $(CONFIGURATION) Object Library $(DestRelinkedLib)
512 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_O) $(DestRelinkedLib)
515 @$(ECHO) Uninstalling $(CONFIGURATION) Object Library $(DestRelinkedLib)
516 $(VERB) $(RM) -f $(DestRelinkedLib)
520 # Does the library want an archive version built?
522 all-local:: $(LIBNAME_A)
524 $(LIBNAME_A): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
525 @$(ECHO) Building $(CONFIGURATION) Archive Library $(notdir $@)
527 $(VERB) $(Archive) $@ $(ObjectsO)
531 ifneq ($(strip $(LIBNAME_A)),)
532 $(VERB) $(RM) -f $(LIBNAME_A)
535 DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
537 install-local:: $(DestArchiveLib)
539 $(DestArchiveLib): $(libdir) $(LIBNAME_A)
540 @$(ECHO) Installing $(CONFIGURATION) Archive Library $(DestArchiveLib)
541 $(VERB) $(MKDIR) $(libdir)
542 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_A) $(DestArchiveLib)
545 @$(ECHO) Uninstalling $(CONFIGURATION) Archive Library $(DestArchiveLib)
546 $(VERB) $(RM) -f $(DestArchiveLib)
553 ###############################################################################
554 # Tool Build Rules: Build executable tool based on TOOLNAME option
555 ###############################################################################
559 # TOOLEXENAME - This is the output filenames to generate
560 TOOLEXENAME := $(TOOLDIR)/$(TOOLNAME)
562 # LIBS_OPTIONS - Compute the options lines that add -llib1 -llib2, etc.
563 PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
564 PROJ_LIBS_OPTIONS := $(patsubst %.o, $(LIBDIR)/%.o, $(PROJ_LIBS_OPTIONS))
565 LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
566 LLVM_LIBS_OPTIONS := $(patsubst %.o, $(LLVMLIBDIR)/%.o, $(LLVM_LIBS_OPTIONS))
568 # USED_LIBS/LIBS_PATHS - Compute dependent library file paths
569 PROJ_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
570 LLVM_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
571 PROJ_LIBS_PATHS := $(addprefix $(LIBDIR)/,$(PROJ_USED_LIBS))
572 LLVM_LIBS_PATHS := $(addprefix $(LLVMLIBDIR)/,$(LLVM_USED_LIBS))
574 # Handle compression libraries automatically
575 ifeq ($(HAVE_BZIP2),1)
578 ifeq ($(HAVE_ZLIB),1)
582 # Tell make that we need to rebuild subdirectories before we can link the tool.
583 # This affects things like LLI which has library subdirectories.
584 $(TOOLEXENAME): $(addsuffix /.makeall, $(PARALLEL_DIRS))
586 all-local:: $(TOOLEXENAME)
589 ifneq ($(strip $(TOOLEXENAME)),)
590 $(VERB) $(RM) -f $(TOOLEXENAME)
593 $(TOOLEXENAME): $(BUILT_SOURCES) $(ObjectsO) $(PROJ_LIBS_PATHS) $(LLVM_LIBS_PATHS) $(TOOLDIR)/.dir
594 @$(ECHO) Linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
595 $(VERB) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(PROJ_LIBS_OPTIONS) \
596 $(LLVM_LIBS_OPTIONS) $(LIBS) $(TOOLLINKOPTSB)
597 @$(ECHO) ======= Finished Linking $(CONFIGURATION) Executable $(TOOLNAME) $(STRIP_WARN_MSG)
599 DestTool = $(bindir)/$(TOOLNAME)
601 install-local:: $(DestTool)
603 $(DestTool): $(bindir) $(TOOLEXENAME)
604 @$(ECHO) Installing $(CONFIGURATION) $(DestTool)
605 $(VERB) $(INSTALL) $(TOOLEXENAME) $(DestTool)
608 @$(ECHO) Uninstalling $(CONFIGURATION) $(DestTool)
609 $(VERB) $(RM) -f $(DestTool)
613 ifndef DISABLE_AUTO_DEPENDENCIES
615 # Create .lo files in the OBJDIR directory from the .cpp and .c files...
618 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
619 @$(ECHO) "Compiling $*.cpp (PIC)"
620 $(VERB) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(OBJDIR)/$*.LACXXd $< -o $@ ; \
621 then $(MV) -f "$(OBJDIR)/$*.LACXXd" "$(OBJDIR)/$*.d"; \
622 else $(RM) -f "$(OBJDIR)/$*.LACXXd"; exit 1; fi
624 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
625 @$(ECHO) "Compiling $*.c (PIC)"
626 $(VERB) if $(LTCompile.C) -MD -MT $@ -MP -MF $(OBJDIR)/$*.LACd $< -o $@ ; \
627 then $(MV) -f "$(OBJDIR)/$*.LACd" "$(OBJDIR)/$*.d"; \
628 else $(RM) -f "$(OBJDIR)/$*.LACd"; exit 1; fi
632 $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
633 @$(ECHO) "Compiling $*.cpp"
634 $(VERB) if $(Compile.CXX) -MD -MT $@ -MP -MF $(OBJDIR)/$*.CXXd $< -o $@ ; \
635 then $(MV) -f "$(OBJDIR)/$*.CXXd" "$(OBJDIR)/$*.d"; \
636 else $(RM) -f "$(OBJDIR)/$*.CXXd"; exit 1; fi
638 $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
639 @$(ECHO) "Compiling $*.c"
640 $(VERB) if $(Compile.C) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Cd $< -o $@ ; \
641 then $(MV) -f "$(OBJDIR)/$*.Cd" "$(OBJDIR)/$*.d"; \
642 else $(RM) -f "$(OBJDIR)/$*.Cd"; exit 1; fi
646 # Create .bc files in the OBJDIR directory from .cpp and .c files...
647 $(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
648 @$(ECHO) "Compiling $*.cpp (bytecode)"
649 $(VERB) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.BCCXXd" $< -o $@ ; \
650 then $(MV) -f "$(OBJDIR)/$*.BCCXXd" "$(OBJDIR)/$*.d"; \
651 else $(RM) -f "$(OBJDIR)/$*.BCCXXd"; exit 1; fi
653 $(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
654 @$(ECHO) "Compiling $*.c (bytecode)"
655 $(VERB) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.BCCd" $< -o $@ ; \
656 then $(MV) -f "$(OBJDIR)/$*.BCCd" "$(OBJDIR)/$*.d"; \
657 else $(RM) -f "$(OBJDIR)/$*.BCCd"; exit 1; fi
663 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
664 @$(ECHO) "Compiling $*.cpp (PIC)"
665 $(LTCompile.CXX) $< -o $@
667 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
668 @$(ECHO) "Compiling $*.cpp (PIC)"
669 $(LTCompile.C) $< -o $@
673 $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
674 @$(ECHO) "Compiling $*.cpp"
675 $(Compile.CXX) $< -o $@
677 $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
678 @$(ECHO) "Compiling $*.cpp"
679 $(Compile.C) $< -o $@
682 # Create .bc files in the OBJDIR directory from .cpp and .c files...
683 $(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
684 @$(ECHO) "Compiling $*.cpp (bytecode)"
685 $(BCCompileCPP) $< -o $@
687 $(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
688 @$(ECHO) "Compiling $*.c (bytecode)"
689 $(BCCompileC) $< -o $@
693 $(OBJDIR)/%.bc: %.ll $(OBJDIR)/.dir $(LLVMAS)
694 @$(ECHO) "Compiling $*.ll"
695 $(VERB) $(LLVMAS) $< -f -o $@
699 TDFILES := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
700 INCFILES := $(filter %.inc,$(BUILT_SOURCES))
702 $(INCFILES) : $(TBLGEN) $(TDFILES)
704 %GenRegisterNames.inc : %.td
705 @$(ECHO) "Building $(<F) register names with tblgen"
706 $(VERB) $(TableGen) -gen-register-enums -o $@ $<
708 %GenRegisterInfo.h.inc : %.td
709 @$(ECHO) "Building $(<F) register information header with tblgen"
710 $(VERB) $(TableGen) -gen-register-desc-header -o $@ $<
712 %GenRegisterInfo.inc : %.td
713 @$(ECHO) "Building $(<F) register info implementation with tblgen"
714 $(VERB) $(TableGen) -gen-register-desc -o $@ $<
716 %GenInstrNames.inc : %.td
717 @$(ECHO) "Building $(<F) instruction names with tblgen"
718 $(VERB) $(TableGen) -gen-instr-enums -o $@ $<
720 %GenInstrInfo.inc : %.td
721 @$(ECHO) "Building $(<F) instruction information with tblgen"
722 $(VERB) $(TableGen) -gen-instr-desc -o $@ $<
724 %GenAsmWriter.inc : %.td
725 @$(ECHO) "Building $(<F) assembly writer with tblgen"
726 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
728 %GenATTAsmWriter.inc : %.td
729 @$(ECHO) "Building $(<F) AT&T assembly writer with tblgen"
730 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
732 %GenIntelAsmWriter.inc : %.td
733 @$(ECHO) "Building $(<F) Intel assembly writer with tblgen"
734 $(VERB) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
736 %GenInstrSelector.inc: %.td
737 @$(ECHO) "Building $(<F) instruction selector with tblgen"
738 $(VERB) $(TableGen) -gen-instr-selector -o $@ $<
740 %GenCodeEmitter.inc:: %.td
741 @$(ECHO) "Building $(<F) code emitter with tblgen"
742 $(VERB) $(TableGen) -gen-emitter -o $@ $<
750 # Rules for building lex/yacc files
752 LEX_FILES = $(filter %.l, $(SOURCES))
753 LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
754 YACC_FILES = $(filter %.y, $(SOURCES))
755 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
756 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
758 # Create a .cpp source file from a flex input file... this uses sed to cut down
759 # on the warnings emited by GCC...
761 # The last line is a gross hack to work around flex aparently not being able to
762 # resize the buffer on a large token input. Currently, for uninitialized string
763 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
764 # FIXME. (f.e. char Buffer[10000] )
768 $(VERB) $(FLEX) -t $< | \
769 $(SED) 's/void yyunput/inline void yyunput/' | \
770 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
771 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
774 # Rule for building the bison parsers...
775 %.c: %.y # Cancel built-in rules for yacc
776 %.cpp: %.y # Cancel built-in rules for yacc
777 %.h: %.y # Cancel built-in rules for yacc
779 @$(ECHO) "Bisoning $*.y"
780 $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
781 $(VERB) $(MV) -f $*.tab.c $*.cpp
782 $(VERB) $(MV) -f $*.tab.h $*.h
784 # To create the directories...
786 $(VERB) $(MKDIR) $* > /dev/null
789 .PRECIOUS: $(OBJDIR)/.dir $(LIBDIR)/.dir $(TOOLDIR)/.dir $(LLVMLIBDIR)/.dir
790 .PRECIOUS: $(LLVMTOOLDIR)/.dir
792 # To create postscript files from dot files...
795 $(DOT) -Tps < $< > $@
798 $(ECHO) "Cannot build $@: The program dot is not installed"
802 # This rules ensures that header files that are removed still have a rule for
803 # which they can be "generated." This allows make to ignore them and
804 # reproduce the dependency lists.
808 # 'make clean' nukes the tree
810 ifneq ($(strip $(OBJDIR)),)
811 $(VERB) $(RM) -rf $(OBJDIR)
813 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
814 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
815 $(VERB) $(RM) -f *$(SHLIBEXT)
817 ifneq ($(strip $(LEX_OUTPUT)),)
818 $(VERB) $(RM) -f $(LEX_OUTPUT)
820 ifneq ($(strip $(YACC_OUTPUT)),)
821 $(VERB) $(RM) -f $(YACC_OUTPUT)
824 ###############################################################################
825 # DEPENDENCIES: Include the dependency files if we should
826 ###############################################################################
827 ifndef DISABLE_AUTO_DEPENDENCIES
829 # If its not one of the cleaning targets
830 ifneq ($strip($(filter-out clean clean-local dist-clean, $(MAKECMDGOALS))),)
832 # Get the list of dependency files
833 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(SOURCES)))
834 DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(CONFIGURATION)/%.d,$(DependFiles))
836 -include /dev/null $(DependFiles)
840 endif # ifndef DISABLE_AUTO_DEPENDENCIES
842 ###############################################################################
843 # Handle construction of a distribution tarball
844 ###############################################################################
846 .PHONY: dist dist-chck dist-clean distdir dist-gzip dist-bzip2 dist-zip
848 #------------------------------------------------------------------------
849 # Define distribution related variables
850 #------------------------------------------------------------------------
851 DistName := $(LLVM_TARBALL_NAME)
852 DistDir := $(BUILD_OBJ_ROOT)/$(DistName)
853 TopDistDir := $(BUILD_OBJ_ROOT)/$(DistName)
854 DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
855 DistZip := $(BUILD_OBJ_ROOT)/$(DistName).zip
856 DistTarBZ2 := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
857 DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
858 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
859 Makefile.config.in configure autoconf
860 DistOther := $(notdir $(wildcard \
861 $(BUILD_SRC_DIR)/*.h \
862 $(BUILD_SRC_DIR)/*.td \
863 $(BUILD_SRC_DIR)/*.def \
864 $(BUILD_SRC_DIR)/*.ll \
865 $(BUILD_SRC_DIR)/*.in))
866 DistSources := $(SOURCES) $(EXTRA_DIST)
867 DistSubDirs := $(SUBDIRS)
868 DistFiles := $(DistAlways) $(DistSources) $(DistOther)
871 #------------------------------------------------------------------------
872 # We MUST build distribution with OBJ_DIR != SRC_DIR
873 #------------------------------------------------------------------------
874 ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
875 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
876 @$(ECHO) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
881 DistCheckTop := check
882 #------------------------------------------------------------------------
883 # Prevent catastrophic remove
884 #------------------------------------------------------------------------
885 ifeq ($(LLVM_TARBALL_NAME),)
886 $(error LLVM_TARBALL_NAME is empty. Please rerun configure)
889 #------------------------------------------------------------------------
890 # Prevent attempt to run dist targets from anywhere but the top level
891 #------------------------------------------------------------------------
894 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
895 @$(ECHO) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
899 #------------------------------------------------------------------------
900 # Provide the top level targets
901 #------------------------------------------------------------------------
903 dist-gzip: $(DistTarGZip)
905 $(DistTarGZip) : distdir
906 @$(ECHO) Packing gzipped distribution tar file.
907 $(VERB) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | gzip -c > "$(DistTarGZip)"
909 dist-bzip2: $(DistTarBZ2)
911 $(DistTarBZ2) : distdir
912 @$(ECHO) Packing bzipped distribution tar file.
913 $(VERB) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - $(DistName) | $(BZIP2) -c >$(DistTarBZ2)
918 @$(ECHO) Packing zipped distribution file.
919 $(VERB) rm -f $(DistZip)
920 $(VERB) cd $(BUILD_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
922 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
923 @$(ECHO) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
925 DistCheckDir := $(LLVM_OBJ_ROOT)/_distcheckdir
927 dist-check:: $(DistCheckTop) $(DistTarGZip)
928 @$(ECHO) Checking distribution tar file.
929 $(VERB) if test -d $(DistCheckDir) ; then \
930 $(RM) -rf $(DistCheckDir) ; \
932 $(VERB) $(MKDIR) $(DistCheckDir)
933 $(VERB) cd $(DistCheckDir) && \
934 $(MKDIR) $(DistCheckDir)/build && \
935 $(MKDIR) $(DistCheckDir)/install && \
936 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
938 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
939 --srcdir=../$(DistName) --with-llvmgccdir="$(LLVMGCCDIR)" && \
942 $(MAKE) uninstall && \
945 $(MAKE) dist-clean && \
946 $(ECHO) ===== $(DistTarGZip) Ready For Distribution =====
949 @$(ECHO) Cleaning distribution files
950 $(VERB) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) $(DistCheckDir)
954 #------------------------------------------------------------------------
955 # Provide the recursive distdir target for building the distribution directory
956 #------------------------------------------------------------------------
957 distdir : $(DistSources)
958 @$(ECHO) Building Distribution Directory $(DistDir)
959 $(VERB) if test "$(DistDir)" = "$(TopDistDir)" ; then \
960 if test -d "$(DistDir)" ; then \
961 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
964 $(ECHO) Removing $(DistDir) ; \
965 $(RM) -rf $(DistDir); \
967 $(VERB) $(MKDIR) $(DistDir)
968 $(VERB) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
969 srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
970 for file in $(DistFiles) ; do \
972 $(BUILD_SRC_DIR)/*) file=`echo "$$file" | sed "s#^$$srcdirstrip/##"`;; \
973 $(BUILD_SRC_ROOT)/*) file=`echo "$$file" | sed "s#^$$srcrootstrip/#$(BUILD_OBJ_ROOT)/#"`;; \
975 if test -f "$$file" || test -d "$$file" ; then \
978 from_dir=$(BUILD_SRC_DIR); \
980 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'`; \
981 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
982 to_dir="$(DistDir)/$$dir"; \
983 $(MKDIR) "$$to_dir" ; \
985 to_dir="$(DistDir)"; \
987 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
988 if test -n "$$mid_dir" ; then \
989 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
991 if test -d "$$from_dir/$$file"; then \
992 if test -d "$(BUILD_SRC_DIR)/$$file" && \
993 test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
994 cp -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
996 cp -pR $$from_dir/$$file $$to_dir || exit 1; \
997 elif test -f "$$from_dir/$$file" ; then \
998 cp -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
999 elif test -L "$$from_dir/$$file" ; then \
1000 cp -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1001 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1002 $(ECHO) "===== WARNING: Distribution Source $$from_dir/$$file Not Found!" ; \
1003 elif test "$(VERB)" != '@' ; then \
1004 $(ECHO) "Skipping non-existent $$from_dir/$$file" ; \
1007 $(VERB) for subdir in $(DistSubDirs) ; do \
1008 if test "$$subdir" \!= "." ; then \
1009 new_distdir="$(DistDir)/$$subdir" ; \
1010 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1011 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || exit 1; \
1014 $(VERB) $(MAKE) DistDir="$(DistDir)" dist-hook || exit 1
1015 -$(VERB) find $(DistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
1016 ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
1017 ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
1018 ! -type d ! -perm -444 -exec $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1019 || chmod -R a+r $(DistDir)
1026 ###############################################################################
1027 # TOP LEVEL - targets only to apply at the top level directory
1028 ###############################################################################
1032 #------------------------------------------------------------------------
1033 # Install support for project's include files:
1034 #------------------------------------------------------------------------
1036 @$(ECHO) Installing include files
1037 $(VERB) $(MKDIR) $(includedir)
1038 $(VERB) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1039 cd $(BUILD_SRC_ROOT)/include && \
1040 find . -path '*/Internal' -prune -o '(' -type f \
1041 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1042 -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
1046 @$(ECHO) Uninstalling include files
1047 $(VERB) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1048 cd $(BUILD_SRC_ROOT)/include && \
1049 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1050 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1051 -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
1054 #------------------------------------------------------------------------
1055 # Build tags database for Emacs/Xemacs:
1056 #------------------------------------------------------------------------
1060 find include lib tools examples -name '*.cpp' -o -name '*.h' | $(ETAGS) $(ETAGSFLAGS) -
1064 ###############################################################################
1065 # MISCELLANEOUS - utility targets
1066 ###############################################################################
1068 #------------------------------------------------------------------------
1069 # Print out the directories used for building
1071 @$(ECHO) "CONFIGURATION : " '$(CONFIGURATION)'
1072 @$(ECHO) "BUILD_SRC_ROOT : " '$(BUILD_SRC_ROOT)'
1073 @$(ECHO) "BUILD_SRC_DIR : " '$(BUILD_SRC_DIR)'
1074 @$(ECHO) "BUILD_OBJ_ROOT : " '$(BUILD_OBJ_ROOT)'
1075 @$(ECHO) "BUILD_OBJ_DIR : " '$(BUILD_OBJ_DIR)'
1076 @$(ECHO) "LLVM_SRC_ROOT : " '$(LLVM_SRC_ROOT)'
1077 @$(ECHO) "LLVM_OBJ_ROOT : " '$(LLVM_OBJ_ROOT)'
1078 @$(ECHO) "libdir : " '$(libdir)'
1079 @$(ECHO) "bindir : " '$(bindir)'
1080 @$(ECHO) "sysconfdir : " '$(sysconfdir)'
1081 @$(ECHO) "bytecode_libdir: " '$(bytecode_libdir)'
1082 @$(ECHO) "USER_TARGETS : " '$(USER_TARGETS)'
1083 @$(ECHO) "OBJMKFILES : " '$(OBJMKFILES)'
1084 @$(ECHO) "SRCMKFILES : " '$(SRCMKFILES)'
1085 @$(ECHO) "OBJDIR : " '$(OBJDIR)'
1086 @$(ECHO) "LIBDIR : " '$(LIBDIR)'
1087 @$(ECHO) "TOOLDIR : " '$(TOOLDIR)'
1088 @$(ECHO) "TDFILES : " '$(TDFILES)'
1089 @$(ECHO) "Compile.CXX : " '$(Compile.CXX)'
1090 @$(ECHO) "Compile.C : " '$(Compile.C)'
1091 @$(ECHO) "Archive : " '$(Archive)'