Vikram S. Adve | 24132e8 | 2002-07-09 12:04:21 +0000 | [diff] [blame] | 1 | #===-- Makefile.common - Common make rules for LLVM -------*- makefile -*--==== |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 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 | ee6e199 | 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 | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 22 | # |
Vikram S. Adve | 24132e8 | 2002-07-09 12:04:21 +0000 | [diff] [blame] | 23 | #===-----------------------------------------------------------------------==== |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 24 | |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 25 | # These are options that can either be enabled here, or can be enabled on the |
Chris Lattner | ead864f | 2002-08-03 20:19:30 +0000 | [diff] [blame] | 26 | # make command line (ie, make ENABLE_PROFILING=1) |
| 27 | # |
| 28 | |
| 29 | # When ENABLE_PROFILING is enabled, the llvm source base is built with profile |
| 30 | # information to allow gprof to be used to get execution frequencies. |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 31 | # |
| 32 | #ENABLE_PROFILING = 1 |
Chris Lattner | ead864f | 2002-08-03 20:19:30 +0000 | [diff] [blame] | 33 | |
| 34 | # When ENABLE_PURIFY is enabled, the LLVM tools are linked with purify (which |
| 35 | # must be locally installed) to allow for some automated memory error debugging. |
| 36 | # |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 37 | #ENABLE_PURIFY = 1 |
Chris Lattner | ead864f | 2002-08-03 20:19:30 +0000 | [diff] [blame] | 38 | |
| 39 | # When ENABLE_OPTIMIZED is enabled, Release builds of all of the LLVM code are |
| 40 | # turned on, and Debug builds are turned off. |
| 41 | # |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 42 | #ENABLE_OPTIMIZED = 1 |
| 43 | |
Vikram S. Adve | 0bfb4cc | 2002-08-29 18:40:51 +0000 | [diff] [blame] | 44 | # Current working directory, used below |
| 45 | CUR_DIRECTORY := $(shell pwd) |
| 46 | |
| 47 | # Path to directory where object files should be stored during a build. |
| 48 | # Set this to "." if you do not want to use a separate place for object files. |
| 49 | # |
| 50 | BUILD_DIR = /shared/$(LOGIN_NAME)$(patsubst $(HOME)%,%,$(CUR_DIRECTORY)) |
| 51 | |
| 52 | # Flag whether or not to use a separate location for build files |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 53 | # |
Vikram S. Adve | 0bfb4cc | 2002-08-29 18:40:51 +0000 | [diff] [blame] | 54 | ifeq ($(BUILD_DIR),".") |
| 55 | BUILD_ROOT = $(BUILD_DIR) |
| 56 | endif |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 57 | |
Chris Lattner | 570c6a6 | 2002-07-23 19:21:31 +0000 | [diff] [blame] | 58 | ifdef SHARED_LIBRARY |
| 59 | # if SHARED_LIBRARY is specified, the default is to build the dynamic lib |
| 60 | dynamic :: |
| 61 | endif |
| 62 | |
Chris Lattner | 44601ba | 2001-06-29 05:20:16 +0000 | [diff] [blame] | 63 | # Default Rule: Make sure it's also a :: rule |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 64 | all :: |
| 65 | |
| 66 | # Default for install is to at least build everything... |
| 67 | install :: |
| 68 | |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 69 | |
| 70 | # Figure out which directory to build stuff into. We want to build into the |
| 71 | # /shared directory by default because it is guaranteed to be local to the |
| 72 | # current machine. |
| 73 | # |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 74 | ifdef BUILD_ROOT |
| 75 | BUILD_ROOT_TOP := $(LEVEL) |
| 76 | else |
| 77 | |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 78 | LOGIN_NAME := $(shell whoami) |
Vikram S. Adve | 0bfb4cc | 2002-08-29 18:40:51 +0000 | [diff] [blame] | 79 | BUILD_ROOT := $(BUILD_DIR) |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 80 | |
| 81 | # Calculate the BUILD_ROOT_TOP variable, which is the top of the llvm/ tree. |
| 82 | # Note that although this is just equal to $(BUILD_ROOT)/$(LEVEL), we cannot use |
| 83 | # this expression because some of the directories on the source tree may not |
| 84 | # exist in the build tree (for example the test/ heirarchy). Thus we evaluate |
| 85 | # the directory to eliminate the ../'s |
| 86 | # |
| 87 | TOP_DIRECTORY := $(shell cd $(LEVEL); pwd) |
| 88 | BUILD_ROOT_TOP := /shared/$(LOGIN_NAME)$(patsubst $(HOME)%,%,$(TOP_DIRECTORY)) |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 89 | endif |
| 90 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 91 | #-------------------------------------------------------------------- |
| 92 | # Installation configuration options... |
| 93 | #-------------------------------------------------------------------- |
| 94 | |
| 95 | #BinInstDir=/usr/local/bin |
| 96 | #LibInstDir=/usrl/local/lib/xxx |
| 97 | #DocInstDir=/usr/doc/xxx |
| 98 | |
Vikram S. Adve | ca4a382 | 2001-08-06 19:01:20 +0000 | [diff] [blame] | 99 | BURG = /home/vadve/vadve/Research/DynOpt/Burg/burg |
| 100 | BURG_OPTS = -I |
| 101 | |
Chris Lattner | b20b290c | 2001-10-30 20:24:08 +0000 | [diff] [blame] | 102 | |
Chris Lattner | 56b56d9 | 2002-08-17 21:39:58 +0000 | [diff] [blame] | 103 | PURIFY = /usr/dcs/applications/purify/bin/purify -cache-dir="$(BUILD_ROOT_TOP)/../purifycache" -chain-length="30" -messages=all |
Chris Lattner | b20b290c | 2001-10-30 20:24:08 +0000 | [diff] [blame] | 104 | |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 105 | # Shorthand for commonly accessed directories |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 106 | LIBDEBUG := $(BUILD_ROOT_TOP)/lib/Debug |
| 107 | LIBRELEASE := $(BUILD_ROOT_TOP)/lib/Release |
| 108 | TOOLDEBUG := $(BUILD_ROOT_TOP)/tools/Debug |
| 109 | TOOLRELEASE := $(BUILD_ROOT_TOP)/tools/Release |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 110 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 111 | #--------------------------------------------------------- |
| 112 | # Compilation options... |
| 113 | #--------------------------------------------------------- |
| 114 | |
Vikram S. Adve | ca4a382 | 2001-08-06 19:01:20 +0000 | [diff] [blame] | 115 | # Special tools used while building |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 116 | RunBurg := $(BURG) $(BURG_OPTS) |
Vikram S. Adve | ca4a382 | 2001-08-06 19:01:20 +0000 | [diff] [blame] | 117 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 118 | # Enable this for profiling support with 'gprof' |
Chris Lattner | 198d5eb | 2002-05-10 18:51:54 +0000 | [diff] [blame] | 119 | ifdef ENABLE_PROFILING |
| 120 | PROFILE = -pg |
| 121 | else |
| 122 | PROFILE = |
| 123 | endif |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 124 | |
Chris Lattner | 068f822 | 2002-01-23 05:46:01 +0000 | [diff] [blame] | 125 | # -Wno-unused-parameter |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 126 | CompileCommonOpts := $(PROFILE) -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 127 | |
| 128 | # Compile a file, don't link... |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 129 | Compile := $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts) |
| 130 | CompileG := $(Compile) -g -D_DEBUG |
| 131 | CompileO := $(Compile) -O3 -DNDEBUG -finline-functions -felide-constructors -fnonnull-objects -freg-struct-return -fshort-enums |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 132 | |
| 133 | # Link final executable |
Chris Lattner | b20b290c | 2001-10-30 20:24:08 +0000 | [diff] [blame] | 134 | |
Chris Lattner | d711a5e | 2002-07-31 21:32:05 +0000 | [diff] [blame] | 135 | ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1' |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 136 | Link := $(PURIFY) $(CXX) $(PROFILE) -static |
Chris Lattner | f0a88d1 | 2002-04-05 18:56:58 +0000 | [diff] [blame] | 137 | else |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 138 | Link := $(CXX) $(PROFILE) |
Chris Lattner | f0a88d1 | 2002-04-05 18:56:58 +0000 | [diff] [blame] | 139 | endif |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 140 | LinkG := $(Link) -g -L $(LIBDEBUG) |
| 141 | LinkO := $(Link) -O3 -L $(LIBRELEASE) |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 142 | |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 143 | # Create a .so file from a .o files... |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 144 | #MakeSO := $(CXX) -shared $(PROFILE) |
| 145 | MakeSO := $(CXX) -G $(PROFILE) |
| 146 | MakeSOO := $(MakeSO) -O3 |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 147 | |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 148 | # Create one .o file from a bunch of .o files... |
| 149 | Relink = ld -r |
| 150 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 151 | # Create dependancy file from CPP file, send to stdout. |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 152 | Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS) |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 153 | |
| 154 | # Archive a bunch of .o files into a .a file... |
| 155 | AR = ar cq |
| 156 | |
| 157 | #---------------------------------------------------------- |
| 158 | |
| 159 | # Source includes all of the cpp files, and objects are derived from the |
| 160 | # source files... |
Chris Lattner | ee6e199 | 2001-10-18 01:48:09 +0000 | [diff] [blame] | 161 | # The local Makefile can list other Source files via ExtraSource = ... |
Vikram S. Adve | bd9cae2 | 2001-10-17 12:33:55 +0000 | [diff] [blame] | 162 | # |
Chris Lattner | ee6e199 | 2001-10-18 01:48:09 +0000 | [diff] [blame] | 163 | Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l) |
Vikram S. Adve | fe34689 | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 164 | |
Chris Lattner | d1a7229 | 2002-07-25 15:01:19 +0000 | [diff] [blame] | 165 | Objs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(basename $(Source))))) |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 166 | ObjectsO = $(addprefix $(BUILD_ROOT)/Release/,$(Objs))) |
| 167 | ObjectsG = $(addprefix $(BUILD_ROOT)/Debug/,$(Objs)) |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 168 | |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 169 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 170 | #--------------------------------------------------------- |
| 171 | # Handle the DIRS option |
| 172 | #--------------------------------------------------------- |
| 173 | |
| 174 | ifdef DIRS # Only do this if we're using DIRS! |
| 175 | |
| 176 | all :: $(addsuffix /.makeall , $(DIRS)) |
| 177 | install :: $(addsuffix /.makeinstall, $(DIRS)) |
| 178 | clean :: $(addsuffix /.makeclean , $(DIRS)) |
| 179 | |
| 180 | %/.makeall %/.makeclean %/.makeinstall: |
| 181 | cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@) |
| 182 | endif |
| 183 | |
| 184 | #--------------------------------------------------------- |
| 185 | # Handle the LIBRARYNAME option - used when building libs... |
| 186 | #--------------------------------------------------------- |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 187 | # |
| 188 | # When libraries are built, they are allowed to optionally define the |
| 189 | # DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file |
| 190 | # from being built for the library. This .o files may then be linked to by a |
| 191 | # tool if the tool does not need (or want) the semantics a .a file provides |
| 192 | # (linking in only object files that are "needed"). If a library is never to |
| 193 | # be used in this way, it is better to define DONT_BUILD_RELINKED, and define |
| 194 | # BUILD_ARCHIVE instead. |
| 195 | # |
| 196 | # Some libraries must be built as .a files (libscalar for example) because if |
Chris Lattner | d711a5e | 2002-07-31 21:32:05 +0000 | [diff] [blame] | 197 | # it's built as a .o file, then all of the constituent .o files in it will be |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 198 | # linked into tools (for example gccas) even if they only use one of the parts |
| 199 | # of it. For this reason, sometimes it's useful to use libraries as .a files. |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 200 | |
| 201 | ifdef LIBRARYNAME |
Vikram S. Adve | fe34689 | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 202 | |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 203 | LIBNAME_O := $(LIBRELEASE)/lib$(LIBRARYNAME).so |
| 204 | LIBNAME_G := $(LIBDEBUG)/lib$(LIBRARYNAME).so |
| 205 | LIBNAME_AO := $(LIBRELEASE)/lib$(LIBRARYNAME).a |
| 206 | LIBNAME_AG := $(LIBDEBUG)/lib$(LIBRARYNAME).a |
| 207 | LIBNAME_OBJO := $(LIBRELEASE)/$(LIBRARYNAME).o |
| 208 | LIBNAME_OBJG := $(LIBDEBUG)/$(LIBRARYNAME).o |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 209 | |
Vikram S. Adve | 15bd3ad | 2002-08-02 18:34:12 +0000 | [diff] [blame] | 210 | |
| 211 | ifndef ENABLE_OPTIMIZED |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 212 | BUILD_LIBNAME_G := $(LIBNAME_G) |
| 213 | ifndef DONT_BUILD_RELINKED |
| 214 | BUILD_LIBNAME_OBJG := $(LIBNAME_OBJG) |
| 215 | endif |
| 216 | ifdef BUILD_ARCHIVE |
| 217 | BUILD_LIBNAME_AG := $(LIBNAME_AG) |
| 218 | endif |
Vikram S. Adve | 15bd3ad | 2002-08-02 18:34:12 +0000 | [diff] [blame] | 219 | endif |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 220 | |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 221 | # If optimized builds are enabled... |
| 222 | ifdef ENABLE_OPTIMIZED |
| 223 | BUILD_LIBNAME_O := $(LIBNAME_O) |
| 224 | ifndef DONT_BUILD_RELINKED |
| 225 | BUILD_LIBNAME_OBJO := $(LIBNAME_OBJO) |
| 226 | endif |
| 227 | ifdef BUILD_ARCHIVE |
| 228 | BUILD_LIBNAME_AO := $(LIBNAME_AO) |
| 229 | endif |
| 230 | endif |
| 231 | |
| 232 | all:: $(BUILD_LIBNAME_AG) $(BUILD_LIBNAME_OBJG) # Debug |
| 233 | all:: $(BUILD_LIBNAME_AO) $(BUILD_LIBNAME_OBJO) # Release |
| 234 | dynamic:: $(BUILD_LIBNAME_G) $(BUILD_LIBNAME_O) # .so files |
| 235 | |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 236 | $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 237 | @echo ======= Linking $(LIBRARYNAME) release library ======= |
| 238 | $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts) |
| 239 | |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 240 | $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 241 | @echo ======= Linking $(LIBRARYNAME) debug library ======= |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 242 | $(MakeSO) -g -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts) |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 243 | |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 244 | $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir |
Vikram S. Adve | fe34689 | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 245 | @echo ======= Linking $(LIBRARYNAME) release library ======= |
Chris Lattner | 07c7c19 | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 246 | @rm -f $@ |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 247 | $(AR) $@ $(ObjectsO) $(LibSubDirs) |
Vikram S. Adve | fe34689 | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 248 | |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 249 | $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir |
Vikram S. Adve | fe34689 | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 250 | @echo ======= Linking $(LIBRARYNAME) debug library ======= |
Chris Lattner | 07c7c19 | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 251 | @rm -f $@ |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 252 | $(AR) $@ $(ObjectsG) $(LibSubDirs) |
Vikram S. Adve | fe34689 | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 253 | |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 254 | $(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(LIBRELEASE)/.dir |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 255 | $(Relink) -o $@ $(ObjectsO) $(LibSubDirs) |
| 256 | |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 257 | $(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(LIBDEBUG)/.dir |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 258 | $(Relink) -o $@ $(ObjectsG) $(LibSubDirs) |
| 259 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 260 | endif |
| 261 | |
Chris Lattner | 07c7c19 | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 262 | #------------------------------------------------------------------------ |
Vikram S. Adve | fa9dc58 | 2001-10-10 22:35:00 +0000 | [diff] [blame] | 263 | # Create a TAGS database for emacs |
| 264 | #------------------------------------------------------------------------ |
| 265 | |
Vikram S. Adve | a0e9908 | 2001-10-13 12:26:59 +0000 | [diff] [blame] | 266 | ifeq ($(LEVEL), .) |
Vikram S. Adve | a0e9908 | 2001-10-13 12:26:59 +0000 | [diff] [blame] | 267 | tags: |
Chris Lattner | 198d5eb | 2002-05-10 18:51:54 +0000 | [diff] [blame] | 268 | etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'` |
Vikram S. Adve | a0e9908 | 2001-10-13 12:26:59 +0000 | [diff] [blame] | 269 | all:: tags |
Vikram S. Adve | a0e9908 | 2001-10-13 12:26:59 +0000 | [diff] [blame] | 270 | endif |
Vikram S. Adve | fa9dc58 | 2001-10-10 22:35:00 +0000 | [diff] [blame] | 271 | |
| 272 | #------------------------------------------------------------------------ |
Chris Lattner | 07c7c19 | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 273 | # Handle the TOOLNAME option - used when building tool executables... |
| 274 | #------------------------------------------------------------------------ |
| 275 | # |
| 276 | # The TOOLNAME option should be used with a USEDLIBS variable that tells the |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 277 | # libraries (and the order of the libs) that should be linked to the |
| 278 | # tool. USEDLIBS should contain a list of library names (some with .a extension) |
| 279 | # that are automatically linked in as .o files unless the .a suffix is added. |
Chris Lattner | 07c7c19 | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 280 | # |
| 281 | ifdef TOOLNAME |
| 282 | |
| 283 | # TOOLEXENAME* - These compute the output filenames to generate... |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 284 | TOOLEXENAME_G := $(BUILD_ROOT_TOP)/tools/Debug/$(TOOLNAME) |
| 285 | TOOLEXENAME_O := $(BUILD_ROOT_TOP)/tools/Release/$(TOOLNAME) |
| 286 | TOOLEXENAMES := $(TOOLEXENAME_G) |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 287 | ifdef ENABLE_OPTIMIZED |
| 288 | TOOLEXENAMES += $(TOOLEXENAME_O) |
| 289 | endif |
Chris Lattner | 07c7c19 | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 290 | |
| 291 | # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc. |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 292 | USED_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS))) |
| 293 | USED_LIBS_OPTIONS_G := $(patsubst %.o, $(LIBDEBUG)/%.o, $(USED_LIBS_OPTIONS)) |
| 294 | USED_LIBS_OPTIONS_O := $(patsubst %.o, $(LIBRELEASE)/%.o,$(USED_LIBS_OPTIONS)) |
| 295 | |
Chris Lattner | 07c7c19 | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 296 | |
| 297 | # USED_LIB_PATHS - Compute the path of the libraries used so that tools are |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 298 | # rebuilt if libraries change. This has to make sure to handle .a/.so and .o |
| 299 | # files seperately. |
Chris Lattner | 07c7c19 | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 300 | # |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 301 | STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS))) |
| 302 | USED_LIB_PATHS_G := $(addprefix $(LIBDEBUG)/, $(STATICUSEDLIBS)) |
| 303 | USED_LIB_PATHS_O := $(addprefix $(LIBRELEASE)/, $(STATICUSEDLIBS)) |
Chris Lattner | 07c7c19 | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 304 | |
Chris Lattner | 1fd501f | 2001-10-13 05:10:29 +0000 | [diff] [blame] | 305 | all:: $(TOOLEXENAMES) |
Chris Lattner | 07c7c19 | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 306 | clean:: |
| 307 | rm -f $(TOOLEXENAMES) |
| 308 | |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 309 | $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(BUILD_ROOT_TOP)/tools/Debug/.dir |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 310 | $(LinkG) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS_G) $(TOOLLINKOPTS) |
Chris Lattner | 07c7c19 | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 311 | |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 312 | $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(BUILD_ROOT_TOP)/tools/Release/.dir |
Chris Lattner | 76d98ba | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 313 | $(LinkO) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS_O) $(TOOLLINKOPTS) |
Chris Lattner | 07c7c19 | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 314 | |
| 315 | endif |
| 316 | |
| 317 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 318 | |
| 319 | #--------------------------------------------------------- |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 320 | .PRECIOUS: $(BUILD_ROOT)/Depend/.dir |
| 321 | .PRECIOUS: $(BUILD_ROOT)/Debug/.dir $(BUILD_ROOT)/Release/.dir |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 322 | |
Vikram S. Adve | fe34689 | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 323 | # Create dependencies for the *.cpp files... |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 324 | $(BUILD_ROOT)/Depend/%.d: %.cpp $(BUILD_ROOT)/Depend/.dir |
Chris Lattner | e5b0f65 | 2002-08-09 19:18:12 +0000 | [diff] [blame] | 325 | $(Depend) $< | sed 's|$*\.o *|$(BUILD_ROOT)/Release/& $(BUILD_ROOT)/Debug/& $(BUILD_ROOT)/Depend/$(@F)|g' > $@ |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 326 | |
Vikram S. Adve | fe34689 | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 327 | # Create dependencies for the *.c files... |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 328 | $(BUILD_ROOT)/Depend/%.d: %.c $(BUILD_ROOT)/Depend/.dir |
Vikram S. Adve | fe34689 | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 329 | $(Depend) $< | sed 's|$*\.o *|Release/& Debug/& Depend/$(@F)|g' > $@ |
| 330 | |
| 331 | # Create .o files in the ObjectFiles directory from the .cpp and .c files... |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 332 | $(BUILD_ROOT)/Release/%.o: %.cpp $(BUILD_ROOT)/Release/.dir |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 333 | $(CompileO) $< -o $@ |
| 334 | |
Chris Lattner | 068f822 | 2002-01-23 05:46:01 +0000 | [diff] [blame] | 335 | #Release/%.o: %.c Release/.dir Depend/.dir |
| 336 | # $(CompileOC) $< -o $@ |
Vikram S. Adve | fe34689 | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 337 | |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 338 | $(BUILD_ROOT)/Debug/%.o: %.cpp $(BUILD_ROOT)/Debug/.dir |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 339 | $(CompileG) $< -o $@ |
| 340 | |
Chris Lattner | 77330fa | 2002-08-09 15:41:55 +0000 | [diff] [blame] | 341 | #Debug/%.o: %.c Debug/.dir |
Chris Lattner | 068f822 | 2002-01-23 05:46:01 +0000 | [diff] [blame] | 342 | # $(CompileGC) $< -o $@ |
Vikram S. Adve | fe34689 | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 343 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 344 | # Create a .cpp source file from a flex input file... this uses sed to cut down |
| 345 | # on the warnings emited by GCC... |
| 346 | %.cpp: %.l |
| 347 | flex -t $< | sed '/^find_rule/d' | sed 's/void yyunput/inline void yyunput/' | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' > $@ |
| 348 | |
| 349 | # Rule for building the bison parsers... |
| 350 | |
| 351 | %.cpp %.h : %.y |
Chris Lattner | 198d5eb | 2002-05-10 18:51:54 +0000 | [diff] [blame] | 352 | bison -v -d -p $(<:%Parser.y=%) $(basename $@).y |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 353 | mv -f $(basename $@).tab.c $(basename $@).cpp |
| 354 | mv -f $(basename $@).tab.h $(basename $@).h |
| 355 | |
| 356 | # To create the directories... |
| 357 | %/.dir: |
| 358 | mkdir -p $(@D) |
| 359 | @date > $@ |
| 360 | |
Chris Lattner | d711a5e | 2002-07-31 21:32:05 +0000 | [diff] [blame] | 361 | # Clean nukes the tree |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 362 | clean:: |
Vikram S. Adve | fddb117 | 2002-08-22 03:20:27 +0000 | [diff] [blame] | 363 | rm -rf $(BUILD_ROOT)/Debug $(BUILD_ROOT)/Release $(BUILD_ROOT)/Depend |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 364 | rm -f core *.o *.d *.so *~ *.flc |
| 365 | |
| 366 | # If dependancies were generated for the file that included this file, |
| 367 | # include the dependancies now... |
| 368 | # |
Chris Lattner | 01f68c6 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 369 | SourceDepend := $(addsuffix .d,$(addprefix $(BUILD_ROOT)/Depend/,$(basename $(filter-out Debug/%, $(Source))))) |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 370 | ifneq ($(SourceDepend),) |
| 371 | include $(SourceDepend) |
| 372 | endif |