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 | |
| 37 | #--------------------------------------------------------- |
| 38 | # Compilation options... |
| 39 | #--------------------------------------------------------- |
| 40 | |
| 41 | # Add -L options to the link command lines... |
| 42 | LibPathsO = -L $(LEVEL)/lib/VMCore/Release \ |
| 43 | -L $(LEVEL)/lib/Assembly/Parser/Release \ |
| 44 | -L $(LEVEL)/lib/Assembly/Writer/Release \ |
| 45 | -L $(LEVEL)/lib/Analysis/Release \ |
| 46 | -L $(LEVEL)/lib/Bytecode/Writer/Release \ |
| 47 | -L $(LEVEL)/lib/Bytecode/Reader/Release \ |
| 48 | -L $(LEVEL)/lib/Optimizations/Release |
| 49 | |
| 50 | LibPathsG = $(LibPathsO:Release=Debug) |
| 51 | |
| 52 | # Enable this for profiling support with 'gprof' |
| 53 | #Prof = -pg |
| 54 | |
| 55 | # TODO: Get rid of exceptions! : -fno-exceptions -fno-rtti |
| 56 | CompileCommonOpts = $(Prof) -Wall -Winline -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include |
| 57 | |
| 58 | # Compile a file, don't link... |
| 59 | Compile = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts) |
| 60 | CompileG = $(Compile) -g -D_DEBUG |
| 61 | # Add This for DebugMalloc: -fno-defer-pop |
| 62 | CompileO = $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums |
| 63 | |
| 64 | # Link final executable |
| 65 | Link = $(CXX) $(Prof) |
| 66 | LinkG = $(Link) -g $(LibPathsG) |
| 67 | LinkO = $(Link) -O3 $(LibPathsO) |
| 68 | |
| 69 | # Create a .so file from a .cpp file... |
| 70 | #MakeSO = $(CXX) -shared $(Prof) |
| 71 | MakeSO = $(CXX) -G $(Prof) |
| 72 | MakeSOG = $(MakeSO) -g |
| 73 | MakeSOO = $(MakeSO) -O3 |
| 74 | |
| 75 | # Create dependancy file from CPP file, send to stdout. |
| 76 | Depend = $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS) |
| 77 | |
| 78 | # Archive a bunch of .o files into a .a file... |
| 79 | AR = ar cq |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 80 | MakeLib = $(AR) |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 81 | |
| 82 | #---------------------------------------------------------- |
| 83 | |
| 84 | # Source includes all of the cpp files, and objects are derived from the |
| 85 | # source files... |
| 86 | ifndef Source |
| 87 | Source = $(wildcard *.cpp *.c *.y *.l) |
| 88 | endif |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 89 | |
| 90 | Objs = $(addsuffix .o,$(basename $(Source))) |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 91 | ObjectsO = $(addprefix Release/,$(Objs)) |
| 92 | ObjectsG = $(addprefix Debug/,$(Objs)) |
| 93 | |
| 94 | #--------------------------------------------------------- |
| 95 | # Handle the DIRS option |
| 96 | #--------------------------------------------------------- |
| 97 | |
| 98 | ifdef DIRS # Only do this if we're using DIRS! |
| 99 | |
| 100 | all :: $(addsuffix /.makeall , $(DIRS)) |
| 101 | install :: $(addsuffix /.makeinstall, $(DIRS)) |
| 102 | clean :: $(addsuffix /.makeclean , $(DIRS)) |
| 103 | |
| 104 | %/.makeall %/.makeclean %/.makeinstall: |
| 105 | cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@) |
| 106 | endif |
| 107 | |
| 108 | #--------------------------------------------------------- |
| 109 | # Handle the LIBRARYNAME option - used when building libs... |
| 110 | #--------------------------------------------------------- |
| 111 | |
| 112 | ifdef LIBRARYNAME |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 113 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 114 | LIBNAME_O := Release/lib$(LIBRARYNAME).so |
| 115 | LIBNAME_G := Debug/lib$(LIBRARYNAME).so |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 116 | LIBNAME_AO := Release/lib$(LIBRARYNAME).a |
| 117 | LIBNAME_AG := Debug/lib$(LIBRARYNAME).a |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 118 | |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 119 | all:: $(LIBNAME_AG) |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 120 | # TODO: Enable optimized builds |
| 121 | |
Chris Lattner | b19e59c | 2001-06-29 05:20:16 +0000 | [diff] [blame] | 122 | $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) Release/.dir Depend/.dir |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 123 | @echo ======= Linking $(LIBRARYNAME) release library ======= |
| 124 | $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts) |
| 125 | |
Chris Lattner | b19e59c | 2001-06-29 05:20:16 +0000 | [diff] [blame] | 126 | $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) Debug/.dir Depend/.dir |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 127 | @echo ======= Linking $(LIBRARYNAME) debug library ======= |
| 128 | $(MakeSOG) -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts) |
| 129 | |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 130 | $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) Release/.dir Depend/.dir |
| 131 | @echo ======= Linking $(LIBRARYNAME) release library ======= |
| 132 | rm -f $@ |
| 133 | $(MakeLib) $@ $(ObjectsO) $(LibSubDirs) |
| 134 | |
| 135 | $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) Debug/.dir Depend/.dir |
| 136 | @echo ======= Linking $(LIBRARYNAME) debug library ======= |
| 137 | rm -f $@ |
| 138 | $(MakeLib) $@ $(ObjectsG) $(LibSubDirs) |
| 139 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 140 | endif |
| 141 | |
| 142 | |
| 143 | #--------------------------------------------------------- |
| 144 | |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 145 | # Create dependencies for the *.cpp files... |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 146 | Depend/%.d: %.cpp Depend/.dir |
| 147 | $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@ |
| 148 | |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 149 | # Create dependencies for the *.c files... |
| 150 | Depend/%.d: %.c Depend/.dir |
| 151 | $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@ |
| 152 | |
| 153 | # 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] | 154 | Release/%.o: %.cpp Release/.dir Depend/.dir |
| 155 | $(CompileO) $< -o $@ |
| 156 | |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 157 | Release/%.o: %.c Release/.dir Depend/.dir |
| 158 | $(CompileO) $< -o $@ |
| 159 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 160 | Debug/%.o: %.cpp Debug/.dir Depend/.dir |
| 161 | $(CompileG) $< -o $@ |
| 162 | |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 163 | Debug/%.o: %.c Debug/.dir Depend/.dir |
| 164 | $(CompileG) $< -o $@ |
| 165 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 166 | # Create a .cpp source file from a flex input file... this uses sed to cut down |
| 167 | # on the warnings emited by GCC... |
| 168 | %.cpp: %.l |
| 169 | flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@ |
| 170 | |
| 171 | # Rule for building the bison parsers... |
| 172 | |
| 173 | %.cpp %.h : %.y |
| 174 | bison -d -p $(<:%Parser.y=%) $(basename $@).y |
| 175 | mv -f $(basename $@).tab.c $(basename $@).cpp |
| 176 | mv -f $(basename $@).tab.h $(basename $@).h |
| 177 | |
| 178 | # To create the directories... |
| 179 | %/.dir: |
| 180 | mkdir -p $(@D) |
| 181 | @date > $@ |
| 182 | |
| 183 | # Clean does not remove the output files... just the temporaries |
| 184 | clean:: |
| 185 | rm -rf Debug Release Depend |
| 186 | rm -f core *.o *.d *.so *~ *.flc |
| 187 | |
| 188 | # If dependancies were generated for the file that included this file, |
| 189 | # include the dependancies now... |
| 190 | # |
| 191 | SourceDepend = $(addsuffix .d,$(addprefix Depend/,$(basename $(Source)))) |
| 192 | ifneq ($(SourceDepend),) |
| 193 | include $(SourceDepend) |
| 194 | endif |