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