Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1 | # Makefile.common |
| 2 | # |
| 3 | # This file is included by all of the LLVM makefiles. This file defines common |
| 4 | # rules to do things like compile a .cpp file or generate dependancy info. |
| 5 | # These are platform dependant, so this is the file used to specify these |
| 6 | # system dependant operations. |
| 7 | # |
| 8 | # The following functionality may be set by setting incoming variables: |
| 9 | # |
| 10 | # 1. LEVEL - The level of the current subdirectory from the top of the |
| 11 | # MagicStats view. This level should be expressed as a path, for |
| 12 | # example, ../.. for two levels deep. |
| 13 | # |
| 14 | # 2. DIRS - A list of subdirectories to be built. Fake targets are set up |
| 15 | # so that each of the targets "all", "install", and "clean" each build. |
| 16 | # the subdirectories before the local target. |
| 17 | # |
| 18 | # 3. Source - If specified, this sets the source code filenames. If this |
| 19 | # is not set, it defaults to be all of the .cpp, .c, .y, and .l files |
Chris Lattner | e001059 | 2001-10-18 01:48:09 +0000 | [diff] [blame] | 20 | # in the current directory. Also, if you want to build files in addition |
| 21 | # to the local files, you can use the ExtraSource variable |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 22 | # |
| 23 | |
Chris Lattner | b19e59c | 2001-06-29 05:20:16 +0000 | [diff] [blame] | 24 | # Default Rule: Make sure it's also a :: rule |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 25 | all :: |
| 26 | |
| 27 | # Default for install is to at least build everything... |
| 28 | install :: |
| 29 | |
| 30 | #-------------------------------------------------------------------- |
| 31 | # Installation configuration options... |
| 32 | #-------------------------------------------------------------------- |
| 33 | |
| 34 | #BinInstDir=/usr/local/bin |
| 35 | #LibInstDir=/usrl/local/lib/xxx |
| 36 | #DocInstDir=/usr/doc/xxx |
| 37 | |
Vikram S. Adve | dba59ef | 2001-08-06 19:01:20 +0000 | [diff] [blame] | 38 | BURG = /home/vadve/vadve/Research/DynOpt/Burg/burg |
| 39 | BURG_OPTS = -I |
| 40 | |
Chris Lattner | 6e39070 | 2001-10-30 20:24:08 +0000 | [diff] [blame] | 41 | |
Chris Lattner | ec6bed2 | 2002-04-07 06:18:40 +0000 | [diff] [blame^] | 42 | PURIFY = /usr/dcs/applications/purify/bin/purify -cache-dir="$(HOME)/purifycache" -chain-length="30" -messages=all |
Chris Lattner | 6e39070 | 2001-10-30 20:24:08 +0000 | [diff] [blame] | 43 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 44 | #--------------------------------------------------------- |
| 45 | # Compilation options... |
| 46 | #--------------------------------------------------------- |
| 47 | |
Vikram S. Adve | dba59ef | 2001-08-06 19:01:20 +0000 | [diff] [blame] | 48 | # Special tools used while building |
| 49 | RunBurg = $(BURG) $(BURG_OPTS) |
| 50 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 51 | # Enable this for profiling support with 'gprof' |
| 52 | #Prof = -pg |
| 53 | |
| 54 | # TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti |
Chris Lattner | c7acf81 | 2002-01-23 05:46:01 +0000 | [diff] [blame] | 55 | # -Wno-unused-parameter |
| 56 | CompileCommonOpts = $(Prof) -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 57 | |
| 58 | # Compile a file, don't link... |
| 59 | Compile = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts) |
| 60 | CompileG = $(Compile) -g -D_DEBUG |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 61 | CompileO = $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums |
| 62 | |
| 63 | # Link final executable |
Chris Lattner | 6e39070 | 2001-10-30 20:24:08 +0000 | [diff] [blame] | 64 | |
| 65 | # To enable purify, do it here: |
Chris Lattner | 12604ed | 2002-04-05 18:56:58 +0000 | [diff] [blame] | 66 | ifdef ENABLE_PURIFY |
| 67 | Link = $(PURIFY) $(CXX) $(Prof) -static |
| 68 | else |
| 69 | Link = LD_RUN_PATH=/usr/dcs/software/evaluation/encap/gcc-3.0.4/lib $(CXX) $(Prof) |
| 70 | endif |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 71 | LinkG = $(Link) -g -L $(LEVEL)/lib/Debug |
| 72 | LinkO = $(Link) -O3 -L $(LEVEL)/lib/Release |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 73 | |
| 74 | # Create a .so file from a .cpp file... |
| 75 | #MakeSO = $(CXX) -shared $(Prof) |
| 76 | MakeSO = $(CXX) -G $(Prof) |
| 77 | MakeSOG = $(MakeSO) -g |
| 78 | MakeSOO = $(MakeSO) -O3 |
| 79 | |
| 80 | # Create dependancy file from CPP file, send to stdout. |
| 81 | Depend = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS) |
| 82 | |
| 83 | # Archive a bunch of .o files into a .a file... |
| 84 | AR = ar cq |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 85 | MakeLib = $(AR) |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 86 | |
| 87 | #---------------------------------------------------------- |
| 88 | |
| 89 | # Source includes all of the cpp files, and objects are derived from the |
| 90 | # source files... |
Chris Lattner | e001059 | 2001-10-18 01:48:09 +0000 | [diff] [blame] | 91 | # The local Makefile can list other Source files via ExtraSource = ... |
Vikram S. Adve | c4bed34 | 2001-10-17 12:33:55 +0000 | [diff] [blame] | 92 | # |
Chris Lattner | e001059 | 2001-10-18 01:48:09 +0000 | [diff] [blame] | 93 | Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l) |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 94 | |
Chris Lattner | c7acf81 | 2002-01-23 05:46:01 +0000 | [diff] [blame] | 95 | Objs := $(sort $(addsuffix .o,$(basename $(Source)))) |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 96 | ObjectsO = $(addprefix Release/,$(Objs)) |
| 97 | ObjectsG = $(addprefix Debug/,$(Objs)) |
| 98 | |
| 99 | #--------------------------------------------------------- |
| 100 | # Handle the DIRS option |
| 101 | #--------------------------------------------------------- |
| 102 | |
| 103 | ifdef DIRS # Only do this if we're using DIRS! |
| 104 | |
| 105 | all :: $(addsuffix /.makeall , $(DIRS)) |
| 106 | install :: $(addsuffix /.makeinstall, $(DIRS)) |
| 107 | clean :: $(addsuffix /.makeclean , $(DIRS)) |
| 108 | |
| 109 | %/.makeall %/.makeclean %/.makeinstall: |
| 110 | cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@) |
| 111 | endif |
| 112 | |
| 113 | #--------------------------------------------------------- |
| 114 | # Handle the LIBRARYNAME option - used when building libs... |
| 115 | #--------------------------------------------------------- |
| 116 | |
| 117 | ifdef LIBRARYNAME |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 118 | |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 119 | LIBNAME_O := $(LEVEL)/lib/Release/lib$(LIBRARYNAME).so |
| 120 | LIBNAME_G := $(LEVEL)/lib/Debug/lib$(LIBRARYNAME).so |
| 121 | LIBNAME_AO := $(LEVEL)/lib/Release/lib$(LIBRARYNAME).a |
| 122 | LIBNAME_AG := $(LEVEL)/lib/Debug/lib$(LIBRARYNAME).a |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 123 | |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 124 | all:: $(LIBNAME_AG) |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 125 | dynamic:: $(LIBNAME_G) |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 126 | # TODO: Enable optimized builds |
| 127 | |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 128 | $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(LEVEL)/lib/Release/.dir Depend/.dir |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 129 | @echo ======= Linking $(LIBRARYNAME) release library ======= |
| 130 | $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts) |
| 131 | |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 132 | $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(LEVEL)/lib/Debug/.dir Depend/.dir |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 133 | @echo ======= Linking $(LIBRARYNAME) debug library ======= |
| 134 | $(MakeSOG) -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts) |
| 135 | |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 136 | $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(LEVEL)/lib/Release/.dir Depend/.dir |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 137 | @echo ======= Linking $(LIBRARYNAME) release library ======= |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 138 | @rm -f $@ |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 139 | $(MakeLib) $@ $(ObjectsO) $(LibSubDirs) |
| 140 | |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 141 | $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(LEVEL)/lib/Debug/.dir Depend/.dir |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 142 | @echo ======= Linking $(LIBRARYNAME) debug library ======= |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 143 | @rm -f $@ |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 144 | $(MakeLib) $@ $(ObjectsG) $(LibSubDirs) |
| 145 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 146 | endif |
| 147 | |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 148 | #------------------------------------------------------------------------ |
Vikram S. Adve | 0193d5e | 2001-10-10 22:35:00 +0000 | [diff] [blame] | 149 | # Create a TAGS database for emacs |
| 150 | #------------------------------------------------------------------------ |
| 151 | |
Vikram S. Adve | 022d06c | 2001-10-13 12:26:59 +0000 | [diff] [blame] | 152 | ifeq ($(LEVEL), .) |
Vikram S. Adve | 0193d5e | 2001-10-10 22:35:00 +0000 | [diff] [blame] | 153 | |
Vikram S. Adve | 022d06c | 2001-10-13 12:26:59 +0000 | [diff] [blame] | 154 | tags: |
Vikram S. Adve | 27dc7b6 | 2001-10-22 13:58:22 +0000 | [diff] [blame] | 155 | etags -l c++ `find . -name '*.cpp' -o -name '*.h'` |
Vikram S. Adve | 022d06c | 2001-10-13 12:26:59 +0000 | [diff] [blame] | 156 | |
| 157 | all:: tags |
| 158 | |
| 159 | endif |
Vikram S. Adve | 0193d5e | 2001-10-10 22:35:00 +0000 | [diff] [blame] | 160 | |
| 161 | #------------------------------------------------------------------------ |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 162 | # Handle the TOOLNAME option - used when building tool executables... |
| 163 | #------------------------------------------------------------------------ |
| 164 | # |
| 165 | # The TOOLNAME option should be used with a USEDLIBS variable that tells the |
| 166 | # libraries (and the order of the libs) that should be linked to the tool. |
| 167 | # |
| 168 | ifdef TOOLNAME |
| 169 | |
| 170 | # TOOLEXENAME* - These compute the output filenames to generate... |
| 171 | TOOLEXENAME_G = $(LEVEL)/tools/Debug/$(TOOLNAME) |
| 172 | TOOLEXENAME_O = $(LEVEL)/tools/Release/$(TOOLNAME) |
Chris Lattner | c7acf81 | 2002-01-23 05:46:01 +0000 | [diff] [blame] | 173 | TOOLEXENAMES := $(TOOLEXENAME_G) ###$(TOOLEXENAME_O) |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 174 | |
| 175 | # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc. |
| 176 | USED_LIBS_OPTIONS = $(addprefix -l, $(USEDLIBS)) |
| 177 | |
| 178 | # USED_LIB_PATHS - Compute the path of the libraries used so that tools are |
| 179 | # rebuilt if libraries change |
| 180 | # |
Chris Lattner | c7acf81 | 2002-01-23 05:46:01 +0000 | [diff] [blame] | 181 | STATICUSEDLIBS := $(addsuffix .a, $(USEDLIBS)) |
| 182 | USED_LIB_PATHS_G := $(addprefix $(LEVEL)/lib/Debug/lib, $(STATICUSEDLIBS)) |
| 183 | USED_LIB_PATHS_O := $(addprefix $(LEVEL)/lib/Release/lib, $(STATICUSEDLIBS)) |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 184 | |
Chris Lattner | 669bd7c | 2001-10-13 05:10:29 +0000 | [diff] [blame] | 185 | all:: $(TOOLEXENAMES) |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 186 | clean:: |
| 187 | rm -f $(TOOLEXENAMES) |
| 188 | |
Chris Lattner | bf2f043 | 2001-09-09 20:59:28 +0000 | [diff] [blame] | 189 | $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(LEVEL)/tools/Debug/.dir |
Chris Lattner | 49f2b94 | 2001-09-10 04:49:26 +0000 | [diff] [blame] | 190 | $(LinkG) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS) $(TOOLLINKOPTS) |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 191 | |
Chris Lattner | bf2f043 | 2001-09-09 20:59:28 +0000 | [diff] [blame] | 192 | $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(LEVEL)/tools/Release/.dir |
Chris Lattner | 49f2b94 | 2001-09-10 04:49:26 +0000 | [diff] [blame] | 193 | $(LinkO) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS) $(TOOLLINKOPTS) |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 194 | |
| 195 | endif |
| 196 | |
| 197 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 198 | |
| 199 | #--------------------------------------------------------- |
Chris Lattner | aa6ec73 | 2001-11-07 14:50:58 +0000 | [diff] [blame] | 200 | .PRECIOUS: Depend/.dir Debug/.dir Release/.dir |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 201 | |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 202 | # Create dependencies for the *.cpp files... |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 203 | Depend/%.d: %.cpp Depend/.dir |
| 204 | $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@ |
| 205 | |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 206 | # Create dependencies for the *.c files... |
| 207 | Depend/%.d: %.c Depend/.dir |
| 208 | $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@ |
| 209 | |
| 210 | # Create .o files in the ObjectFiles directory from the .cpp and .c files... |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 211 | Release/%.o: %.cpp Release/.dir Depend/.dir |
| 212 | $(CompileO) $< -o $@ |
| 213 | |
Chris Lattner | c7acf81 | 2002-01-23 05:46:01 +0000 | [diff] [blame] | 214 | #Release/%.o: %.c Release/.dir Depend/.dir |
| 215 | # $(CompileOC) $< -o $@ |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 216 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 217 | Debug/%.o: %.cpp Debug/.dir Depend/.dir |
| 218 | $(CompileG) $< -o $@ |
| 219 | |
Chris Lattner | c7acf81 | 2002-01-23 05:46:01 +0000 | [diff] [blame] | 220 | #Debug/%.o: %.c Debug/.dir Depend/.dir |
| 221 | # $(CompileGC) $< -o $@ |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 222 | |
Vikram S. Adve | bedbcf6 | 2001-08-06 19:06:43 +0000 | [diff] [blame] | 223 | # Create a .cpp source file from a burg input file |
Chris Lattner | 0cac4b8 | 2002-02-11 17:12:03 +0000 | [diff] [blame] | 224 | %.burm.cpp: Debug/%.burg Debug/.dir |
Vikram S. Adve | bedbcf6 | 2001-08-06 19:06:43 +0000 | [diff] [blame] | 225 | $(RunBurg) $< -o $@ |
| 226 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 227 | # Create a .cpp source file from a flex input file... this uses sed to cut down |
| 228 | # on the warnings emited by GCC... |
| 229 | %.cpp: %.l |
| 230 | flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@ |
| 231 | |
| 232 | # Rule for building the bison parsers... |
| 233 | |
| 234 | %.cpp %.h : %.y |
| 235 | bison -d -p $(<:%Parser.y=%) $(basename $@).y |
| 236 | mv -f $(basename $@).tab.c $(basename $@).cpp |
| 237 | mv -f $(basename $@).tab.h $(basename $@).h |
| 238 | |
| 239 | # To create the directories... |
| 240 | %/.dir: |
| 241 | mkdir -p $(@D) |
| 242 | @date > $@ |
| 243 | |
| 244 | # Clean does not remove the output files... just the temporaries |
| 245 | clean:: |
| 246 | rm -rf Debug Release Depend |
| 247 | rm -f core *.o *.d *.so *~ *.flc |
| 248 | |
| 249 | # If dependancies were generated for the file that included this file, |
| 250 | # include the dependancies now... |
| 251 | # |
| 252 | SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(Source)))) |
| 253 | ifneq ($(SourceDepend),) |
| 254 | include $(SourceDepend) |
| 255 | endif |