blob: 1175d89d73da14dc2d0f18441a57b58da790eaca [file] [log] [blame]
Misha Brukman6d5ab862004-04-24 00:10:56 +00001#===-- Makefile.rules - Common make rules for LLVM ---------*- Makefile -*--===#
2#
John Criswelld8846c12003-10-21 14:33:46 +00003# The LLVM Compiler Infrastructure
4#
5# This file was developed by the LLVM research group and is distributed under
6# the University of Illinois Open Source License. See LICENSE.TXT for details.
7#
Misha Brukman6d5ab862004-04-24 00:10:56 +00008#===------------------------------------------------------------------------===#
Chris Lattner00950542001-06-06 20:29:01 +00009#
Reid Spencer3a561f52004-10-23 20:04:14 +000010# 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.
Chris Lattneraf06a082003-08-15 03:02:52 +000012#
Vikram S. Adved60aede2002-07-09 12:04:21 +000013#===-----------------------------------------------------------------------====
Chris Lattner00950542001-06-06 20:29:01 +000014
John Criswell2a6530f2003-06-27 16:58:44 +000015#
John Criswell7f336952003-09-06 14:44:17 +000016# Set the VPATH so that we can find source files.
John Criswell8bff5092003-06-11 13:55:44 +000017#
Reid Spencer4d71b662004-10-22 21:01:56 +000018VPATH=$(BUILD_SRC_DIR)
John Criswell8bff5092003-06-11 13:55:44 +000019
Reid Spencer3a561f52004-10-23 20:04:14 +000020###############################################################################
21# TARGETS: Define standard targets that can be invoked
22###############################################################################
John Criswell7a73b802003-06-30 21:59:07 +000023
Chris Lattner00950542001-06-06 20:29:01 +000024#--------------------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +000025# Define the various target sets
26#--------------------------------------------------------------------
27RECURSIVE_TARGETS := all clean check install uninstall
Reid Spencer9411c642004-10-26 22:26:33 +000028LOCAL_TARGETS := all-local clean-local check-local install-local \
29 printvars uninstall-local
Reid Spencere5487ba2004-10-24 07:53:21 +000030TOPLEV_TARGETS := dist dist-check dist-clean tags
Reid Spencer151f8ba2004-10-25 08:27:37 +000031USER_TARGETS := $(RECURSIVE_TARGETS) $(LOCAL_TARGETS) $(TOPLEV_TARGETS)
Reid Spencerc6dcc6a2004-10-28 07:57:28 +000032INTERNAL_TARGETS := preconditions
Reid Spencer3a561f52004-10-23 20:04:14 +000033
Reid Spencer9411c642004-10-26 22:26:33 +000034###############################################################################
35# INITIALIZATION: Basic things the makefile needs
36###############################################################################
37
38#--------------------------------------------------------------------
39# Reset the list of suffixes we know how to build
40#--------------------------------------------------------------------
41.SUFFIXES:
42.SUFFIXES: .c .cpp .h .hpp .y .l .lo .o .a $(SHLIBEXT) .bc .td .ps .dot $(SUFFIXES)
43
Reid Spencer3a561f52004-10-23 20:04:14 +000044#--------------------------------------------------------------------
45# Mark all of these targets as phony to avoid implicit rule search
46#--------------------------------------------------------------------
Reid Spencer151f8ba2004-10-25 08:27:37 +000047.PHONY: $(USER_TARGETS) $(INTERNAL_TARGETS)
Reid Spencer3a561f52004-10-23 20:04:14 +000048
49#--------------------------------------------------------------------
Reid Spencer9411c642004-10-26 22:26:33 +000050# Make sure all the user-target rules are double colon rules and
51# they are defined first.
Reid Spencer3a561f52004-10-23 20:04:14 +000052#--------------------------------------------------------------------
53
Reid Spencer9411c642004-10-26 22:26:33 +000054$(USER_TARGETS)::
Reid Spencer151f8ba2004-10-25 08:27:37 +000055
Reid Spencer9411c642004-10-26 22:26:33 +000056################################################################################
57# PRECONDITIONS: that which must be built/checked first
58################################################################################
59
Reid Spencer80f0ef72004-10-28 00:41:43 +000060SRCMKFILES := $(BUILD_SRC_DIR)/Makefile $(filter-out Makefile.rules %.in,\
Reid Spencer86606782004-10-26 23:10:00 +000061 $(wildcard $(BUILD_SRC_DIR)/Makefile.*))
Reid Spencer9411c642004-10-26 22:26:33 +000062OBJMKFILES := $(subst $(BUILD_SRC_DIR),$(BUILD_OBJ_DIR),$(SRCMKFILES))
63CONFIGURE := $(LLVM_SRC_ROOT)/configure
64CONFIG_STATUS := $(LLVM_OBJ_ROOT)/config.status
65MAKE_CONFIG_IN:= $(LLVM_SRC_ROOT)/Makefile.config.in
66MAKE_CONFIG := $(LLVM_OBJ_ROOT)/Makefile.config
67PRECONDITIONS := $(CONFIG_STATUS) $(MAKE_CONFIG) $(OBJMKFILES)
68
69preconditions : $(PRECONDITIONS)
70
71#------------------------------------------------------------------------
72# Make sure the BUILT_SOURCES are built first
73#------------------------------------------------------------------------
74$(filter-out clean clean-local,USER_TARGETS):: $(BUILT_SOURCES)
75
76clean-local::
77ifneq ($(strip $(BUILT_SOURCES)),)
78 $(VERB) $(RM) -f $(BUILT_SOURCES)
79endif
80
Reid Spencer80f0ef72004-10-28 00:41:43 +000081$(BUILT_SOURCES) : $(BUILD_OBJ_ROOT)/Makefile
82
Reid Spencer9411c642004-10-26 22:26:33 +000083#------------------------------------------------------------------------
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)
Reid Spencer0b8d2f92004-10-27 22:48:58 +000090 $(VERB) $(CONFIG_STATUS)
Reid Spencer9411c642004-10-26 22:26:33 +000091
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
98
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#------------------------------------------------------------------------
103ifneq ($(BUILD_OBJ_DIR),$(BUILD_SRC_DIR))
104
105$(BUILD_OBJ_DIR)/Makefile : $(BUILD_SRC_DIR)/Makefile
106 @$(ECHO) "Updating Makefile"
107 $(VERB) $(MKDIR) $(@D)
108 $(VERB) cp -f $< $@
Reid Spencer9411c642004-10-26 22:26:33 +0000109
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
112# taken care of.
Reid Spencer9411c642004-10-26 22:26:33 +0000113$(BUILD_OBJ_DIR)/Makefile% : $(BUILD_SRC_DIR)/Makefile%
Reid Spencer86606782004-10-26 23:10:00 +0000114 @case '$?' in \
115 *Makefile.rules) ;; \
116 *.in) ;; \
117 *) $(ECHO) "Updating $(@F)" ; \
118 $(MKDIR) $(@D) ; \
119 cp -f $< $@ ;; \
120 esac
121
Reid Spencer9411c642004-10-26 22:26:33 +0000122endif
123
124#------------------------------------------------------------------------
125# Set up the basic dependencies
126#------------------------------------------------------------------------
127$(USER_TARGETS):: $(PRECONDITIONS)
128
129all:: all-local
Reid Spencer3a561f52004-10-23 20:04:14 +0000130check:: check-local
131clean:: clean-local
Reid Spencer9411c642004-10-26 22:26:33 +0000132install:: install-local
133uninstall:: uninstall-local
134check-local:: all-local
135install-local:: all-local
Reid Spencer3a561f52004-10-23 20:04:14 +0000136
137###############################################################################
138# VARIABLES: Set up various variables based on configuration data
139###############################################################################
140
141#--------------------------------------------------------------------
142# Variables derived from configuration we are building
Chris Lattner00950542001-06-06 20:29:01 +0000143#--------------------------------------------------------------------
144
Chris Lattner760da062003-03-14 20:25:22 +0000145ifdef ENABLE_PROFILING
Chris Lattner760da062003-03-14 20:25:22 +0000146 CONFIGURATION := Profile
Reid Spencer4d71b662004-10-22 21:01:56 +0000147 CXXFLAGS += -O3 -DNDEBUG -felide-constructors -finline-functions -pg
148 CFLAGS += -O3 -DNDEBUG -pg
149 LDFLAGS += -O3 -DNDEBUG -pg
Chris Lattner760da062003-03-14 20:25:22 +0000150else
151 ifdef ENABLE_OPTIMIZED
152 CONFIGURATION := Release
Reid Spencer4d71b662004-10-22 21:01:56 +0000153 CXXFLAGS += -O3 -DNDEBUG -finline-functions -felide-constructors -fomit-frame-pointer
154 CFLAGS += -O3 -DNDEBUG -fomit-frame-pointer
155 LDFLAGS += -O3 -DNDEBUG
Chris Lattner760da062003-03-14 20:25:22 +0000156 else
157 CONFIGURATION := Debug
Reid Spencer4d71b662004-10-22 21:01:56 +0000158 CXXFLAGS += -g -D_DEBUG
159 CFLAGS += -g -D_DEBUG
160 LDFLAGS += -g -D_DEBUG
161 KEEP_SYMBOLS := 1
Chris Lattner760da062003-03-14 20:25:22 +0000162 endif
163endif
164
Reid Spencer4d71b662004-10-22 21:01:56 +0000165ARFLAGS := cru
Reid Spencer3a561f52004-10-23 20:04:14 +0000166
167#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000168# Directory locations
Reid Spencer3a561f52004-10-23 20:04:14 +0000169#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000170OBJDIR := $(BUILD_OBJ_DIR)/$(CONFIGURATION)
171LIBDIR := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION)
172TOOLDIR := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION)
173LLVMLIBDIR := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION)
174LLVMTOOLDIR := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION)
John Criswell7a73b802003-06-30 21:59:07 +0000175
Reid Spencer3a561f52004-10-23 20:04:14 +0000176#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000177# Full Paths To Compiled Tools and Utilities
Reid Spencer3a561f52004-10-23 20:04:14 +0000178#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000179LIBTOOL := $(LLVM_OBJ_ROOT)/mklib
180LLVMAS := $(LLVMTOOLDIR)/llvm-as$(EXEEXT)
181BURG := $(LLVMTOOLDIR)/burg$(EXEEXT)
182TBLGEN := $(LLVMTOOLDIR)/tblgen$(EXEEXT)
183GCCLD := $(LLVMTOOLDIR)/gccld$(EXEEXT)
184LLVMGCC := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/gcc
185LLVMGXX := PATH=$(LLVMTOOLDIR):$(PATH) $(LLVMGCCDIR)/bin/g++
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000186
Reid Spencer4d71b662004-10-22 21:01:56 +0000187# Need a better way to compute this.
188LLVMGCCLIBDIR := $(dir $(shell $(LLVMGCC) -print-file-name=libgcc.a))/
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000189
Reid Spencer3a561f52004-10-23 20:04:14 +0000190#--------------------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000191# Adjust to user's request
Reid Spencer3a561f52004-10-23 20:04:14 +0000192#--------------------------------------------------------------------
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000193
Reid Spencer3a561f52004-10-23 20:04:14 +0000194# Adjust LIBTOOL options for shared libraries, or not.
John Criswell82f4a5a2003-07-31 20:58:51 +0000195ifndef SHARED_LIBRARY
Reid Spencer4d71b662004-10-22 21:01:56 +0000196 LIBTOOL += --tag=disable-shared
197else
198 LDFLAGS += -rpath $(LIBDIR)
John Criswell82f4a5a2003-07-31 20:58:51 +0000199endif
200
Reid Spencer3a561f52004-10-23 20:04:14 +0000201# Adjust settings for verbose mode
Chris Lattner760da062003-03-14 20:25:22 +0000202ifndef VERBOSE
Reid Spencer4d71b662004-10-22 21:01:56 +0000203 VERB := @
204 LIBTOOL += --silent
205 AR += >/dev/null 2>/dev/null
Reid Spencer151f8ba2004-10-25 08:27:37 +0000206 CONFIGUREFLAGS += >$(BUILD_OBJ_DIR)/configure.out 2>&1
207else
208 CONFIGUREFLAGS :=
Misha Brukmanb5f096f2002-09-12 16:05:39 +0000209endif
210
Vikram S. Advefeeae582002-09-18 11:55:13 +0000211# By default, strip symbol information from executable
Chris Lattner760da062003-03-14 20:25:22 +0000212ifndef KEEP_SYMBOLS
Reid Spencer4d71b662004-10-22 21:01:56 +0000213 STRIP = $(PLATFORMSTRIPOPTS)
214 STRIP_WARN_MSG = "(without symbols)"
Vikram S. Advefeeae582002-09-18 11:55:13 +0000215endif
216
Reid Spencer3a561f52004-10-23 20:04:14 +0000217# Adjust linker flags for building an executable
Reid Spencer4d71b662004-10-22 21:01:56 +0000218ifdef TOOLNAME
219 LDFLAGS += -rpath $(TOOLDIR) -export-dynamic $(TOOLLINKOPTS)
220endif
Chris Lattner00950542001-06-06 20:29:01 +0000221
Reid Spencer3a561f52004-10-23 20:04:14 +0000222# Use TOOLLINKOPTSB to pass options to the linker like library search
223# path etc.
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000224# Note that this is different from TOOLLINKOPTS, these options
225# are passed to the linker *before* the USEDLIBS options are passed.
226# e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
227ifdef TOOLLINKOPTSB
Reid Spencer4d71b662004-10-22 21:01:56 +0000228LDFLAGS += $(TOOLLINKOPTSB)
Dinakar Dhurjati87ea8aa2003-10-29 14:28:35 +0000229endif
230
Reid Spencer3a561f52004-10-23 20:04:14 +0000231#----------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000232# Options To Invoke Tools
Reid Spencer3a561f52004-10-23 20:04:14 +0000233#----------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000234
235CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused
236
Reid Spencer3a561f52004-10-23 20:04:14 +0000237LDFLAGS += -L$(LIBDIR) -L$(LLVMLIBDIR)
Reid Spencer4d71b662004-10-22 21:01:56 +0000238CPPFLAGS += -I$(BUILD_OBJ_DIR) \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000239 -I$(BUILD_SRC_DIR) \
240 -I$(BUILD_SRC_ROOT)/include \
241 -I$(BUILD_OBJ_ROOT)/include \
242 -I$(LLVM_OBJ_ROOT)/include \
243 -I$(LLVM_SRC_ROOT)/include \
244 -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
Reid Spencer4d71b662004-10-22 21:01:56 +0000245
Reid Spencer3a561f52004-10-23 20:04:14 +0000246Compile.C = $(CC) $(CPPFLAGS) $(CompileCommonOpts) -c $(CFLAGS)
247Compile.CXX = $(CXX) $(CPPFLAGS) $(CompileCommonOpts) $(CXXFLAGS) -c
248LTCompile.C = $(LIBTOOL) --mode=compile $(Compile.C)
249LTCompile.CXX = $(LIBTOOL) --tag=CXX --mode=compile $(Compile.CXX)
250BCCompile.CXX = $(LLVMGXX) $(CPPFLAGS) $(CompileCommonOpts) $(CXXFLAGS) -c
251BCCompile.C = $(LLVMGCC) $(CPPFLAGS) $(CompileCommonOpts) $(CFLAGS) -c
252Link = $(LIBTOOL) --tag=CXX --mode=link $(CXX) $(CPPFLAGS) \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000253 $(CompileCommonOpts) $(LDFLAGS) $(STRIP)
Reid Spencer3a561f52004-10-23 20:04:14 +0000254Relink = $(LIBTOOL) --tag=CXX --mode=link $(CXX)
255BCLinkLib = $(LLVMGCC) -shared -nostdlib
256Burg = $(BURG) -I $(BUILD_SRC_DIR)
257TableGen = $(TBLGEN) -I $(BUILD_SRC_DIR)
258Archive = $(AR) $(ARFLAGS)
Reid Spencer4d71b662004-10-22 21:01:56 +0000259ifdef RANLIB
Reid Spencer3a561f52004-10-23 20:04:14 +0000260Ranlib = $(RANLIB)
Reid Spencer4d71b662004-10-22 21:01:56 +0000261else
Reid Spencer3a561f52004-10-23 20:04:14 +0000262Ranlib = ranlib
John Criswell7a73b802003-06-30 21:59:07 +0000263endif
264
Chris Lattner00950542001-06-06 20:29:01 +0000265#----------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000266# Get the list of source files
267#----------------------------------------------------------
268ifndef SOURCES
269SOURCES := $(notdir $(wildcard $(BUILD_SRC_DIR)/*.cpp \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000270 $(BUILD_SRC_DIR)/*.cc $(BUILD_SRC_DIR)/*.c $(BUILD_SRC_DIR)/*.y \
271 $(BUILD_SRC_DIR)/*.l))
Reid Spencer4d71b662004-10-22 21:01:56 +0000272endif
273
274ifdef BUILT_SOURCES
Reid Spencer3a561f52004-10-23 20:04:14 +0000275SOURCES += $(filter %.cpp %.c %.cc %.y %.l,$(BUILT_SOURCES))
Vikram S. Advead9ea7e2002-10-14 16:40:04 +0000276endif
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000277
Reid Spencer3a561f52004-10-23 20:04:14 +0000278#----------------------------------------------------------
279# Types of objects that can be built from sources
280#----------------------------------------------------------
281BASENAME_SOURCES := $(sort $(basename $(SOURCES)))
282ObjectsO := $(BASENAME_SOURCES:%=$(OBJDIR)/%.o)
283ObjectsLO := $(BASENAME_SOURCES:%=$(OBJDIR)/%.lo)
284ObjectsBC := $(BASENAME_SOURCES:%=$(OBJDIR)/%.bc)
285
286
287###############################################################################
288# DIRECTORIES: Handle recursive descent of directory structure
289###############################################################################
John Criswell82f4a5a2003-07-31 20:58:51 +0000290
Chris Lattner00950542001-06-06 20:29:01 +0000291#---------------------------------------------------------
Reid Spencer3a561f52004-10-23 20:04:14 +0000292# Handle the DIRS options for sequential construction
Chris Lattner00950542001-06-06 20:29:01 +0000293#---------------------------------------------------------
294
Reid Spencer151f8ba2004-10-25 08:27:37 +0000295SUBDIRS :=
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000296ifdef DIRS
Reid Spencer151f8ba2004-10-25 08:27:37 +0000297SUBDIRS += $(DIRS)
Reid Spencer3a561f52004-10-23 20:04:14 +0000298$(RECURSIVE_TARGETS)::
Reid Spencer4d71b662004-10-22 21:01:56 +0000299 $(VERB) for dir in $(DIRS); do \
300 if [ ! -f $$dir/Makefile ]; then \
301 $(MKDIR) $$dir; \
302 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
303 fi; \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000304 ($(MAKE) -C $$dir $@ ) || exit 1; \
Chris Lattnerf1ffd992002-09-17 23:35:02 +0000305 done
Anand Shukla7c7a07e2002-09-18 04:29:30 +0000306endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000307
Reid Spencer3a561f52004-10-23 20:04:14 +0000308#---------------------------------------------------------
309# Handle the EXPERIMENTAL_DIRS options ensuring success
310# after each directory is built.
311#---------------------------------------------------------
312ifdef EXPERIMENTAL_DIRS
313$(RECURSIVE_TARGETS)::
314 $(VERB) for dir in $(EXPERIMENTAL_DIRS); do \
315 if [ ! -f $$dir/Makefile ]; then \
316 $(MKDIR) $$dir; \
317 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
318 fi; \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000319 ($(MAKE) -C $$dir $@ ) || exit 0; \
Reid Spencer3a561f52004-10-23 20:04:14 +0000320 done
321endif
Chris Lattnera8abc222002-09-18 03:22:27 +0000322
Reid Spencer3a561f52004-10-23 20:04:14 +0000323#---------------------------------------------------------
324# Handle the PARALLEL_DIRS options for parallel construction
325#---------------------------------------------------------
326ifdef PARALLEL_DIRS
327
Reid Spencer151f8ba2004-10-25 08:27:37 +0000328SUBDIRS += $(PARALLEL_DIRS)
Reid Spencer3a561f52004-10-23 20:04:14 +0000329# Unfortunately, this list must be maintained if new
330# recursive targets are added.
331all :: $(addsuffix /.makeall , $(PARALLEL_DIRS))
332clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS))
333check :: $(addsuffix /.makecheck , $(PARALLEL_DIRS))
334install :: $(addsuffix /.makeinstall , $(PARALLEL_DIRS))
335uninstall:: $(addsuffix /.makeuninstall,$(PARALLEL_DIRS))
336
337Parallel_Targets := $(foreach T,$(RECURSIVE_TARGETS),%/.make$(T))
338
339$(Parallel_Targets) :
Reid Spencer4d71b662004-10-22 21:01:56 +0000340 $(VERB) if [ ! -f $(@D)/Makefile ]; then \
341 $(MKDIR) $(@D); \
342 cp $(BUILD_SRC_DIR)/$(@D)/Makefile $(@D)/Makefile; \
John Criswellb3866b62003-11-25 19:32:22 +0000343 fi; \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000344 $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@)
Chris Lattner00950542001-06-06 20:29:01 +0000345endif
346
Reid Spencer3a561f52004-10-23 20:04:14 +0000347#---------------------------------------------------------
348# Handle the OPTIONAL_DIRS options for directores that may
349# or may not exist.
350#---------------------------------------------------------
John Criswell2a6530f2003-06-27 16:58:44 +0000351ifdef OPTIONAL_DIRS
Reid Spencer151f8ba2004-10-25 08:27:37 +0000352
353SUBDIRS += $(OPTIONAL_DIRS)
354
Reid Spencer3a561f52004-10-23 20:04:14 +0000355$(RECURSIVE_TARGETS)::
Reid Spencer4d71b662004-10-22 21:01:56 +0000356 $(VERB) for dir in $(OPTIONAL_DIRS); do \
357 if [ -d $(BUILD_SRC_DIR)/$$dir ]; then\
358 if [ ! -f $$dir/Makefile ]; then \
359 $(MKDIR) $$dir; \
360 cp $(BUILD_SRC_DIR)/$$dir/Makefile $$dir/Makefile; \
361 fi; \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000362 ($(MAKE) -C$$dir $@ ) || exit 1; \
Reid Spencer4d71b662004-10-22 21:01:56 +0000363 fi \
John Criswell2a6530f2003-06-27 16:58:44 +0000364 done
365endif
366
Reid Spencerfc945082004-08-20 09:20:05 +0000367#---------------------------------------------------------
368# Handle the CONFIG_FILES options
369#---------------------------------------------------------
370ifdef CONFIG_FILES
Reid Spencerfc945082004-08-20 09:20:05 +0000371
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000372install-local:: $(sysconfdir) $(CONFIG_FILES)
Reid Spencer37130d22004-10-04 07:05:07 +0000373 $(VERB)$(ECHO) Installing Configuration Files To $(sysconfdir)
374 $(VERB)for file in $(CONFIG_FILES); do \
Reid Spencer4d71b662004-10-22 21:01:56 +0000375 $(INSTALL) $(BUILD_SRC_DIR)/$${file} $(sysconfdir) ; \
Reid Spencerfc945082004-08-20 09:20:05 +0000376 done
Reid Spencer3a561f52004-10-23 20:04:14 +0000377
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000378uninstall-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000379 $(VERB)$(ECHO) Uninstalling Configuration Files From $(sysconfdir)
380 $(VERB)for file in $(CONFIG_FILES); do \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000381 $(RM) -f $(sysconfdir)/$${file} ; \
Reid Spencere5487ba2004-10-24 07:53:21 +0000382 done
383
Reid Spencer3a561f52004-10-23 20:04:14 +0000384$(sysconfdir):
Reid Spencer9411c642004-10-26 22:26:33 +0000385 $(VERB) $(MKDIR) $(sysconfdir)
Reid Spencer3a561f52004-10-23 20:04:14 +0000386
Reid Spencerfc945082004-08-20 09:20:05 +0000387endif
388
Reid Spencer3a561f52004-10-23 20:04:14 +0000389###############################################################################
390# Library Build Rules: Four ways to build a library
391###############################################################################
Chris Lattner00950542001-06-06 20:29:01 +0000392
Reid Spencere45ebfa2004-10-26 07:09:33 +0000393$(libdir):
394 $(VERB) $(MKDIR) $(libdir)
395
396$(bytecode_libdir):
397 $(VERB) $(MKDIR) $(bytecode_libdir)
398
399
Brian Gaeke8abff792004-01-22 22:53:48 +0000400
Reid Spencer3a561f52004-10-23 20:04:14 +0000401# if we're building a library ...
Chris Lattner00950542001-06-06 20:29:01 +0000402ifdef LIBRARYNAME
Vikram S. Adve112a72c2001-07-15 13:16:47 +0000403
Chris Lattner2a548c52002-09-16 22:36:42 +0000404# Make sure there isn't any extranous whitespace on the LIBRARYNAME option
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000405LIBRARYNAME := $(strip $(LIBRARYNAME))
Reid Spencer4d71b662004-10-22 21:01:56 +0000406LIBNAME_LA := $(LIBDIR)/lib$(LIBRARYNAME).la
407LIBNAME_A := $(LIBDIR)/lib$(LIBRARYNAME).a
408LIBNAME_O := $(LIBDIR)/$(LIBRARYNAME).o
409LIBNAME_BC := $(LIBDIR)/lib$(LIBRARYNAME).bc
Chris Lattnerccb4ebd2002-09-16 22:34:56 +0000410
Reid Spencer3a561f52004-10-23 20:04:14 +0000411#---------------------------------------------------------
412# Shared Library Targets:
413# If the user asked for a shared library to be built
414# with the SHARED_LIBRARY variable, then we provide
415# targets for building them.
416#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000417ifdef SHARED_LIBRARY
418
Reid Spencer3a561f52004-10-23 20:04:14 +0000419all-local:: $(LIBNAME_LA)
Reid Spencer4d71b662004-10-22 21:01:56 +0000420
421$(LIBNAME_LA): $(BUILT_SOURCES) $(ObjectsLO) $(LIBDIR)/.dir
Reid Spencere45ebfa2004-10-26 07:09:33 +0000422 @$(ECHO) Linking $(CONFIGURATION) Shared Library $(notdir $@)
Reid Spencer4d71b662004-10-22 21:01:56 +0000423 $(VERB) $(Link) -o $@ $(ObjectsLO)
424 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $@ $(LIBDIR)
Reid Spencer3a561f52004-10-23 20:04:14 +0000425
426clean-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000427ifneq ($(strip $(LIBNAME_LA)),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000428 $(VERB) $(RM) -f $(LIBNAME_LA)
Reid Spencere5487ba2004-10-24 07:53:21 +0000429endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000430
Reid Spencere5487ba2004-10-24 07:53:21 +0000431DestSharedLib = $(libdir)/lib$(LIBRARYNAME)$(SHLIBEXT)
Reid Spencer4d71b662004-10-22 21:01:56 +0000432
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000433install-local:: $(DestSharedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000434
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000435$(DestSharedLib): $(libdir) $(LIBNAME_LA)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000436 @$(ECHO) Installing $(CONFIGURATION) Shared Library $(DestSharedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000437 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_LA) $(DestSharedLib)
438 $(VERB) $(LIBTOOL) --finish $(libdir)
439
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000440uninstall-local::
Reid Spencere45ebfa2004-10-26 07:09:33 +0000441 @$(ECHO) Uninstalling $(CONFIGURATION) Shared Library $(DestSharedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000442 $(VERB) $(RM) -f $(DestSharedLib)
443
Reid Spencer4d71b662004-10-22 21:01:56 +0000444endif
445
Reid Spencer3a561f52004-10-23 20:04:14 +0000446#---------------------------------------------------------
447# Bytecode Library Targets:
448# If the user asked for a bytecode library to be built
449# with the BYTECODE_LIBRARY variable, then we provide
450# targets for building them.
451#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000452ifdef BYTECODE_LIBRARY
453
454ifdef EXPORTED_SYMBOL_LIST
455 BCLinkLib += -Xlinker -internalize-public-api-list=$(EXPORTED_SYMBOL_LIST)
456else
457 ifdef EXPORTED_SYMBOL_FILE
458 BCLinkLib += -Xlinker -internalize-public-api-file=$(EXPORTED_SYMBOL_FILE)
459 else
460 BCLinkLib += -Xlinker -disable-internalize
461 endif
462endif
463
Reid Spencer3a561f52004-10-23 20:04:14 +0000464all-local:: $(LIBNAME_BC)
Reid Spencer4d71b662004-10-22 21:01:56 +0000465
466$(LIBNAME_BC): $(BUILT_SOURCES) $(ObjectsBC) $(LIBDIR)/.dir
Reid Spencere45ebfa2004-10-26 07:09:33 +0000467 @$(ECHO) Linking $(CONFIGURATION) Bytecode Library $(notdir $@)
Reid Spencer4d71b662004-10-22 21:01:56 +0000468 $(VERB) $(BCLinkLib) -o $@ $(ObjectsBC)
469
Reid Spencer3a561f52004-10-23 20:04:14 +0000470clean-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000471ifneq ($(strip $(LIBNAME_BC)),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000472 $(VERB) $(RM) -f $(LIBNAME_BC)
Reid Spencere5487ba2004-10-24 07:53:21 +0000473endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000474
Reid Spencere5487ba2004-10-24 07:53:21 +0000475DestBytecodeLib = $(bytecode_libdir)/lib$(LIBRARYNAME).bc
Reid Spencere45ebfa2004-10-26 07:09:33 +0000476
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000477install-local:: $(DestBytecodeLib)
Chris Lattner481cc7c2003-08-15 02:18:35 +0000478
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000479$(DestBytecodeLib): $(bytecode_libdir) $(LIBNAME_BC)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000480 @$(ECHO) Installing $(CONFIGURATION) Bytecode Library $(DestBytecodeLib)
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000481 $(VERB) $(INSTALL) $(LIBNAME_BC) $@
Reid Spencere5487ba2004-10-24 07:53:21 +0000482
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000483uninstall-local::
Reid Spencere45ebfa2004-10-26 07:09:33 +0000484 @$(ECHO) Uninstalling $(CONFIGURATION) Bytecode Library $(DestBytecodeLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000485 $(VERB) $(RM) -f $(DestBytecodeLib)
Reid Spencer4d71b662004-10-22 21:01:56 +0000486
487endif
Vikram S. Adve60f56062002-08-02 18:34:12 +0000488
Chris Lattner760da062003-03-14 20:25:22 +0000489# Does the library want a .o version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000490ifndef DONT_BUILD_RELINKED
Reid Spencer3a561f52004-10-23 20:04:14 +0000491all-local:: $(LIBNAME_O)
Reid Spencer4d71b662004-10-22 21:01:56 +0000492
493$(LIBNAME_O): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
Reid Spencere45ebfa2004-10-26 07:09:33 +0000494 @$(ECHO) Linking $(CONFIGURATION) Object Library $(notdir $@)
Reid Spencer4d71b662004-10-22 21:01:56 +0000495 $(VERB) $(Relink) -o $@ $(ObjectsO)
496
Reid Spencer3a561f52004-10-23 20:04:14 +0000497clean-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000498ifneq ($(strip $(LIBNAME_O)),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000499 $(VERB) $(RM) -f $(LIBNAME_O)
Reid Spencere5487ba2004-10-24 07:53:21 +0000500endif
501
502DestRelinkedLib = $(libdir)/$(LIBRARYNAME).o
503
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000504install-local:: $(DestRelinkedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000505
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000506$(DestRelinkedLib): $(libdir) $(LIBNAME_O)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000507 @$(ECHO) Installing $(CONFIGURATION) Object Library $(DestRelinkedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000508 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_O) $(DestRelinkedLib)
509
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000510uninstall-local::
Reid Spencere45ebfa2004-10-26 07:09:33 +0000511 @$(ECHO) Uninstalling $(CONFIGURATION) Object Library $(DestRelinkedLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000512 $(VERB) $(RM) -f $(DestRelinkedLib)
Reid Spencer4d71b662004-10-22 21:01:56 +0000513
Chris Lattnere62dbe92002-07-23 17:56:16 +0000514endif
Chris Lattner760da062003-03-14 20:25:22 +0000515
516# Does the library want an archive version built?
Chris Lattnere62dbe92002-07-23 17:56:16 +0000517ifdef BUILD_ARCHIVE
Reid Spencer3a561f52004-10-23 20:04:14 +0000518all-local:: $(LIBNAME_A)
Chris Lattnere62dbe92002-07-23 17:56:16 +0000519
Reid Spencer4d71b662004-10-22 21:01:56 +0000520$(LIBNAME_A): $(BUILT_SOURCES) $(ObjectsO) $(LIBDIR)/.dir
Reid Spencere45ebfa2004-10-26 07:09:33 +0000521 @$(ECHO) Building $(CONFIGURATION) Archive Library $(notdir $@)
Reid Spencer37130d22004-10-04 07:05:07 +0000522 $(VERB)$(RM) -f $@
Reid Spencer4d71b662004-10-22 21:01:56 +0000523 $(VERB) $(Archive) $@ $(ObjectsO)
524 $(VERB) $(Ranlib) $@
Vikram S. Adve41e78912002-09-20 14:03:13 +0000525
Reid Spencer3a561f52004-10-23 20:04:14 +0000526clean-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000527ifneq ($(strip $(LIBNAME_A)),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000528 $(VERB) $(RM) -f $(LIBNAME_A)
Chris Lattner00950542001-06-06 20:29:01 +0000529endif
530
Reid Spencere5487ba2004-10-24 07:53:21 +0000531DestArchiveLib := $(libdir)/lib$(LIBRARYNAME).a
532
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000533install-local:: $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000534
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000535$(DestArchiveLib): $(libdir) $(LIBNAME_A)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000536 @$(ECHO) Installing $(CONFIGURATION) Archive Library $(DestArchiveLib)
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000537 $(VERB) $(MKDIR) $(libdir)
Reid Spencere5487ba2004-10-24 07:53:21 +0000538 $(VERB) $(LIBTOOL) --mode=install $(INSTALL) $(LIBNAME_A) $(DestArchiveLib)
539
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000540uninstall-local::
Reid Spencere45ebfa2004-10-26 07:09:33 +0000541 @$(ECHO) Uninstalling $(CONFIGURATION) Archive Library $(DestArchiveLib)
Reid Spencere5487ba2004-10-24 07:53:21 +0000542 $(VERB) $(RM) -f $(DestArchiveLib)
543
544endif
545
546# endif LIBRARYNAME
Reid Spencer4d71b662004-10-22 21:01:56 +0000547endif
548
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000549###############################################################################
550# Tool Build Rules: Build executable tool based on TOOLNAME option
551###############################################################################
552
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000553ifdef TOOLNAME
554
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000555#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000556# TOOLLINKOPTSB to pass options to the linker like library search path etc
557# Note that this is different from TOOLLINKOPTS, these options
558# are passed to the linker *before* the USEDLIBS options are passed.
559# e.g. usage TOOLLINKOPTSB = -L/home/xxx/lib
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000560#---------------------------------------------------------
Reid Spencer4d71b662004-10-22 21:01:56 +0000561ifdef TOOLLINKOPTSB
562Link += $(TOOLLINKOPTSB)
Reid Spencer37130d22004-10-04 07:05:07 +0000563endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000564
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000565# TOOLEXENAME - This is the output filenames to generate
Reid Spencer4d71b662004-10-22 21:01:56 +0000566TOOLEXENAME := $(TOOLDIR)/$(TOOLNAME)
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000567
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000568# LIBS_OPTIONS - Compute the options lines that add -llib1 -llib2, etc.
Reid Spencer4d71b662004-10-22 21:01:56 +0000569PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
570PROJ_LIBS_OPTIONS := $(patsubst %.o, $(LIBDIR)/%.o, $(PROJ_LIBS_OPTIONS))
571LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS)))
572LLVM_LIBS_OPTIONS := $(patsubst %.o, $(LLVMLIBDIR)/%.o, $(LLVM_LIBS_OPTIONS))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000573
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000574# USED_LIBS/LIBS_PATHS - Compute dependent library file paths
Reid Spencer4d71b662004-10-22 21:01:56 +0000575PROJ_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
576LLVM_USED_LIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(LLVMLIBS)))
577PROJ_LIBS_PATHS := $(addprefix $(LIBDIR)/,$(PROJ_USED_LIBS))
578LLVM_LIBS_PATHS := $(addprefix $(LLVMLIBDIR)/,$(LLVM_USED_LIBS))
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000579
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000580# Concatenate all the optoins
Reid Spencer4d71b662004-10-22 21:01:56 +0000581LINK_OPTS := $(TOOLLINKOPTS) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS)
John Criswellfe785bd2004-09-16 14:11:25 +0000582
Reid Spencer4d71b662004-10-22 21:01:56 +0000583# Handle compression libraries automatically
584ifeq ($(HAVE_BZIP2),1)
585LIBS += -lbz2
586endif
587ifeq ($(HAVE_ZLIB),1)
588LIBS += -lz
589endif
Dinakar Dhurjatiffb55cd2003-05-29 16:18:20 +0000590
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000591# Tell make that we need to rebuild subdirectories before we can link the tool.
592# This affects things like LLI which has library subdirectories.
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000593$(TOOLEXENAME): $(addsuffix /.makeall, $(PARALLEL_DIRS))
Chris Lattner8d7dfb32003-01-22 16:13:31 +0000594
Reid Spencerb1dd3dd2004-10-24 08:21:04 +0000595all-local:: $(TOOLEXENAME)
John Criswell2a6530f2003-06-27 16:58:44 +0000596
Reid Spencer3a561f52004-10-23 20:04:14 +0000597clean-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000598ifneq ($(strip $(TOOLEXENAME)),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000599 $(VERB) $(RM) -f $(TOOLEXENAME)
Reid Spencere5487ba2004-10-24 07:53:21 +0000600endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000601
Reid Spencer4d71b662004-10-22 21:01:56 +0000602$(TOOLEXENAME): $(BUILT_SOURCES) $(ObjectsO) $(PROJ_LIBS_PATHS) $(LLVM_LIBS_PATHS) $(TOOLDIR)/.dir
603 @$(ECHO) Linking $(CONFIGURATION) executable $(TOOLNAME) $(STRIP_WARN_MSG)
604 $(VERB) $(Link) -o $@ $(ObjectsO) $(PROJ_LIBS_OPTIONS) $(LLVM_LIBS_OPTIONS) $(LIBS)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000605 @$(ECHO) ======= Finished Linking $(CONFIGURATION) Executable $(TOOLNAME) $(STRIP_WARN_MSG)
Reid Spencere5487ba2004-10-24 07:53:21 +0000606
607DestTool = $(bindir)/$(TOOLNAME)
608
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000609install-local:: $(DestTool)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000610
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000611$(DestTool): $(bindir) $(TOOLEXENAME)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000612 @$(ECHO) Installing $(CONFIGURATION) $(DestTool)
613 $(VERB) $(INSTALL) $(TOOLEXENAME) $(DestTool)
Reid Spencere5487ba2004-10-24 07:53:21 +0000614
Reid Spencere45ebfa2004-10-26 07:09:33 +0000615$(bindir):
616 $(VERB) $(MKDIR) $(bindir)
617
Reid Spencerc6dcc6a2004-10-28 07:57:28 +0000618uninstall-local::
Reid Spencere45ebfa2004-10-26 07:09:33 +0000619 @$(ECHO) Uninstalling $(CONFIGURATION) $(DestTool)
Reid Spencere5487ba2004-10-24 07:53:21 +0000620 $(VERB) $(RM) -f $(DestTool)
621
Reid Spencer4d71b662004-10-22 21:01:56 +0000622endif
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000623
Reid Spencer4d71b662004-10-22 21:01:56 +0000624ifndef DISABLE_AUTO_DEPENDENCIES
Vikram S. Adve41e78912002-09-20 14:03:13 +0000625
Reid Spencer4d71b662004-10-22 21:01:56 +0000626# Create .lo files in the OBJDIR directory from the .cpp and .c files...
Reid Spencer3a561f52004-10-23 20:04:14 +0000627ifdef SHARED_LIBRARY
628
629$(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
Reid Spencere45ebfa2004-10-26 07:09:33 +0000630 @$(ECHO) "Compiling $*.cpp (PIC)"
Reid Spencer3a561f52004-10-23 20:04:14 +0000631 $(VERB) if $(LTCompile.CXX) -MD -MT $@ -MP -MF $(OBJDIR)/$*.LACXXd $< -o $@ ; \
632 then $(MV) -f "$(OBJDIR)/$*.LACXXd" "$(OBJDIR)/$*.d"; \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000633 else $(RM) -f "$(OBJDIR)/$*.LACXXd"; exit 1; fi
Reid Spencer3a561f52004-10-23 20:04:14 +0000634
635$(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
Reid Spencere45ebfa2004-10-26 07:09:33 +0000636 @$(ECHO) "Compiling $*.c (PIC)"
Reid Spencer3a561f52004-10-23 20:04:14 +0000637 $(VERB) if $(LTCompile.C) -MD -MT $@ -MP -MF $(OBJDIR)/$*.LACd $< -o $@ ; \
638 then $(MV) -f "$(OBJDIR)/$*.LACd" "$(OBJDIR)/$*.d"; \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000639 else $(RM) -f "$(OBJDIR)/$*.LACd"; exit 1; fi
Reid Spencer3a561f52004-10-23 20:04:14 +0000640
641else
Reid Spencer4d71b662004-10-22 21:01:56 +0000642
643$(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
Reid Spencere45ebfa2004-10-26 07:09:33 +0000644 @$(ECHO) "Compiling $*.cpp"
Reid Spencer3a561f52004-10-23 20:04:14 +0000645 $(VERB) if $(Compile.CXX) -MD -MT $@ -MP -MF $(OBJDIR)/$*.CXXd $< -o $@ ; \
646 then $(MV) -f "$(OBJDIR)/$*.CXXd" "$(OBJDIR)/$*.d"; \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000647 else $(RM) -f "$(OBJDIR)/$*.CXXd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000648
649$(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
Reid Spencere45ebfa2004-10-26 07:09:33 +0000650 @$(ECHO) "Compiling $*.c"
Reid Spencer3a561f52004-10-23 20:04:14 +0000651 $(VERB) if $(Compile.C) -MD -MT $@ -MP -MF $(OBJDIR)/$*.Cd $< -o $@ ; \
652 then $(MV) -f "$(OBJDIR)/$*.Cd" "$(OBJDIR)/$*.d"; \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000653 else $(RM) -f "$(OBJDIR)/$*.Cd"; exit 1; fi
Reid Spencer3a561f52004-10-23 20:04:14 +0000654
655endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000656
657# Create .bc files in the OBJDIR directory from .cpp and .c files...
658$(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
Reid Spencere45ebfa2004-10-26 07:09:33 +0000659 @$(ECHO) "Compiling $*.cpp (bytecode)"
Reid Spencer3a561f52004-10-23 20:04:14 +0000660 $(VERB) if $(BCCompile.CXX) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.BCCXXd" $< -o $@ ; \
661 then $(MV) -f "$(OBJDIR)/$*.BCCXXd" "$(OBJDIR)/$*.d"; \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000662 else $(RM) -f "$(OBJDIR)/$*.BCCXXd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000663
664$(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
Reid Spencere45ebfa2004-10-26 07:09:33 +0000665 @$(ECHO) "Compiling $*.c (bytecode)"
Reid Spencer3a561f52004-10-23 20:04:14 +0000666 $(VERB) if $(BCCompile.C) -MD -MT $@ -MP -MF "$(OBJDIR)/$*.BCCd" $< -o $@ ; \
667 then $(MV) -f "$(OBJDIR)/$*.BCCd" "$(OBJDIR)/$*.d"; \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000668 else $(RM) -f "$(OBJDIR)/$*.BCCd"; exit 1; fi
Reid Spencer4d71b662004-10-22 21:01:56 +0000669
670else
671
Reid Spencer3a561f52004-10-23 20:04:14 +0000672ifdef SHARED_LIBRARY
673
674$(OBJDIR)/%.lo $(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
Reid Spencere45ebfa2004-10-26 07:09:33 +0000675 @$(ECHO) "Compiling $*.cpp (PIC)"
Reid Spencer3a561f52004-10-23 20:04:14 +0000676 $(LTCompile.CXX) $< -o $@
677
678$(OBJDIR)/%.lo $(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
Reid Spencere45ebfa2004-10-26 07:09:33 +0000679 @$(ECHO) "Compiling $*.cpp (PIC)"
Reid Spencer3a561f52004-10-23 20:04:14 +0000680 $(LTCompile.C) $< -o $@
681
682else
Reid Spencer4d71b662004-10-22 21:01:56 +0000683
684$(OBJDIR)/%.o: %.cpp $(OBJDIR)/.dir
Reid Spencere45ebfa2004-10-26 07:09:33 +0000685 @$(ECHO) "Compiling $*.cpp"
Reid Spencer3a561f52004-10-23 20:04:14 +0000686 $(Compile.CXX) $< -o $@
Reid Spencer4d71b662004-10-22 21:01:56 +0000687
688$(OBJDIR)/%.o: %.c $(OBJDIR)/.dir
Reid Spencere45ebfa2004-10-26 07:09:33 +0000689 @$(ECHO) "Compiling $*.cpp"
Reid Spencer3a561f52004-10-23 20:04:14 +0000690 $(Compile.C) $< -o $@
691endif
Reid Spencer4d71b662004-10-22 21:01:56 +0000692
693# Create .bc files in the OBJDIR directory from .cpp and .c files...
694$(OBJDIR)/%.bc: %.cpp $(OBJDIR)/.dir
Reid Spencere45ebfa2004-10-26 07:09:33 +0000695 @$(ECHO) "Compiling $*.cpp (bytecode)"
Reid Spencer4d71b662004-10-22 21:01:56 +0000696 $(BCCompileCPP) $< -o $@
697
698$(OBJDIR)/%.bc: %.c $(OBJDIR)/.dir
Reid Spencere45ebfa2004-10-26 07:09:33 +0000699 @$(ECHO) "Compiling $*.c (bytecode)"
Reid Spencer4d71b662004-10-22 21:01:56 +0000700 $(BCCompileC) $< -o $@
Brian Gaeke44909cf2003-12-10 00:26:28 +0000701
Chris Lattner1cbc29f2001-09-07 22:57:58 +0000702endif
703
Reid Spencer4d71b662004-10-22 21:01:56 +0000704$(OBJDIR)/%.bc: %.ll $(OBJDIR)/.dir $(LLVMAS)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000705 @$(ECHO) "Compiling $*.ll"
Chris Lattner481cc7c2003-08-15 02:18:35 +0000706 $(VERB) $(LLVMAS) $< -f -o $@
707
Reid Spencer4d71b662004-10-22 21:01:56 +0000708ifdef TARGET
709
Reid Spencerc64b2b32004-10-23 08:19:37 +0000710TDFILES := $(strip $(wildcard $(BUILD_SRC_DIR)/*.td) $(LLVM_SRC_ROOT)/lib/Target/Target.td)
Reid Spencer16544482004-10-27 04:34:35 +0000711INCFILES := $(filter %.inc,$(BUILT_SOURCES))
Reid Spencer4d71b662004-10-22 21:01:56 +0000712
Reid Spencer16544482004-10-27 04:34:35 +0000713$(INCFILES) : $(TBLGEN) $(TDFILES)
Reid Spencer4d71b662004-10-22 21:01:56 +0000714
Reid Spencer16544482004-10-27 04:34:35 +0000715%GenRegisterNames.inc : %.td
Reid Spencer4d71b662004-10-22 21:01:56 +0000716 @echo "Building $(<F) register names with tblgen"
717 $(VERB) $(TableGen) -gen-register-enums -o $@ $<
718
Reid Spencer16544482004-10-27 04:34:35 +0000719%GenRegisterInfo.h.inc : %.td
Reid Spencer4d71b662004-10-22 21:01:56 +0000720 @echo "Building $(<F) register information header with tblgen"
721 $(VERB) $(TableGen) -gen-register-desc-header -o $@ $<
722
723%GenRegisterInfo.inc : %.td
724 @echo "Building $(<F) register info implementation with tblgen"
725 $(VERB) $(TableGen) -gen-register-desc -o $@ $<
726
727%GenInstrNames.inc : %.td
728 @echo "Building $(<F) instruction names with tblgen"
729 $(VERB) $(TableGen) -gen-instr-enums -o $@ $<
730
731%GenInstrInfo.inc : %.td
732 @echo "Building $(<F) instruction information with tblgen"
733 $(VERB) $(TableGen) -gen-instr-desc -o $@ $<
734
735%GenAsmWriter.inc : %.td
736 @echo "Building $(<F) assembly writer with tblgen"
737 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
738
739%GenATTAsmWriter.inc : %.td
740 @echo "Building $(<F) AT&T assembly writer with tblgen"
741 $(VERB) $(TableGen) -gen-asm-writer -o $@ $<
742
743%GenIntelAsmWriter.inc : %.td
744 @echo "Building $(<F) Intel assembly writer with tblgen"
745 $(VERB) $(TableGen) -gen-asm-writer -asmwriternum=1 -o $@ $<
746
747%GenInstrSelector.inc: %.td
748 @echo "Building $(<F) instruction selector with tblgen"
749 $(VERB) $(TableGen) -gen-instr-selector -o $@ $<
750
751%GenCodeEmitter.inc:: %.td
752 @echo "Building $(<F) code emitter with tblgen"
753 $(VERB) $(TableGen) -gen-emitter -o $@ $<
754
Reid Spencer3a561f52004-10-23 20:04:14 +0000755clean-local::
Reid Spencer4d71b662004-10-22 21:01:56 +0000756 $(VERB) rm -f *.inc
757
758endif
Chris Lattner481cc7c2003-08-15 02:18:35 +0000759
Chris Lattnere8996782003-01-16 22:44:19 +0000760#
761# Rules for building lex/yacc files
762#
Reid Spencer3a561f52004-10-23 20:04:14 +0000763LEX_FILES = $(filter %.l, $(SOURCES))
Chris Lattnere8996782003-01-16 22:44:19 +0000764LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp)
Reid Spencer3a561f52004-10-23 20:04:14 +0000765YACC_FILES = $(filter %.y, $(SOURCES))
Chris Lattnere8996782003-01-16 22:44:19 +0000766YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output)
767.PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT)
768
Chris Lattner00950542001-06-06 20:29:01 +0000769# Create a .cpp source file from a flex input file... this uses sed to cut down
770# on the warnings emited by GCC...
Chris Lattner6d131b42003-01-23 16:33:10 +0000771#
772# The last line is a gross hack to work around flex aparently not being able to
773# resize the buffer on a large token input. Currently, for uninitialized string
774# buffers in LLVM we can generate very long tokens, so this is a hack around it.
Chris Lattnerb7dc2b92003-08-15 20:00:47 +0000775# FIXME. (f.e. char Buffer[10000] )
Chris Lattner6d131b42003-01-23 16:33:10 +0000776#
Chris Lattner00950542001-06-06 20:29:01 +0000777%.cpp: %.l
Reid Spencer4d71b662004-10-22 21:01:56 +0000778 @$(ECHO) Flexing $<
Chris Lattner7bb107d2003-08-04 19:48:10 +0000779 $(VERB) $(FLEX) -t $< | \
Reid Spencer4d71b662004-10-22 21:01:56 +0000780 $(SED) '/^find_rule/d' | \
781 $(SED) 's/void yyunput/inline void yyunput/' | \
782 $(SED) 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \
783 $(SED) 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' \
Reid Spencer80f0ef72004-10-28 00:41:43 +0000784 > $@
Chris Lattner00950542001-06-06 20:29:01 +0000785
786# Rule for building the bison parsers...
Chris Lattner694c5df2003-05-15 21:28:55 +0000787%.c: %.y # Cancel built-in rules for yacc
Reid Spencer80f0ef72004-10-28 00:41:43 +0000788%.cpp: %.y # Cancel built-in rules for yacc
Chris Lattner694c5df2003-05-15 21:28:55 +0000789%.h: %.y # Cancel built-in rules for yacc
Chris Lattner00950542001-06-06 20:29:01 +0000790%.cpp %.h : %.y
Reid Spencer4d71b662004-10-22 21:01:56 +0000791 @$(ECHO) "Bisoning $*.y"
John Criswell410d1b52003-09-09 20:57:03 +0000792 $(VERB) $(BISON) -v -d -p $(<F:%Parser.y=%) -o $*.tab.c $<
Reid Spencer80f0ef72004-10-28 00:41:43 +0000793 $(VERB) $(MV) -f $*.tab.c $*.cpp
794 $(VERB) $(MV) -f $*.tab.h $*.h
Chris Lattner00950542001-06-06 20:29:01 +0000795
796# To create the directories...
797%/.dir:
Reid Spencer4d71b662004-10-22 21:01:56 +0000798 $(VERB) $(MKDIR) $* > /dev/null
John Criswell7a73b802003-06-30 21:59:07 +0000799 @$(DATE) > $@
Chris Lattner00950542001-06-06 20:29:01 +0000800
Reid Spencer4d71b662004-10-22 21:01:56 +0000801.PRECIOUS: $(OBJDIR)/.dir $(LIBDIR)/.dir $(TOOLDIR)/.dir $(LLVMLIBDIR)/.dir
802.PRECIOUS: $(LLVMTOOLDIR)/.dir
803
Chris Lattner30440c62003-01-16 21:06:18 +0000804# To create postscript files from dot files...
John Criswelle0f9ac62003-10-02 19:02:02 +0000805ifneq ($(DOT),false)
Chris Lattner30440c62003-01-16 21:06:18 +0000806%.ps: %.dot
Reid Spencer4d71b662004-10-22 21:01:56 +0000807 $(DOT) -Tps < $< > $@
John Criswell7a73b802003-06-30 21:59:07 +0000808else
809%.ps: %.dot
Reid Spencer4d71b662004-10-22 21:01:56 +0000810 $(ECHO) "Cannot build $@: The program dot is not installed"
John Criswell7a73b802003-06-30 21:59:07 +0000811endif
Chris Lattner30440c62003-01-16 21:06:18 +0000812
John Criswell7f336952003-09-06 14:44:17 +0000813#
814# This rules ensures that header files that are removed still have a rule for
815# which they can be "generated." This allows make to ignore them and
816# reproduce the dependency lists.
817#
John Criswell4b6e5d12003-09-18 18:37:08 +0000818%.h:: ;
John Criswell7f336952003-09-06 14:44:17 +0000819
Chris Lattner172b6482002-09-22 02:47:15 +0000820# 'make clean' nukes the tree
Reid Spencer3a561f52004-10-23 20:04:14 +0000821clean-local::
Reid Spencere5487ba2004-10-24 07:53:21 +0000822ifneq ($(strip $(OBJDIR)),)
Reid Spencer83cbcb92004-10-24 02:26:09 +0000823 $(VERB) $(RM) -rf $(OBJDIR)
Reid Spencere5487ba2004-10-24 07:53:21 +0000824endif
Brian Gaeke9d3cd402004-01-21 19:53:11 +0000825 $(VERB) $(RM) -f core core.[0-9][0-9]* *.o *.d *~ *.flc
826ifneq ($(strip $(SHLIBEXT)),) # Extra paranoia - make real sure SHLIBEXT is set
827 $(VERB) $(RM) -f *$(SHLIBEXT)
828endif
Reid Spencere5487ba2004-10-24 07:53:21 +0000829ifneq ($(strip $(LEX_OUTPUT)),)
830 $(VERB) $(RM) -f $(LEX_OUTPUT)
831endif
832ifneq ($(strip $(YACC_OUTPUT)),)
833 $(VERB) $(RM) -f $(YACC_OUTPUT)
834endif
John Criswell7a73b802003-06-30 21:59:07 +0000835
Reid Spencer3a561f52004-10-23 20:04:14 +0000836###############################################################################
837# DEPENDENCIES: Include the dependency files if we should
838###############################################################################
Chris Lattner33ad24a2003-08-22 14:10:16 +0000839ifndef DISABLE_AUTO_DEPENDENCIES
840
Reid Spencer3a561f52004-10-23 20:04:14 +0000841# If its not one of the cleaning targets
842ifneq ($strip($(filter-out clean clean-local dist-clean, $(MAKECMDGOALS))),)
Reid Spencer4d71b662004-10-22 21:01:56 +0000843
Reid Spencer3a561f52004-10-23 20:04:14 +0000844# Get the list of dependency files
845DependFiles := $(basename $(filter %.cpp %.c %.cc, $(SOURCES)))
846DependFiles := $(patsubst %,$(BUILD_OBJ_DIR)/$(CONFIGURATION)/%.d,$(DependFiles))
Misha Brukman4f7a8cf2003-11-09 21:36:19 +0000847
Reid Spencer3a561f52004-10-23 20:04:14 +0000848-include /dev/null $(DependFiles)
849
John Criswelld741bcf2003-08-12 18:51:51 +0000850endif
Chris Lattner1ddb6b62003-08-18 17:27:40 +0000851
Chris Lattner33ad24a2003-08-22 14:10:16 +0000852endif # ifndef DISABLE_AUTO_DEPENDENCIES
Reid Spencer4d71b662004-10-22 21:01:56 +0000853
Reid Spencer151f8ba2004-10-25 08:27:37 +0000854###############################################################################
855# Handle construction of a distribution tarball
856###############################################################################
857
858.PHONY: dist dist-chck dist-clean distdir dist-gzip dist-bzip2 dist-zip
859
Reid Spencere45ebfa2004-10-26 07:09:33 +0000860#------------------------------------------------------------------------
861# Define distribution related variables
862#------------------------------------------------------------------------
Reid Spencer151f8ba2004-10-25 08:27:37 +0000863DistName := $(LLVM_TARBALL_NAME)
864DistDir := $(BUILD_OBJ_ROOT)/$(DistName)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000865TopDistDir := $(BUILD_OBJ_ROOT)/$(DistName)
Reid Spencer151f8ba2004-10-25 08:27:37 +0000866DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
867DistZip := $(BUILD_OBJ_ROOT)/$(DistName).zip
868DistTarBZ2 := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
869DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
870 ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
Reid Spencere45ebfa2004-10-26 07:09:33 +0000871 Makefile.config.in configure autoconf
872DistOther := $(notdir $(wildcard \
873 $(BUILD_SRC_DIR)/*.h \
874 $(BUILD_SRC_DIR)/*.td \
875 $(BUILD_SRC_DIR)/*.def \
876 $(BUILD_SRC_DIR)/*.ll \
877 $(BUILD_SRC_DIR)/*.in))
878DistSources := $(SOURCES) $(EXTRA_DIST)
879DistSubDirs := $(SUBDIRS)
880DistFiles := $(DistAlways) $(DistSources) $(DistOther)
Reid Spencer151f8ba2004-10-25 08:27:37 +0000881
Reid Spencere45ebfa2004-10-26 07:09:33 +0000882
883#------------------------------------------------------------------------
884# We MUST build distribution with OBJ_DIR != SRC_DIR
885#------------------------------------------------------------------------
886ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
887dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
888 @$(ECHO) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
889
890DistCheckTop :=
891else
892
893DistCheckTop := check
894#------------------------------------------------------------------------
895# Prevent catastrophic remove
896#------------------------------------------------------------------------
897ifeq ($(LLVM_TARBALL_NAME),)
898$(error LLVM_TARBALL_NAME is empty. Please rerun configure)
899endif
900
901#------------------------------------------------------------------------
902# Prevent attempt to run dist targets from anywhere but the top level
903#------------------------------------------------------------------------
904ifneq ($(LEVEL),.)
905
906dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
907 @$(ECHO) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
908
909else
910
911#------------------------------------------------------------------------
912# Provide the top level targets
913#------------------------------------------------------------------------
914
915dist-gzip: $(DistTarGZip)
916
917$(DistTarGZip) : distdir
918 @$(ECHO) Packing gzipped distribution tar file.
919 $(VERB) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | gzip -c > "$(DistTarGZip)"
920
921dist-bzip2: $(DistTarBZ2)
922
923$(DistTarBZ2) : distdir
924 @$(ECHO) Packing bzipped distribution tar file.
925 $(VERB) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - $(DistName) | $(BZIP2) -c >$(DistTarBZ2)
926
927dist-zip: $(DistZip)
928
929$(DistZip) : distdir
930 @$(ECHO) Packing zipped distribution file.
931 $(VERB) rm -f $(DistZip)
932 $(VERB) cd $(BUILD_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
933
934dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
935 @$(ECHO) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
936
937DistCheckDir := $(LLVM_OBJ_ROOT)/_distcheckdir
938
Reid Spencer9411c642004-10-26 22:26:33 +0000939dist-check:: $(DistCheckTop) $(DistTarGZip)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000940 @$(ECHO) Checking distribution tar file.
941 $(VERB) if test -d $(DistCheckDir) ; then \
942 $(RM) -rf $(DistCheckDir) ; \
943 fi
944 $(VERB) $(MKDIR) $(DistCheckDir)
945 $(VERB) cd $(DistCheckDir) && \
946 $(MKDIR) $(DistCheckDir)/build && \
947 $(MKDIR) $(DistCheckDir)/install && \
948 gunzip -c $(DistTarGZip) | $(TAR) xf - && \
949 cd build && \
950 ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
951 --srcdir=../$(DistName) --with-llvmgccdir="$(LLVMGCCDIR)" && \
952 $(MAKE) check && \
953 $(MAKE) install && \
954 $(MAKE) uninstall && \
955 $(MAKE) dist && \
956 $(MAKE) clean && \
957 $(MAKE) dist-clean && \
958 $(ECHO) ===== $(DistTarGZip) Ready For Distribution =====
959
960dist-clean::
961 @$(ECHO) Cleaning distribution files
962 $(VERB) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) $(DistCheckDir)
963
964endif
965
966#------------------------------------------------------------------------
967# Provide the recursive distdir target for building the distribution directory
968#------------------------------------------------------------------------
Reid Spencer9411c642004-10-26 22:26:33 +0000969distdir : $(DistSources)
Reid Spencer151f8ba2004-10-25 08:27:37 +0000970 @$(ECHO) Building Distribution Directory $(DistDir)
Reid Spencere45ebfa2004-10-26 07:09:33 +0000971 $(VERB) if test "$(DistDir)" = "$(TopDistDir)" ; then \
972 if test -d "$(DistDir)" ; then \
973 find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
974 exit 1 ; \
975 fi ; \
976 echo Removing $(DistDir) ; \
977 $(RM) -rf $(DistDir); \
978 fi
Reid Spencer151f8ba2004-10-25 08:27:37 +0000979 $(VERB) $(MKDIR) $(DistDir)
980 $(VERB) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
981 srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
982 for file in $(DistFiles) ; do \
983 case "$$file" in \
984 $(BUILD_SRC_DIR)/*) file=`echo "$$file" | sed "s#^$$srcdirstrip/##"`;; \
Reid Spencere45ebfa2004-10-26 07:09:33 +0000985 $(BUILD_SRC_ROOT)/*) file=`echo "$$file" | sed "s#^$$srcrootstrip/#$(BUILD_OBJ_ROOT)/#"`;; \
Reid Spencer151f8ba2004-10-25 08:27:37 +0000986 esac; \
987 if test -f "$$file" || test -d "$$file" ; then \
988 from_dir=. ; \
989 else \
990 from_dir=$(BUILD_SRC_DIR); \
991 fi; \
992 to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'`; \
993 if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
994 to_dir="$(DistDir)/$$dir"; \
995 $(MKDIR) "$$to_dir" ; \
996 else \
997 to_dir="$(DistDir)"; \
998 fi; \
999 mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
1000 if test -n "$$mid_dir" ; then \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001001 $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001002 fi ; \
1003 if test -d "$$from_dir/$$file"; then \
1004 if test -d "$(BUILD_SRC_DIR)/$$file" && \
1005 test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
1006 cp -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
1007 fi; \
1008 cp -pR $$from_dir/$$file $$to_dir || exit 1; \
1009 elif test -f "$$from_dir/$$file" ; then \
1010 cp -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
1011 elif test -L "$$from_dir/$$file" ; then \
1012 cp -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
1013 elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
1014 $(ECHO) "===== WARNING: Distribution Source $$from_dir/$$file Not Found!" ; \
1015 elif test "$(VERB)" != '@' ; then \
1016 $(ECHO) "Skipping non-existent $$from_dir/$$file" ; \
1017 fi; \
1018 done
Reid Spencere45ebfa2004-10-26 07:09:33 +00001019 $(VERB) for subdir in $(DistSubDirs) ; do \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001020 if test "$$subdir" \!= "." ; then \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001021 new_distdir="$(DistDir)/$$subdir" ; \
Reid Spencere45ebfa2004-10-26 07:09:33 +00001022 test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
1023 ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || exit 1; \
Reid Spencer151f8ba2004-10-25 08:27:37 +00001024 fi; \
1025 done
Reid Spencere45ebfa2004-10-26 07:09:33 +00001026 $(VERB) $(MAKE) DistDir="$(DistDir)" dist-hook || exit 1
Reid Spencer151f8ba2004-10-25 08:27:37 +00001027 -$(VERB) find $(DistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
1028 ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
1029 ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
1030 ! -type d ! -perm -444 -exec $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
1031 || chmod -R a+r $(DistDir)
1032
1033dist-hook::
1034
1035
Reid Spencere53e3972004-10-22 23:06:30 +00001036endif
Reid Spencer4d71b662004-10-22 21:01:56 +00001037
1038###############################################################################
Reid Spencere5487ba2004-10-24 07:53:21 +00001039# TOP LEVEL - targets only to apply at the top level directory
1040###############################################################################
1041
1042ifeq ($(LEVEL),.)
1043
1044#------------------------------------------------------------------------
Reid Spencere5487ba2004-10-24 07:53:21 +00001045# Install support for project's include files:
1046#------------------------------------------------------------------------
1047install-local::
1048 @$(ECHO) Installing include files
1049 $(VERB) $(MKDIR) $(includedir)
1050 $(VERB) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1051 cd $(BUILD_SRC_ROOT)/include && \
1052 find . -path '*/Internal' -prune -o '(' -type f \
1053 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1054 -print ')' | grep -v CVS | pax -rwdvpe $(includedir) ; \
1055 fi
1056
1057uninstall-local::
1058 @$(ECHO) Uninstalling include files
1059 $(VERB) if [ -d "$(BUILD_SRC_ROOT)/include" ] ; then \
1060 cd $(BUILD_SRC_ROOT)/include && \
1061 $(RM) -f `find . -path '*/Internal' -prune -o '(' -type f \
1062 '!' '(' -name '*~' -o -name '.cvsignore' -o -name '.#*' ')' \
1063 -print ')' | grep -v CVS | sed 's#^#$(includedir)/#'` ; \
1064 fi
1065
1066#------------------------------------------------------------------------
1067# Build tags database for Emacs/Xemacs:
1068#------------------------------------------------------------------------
Reid Spencer151f8ba2004-10-25 08:27:37 +00001069tags:: TAGS
Reid Spencere5487ba2004-10-24 07:53:21 +00001070
Reid Spencer151f8ba2004-10-25 08:27:37 +00001071TAGS:
Reid Spencere5487ba2004-10-24 07:53:21 +00001072 find include lib tools examples -name '*.cpp' -o -name '*.h' | $(ETAGS) $(ETAGSFLAGS) -
1073
Reid Spencere5487ba2004-10-24 07:53:21 +00001074endif
1075
1076###############################################################################
Reid Spencer4d71b662004-10-22 21:01:56 +00001077# MISCELLANEOUS - utility targets
1078###############################################################################
1079
1080#------------------------------------------------------------------------
1081# Print out the directories used for building
Reid Spencer3a561f52004-10-23 20:04:14 +00001082printvars::
Reid Spencer9411c642004-10-26 22:26:33 +00001083 @$(ECHO) "CONFIGURATION : " $(CONFIGURATION)
Reid Spencer4d71b662004-10-22 21:01:56 +00001084 @$(ECHO) "BUILD_SRC_ROOT: " $(BUILD_SRC_ROOT)
1085 @$(ECHO) "BUILD_SRC_DIR : " $(BUILD_SRC_DIR)
1086 @$(ECHO) "BUILD_OBJ_ROOT: " $(BUILD_OBJ_ROOT)
1087 @$(ECHO) "BUILD_OBJ_DIR : " $(BUILD_OBJ_DIR)
1088 @$(ECHO) "LLVM_SRC_ROOT : " $(LLVM_SRC_ROOT)
1089 @$(ECHO) "LLVM_OBJ_ROOT : " $(LLVM_OBJ_ROOT)
Reid Spencer9411c642004-10-26 22:26:33 +00001090 @$(ECHO) "libdir : " $(libdir)
1091 @$(ECHO) "bindir : " $(bindir)
1092 @$(ECHO) "sysconfdir : " $(sysconfdir)
1093 @$(ECHO) "bytecode_libdir : " $(bytecode_libdir)
1094 @$(ECHO) "USER_TARGETS : " $(USER_TARGETS)
1095 @$(ECHO) "OBJMKFILES: $(OBJMKFILES)"
1096 @$(ECHO) "SRCMKFILES: $(SRCMKFILES)"
Reid Spencer4d71b662004-10-22 21:01:56 +00001097 @$(ECHO) "OBJDIR: " $(OBJDIR)
1098 @$(ECHO) "LIBDIR: " $(LIBDIR)
1099 @$(ECHO) "TOOLDIR: " $(TOOLDIR)
1100 @$(ECHO) "TDFILES:" '$(TDFILES)'
Reid Spencer3a561f52004-10-23 20:04:14 +00001101 @$(ECHO) "Compile.CXX: " '$(Compile.CXX)'
1102 @$(ECHO) "Compile.C: " '$(Compile.C)'
Reid Spencere5487ba2004-10-24 07:53:21 +00001103