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 $(VERB) $(MKDIR) $(libdir)
328 $(VERB) $(MKDIR) $(bytecode_libdir)
332 # if we're building a library ...
335 # Make sure there isn't any extranous whitespace on the LIBRARYNAME option
336 LIBRARYNAME := $(strip $(LIBRARYNAME))
337 LIBNAME_LA := $(LIBDIR)/lib$(LIBRARYNAME).la
338 LIBNAME_A := $(LIBDIR)/lib$(LIBRARYNAME).a
339 LIBNAME_O := $(LIBDIR)/$(LIBRARYNAME).o
340 LIBNAME_BC := $(LIBDIR)/lib$(LIBRARYNAME).bc
342 #---------------------------------------------------------
343 # Shared Library Targets:
344 # If the user asked for a shared library to be built
345 # with the SHARED_LIBRARY variable, then we provide
346 # targets for building them.
347 #---------------------------------------------------------
350 all-local:: $(LIBNAME_LA)
352 $(LIBNAME_LA): $(BUILT_SOURCES) $(ObjectsLO) $(LIBDIR)/.dir
353 @$(ECHO) Linking $(CONFIGURATION) Shared Library $(notdir $@)
354 $(VERB) $(Link) -o $@ $(ObjectsLO)
355 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $@ $(LIBDIR)
358 ifneq ($(strip $(LIBNAME_LA)),)
359 $(VERB) $(RM) -f $(LIBNAME_LA)
362 DestSharedLib = $(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
363 install-local:: install-shared-library
365 install-shared-library: $(libdir) $(DestSharedLib)
367 $(DestSharedLib): $(LIBNAME_LA)
368 @$(ECHO) Installing $(CONFIGURATION) Shared Library $(DestSharedLib)
369 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_LA) $(DestSharedLib)
370 $(VERB) $(LIBTOOL) --finish $(libdir)
372 uninstall-local:: uninstall-shared-library
374 uninstall-shared-library:
375 @$(ECHO) Uninstalling $(CONFIGURATION) Shared Library $(DestSharedLib)
376 $(VERB) $(RM) -f $(DestSharedLib)
380 #---------------------------------------------------------
381 # Bytecode Library Targets:
382 # If the user asked for a bytecode library to be built
383 # with the BYTECODE_LIBRARY variable, then we provide
384 # targets for building them.
385 #---------------------------------------------------------
386 ifdef BYTECODE_LIBRARY
388 ifdef EXPORTED_SYMBOL_LIST
389 BCLinkLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
391 ifdef EXPORTED_SYMBOL_FILE
392 BCLinkLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
394 BCLinkLib += -Xlinker -disable-internalize
398 all-local:: $(LIBNAME_BC)
400 $(LIBNAME_BC): $(BUILT_SOURCES) $(ObjectsBC) $(LIBDIR)/.dir
401 @$(ECHO) Linking $(CONFIGURATION) Bytecode Library $(notdir $@)
402 $(VERB) $(BCLinkLib) -o $@ $(ObjectsBC)
405 ifneq ($(strip $(LIBNAME_BC)),)
406 $(VERB) $(RM) -f $(LIBNAME_BC)
409 DestBytecodeLib = $(bytecode_libdir)/lib$(LIBRARYNAME).bc
411 install-local:: install-bytecode-library
413 install-bytecode-library: $(bytecode_libdir) $(DestBytecodeLib)
415 $(DestBytecodeLib): $(LIBNAME_BC) $(bytecode_libdir)
416 @$(ECHO) Installing $(CONFIGURATION) Bytecode Library $(DestBytecodeLib)
417 $(VERB) $(INSTALL) $< $@
419 uninstall-local:: uninstall-bytecode-library
421 uninstall-bytecode-library:
422 @$(ECHO) Uninstalling $(CONFIGURATION) Bytecode Library $(DestBytecodeLib)
423 $(VERB) $(RM) -f $(DestBytecodeLib)
427 # Does the library want a .o version built?
428 ifndef DONT_BUILD_RELINKED
429 all-local:: $(LIBNAME_O)
431 $(LIBNAME_O): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
432 @$(ECHO) Linking $(CONFIGURATION) Object Library $(notdir $@)
433 $(VERB) $(Relink) -o $@ $(ObjectsO)
436 ifneq ($(strip $(LIBNAME_O)),)
437 $(VERB) $(RM) -f $(LIBNAME_O)
440 DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
442 install-local:: install-relinked-library
444 install-relinked-library: $(libdir) $(DestRelinkedLib)
446 $(DestRelinkedLib): $(LIBNAME_O)
447 @$(ECHO) Installing $(CONFIGURATION) Object Library $(DestRelinkedLib)
448 $(VERB) $(MKDIR) $(libdir)
449 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_O) $(DestRelinkedLib)
451 uninstall-local:: uninstall-relinked-library
453 uninstall-relinked-library:
454 @$(ECHO) Uninstalling $(CONFIGURATION) Object Library $(DestRelinkedLib)
455 $(VERB) $(RM) -f $(DestRelinkedLib)
459 # Does the library want an archive version built?
461 all-local:: $(LIBNAME_A)
463 $(LIBNAME_A): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
464 @$(ECHO) Building $(CONFIGURATION) Archive Library $(notdir $@)
466 $(VERB) $(Archive) $@ $(ObjectsO)
470 ifneq ($(strip $(LIBNAME_A)),)
471 $(VERB) $(RM) -f $(LIBNAME_A)
474 DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
476 install-local:: install-archive-library
478 install-archive-library: $(libdir) $(DestArchiveLib)
480 $(DestArchiveLib): $(LIBNAME_A)
481 @$(ECHO) Installing $(CONFIGURATION) Archive Library $(DestArchiveLib)
482 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_A) $(DestArchiveLib)
484 uninstall-local:: uninstall-archive-library
486 uninstall-archive-library:
487 @$(ECHO) Uninstalling $(CONFIGURATION) Archive Library $(DestArchiveLib)
488 $(VERB) $(RM) -f $(DestArchiveLib)
495 ###############################################################################
496 # Tool Build Rules: Build executable tool based on TOOLNAME option
497 ###############################################################################
501 #---------------------------------------------------------
502 # TOOLLINKOPTSB to pass options to the linker like library search path etc
503 # Note that this is different from TOOLLINKOPTS, these options
504 # are passed to the linker *before* the USEDLIBS options are passed.
505 # e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
506 #---------------------------------------------------------
508 Link += $(TOOLLINKOPTSB)
511 # TOOLEXENAME - This is the output filenames to generate
512 TOOLEXENAME := $(TOOLDIR)/$(TOOLNAME)
514 # LIBS_OPTIONS - Compute the options lines that add -llib1 -llib2, etc.
515 PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
516 PROJ_LIBS_OPTIONS := $(patsubst %.o, $(LIBDIR)/%.o, $(PROJ_LIBS_OPTIONS))
517 LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
518 LLVM_LIBS_OPTIONS := $(patsubst %.o, $(LLVMLIBDIR)/%.o, $(LLVM_LIBS_OPTIONS))
520 # USED_LIBS/LIBS_PATHS - Compute dependent library file paths
521 PROJ_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
522 LLVM_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
523 PROJ_LIBS_PATHS := $(addprefix $(LIBDIR)/,$(PROJ_USED_LIBS))
524 LLVM_LIBS_PATHS := $(addprefix $(LLVMLIBDIR)/,$(LLVM_USED_LIBS))
526 # Concatenate all the optoins
527 LINK_OPTS := $(TOOLLINKOPTS) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS)
529 # Handle compression libraries automatically
530 ifeq ($(HAVE_BZIP2),1)
533 ifeq ($(HAVE_ZLIB),1)
537 # Tell make that we need to rebuild subdirectories before we can link the tool.
538 # This affects things like LLI which has library subdirectories.
539 $(TOOLEXENAME): $(addsuffix /.makeall, $(PARALLEL_DIRS))
541 all-local:: $(TOOLEXENAME)
544 ifneq ($(strip $(TOOLEXENAME)),)
545 $(VERB) $(RM) -f $(TOOLEXENAME)
548 $(TOOLEXENAME): $(BUILT_SOURCES) $(ObjectsO) $(PROJ_LIBS_PATHS) $(LLVM_LIBS_PATHS) $(TOOLDIR)/.dir
549 @$(ECHO) Linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
550 $(VERB) $(Link) -o $@ $(ObjectsO) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS) $(LIBS)
551 @$(ECHO) ======= Finished Linking $(CONFIGURATION) Executable $(TOOLNAME) $(STRIP_WARN_MSG)
553 DestTool = $(bindir)/$(TOOLNAME)
555 install-local:: install-tool
557 install-tool: $(bindir) $(DestTool)
559 $(DestTool): $(TOOLEXENAME)
560 @$(ECHO) Installing $(CONFIGURATION) $(DestTool)
561 $(VERB) $(INSTALL) $(TOOLEXENAME) $(DestTool)
564 $(VERB) $(MKDIR) $(bindir)
566 uninstall-local:: uninstall-tool
569 @$(ECHO) Uninstalling $(CONFIGURATION) $(DestTool)
570 $(VERB) $(RM) -f $(DestTool)
574 ifndef DISABLE_AUTO_DEPENDENCIES
576 # Create .lo files in the OBJDIR directory from the .cpp and .c files...
579 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
580 @$(ECHO) "Compiling $*.cpp (PIC)"
581 $(VERB) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(OBJDIR)/$*.LACXXd $< -o $@ ; \
582 then $(MV) -f "$(OBJDIR)/$*.LACXXd" "$(OBJDIR)/$*.d"; \
583 else $(RM) -f "$(OBJDIR)/$*.LACXXd"; exit 1; fi
585 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
586 @$(ECHO) "Compiling $*.c (PIC)"
587 $(VERB) if $(LTCompile.C) -MD -MT $@ -MP -MF $(OBJDIR)/$*.LACd $< -o $@ ; \
588 then $(MV) -f "$(OBJDIR)/$*.LACd" "$(OBJDIR)/$*.d"; \
589 else $(RM) -f "$(OBJDIR)/$*.LACd"; exit 1; fi
593 $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
594 @$(ECHO) "Compiling $*.cpp"
595 $(VERB) if $(Compile.CXX) -MD -MT $@ -MP -MF $(OBJDIR)/$*.CXXd $< -o $@ ; \
596 then $(MV) -f "$(OBJDIR)/$*.CXXd" "$(OBJDIR)/$*.d"; \
597 else $(RM) -f "$(OBJDIR)/$*.CXXd"; exit 1; fi
599 $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
600 @$(ECHO) "Compiling $*.c"
601 $(VERB) if $(Compile.C) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Cd $< -o $@ ; \
602 then $(MV) -f "$(OBJDIR)/$*.Cd" "$(OBJDIR)/$*.d"; \
603 else $(RM) -f "$(OBJDIR)/$*.Cd"; exit 1; fi
607 # Create .bc files in the OBJDIR directory from .cpp and .c files...
608 $(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
609 @$(ECHO) "Compiling $*.cpp (bytecode)"
610 $(VERB) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.BCCXXd" $< -o $@ ; \
611 then $(MV) -f "$(OBJDIR)/$*.BCCXXd" "$(OBJDIR)/$*.d"; \
612 else $(RM) -f "$(OBJDIR)/$*.BCCXXd"; exit 1; fi
614 $(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
615 @$(ECHO) "Compiling $*.c (bytecode)"
616 $(VERB) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.BCCd" $< -o $@ ; \
617 then $(MV) -f "$(OBJDIR)/$*.BCCd" "$(OBJDIR)/$*.d"; \
618 else $(RM) -f "$(OBJDIR)/$*.BCCd"; exit 1; fi
624 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
625 @$(ECHO) "Compiling $*.cpp (PIC)"
626 $(LTCompile.CXX) $< -o $@
628 $(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
629 @$(ECHO) "Compiling $*.cpp (PIC)"
630 $(LTCompile.C) $< -o $@
634 $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
635 @$(ECHO) "Compiling $*.cpp"
636 $(Compile.CXX) $< -o $@
638 $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
639 @$(ECHO) "Compiling $*.cpp"
640 $(Compile.C) $< -o $@
643 # Create .bc files in the OBJDIR directory from .cpp and .c files...
644 $(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
645 @$(ECHO) "Compiling $*.cpp (bytecode)"
646 $(BCCompileCPP) $< -o $@
648 $(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
649 @$(ECHO) "Compiling $*.c (bytecode)"
650 $(BCCompileC) $< -o $@
654 $(OBJDIR)/%.bc: %.ll $(OBJDIR)/.dir $(LLVMAS)
655 @$(ECHO) "Compiling $*.ll"
656 $(VERB) $(LLVMAS) $< -f -o $@
660 TDFILES := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
662 $(BUILT_SOURCES): $(TDFILES)
664 %GenRegisterNames.inc : %.td
665 @echo "Building $(<F) register names with tblgen"
666 $(VERB) $(TableGen) -gen-register-enums -o $@ $<
668 %GenRegisterInfo.h.inc : %.td
669 @echo "Building $(<F) register information header with tblgen"
670 $(VERB) $(TableGen) -gen-register-desc-header -o $@ $<
672 %GenRegisterInfo.inc : %.td
673 @echo "Building $(<F) register info implementation with tblgen"
674 $(VERB) $(TableGen) -gen-register-desc -o $@ $<
676 %GenInstrNames.inc : %.td
677 @echo "Building $(<F) instruction names with tblgen"
678 $(VERB) $(TableGen) -gen-instr-enums -o $@ $<
680 %GenInstrInfo.inc : %.td
681 @echo "Building $(<F) instruction information with tblgen"
682 $(VERB) $(TableGen) -gen-instr-desc -o $@ $<
684 %GenAsmWriter.inc : %.td
685 @echo "Building $(<F) assembly writer with tblgen"
686 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
688 %GenATTAsmWriter.inc : %.td
689 @echo "Building $(<F) AT&T assembly writer with tblgen"
690 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
692 %GenIntelAsmWriter.inc : %.td
693 @echo "Building $(<F) Intel assembly writer with tblgen"
694 $(VERB) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
696 %GenInstrSelector.inc: %.td
697 @echo "Building $(<F) instruction selector with tblgen"
698 $(VERB) $(TableGen) -gen-instr-selector -o $@ $<
700 %GenCodeEmitter.inc:: %.td
701 @echo "Building $(<F) code emitter with tblgen"
702 $(VERB) $(TableGen) -gen-emitter -o $@ $<
710 # Rules for building lex/yacc files
712 LEX_FILES = $(filter %.l, $(SOURCES))
713 LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
714 YACC_FILES = $(filter %.y, $(SOURCES))
715 YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
716 .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
718 # Create a .cpp source file from a flex input file... this uses sed to cut down
719 # on the warnings emited by GCC...
721 # The last line is a gross hack to work around flex aparently not being able to
722 # resize the buffer on a large token input. Currently, for uninitialized string
723 # buffers in LLVM we can generate very long tokens, so this is a hack around it.
724 # FIXME. (f.e. char Buffer[10000] )
728 $(VERB) $(FLEX) -t $< | \
729 $(SED) '/^find_rule/d' | \
730 $(SED) 's/void yyunput/inline void yyunput/' | \
731 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
732 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
734 $(VERB) cmp -s $@ $@.tmp > /dev/null || $(MV) -f $@.tmp $@
735 @# remove the output of flex if it didn't get moved over...
738 # Rule for building the bison parsers...
739 %.c: %.y # Cancel built-in rules for yacc
740 %.h: %.y # Cancel built-in rules for yacc
742 @$(ECHO) "Bisoning $*.y"
743 $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
744 $(VERB) cmp -s $*.tab.c $*.cpp > /dev/null || $(MV) -f $*.tab.c $*.cpp
745 $(VERB) cmp -s $*.tab.h $*.h > /dev/null || $(MV) -f $*.tab.h $*.h
746 @# If the files were not updated, don't leave them lying around...
747 @rm -f $*.tab.c $*.tab.h
749 # To create the directories...
751 $(VERB) $(MKDIR) $* > /dev/null
754 .PRECIOUS: $(OBJDIR)/.dir $(LIBDIR)/.dir $(TOOLDIR)/.dir $(LLVMLIBDIR)/.dir
755 .PRECIOUS: $(LLVMTOOLDIR)/.dir
757 # To create postscript files from dot files...
760 $(DOT) -Tps < $< > $@
763 $(ECHO) "Cannot build $@: The program dot is not installed"
767 # This rules ensures that header files that are removed still have a rule for
768 # which they can be "generated." This allows make to ignore them and
769 # reproduce the dependency lists.
773 # 'make clean' nukes the tree
775 ifneq ($(strip $(OBJDIR)),)
776 $(VERB) $(RM) -rf $(OBJDIR)
778 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
779 ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
780 $(VERB) $(RM) -f *$(SHLIBEXT)
782 ifneq ($(strip $(LEX_OUTPUT)),)
783 $(VERB) $(RM) -f $(LEX_OUTPUT)
785 ifneq ($(strip $(YACC_OUTPUT)),)
786 $(VERB) $(RM) -f $(YACC_OUTPUT)
789 ###############################################################################
790 # DEPENDENCIES: Include the dependency files if we should
791 ###############################################################################
792 ifndef DISABLE_AUTO_DEPENDENCIES
794 # If its not one of the cleaning targets
795 ifneq ($strip($(filter-out clean clean-local dist-clean, $(MAKECMDGOALS))),)
797 # Get the list of dependency files
798 DependFiles := $(basename $(filter %.cpp %.c %.cc, $(SOURCES)))
799 DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(CONFIGURATION)/%.d,$(DependFiles))
801 -include /dev/null $(DependFiles)
805 endif # ifndef DISABLE_AUTO_DEPENDENCIES
807 ################################################################################
808 # PRECONDITIONS - that which must be built/checked first
809 ################################################################################
811 OBJMKFILE := $(BUILD_OBJ_DIR)/Makefile
812 SRCMKFILE := $(BUILD_SRC_DIR)/Makefile
813 CONFIGURE := $(LLVM_SRC_ROOT)/configure
814 CONFIG_STATUS := $(LLVM_OBJ_ROOT)/config.status
815 MAKE_CONFIG_IN := $(LLVM_SRC_ROOT)/Makefile.config.in
816 MAKE_CONFIG := $(LLVM_OBJ_ROOT)/Makefile.config
818 #------------------------------------------------------------------------
819 # List of the preconditions
820 #------------------------------------------------------------------------
822 preconditions: $(CONFIG_STATUS) $(MAKE_CONFIG) $(OBJMKFILE)
824 $(filter-out clean clean-local,USER_TARGETS):: $(BUILT_SOURCES)
827 ifneq ($(strip $(BUILT_SOURCES)),)
828 $(VERB) $(RM) -f $(BUILT_SOURCES)
831 #------------------------------------------------------------------------
832 # Make sure we're not using a stale configuration
833 #------------------------------------------------------------------------
834 .PRECIOUS: $(CONFIG_STATUS)
835 $(CONFIG_STATUS): $(CONFIGURE)
836 @$(ECHO) Reconfiguring with $<
837 $(VERB) $(CONFIG_STATUS) --recheck $(CONFIGUREFLAGS)
839 #------------------------------------------------------------------------
840 # Make sure the configuration makefile is up to date
841 #------------------------------------------------------------------------
842 $(MAKE_CONFIG): $(MAKE_CONFIG_IN) $(CONFIG_STATUS)
843 @$(ECHO) Regenerating $@
844 $(VERB) cd $(LLVM_OBJ_ROOT) ; $(CONFIG_STATUS) Makefile.config
846 #------------------------------------------------------------------------
847 # If the Makefile in the source tree has been updated, copy it over into the
848 # build tree. But, only do this if the source and object makefiles differ
849 #------------------------------------------------------------------------
850 ifneq ($(OBJMKFILE),$(SRCMKFILE))
851 .PRECIOUS: $(OBJMKFILE)
852 $(OBJMKFILE): $(SRCMKFILE)
853 @$(ECHO) "Updating Makefile from: $(dir $<)"
854 $(VERB) $(MKDIR) $(@D)
858 ###############################################################################
859 # Handle construction of a distribution tarball
860 ###############################################################################
862 .PHONY: dist dist-chck dist-clean distdir dist-gzip dist-bzip2 dist-zip
864 #------------------------------------------------------------------------
865 # Define distribution related variables
866 #------------------------------------------------------------------------
867 DistName := $(LLVM_TARBALL_NAME)
868 DistDir := $(BUILD_OBJ_ROOT)/$(DistName)
869 TopDistDir := $(BUILD_OBJ_ROOT)/$(DistName)
870 DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
871 DistZip := $(BUILD_OBJ_ROOT)/$(DistName).zip
872 DistTarBZ2 := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
873 DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
874 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
875 Makefile.config.in configure autoconf
876 DistOther := $(notdir $(wildcard \
877 $(BUILD_SRC_DIR)/*.h \
878 $(BUILD_SRC_DIR)/*.td \
879 $(BUILD_SRC_DIR)/*.def \
880 $(BUILD_SRC_DIR)/*.ll \
881 $(BUILD_SRC_DIR)/*.in))
882 DistSources := $(SOURCES) $(EXTRA_DIST)
883 DistSubDirs := $(SUBDIRS)
884 DistFiles := $(DistAlways) $(DistSources) $(DistOther)
887 #------------------------------------------------------------------------
888 # We MUST build distribution with OBJ_DIR != SRC_DIR
889 #------------------------------------------------------------------------
890 ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
891 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
892 @$(ECHO) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
897 DistCheckTop := check
898 #------------------------------------------------------------------------
899 # Prevent catastrophic remove
900 #------------------------------------------------------------------------
901 ifeq ($(LLVM_TARBALL_NAME),)
902 $(error LLVM_TARBALL_NAME is empty. Please rerun configure)
905 #------------------------------------------------------------------------
906 # Prevent attempt to run dist targets from anywhere but the top level
907 #------------------------------------------------------------------------
910 dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
911 @$(ECHO) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
915 #------------------------------------------------------------------------
916 # Provide the top level targets
917 #------------------------------------------------------------------------
919 dist-gzip: $(DistTarGZip)
921 $(DistTarGZip) : distdir
922 @$(ECHO) Packing gzipped distribution tar file.
923 $(VERB) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | gzip -c > "$(DistTarGZip)"
925 dist-bzip2: $(DistTarBZ2)
927 $(DistTarBZ2) : distdir
928 @$(ECHO) Packing bzipped distribution tar file.
929 $(VERB) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - $(DistName) | $(BZIP2) -c >$(DistTarBZ2)
934 @$(ECHO) Packing zipped distribution file.
935 $(VERB) rm -f $(DistZip)
936 $(VERB) cd $(BUILD_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
938 dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
939 @$(ECHO) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
941 DistCheckDir := $(LLVM_OBJ_ROOT)/_distcheckdir
943 dist-check:: $(DistTopDir) $(DistTarGZip)
944 @$(ECHO) Checking distribution tar file.
945 $(VERB) if test -d $(DistCheckDir) ; then \
946 $(RM) -rf $(DistCheckDir) ; \
948 $(VERB) $(MKDIR) $(DistCheckDir)
949 $(VERB) cd $(DistCheckDir) && \
950 $(MKDIR) $(DistCheckDir)/build && \
951 $(MKDIR) $(DistCheckDir)/install && \
952 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
954 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
955 --srcdir=../$(DistName) --with-llvmgccdir="$(LLVMGCCDIR)" && \
958 $(MAKE) uninstall && \
961 $(MAKE) dist-clean && \
962 $(ECHO) ===== $(DistTarGZip) Ready For Distribution =====
965 @$(ECHO) Cleaning distribution files
966 $(VERB) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) $(DistCheckDir)
970 #------------------------------------------------------------------------
971 # Provide the recursive distdir target for building the distribution directory
972 #------------------------------------------------------------------------
973 distdir : $(DistCheckTop) $(DistSources)
974 @$(ECHO) Building Distribution Directory $(DistDir)
975 $(VERB) if test "$(DistDir)" = "$(TopDistDir)" ; then \
976 if test -d "$(DistDir)" ; then \
977 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
980 echo Removing $(DistDir) ; \
981 $(RM) -rf $(DistDir); \
983 $(VERB) $(MKDIR) $(DistDir)
984 $(VERB) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
985 srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
986 for file in $(DistFiles) ; do \
988 $(BUILD_SRC_DIR)/*) file=`echo "$$file" | sed "s#^$$srcdirstrip/##"`;; \
989 $(BUILD_SRC_ROOT)/*) file=`echo "$$file" | sed "s#^$$srcrootstrip/#$(BUILD_OBJ_ROOT)/#"`;; \
991 if test -f "$$file" || test -d "$$file" ; then \
994 from_dir=$(BUILD_SRC_DIR); \
996 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'`; \
997 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
998 to_dir="$(DistDir)/$$dir"; \
999 $(MKDIR) "$$to_dir" ; \
1001 to_dir="$(DistDir)"; \
1003 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1004 if test -n "$$mid_dir" ; then \
1005 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
1007 if test -d "$$from_dir/$$file"; then \
1008 if test -d "$(BUILD_SRC_DIR)/$$file" && \
1009 test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
1010 cp -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
1012 cp -pR $$from_dir/$$file $$to_dir || exit 1; \
1013 elif test -f "$$from_dir/$$file" ; then \
1014 cp -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1015 elif test -L "$$from_dir/$$file" ; then \
1016 cp -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1017 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1018 $(ECHO) "===== WARNING: Distribution Source $$from_dir/$$file Not Found!" ; \
1019 elif test "$(VERB)" != '@' ; then \
1020 $(ECHO) "Skipping non-existent $$from_dir/$$file" ; \
1023 $(VERB) for subdir in $(DistSubDirs) ; do \
1024 if test "$$subdir" \!= "." ; then \
1025 new_distdir="$(DistDir)/$$subdir" ; \
1026 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1027 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || exit 1; \
1030 $(VERB) $(MAKE) DistDir="$(DistDir)" dist-hook || exit 1
1031 -$(VERB) find $(DistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
1032 ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
1033 ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
1034 ! -type d ! -perm -444 -exec $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1035 || chmod -R a+r $(DistDir)
1042 ###############################################################################
1043 # TOP LEVEL - targets only to apply at the top level directory
1044 ###############################################################################
1048 #------------------------------------------------------------------------
1049 # Install support for project's include files:
1050 #------------------------------------------------------------------------
1052 @$(ECHO) Installing include files
1053 $(VERB) $(MKDIR) $(includedir)
1054 $(VERB) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1055 cd $(BUILD_SRC_ROOT)/include && \
1056 find . -path '*/Internal' -prune -o '(' -type f \
1057 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1058 -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
1062 @$(ECHO) Uninstalling include files
1063 $(VERB) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1064 cd $(BUILD_SRC_ROOT)/include && \
1065 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1066 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1067 -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
1070 #------------------------------------------------------------------------
1071 # Build tags database for Emacs/Xemacs:
1072 #------------------------------------------------------------------------
1076 find include lib tools examples -name '*.cpp' -o -name '*.h' | $(ETAGS) $(ETAGSFLAGS) -
1080 ###############################################################################
1081 # MISCELLANEOUS - utility targets
1082 ###############################################################################
1084 #------------------------------------------------------------------------
1085 # Print out the directories used for building
1087 @$(ECHO) "BUILD_SRC_ROOT: " $(BUILD_SRC_ROOT)
1088 @$(ECHO) "BUILD_SRC_DIR : " $(BUILD_SRC_DIR)
1089 @$(ECHO) "BUILD_OBJ_ROOT: " $(BUILD_OBJ_ROOT)
1090 @$(ECHO) "BUILD_OBJ_DIR : " $(BUILD_OBJ_DIR)
1091 @$(ECHO) "LLVM_SRC_ROOT : " $(LLVM_SRC_ROOT)
1092 @$(ECHO) "LLVM_OBJ_ROOT : " $(LLVM_OBJ_ROOT)
1093 @$(ECHO) "CONFIGURATION : " $(CONFIGURATION)
1094 @$(ECHO) "OBJDIR: " $(OBJDIR)
1095 @$(ECHO) "LIBDIR: " $(LIBDIR)
1096 @$(ECHO) "TOOLDIR: " $(TOOLDIR)
1097 @$(ECHO) "TDFILES:" '$(TDFILES)'
1098 @$(ECHO) "Compile.CXX: " '$(Compile.CXX)'
1099 @$(ECHO) "Compile.C: " '$(Compile.C)'