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