Vikram S. Adve | d60aede | 2002-07-09 12:04:21 +0000 | [diff] [blame] | 1 | #===-- Makefile.common - Common make rules for LLVM -------*- makefile -*--==== |
Chris Lattner | 0095054 | 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 | # |
Vikram S. Adve | c214e71 | 2002-08-29 23:28:46 +0000 | [diff] [blame] | 8 | # The following functionality can be set by setting incoming variables. |
| 9 | # The variable $(LEVEL) *must* be set: |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 10 | # |
| 11 | # 1. LEVEL - The level of the current subdirectory from the top of the |
| 12 | # MagicStats view. This level should be expressed as a path, for |
| 13 | # example, ../.. for two levels deep. |
| 14 | # |
| 15 | # 2. DIRS - A list of subdirectories to be built. Fake targets are set up |
Chris Lattner | a8abc22 | 2002-09-18 03:22:27 +0000 | [diff] [blame] | 16 | # so that each of the targets "all", "install", and "clean" each build |
| 17 | # the subdirectories before the local target. DIRS are guaranteed to be |
| 18 | # built in order. |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 19 | # |
Chris Lattner | a8abc22 | 2002-09-18 03:22:27 +0000 | [diff] [blame] | 20 | # 3. PARALLEL_DIRS - A list of subdirectories to be built, but that may be |
| 21 | # built in any order. All DIRS are built in order before PARALLEL_DIRS are |
| 22 | # built, which are then built in any order. |
| 23 | # |
| 24 | # 4. Source - If specified, this sets the source code filenames. If this |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 25 | # 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] | 26 | # in the current directory. Also, if you want to build files in addition |
| 27 | # to the local files, you can use the ExtraSource variable |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 28 | # |
Chris Lattner | 694c5df | 2003-05-15 21:28:55 +0000 | [diff] [blame] | 29 | # 5. SourceDir - If specified, this specifies a directory that the source files |
| 30 | # are in, if they are not in the current directory. This should include a |
| 31 | # trailing / character. |
| 32 | # |
Dinakar Dhurjati | 584dd18 | 2003-05-29 21:49:00 +0000 | [diff] [blame] | 33 | # 6. PROJ_COMPILE - If set to 1, then this makefile can also be used to |
| 34 | # compile other projects using llvm. Note if this option is set then the |
| 35 | # following *must* hold |
| 36 | # PROJLEVEL should be set to the top of the source directory for the |
| 37 | # project files |
| 38 | # LEVEL should be set to the top of LLVM source tree |
| 39 | # LLVM_LIB_DIR should be set to the top of the LLVM build tree |
| 40 | # |
| 41 | # |
Vikram S. Adve | d60aede | 2002-07-09 12:04:21 +0000 | [diff] [blame] | 42 | #===-----------------------------------------------------------------------==== |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 43 | |
Vikram S. Adve | c214e71 | 2002-08-29 23:28:46 +0000 | [diff] [blame] | 44 | # Configuration file to set paths specific to local installation of LLVM |
| 45 | # |
| 46 | include $(LEVEL)/Makefile.config |
| 47 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 48 | ########################################################################### |
| 49 | # Directory Configuration |
| 50 | # This section of the Makefile determines what is where. To be |
| 51 | # specific, there are several locations that need to be defined: |
| 52 | # |
| 53 | # o LLVM_SRC_ROOT : The root directory of the LLVM source code. |
| 54 | # o LLVM_OBJ_ROOT : The root directory containing the built LLVM code. |
| 55 | # |
| 56 | # o BUILD_SRC_DIR : The directory containing the code to build. |
| 57 | # o BUILD_SRC_ROOT : The root directory of the code to build. |
| 58 | # |
| 59 | # o BUILD_OBJ_DIR : The directory in which compiled code will be placed. |
| 60 | # o BUILD_OBJ_ROOT : The root directory in which compiled code is placed. |
| 61 | # |
| 62 | ########################################################################### |
| 63 | |
| 64 | # |
| 65 | # Set the source build directory. That is almost always the current directory. |
| 66 | # |
| 67 | ifndef BUILD_SRC_DIR |
| 68 | BUILD_SRC_DIR = $(shell pwd) |
| 69 | endif |
| 70 | |
| 71 | # |
| 72 | # Set the source root directory. |
| 73 | # |
| 74 | ifndef BUILD_SRC_ROOT |
| 75 | BUILD_SRC_ROOT = $(BUILD_SRC_DIR)/$(LEVEL) |
| 76 | endif |
| 77 | |
| 78 | # |
| 79 | # Set the object build directory. Its location depends upon the source path |
| 80 | # and where object files should go. |
| 81 | # |
| 82 | ifndef BUILD_OBJ_DIR |
| 83 | ifeq ($(OBJ_ROOT),.) |
| 84 | BUILD_OBJ_DIR = $(shell pwd) |
| 85 | else |
| 86 | BUILD_OBJ_DIR := $(OBJ_ROOT)$(patsubst $(HOME)%,%,$(shell cd $(BUILD_SRC_DIR); pwd)) |
| 87 | endif |
| 88 | endif |
| 89 | |
| 90 | # |
| 91 | # Set the root of the object directory. |
| 92 | # |
| 93 | ifndef BUILD_OBJ_ROOT |
| 94 | ifeq ($(OBJ_ROOT),.) |
| 95 | BUILD_OBJ_ROOT = $(shell cd $(LEVEL); pwd) |
| 96 | else |
| 97 | BUILD_OBJ_ROOT := $(OBJ_ROOT)$(patsubst $(HOME)%,%,$(shell cd $(LEVEL); pwd)) |
| 98 | endif |
| 99 | endif |
| 100 | |
| 101 | # |
| 102 | # Set the LLVM source directory. |
| 103 | # It is typically the root directory of what we're compiling now. |
| 104 | # |
| 105 | ifndef LLVM_SRC_ROOT |
| 106 | LLVM_SRC_ROOT = $(BUILD_SRC_ROOT) |
| 107 | endif |
| 108 | |
| 109 | # |
| 110 | # Set the LLVM object directory. |
| 111 | # |
| 112 | ifndef LLVM_OBJ_ROOT |
| 113 | LLVM_OBJ_ROOT = $(BUILD_OBJ_ROOT) |
| 114 | endif |
| 115 | |
Chris Lattner | 4bb13b8 | 2002-09-13 22:14:47 +0000 | [diff] [blame] | 116 | # Figure out how to do platform specific stuff on this platform. This is really |
| 117 | # gross and should be autoconfiscated (automake actually), but should hopefully |
| 118 | # work on Linux and solaris (SunOS). |
| 119 | # |
| 120 | UNAME := $(shell uname) |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 121 | include $(LLVM_SRC_ROOT)/Makefile.$(UNAME) |
Chris Lattner | 4bb13b8 | 2002-09-13 22:14:47 +0000 | [diff] [blame] | 122 | |
Chris Lattner | edf1f23 | 2002-07-23 19:21:31 +0000 | [diff] [blame] | 123 | ifdef SHARED_LIBRARY |
| 124 | # if SHARED_LIBRARY is specified, the default is to build the dynamic lib |
| 125 | dynamic :: |
| 126 | endif |
| 127 | |
Chris Lattner | b19e59c | 2001-06-29 05:20:16 +0000 | [diff] [blame] | 128 | # Default Rule: Make sure it's also a :: rule |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 129 | all :: |
| 130 | |
| 131 | # Default for install is to at least build everything... |
| 132 | install :: |
| 133 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 134 | # Default rule for test. It ensures everything has a test rule |
| 135 | test:: |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 136 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 137 | #-------------------------------------------------------------------- |
Vikram S. Adve | c214e71 | 2002-08-29 23:28:46 +0000 | [diff] [blame] | 138 | # Variables derived from configuration options... |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 139 | #-------------------------------------------------------------------- |
| 140 | |
| 141 | #BinInstDir=/usr/local/bin |
John Criswell | 65aa5934 | 2003-05-29 18:52:10 +0000 | [diff] [blame] | 142 | #LibInstDir=/usr/local/lib/xxx |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 143 | #DocInstDir=/usr/doc/xxx |
| 144 | |
Vikram S. Adve | dba59ef | 2001-08-06 19:01:20 +0000 | [diff] [blame] | 145 | BURG_OPTS = -I |
| 146 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 147 | PURIFY := $(PURIFY) -cache-dir="$(BUILD_OBJ_ROOT)/../purifycache" -chain-length="30" -messages=all |
Chris Lattner | 6e39070 | 2001-10-30 20:24:08 +0000 | [diff] [blame] | 148 | |
Chris Lattner | 760da06 | 2003-03-14 20:25:22 +0000 | [diff] [blame] | 149 | ifdef ENABLE_PROFILING |
| 150 | ENABLE_OPTIMIZED = 1 |
| 151 | CONFIGURATION := Profile |
| 152 | else |
| 153 | ifdef ENABLE_OPTIMIZED |
| 154 | CONFIGURATION := Release |
| 155 | else |
| 156 | CONFIGURATION := Debug |
| 157 | endif |
| 158 | endif |
| 159 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 160 | ########################################################################### |
| 161 | # Library Locations |
| 162 | # These variables describe various library locations: |
| 163 | # |
| 164 | # DEST* = Location of where libraries that are built will be placed. |
| 165 | # LLVM* = Location of LLVM libraries used for linking. |
| 166 | # PROJ* = Location of previously built libraries used for linking. |
| 167 | ########################################################################### |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 168 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 169 | # Libraries that are being built |
| 170 | DESTLIBDEBUG := $(BUILD_OBJ_ROOT)/lib/Debug |
| 171 | DESTLIBRELEASE := $(BUILD_OBJ_ROOT)/lib/Release |
| 172 | DESTLIBPROFILE := $(BUILD_OBJ_ROOT)/lib/Profile |
| 173 | DESTLIBCURRENT := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION) |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 174 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 175 | # LLVM libraries used for linking |
| 176 | LLVMLIBDEBUGSOURCE := $(LLVM_OBJ_ROOT)/lib/Debug |
| 177 | LLVMLIBRELEASESOURCE := $(LLVM_OBJ_ROOT)/lib/Release |
| 178 | LLVMLIBPROFILESOURCE := $(LLVM_OBJ_ROOT)/lib/Profile |
| 179 | LLVMLIBCURRENTSOURCE := $(LLVM_OBJ_ROOT)/lib/$(CONFIGURATION) |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 180 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 181 | # Libraries that were built that will now be used for linking |
| 182 | PROJLIBDEBUGSOURCE := $(BUILD_OBJ_ROOT)/lib/Debug |
| 183 | PROJLIBRELEASESOURCE := $(BUILD_OBJ_ROOT)/lib/Release |
| 184 | PROJLIBPROFILESOURCE := $(BUILD_OBJ_ROOT)/lib/Profile |
| 185 | PROJLIBCURRENTSOURCE := $(BUILD_OBJ_ROOT)/lib/$(CONFIGURATION) |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 186 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 187 | ########################################################################### |
| 188 | # Tool Locations |
| 189 | # These variables describe various tool locations: |
| 190 | # |
| 191 | # DEST* = Location of where tools that are built will be placed. |
| 192 | # LLVM* = Location of LLVM tools used for building. |
| 193 | # PROJ* = Location of previously built tools used for linking. |
| 194 | ########################################################################### |
Chris Lattner | 760da06 | 2003-03-14 20:25:22 +0000 | [diff] [blame] | 195 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 196 | DESTTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug |
| 197 | DESTTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release |
| 198 | DESTTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile |
| 199 | DESTTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION) |
| 200 | |
| 201 | LLVMTOOLDEBUG := $(LLVM_OBJ_ROOT)/tools/Debug |
| 202 | LLVMTOOLRELEASE := $(LLVM_OBJ_ROOT)/tools/Release |
| 203 | LLVMTOOLPROFILE := $(LLVM_OBJ_ROOT)/tools/Profile |
| 204 | LLVMTOOLCURRENT := $(LLVM_OBJ_ROOT)/tools/$(CONFIGURATION) |
| 205 | |
| 206 | PROJTOOLDEBUG := $(BUILD_OBJ_ROOT)/tools/Debug |
| 207 | PROJTOOLRELEASE := $(BUILD_OBJ_ROOT)/tools/Release |
| 208 | PROJTOOLPROFILE := $(BUILD_OBJ_ROOT)/tools/Profile |
| 209 | PROJTOOLCURRENT := $(BUILD_OBJ_ROOT)/tools/$(CONFIGURATION) |
Chris Lattner | e62dbe9 | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 210 | |
Misha Brukman | b5f096f | 2002-09-12 16:05:39 +0000 | [diff] [blame] | 211 | # Verbosity levels |
Chris Lattner | 760da06 | 2003-03-14 20:25:22 +0000 | [diff] [blame] | 212 | ifndef VERBOSE |
Misha Brukman | b5f096f | 2002-09-12 16:05:39 +0000 | [diff] [blame] | 213 | VERB := @ |
| 214 | endif |
| 215 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 216 | #--------------------------------------------------------- |
| 217 | # Compilation options... |
| 218 | #--------------------------------------------------------- |
| 219 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 220 | ########################################################################### |
Chris Lattner | 9b94701 | 2002-09-19 19:42:24 +0000 | [diff] [blame] | 221 | # Special tools used while building the LLVM tree. Burg is built as part of the |
| 222 | # utils directory. |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 223 | ########################################################################### |
| 224 | BURG := $(LLVMTOOLCURRENT)/burg |
Chris Lattner | 9b94701 | 2002-09-19 19:42:24 +0000 | [diff] [blame] | 225 | RunBurg := $(BURG) $(BURG_OPTS) |
| 226 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 227 | TBLGEN := $(LLVMTOOLCURRENT)/tblgen |
Vikram S. Adve | dba59ef | 2001-08-06 19:01:20 +0000 | [diff] [blame] | 228 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 229 | # Enable this for profiling support with 'gprof' |
Vikram S. Adve | 41e7891 | 2002-09-20 14:03:13 +0000 | [diff] [blame] | 230 | # This automatically enables optimized builds. |
Chris Lattner | 18f4701 | 2002-05-10 18:51:54 +0000 | [diff] [blame] | 231 | ifdef ENABLE_PROFILING |
Vikram S. Adve | 41e7891 | 2002-09-20 14:03:13 +0000 | [diff] [blame] | 232 | PROFILE = -pg |
Chris Lattner | 18f4701 | 2002-05-10 18:51:54 +0000 | [diff] [blame] | 233 | endif |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 234 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 235 | ########################################################################### |
| 236 | # Compile Time Flags |
| 237 | ########################################################################### |
| 238 | |
| 239 | # |
| 240 | # Include both the project headers and the LLVM headers for compilation |
| 241 | # |
| 242 | CPPFLAGS += -I$(BUILD_SRC_ROOT)/include -I$(LLVM_SRC_ROOT)/include |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 243 | |
Vikram S. Adve | feeae58 | 2002-09-18 11:55:13 +0000 | [diff] [blame] | 244 | # By default, strip symbol information from executable |
Chris Lattner | 760da06 | 2003-03-14 20:25:22 +0000 | [diff] [blame] | 245 | ifndef KEEP_SYMBOLS |
Chris Lattner | 527002c | 2003-01-31 19:00:26 +0000 | [diff] [blame] | 246 | STRIP = $(PLATFORMSTRIPOPTS) |
| 247 | STRIP_WARN_MSG = "(without symbols) " |
Vikram S. Adve | feeae58 | 2002-09-18 11:55:13 +0000 | [diff] [blame] | 248 | endif |
| 249 | |
Chris Lattner | 73e1d0f | 2002-09-13 16:02:26 +0000 | [diff] [blame] | 250 | # Allow gnu extensions... |
| 251 | CPPFLAGS += -D_GNU_SOURCE |
| 252 | |
Chris Lattner | c7acf81 | 2002-01-23 05:46:01 +0000 | [diff] [blame] | 253 | # -Wno-unused-parameter |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 254 | CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused -I$(LEVEL)/include |
Chris Lattner | 1d1e5b5 | 2003-02-13 16:56:30 +0000 | [diff] [blame] | 255 | CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions -fshort-enums |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 256 | |
Chris Lattner | 172b648 | 2002-09-22 02:47:15 +0000 | [diff] [blame] | 257 | # Compile a cpp file, don't link... |
Chris Lattner | 285af38 | 2002-08-12 21:19:28 +0000 | [diff] [blame] | 258 | Compile := $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CompileCommonOpts) |
| 259 | CompileG := $(Compile) -g -D_DEBUG |
Chris Lattner | 1d1e5b5 | 2003-02-13 16:56:30 +0000 | [diff] [blame] | 260 | CompileO := $(Compile) $(CompileOptimizeOpts) -felide-constructors -fomit-frame-pointer |
| 261 | CompileP := $(Compile) $(CompileOptimizeOpts) -felide-constructors $(PROFILE) |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 262 | |
Chris Lattner | 172b648 | 2002-09-22 02:47:15 +0000 | [diff] [blame] | 263 | # Compile a c file, don't link... |
| 264 | CompileC := $(CC) -c $(CPPFLAGS) $(CCFLAGS) $(CompileCommonOpts) |
| 265 | CompileCG := $(CompileC) -g -D_DEBUG |
Chris Lattner | fe95dae | 2003-02-19 22:12:20 +0000 | [diff] [blame] | 266 | CompileCO := $(CompileC) $(CompileOptimizeOpts) -fomit-frame-pointer |
| 267 | CompileCP := $(CompileC) $(CompileOptimizeOpts) $(PROFILE) |
Chris Lattner | 172b648 | 2002-09-22 02:47:15 +0000 | [diff] [blame] | 268 | |
| 269 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 270 | # Link final executable |
Chris Lattner | 6e39070 | 2001-10-30 20:24:08 +0000 | [diff] [blame] | 271 | |
Chris Lattner | 1917e95 | 2002-07-31 21:32:05 +0000 | [diff] [blame] | 272 | ifdef ENABLE_PURIFY # To enable purify, build with 'gmake ENABLE_PURIFY=1' |
Vikram S. Adve | 41e7891 | 2002-09-20 14:03:13 +0000 | [diff] [blame] | 273 | Link := $(PURIFY) $(CXX) -static |
Chris Lattner | 12604ed | 2002-04-05 18:56:58 +0000 | [diff] [blame] | 274 | else |
Vikram S. Adve | 41e7891 | 2002-09-20 14:03:13 +0000 | [diff] [blame] | 275 | Link := $(CXX) |
Chris Lattner | 12604ed | 2002-04-05 18:56:58 +0000 | [diff] [blame] | 276 | endif |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 277 | |
| 278 | ifdef PROJ_COMPILE |
Dinakar Dhurjati | 584dd18 | 2003-05-29 21:49:00 +0000 | [diff] [blame] | 279 | # include both projlib source and llvmlib source |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 280 | LinkG := $(Link) -g -L$(PROJLIBDEBUGSOURCE) -L$(LLVMLIBDEBUGSOURCE) $(STRIP) |
| 281 | LinkO := $(Link) -O3 -L$(PROJLIBRELEASESOURCE) -L$(LLVMLIBRELEASESOURCE) |
| 282 | LinkP := $(Link) -O3 -L$(PROJLIBPROFILESOURCE) -L$(LLVMLIBPROFILESOURCE) $(PROFILE) |
| 283 | else |
| 284 | LinkG := $(Link) -g -L$(LLVMLIBDEBUGSOURCE) $(STRIP) |
| 285 | LinkO := $(Link) -O3 -L$(LLVMLIBRELEASESOURCE) |
| 286 | LinkP := $(Link) -O3 -L$(LLVMLIBPROFILESOURCE) $(PROFILE) |
| 287 | endif |
| 288 | |
| 289 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 290 | |
Chris Lattner | e62dbe9 | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 291 | # Create one .o file from a bunch of .o files... |
John Criswell | 794fcd2 | 2003-05-30 15:50:31 +0000 | [diff] [blame] | 292 | Relink = ${LD} -r |
Chris Lattner | e62dbe9 | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 293 | |
Chris Lattner | 4bb13b8 | 2002-09-13 22:14:47 +0000 | [diff] [blame] | 294 | # MakeSO - Create a .so file from a .o files... |
Vikram S. Adve | 41e7891 | 2002-09-20 14:03:13 +0000 | [diff] [blame] | 295 | MakeSO := $(CXX) $(MakeSharedObjectOption) |
Chris Lattner | 4bb13b8 | 2002-09-13 22:14:47 +0000 | [diff] [blame] | 296 | MakeSOO := $(MakeSO) -O3 |
Vikram S. Adve | 41e7891 | 2002-09-20 14:03:13 +0000 | [diff] [blame] | 297 | MakeSOP := $(MakeSOO) $(PROFILE) |
Chris Lattner | 4bb13b8 | 2002-09-13 22:14:47 +0000 | [diff] [blame] | 298 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 299 | # Create dependancy file from CPP file, send to stdout. |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 300 | Depend := $(CXX) -MM -I$(LEVEL)/include $(CPPFLAGS) |
| 301 | DependC := $(CC) -MM -I$(LEVEL)/include $(CPPFLAGS) |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 302 | |
| 303 | # Archive a bunch of .o files into a .a file... |
John Criswell | 794fcd2 | 2003-05-30 15:50:31 +0000 | [diff] [blame] | 304 | AR = ${AR_PATH} cq |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 305 | |
| 306 | #---------------------------------------------------------- |
| 307 | |
| 308 | # Source includes all of the cpp files, and objects are derived from the |
| 309 | # source files... |
Chris Lattner | e001059 | 2001-10-18 01:48:09 +0000 | [diff] [blame] | 310 | # The local Makefile can list other Source files via ExtraSource = ... |
Vikram S. Adve | c4bed34 | 2001-10-17 12:33:55 +0000 | [diff] [blame] | 311 | # |
Vikram S. Adve | ad9ea7e | 2002-10-14 16:40:04 +0000 | [diff] [blame] | 312 | ifndef Source |
Chris Lattner | e001059 | 2001-10-18 01:48:09 +0000 | [diff] [blame] | 313 | Source := $(ExtraSource) $(wildcard *.cpp *.c *.y *.l) |
Vikram S. Adve | ad9ea7e | 2002-10-14 16:40:04 +0000 | [diff] [blame] | 314 | endif |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 315 | |
Chris Lattner | 694c5df | 2003-05-15 21:28:55 +0000 | [diff] [blame] | 316 | Objs := $(sort $(patsubst Debug/%.o, %.o, $(addsuffix .o,$(notdir $(basename $(Source)))))) |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 317 | ObjectsO := $(addprefix $(BUILD_OBJ_DIR)/Release/,$(Objs)) |
| 318 | ObjectsP := $(addprefix $(BUILD_OBJ_DIR)/Profile/,$(Objs)) |
| 319 | ObjectsG := $(addprefix $(BUILD_OBJ_DIR)/Debug/,$(Objs)) |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 320 | |
Chris Lattner | e62dbe9 | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 321 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 322 | #--------------------------------------------------------- |
Chris Lattner | a8abc22 | 2002-09-18 03:22:27 +0000 | [diff] [blame] | 323 | # Handle the DIRS and PARALLEL_DIRS options |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 324 | #--------------------------------------------------------- |
| 325 | |
Anand Shukla | 7c7a07e | 2002-09-18 04:29:30 +0000 | [diff] [blame] | 326 | ifdef DIRS |
Chris Lattner | dc95ade | 2003-01-16 20:02:30 +0000 | [diff] [blame] | 327 | all install clean test :: |
Chris Lattner | 16d1f73 | 2002-09-17 23:45:34 +0000 | [diff] [blame] | 328 | $(VERB) for dir in ${DIRS}; do \ |
Chris Lattner | f1ffd99 | 2002-09-17 23:35:02 +0000 | [diff] [blame] | 329 | (cd $$dir; $(MAKE) $@) || exit 1; \ |
| 330 | done |
Anand Shukla | 7c7a07e | 2002-09-18 04:29:30 +0000 | [diff] [blame] | 331 | endif |
Chris Lattner | a8abc22 | 2002-09-18 03:22:27 +0000 | [diff] [blame] | 332 | |
| 333 | # Handle PARALLEL_DIRS |
| 334 | ifdef PARALLEL_DIRS |
| 335 | all :: $(addsuffix /.makeall , $(PARALLEL_DIRS)) |
| 336 | install :: $(addsuffix /.makeinstall, $(PARALLEL_DIRS)) |
| 337 | clean :: $(addsuffix /.makeclean , $(PARALLEL_DIRS)) |
Chris Lattner | dc95ade | 2003-01-16 20:02:30 +0000 | [diff] [blame] | 338 | test :: $(addsuffix /.maketest , $(PARALLEL_DIRS)) |
Chris Lattner | a8abc22 | 2002-09-18 03:22:27 +0000 | [diff] [blame] | 339 | |
Chris Lattner | dc95ade | 2003-01-16 20:02:30 +0000 | [diff] [blame] | 340 | %/.makeall %/.makeinstall %/.makeclean %/.maketest: |
Chris Lattner | a8abc22 | 2002-09-18 03:22:27 +0000 | [diff] [blame] | 341 | $(VERB) cd $(@D); $(MAKE) $(subst $(@D)/.make,,$@) |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 342 | endif |
| 343 | |
| 344 | #--------------------------------------------------------- |
| 345 | # Handle the LIBRARYNAME option - used when building libs... |
| 346 | #--------------------------------------------------------- |
Chris Lattner | e62dbe9 | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 347 | # |
| 348 | # When libraries are built, they are allowed to optionally define the |
| 349 | # DONT_BUILD_RELINKED make variable, which, when defined, prevents a .o file |
| 350 | # from being built for the library. This .o files may then be linked to by a |
| 351 | # tool if the tool does not need (or want) the semantics a .a file provides |
| 352 | # (linking in only object files that are "needed"). If a library is never to |
| 353 | # be used in this way, it is better to define DONT_BUILD_RELINKED, and define |
| 354 | # BUILD_ARCHIVE instead. |
| 355 | # |
| 356 | # Some libraries must be built as .a files (libscalar for example) because if |
Chris Lattner | 1917e95 | 2002-07-31 21:32:05 +0000 | [diff] [blame] | 357 | # it's built as a .o file, then all of the constituent .o files in it will be |
Chris Lattner | e62dbe9 | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 358 | # linked into tools (for example gccas) even if they only use one of the parts |
| 359 | # of it. For this reason, sometimes it's useful to use libraries as .a files. |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 360 | |
| 361 | ifdef LIBRARYNAME |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 362 | |
Chris Lattner | 2a548c5 | 2002-09-16 22:36:42 +0000 | [diff] [blame] | 363 | # Make sure there isn't any extranous whitespace on the LIBRARYNAME option |
Chris Lattner | ccb4ebd | 2002-09-16 22:34:56 +0000 | [diff] [blame] | 364 | LIBRARYNAME := $(strip $(LIBRARYNAME)) |
| 365 | |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 366 | LIBNAME_O := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).so |
| 367 | LIBNAME_P := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).so |
| 368 | LIBNAME_G := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).so |
| 369 | LIBNAME_AO := $(DESTLIBRELEASE)/lib$(LIBRARYNAME).a |
| 370 | LIBNAME_AP := $(DESTLIBPROFILE)/lib$(LIBRARYNAME).a |
| 371 | LIBNAME_AG := $(DESTLIBDEBUG)/lib$(LIBRARYNAME).a |
| 372 | LIBNAME_OBJO := $(DESTLIBRELEASE)/$(LIBRARYNAME).o |
| 373 | LIBNAME_OBJP := $(DESTLIBPROFILE)/$(LIBRARYNAME).o |
| 374 | LIBNAME_OBJG := $(DESTLIBDEBUG)/$(LIBRARYNAME).o |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 375 | |
Chris Lattner | 760da06 | 2003-03-14 20:25:22 +0000 | [diff] [blame] | 376 | # dynamic target builds a shared object version of the library... |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 377 | dynamic:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).so |
Vikram S. Adve | 60f5606 | 2002-08-02 18:34:12 +0000 | [diff] [blame] | 378 | |
Chris Lattner | 760da06 | 2003-03-14 20:25:22 +0000 | [diff] [blame] | 379 | # Does the library want a .o version built? |
Chris Lattner | e62dbe9 | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 380 | ifndef DONT_BUILD_RELINKED |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 381 | all:: $(DESTLIBCURRENT)/$(LIBRARYNAME).o |
Chris Lattner | e62dbe9 | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 382 | endif |
Chris Lattner | 760da06 | 2003-03-14 20:25:22 +0000 | [diff] [blame] | 383 | |
| 384 | # Does the library want an archive version built? |
Chris Lattner | e62dbe9 | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 385 | ifdef BUILD_ARCHIVE |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 386 | all:: $(DESTLIBCURRENT)/lib$(LIBRARYNAME).a |
Chris Lattner | e62dbe9 | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 387 | endif |
Chris Lattner | e62dbe9 | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 388 | |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 389 | $(LIBNAME_O): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 390 | @echo ======= Linking $(LIBRARYNAME) release library ======= |
Misha Brukman | b5f096f | 2002-09-12 16:05:39 +0000 | [diff] [blame] | 391 | $(VERB) $(MakeSOO) -o $@ $(ObjectsO) $(LibSubDirs) $(LibLinkOpts) |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 392 | |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 393 | $(LIBNAME_P): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir |
Vikram S. Adve | 41e7891 | 2002-09-20 14:03:13 +0000 | [diff] [blame] | 394 | @echo ======= Linking $(LIBRARYNAME) profile library ======= |
| 395 | $(VERB) $(MakeSOP) -o $@ $(ObjectsP) $(LibSubDirs) $(LibLinkOpts) |
| 396 | |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 397 | $(LIBNAME_G): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 398 | @echo ======= Linking $(LIBRARYNAME) debug library ======= |
Misha Brukman | b5f096f | 2002-09-12 16:05:39 +0000 | [diff] [blame] | 399 | $(VERB) $(MakeSO) -g -o $@ $(ObjectsG) $(LibSubDirs) $(LibLinkOpts) |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 400 | |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 401 | $(LIBNAME_AO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 402 | @echo ======= Linking $(LIBRARYNAME) release library ======= |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 403 | @rm -f $@ |
Misha Brukman | b5f096f | 2002-09-12 16:05:39 +0000 | [diff] [blame] | 404 | $(VERB) $(AR) $@ $(ObjectsO) $(LibSubDirs) |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 405 | |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 406 | $(LIBNAME_AP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir |
Vikram S. Adve | 41e7891 | 2002-09-20 14:03:13 +0000 | [diff] [blame] | 407 | @echo ======= Linking $(LIBRARYNAME) profile library ======= |
| 408 | @rm -f $@ |
| 409 | $(VERB) $(AR) $@ $(ObjectsP) $(LibSubDirs) |
| 410 | |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 411 | $(LIBNAME_AG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 412 | @echo ======= Linking $(LIBRARYNAME) debug library ======= |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 413 | @rm -f $@ |
Misha Brukman | b5f096f | 2002-09-12 16:05:39 +0000 | [diff] [blame] | 414 | $(VERB) $(AR) $@ $(ObjectsG) $(LibSubDirs) |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 415 | |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 416 | $(LIBNAME_OBJO): $(ObjectsO) $(LibSubDirs) $(DESTLIBRELEASE)/.dir |
Misha Brukman | b5f096f | 2002-09-12 16:05:39 +0000 | [diff] [blame] | 417 | @echo "Linking $@" |
| 418 | $(VERB) $(Relink) -o $@ $(ObjectsO) $(LibSubDirs) |
Chris Lattner | e62dbe9 | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 419 | |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 420 | $(LIBNAME_OBJP): $(ObjectsP) $(LibSubDirs) $(DESTLIBPROFILE)/.dir |
Vikram S. Adve | 41e7891 | 2002-09-20 14:03:13 +0000 | [diff] [blame] | 421 | @echo "Linking $@" |
| 422 | $(VERB) $(Relink) -o $@ $(ObjectsP) $(LibSubDirs) |
| 423 | |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 424 | $(LIBNAME_OBJG): $(ObjectsG) $(LibSubDirs) $(DESTLIBDEBUG)/.dir |
Chris Lattner | 9e39816 | 2002-09-25 17:15:22 +0000 | [diff] [blame] | 425 | @echo "Linking $@" |
Misha Brukman | b5f096f | 2002-09-12 16:05:39 +0000 | [diff] [blame] | 426 | $(VERB) $(Relink) -o $@ $(ObjectsG) $(LibSubDirs) |
Chris Lattner | e62dbe9 | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 427 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 428 | endif |
| 429 | |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 430 | #------------------------------------------------------------------------ |
Vikram S. Adve | 0193d5e | 2001-10-10 22:35:00 +0000 | [diff] [blame] | 431 | # Create a TAGS database for emacs |
| 432 | #------------------------------------------------------------------------ |
| 433 | |
Vikram S. Adve | 022d06c | 2001-10-13 12:26:59 +0000 | [diff] [blame] | 434 | ifeq ($(LEVEL), .) |
Vikram S. Adve | 022d06c | 2001-10-13 12:26:59 +0000 | [diff] [blame] | 435 | tags: |
Chris Lattner | 18f4701 | 2002-05-10 18:51:54 +0000 | [diff] [blame] | 436 | etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'` |
Vikram S. Adve | 022d06c | 2001-10-13 12:26:59 +0000 | [diff] [blame] | 437 | all:: tags |
Vikram S. Adve | 022d06c | 2001-10-13 12:26:59 +0000 | [diff] [blame] | 438 | endif |
Vikram S. Adve | 0193d5e | 2001-10-10 22:35:00 +0000 | [diff] [blame] | 439 | |
| 440 | #------------------------------------------------------------------------ |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 441 | # Handle the TOOLNAME option - used when building tool executables... |
| 442 | #------------------------------------------------------------------------ |
| 443 | # |
| 444 | # The TOOLNAME option should be used with a USEDLIBS variable that tells the |
Chris Lattner | e62dbe9 | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 445 | # libraries (and the order of the libs) that should be linked to the |
| 446 | # tool. USEDLIBS should contain a list of library names (some with .a extension) |
| 447 | # that are automatically linked in as .o files unless the .a suffix is added. |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 448 | # |
| 449 | ifdef TOOLNAME |
| 450 | |
| 451 | # TOOLEXENAME* - These compute the output filenames to generate... |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 452 | TOOLEXENAME_G := $(DESTTOOLDEBUG)/$(TOOLNAME) |
| 453 | TOOLEXENAME_O := $(DESTTOOLRELEASE)/$(TOOLNAME) |
| 454 | TOOLEXENAME_P := $(DESTTOOLPROFILE)/$(TOOLNAME) |
| 455 | TOOLEXENAMES := $(DESTTOOLCURRENT)/$(TOOLNAME) |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 456 | |
| 457 | # USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc. |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 458 | PROJ_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS))) |
| 459 | PROJ_LIBS_OPTIONS_G := $(patsubst %.o, $(PROJLIBDEBUGSOURCE)/%.o, $(PROJ_LIBS_OPTIONS)) |
| 460 | PROJ_LIBS_OPTIONS_O := $(patsubst %.o, $(PROJLIBRELEASESOURCE)/%.o,$(PROJ_LIBS_OPTIONS)) |
| 461 | PROJ_LIBS_OPTIONS_P := $(patsubst %.o, $(PROJLIBPROFILESOURCE)/%.o,$(PROJ_LIBS_OPTIONS)) |
| 462 | |
| 463 | LLVM_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(LLVMLIBS))) |
| 464 | LLVM_LIBS_OPTIONS_G := $(patsubst %.o, $(LLVMLIBDEBUGSOURCE)/%.o, $(LLVM_LIBS_OPTIONS)) |
| 465 | LLVM_LIBS_OPTIONS_O := $(patsubst %.o, $(LLVMLIBRELEASESOURCE)/%.o,$(LLVM_LIBS_OPTIONS)) |
| 466 | LLVM_LIBS_OPTIONS_P := $(patsubst %.o, $(LLVMLIBPROFILESOURCE)/%.o,$(LLVM_LIBS_OPTIONS)) |
| 467 | |
| 468 | LIB_OPTS_G := $(LLVM_LIBS_OPTIONS_G) $(PROJ_LIBS_OPTIONS_G) |
| 469 | LIB_OPTS_O := $(LLVM_LIBS_OPTIONS_O) $(PROJ_LIBS_OPTIONS_P) |
| 470 | LIB_OPTS_P := $(LLVM_LIBS_OPTIONS_P) $(PROJ_LIBS_OPTIONS_P) |
| 471 | |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 472 | # USED_LIB_PATHS - Compute the path of the libraries used so that tools are |
Chris Lattner | e62dbe9 | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 473 | # rebuilt if libraries change. This has to make sure to handle .a/.so and .o |
| 474 | # files seperately. |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 475 | # |
Chris Lattner | e62dbe9 | 2002-07-23 17:56:16 +0000 | [diff] [blame] | 476 | STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS))) |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 477 | USED_LIB_PATHS_G := $(addprefix $(DESTLIBDEBUG)/, $(STATICUSEDLIBS)) |
| 478 | USED_LIB_PATHS_O := $(addprefix $(DESTLIBRELEASE)/, $(STATICUSEDLIBS)) |
| 479 | USED_LIB_PATHS_P := $(addprefix $(DESTLIBPROFILE)/, $(STATICUSEDLIBS)) |
Chris Lattner | 1c58850 | 2002-11-04 20:50:33 +0000 | [diff] [blame] | 480 | LINK_OPTS := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS) |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 481 | |
Chris Lattner | 8d7dfb3 | 2003-01-22 16:13:31 +0000 | [diff] [blame] | 482 | |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 483 | |
| 484 | |
| 485 | |
| 486 | |
Chris Lattner | 8d7dfb3 | 2003-01-22 16:13:31 +0000 | [diff] [blame] | 487 | # Tell make that we need to rebuild subdirectories before we can link the tool. |
| 488 | # This affects things like LLI which has library subdirectories. |
| 489 | $(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \ |
| 490 | $(addsuffix /.makeall, $(PARALLEL_DIRS)) |
| 491 | |
Chris Lattner | 669bd7c | 2001-10-13 05:10:29 +0000 | [diff] [blame] | 492 | all:: $(TOOLEXENAMES) |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 493 | clean:: |
Misha Brukman | b5f096f | 2002-09-12 16:05:39 +0000 | [diff] [blame] | 494 | $(VERB) rm -f $(TOOLEXENAMES) |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 495 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 496 | $(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(DESTTOOLDEBUG)/.dir |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 497 | @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG)======= |
| 498 | $(VERB) $(LinkG) -o $@ $(ObjectsG) $(LIB_OPTS_G) $(LINK_OPTS) |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 499 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 500 | $(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(DESTTOOLRELEASE)/.dir |
Chris Lattner | 287d443 | 2002-09-12 17:02:40 +0000 | [diff] [blame] | 501 | @echo ======= Linking $(TOOLNAME) release executable ======= |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 502 | $(VERB) $(LinkO) -o $@ $(ObjectsO) $(LIB_OPTS_O) $(LINK_OPTS) |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 503 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 504 | $(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(DESTTOOLPROFILE)/.dir |
Vikram S. Adve | 41e7891 | 2002-09-20 14:03:13 +0000 | [diff] [blame] | 505 | @echo ======= Linking $(TOOLNAME) profile executable ======= |
Dinakar Dhurjati | ffb55cd | 2003-05-29 16:18:20 +0000 | [diff] [blame] | 506 | $(VERB) $(LinkP) -o $@ $(ObjectsP) $(LIB_OPTS_P) $(LINK_OPTS) |
Vikram S. Adve | 41e7891 | 2002-09-20 14:03:13 +0000 | [diff] [blame] | 507 | |
Chris Lattner | 1cbc29f | 2001-09-07 22:57:58 +0000 | [diff] [blame] | 508 | endif |
| 509 | |
| 510 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 511 | |
| 512 | #--------------------------------------------------------- |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 513 | .PRECIOUS: $(BUILD_OBJ_DIR)/Depend/.dir |
| 514 | .PRECIOUS: $(BUILD_OBJ_DIR)/Debug/.dir $(BUILD_OBJ_DIR)/Release/.dir |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 515 | |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 516 | # Create .o files in the ObjectFiles directory from the .cpp and .c files... |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 517 | $(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Release/.dir |
Misha Brukman | b5f096f | 2002-09-12 16:05:39 +0000 | [diff] [blame] | 518 | @echo "Compiling $<" |
| 519 | $(VERB) $(CompileO) $< -o $@ |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 520 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 521 | $(BUILD_OBJ_DIR)/Release/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Release/.dir |
Chris Lattner | 1eeac66 | 2002-10-22 23:28:23 +0000 | [diff] [blame] | 522 | $(VERB) $(CompileCO) $< -o $@ |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 523 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 524 | $(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Profile/.dir |
Vikram S. Adve | 41e7891 | 2002-09-20 14:03:13 +0000 | [diff] [blame] | 525 | @echo "Compiling $<" |
| 526 | $(VERB) $(CompileP) $< -o $@ |
| 527 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 528 | $(BUILD_OBJ_DIR)/Profile/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Profile/.dir |
Chris Lattner | 172b648 | 2002-09-22 02:47:15 +0000 | [diff] [blame] | 529 | @echo "Compiling $<" |
| 530 | $(VERB) $(CompileCP) $< -o $@ |
| 531 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 532 | $(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Debug/.dir |
Misha Brukman | b5f096f | 2002-09-12 16:05:39 +0000 | [diff] [blame] | 533 | @echo "Compiling $<" |
| 534 | $(VERB) $(CompileG) $< -o $@ |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 535 | |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 536 | $(BUILD_OBJ_DIR)/Debug/%.o: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Debug/.dir |
Chris Lattner | 172b648 | 2002-09-22 02:47:15 +0000 | [diff] [blame] | 537 | $(VERB) $(CompileCG) $< -o $@ |
Vikram S. Adve | 112a72c | 2001-07-15 13:16:47 +0000 | [diff] [blame] | 538 | |
Chris Lattner | e899678 | 2003-01-16 22:44:19 +0000 | [diff] [blame] | 539 | # |
| 540 | # Rules for building lex/yacc files |
| 541 | # |
| 542 | LEX_FILES = $(filter %.l, $(Source)) |
| 543 | LEX_OUTPUT = $(LEX_FILES:%.l=%.cpp) |
| 544 | YACC_FILES = $(filter %.y, $(Source)) |
| 545 | YACC_OUTPUT = $(addprefix $(YACC_FILES:%.y=%), .h .cpp .output) |
| 546 | .PRECIOUS: $(LEX_OUTPUT) $(YACC_OUTPUT) |
| 547 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 548 | # Create a .cpp source file from a flex input file... this uses sed to cut down |
| 549 | # on the warnings emited by GCC... |
Chris Lattner | 6d131b4 | 2003-01-23 16:33:10 +0000 | [diff] [blame] | 550 | # |
| 551 | # The last line is a gross hack to work around flex aparently not being able to |
| 552 | # resize the buffer on a large token input. Currently, for uninitialized string |
| 553 | # buffers in LLVM we can generate very long tokens, so this is a hack around it. |
| 554 | # FIXME. (f.e. char Buffer[10000]; ) |
| 555 | # |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 556 | %.cpp: %.l |
John Criswell | 65aa5934 | 2003-05-29 18:52:10 +0000 | [diff] [blame] | 557 | $(FLEX) -t $< | sed '/^find_rule/d' | \ |
Chris Lattner | 6d131b4 | 2003-01-23 16:33:10 +0000 | [diff] [blame] | 558 | sed 's/void yyunput/inline void yyunput/' | \ |
| 559 | sed 's/void \*yy_flex_realloc/inline void *yy_flex_realloc/' | \ |
| 560 | sed 's/#define YY_BUF_SIZE 16384/#define YY_BUF_SIZE (16384*64)/' > $@ |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 561 | |
| 562 | # Rule for building the bison parsers... |
Chris Lattner | 694c5df | 2003-05-15 21:28:55 +0000 | [diff] [blame] | 563 | %.c: %.y # Cancel built-in rules for yacc |
| 564 | %.h: %.y # Cancel built-in rules for yacc |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 565 | %.cpp %.h : %.y |
Chris Lattner | 694c5df | 2003-05-15 21:28:55 +0000 | [diff] [blame] | 566 | @echo Bison\'ing $<... |
Chris Lattner | e899678 | 2003-01-16 22:44:19 +0000 | [diff] [blame] | 567 | $(VERB) $(BISON) -v -d -p $(<:%Parser.y=%) $*.y |
| 568 | $(VERB) mv -f $*.tab.c $*.cpp |
| 569 | $(VERB) mv -f $*.tab.h $*.h |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 570 | |
| 571 | # To create the directories... |
| 572 | %/.dir: |
Chris Lattner | e899678 | 2003-01-16 22:44:19 +0000 | [diff] [blame] | 573 | $(VERB) mkdir -p $* |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 574 | @date > $@ |
| 575 | |
Chris Lattner | 30440c6 | 2003-01-16 21:06:18 +0000 | [diff] [blame] | 576 | # To create postscript files from dot files... |
| 577 | %.ps: %.dot |
| 578 | dot -Tps < $< > $@ |
| 579 | |
Chris Lattner | 172b648 | 2002-09-22 02:47:15 +0000 | [diff] [blame] | 580 | # 'make clean' nukes the tree |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 581 | clean:: |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 582 | $(VERB) rm -rf $(BUILD_OBJ_DIR)/Debug $(BUILD_OBJ_DIR)/Release $(BUILD_OBJ_DIR)/Profile $(BUILD_OBJ_DIR)/Depend |
Misha Brukman | ab6d293 | 2002-12-04 17:08:15 +0000 | [diff] [blame] | 583 | $(VERB) rm -f core core.[0-9][0-9]* *.o *.d *.so *~ *.flc |
Chris Lattner | e899678 | 2003-01-16 22:44:19 +0000 | [diff] [blame] | 584 | $(VERB) rm -f $(LEX_OUTPUT) $(YACC_OUTPUT) |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 585 | |
Chris Lattner | 694c5df | 2003-05-15 21:28:55 +0000 | [diff] [blame] | 586 | # If dependencies were generated for the file that included this file, |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 587 | # include the dependancies now... |
| 588 | # |
Chris Lattner | 694c5df | 2003-05-15 21:28:55 +0000 | [diff] [blame] | 589 | SourceBaseNames := $(basename $(notdir $(filter-out Debug/%, $(Source)))) |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 590 | SourceDepend := $(SourceBaseNames:%=$(BUILD_OBJ_DIR)/Depend/%.d) |
Chris Lattner | 694c5df | 2003-05-15 21:28:55 +0000 | [diff] [blame] | 591 | |
| 592 | # Create dependencies for the *.cpp files... |
| 593 | #$(SourceDepend): \x |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 594 | $(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.cpp $(BUILD_OBJ_DIR)/Depend/.dir |
| 595 | $(VERB) $(Depend) $< | sed 's|$*\.o *|$(BUILD_OBJ_DIR)/Release/& $(BUILD_OBJ_DIR)/Profile/& $(BUILD_OBJ_DIR)/Debug/& $(BUILD_OBJ_DIR)/Depend/$(@F)|g' > $@ |
Chris Lattner | 694c5df | 2003-05-15 21:28:55 +0000 | [diff] [blame] | 596 | |
| 597 | # Create dependencies for the *.c files... |
| 598 | #$(SourceDepend): \x |
John Criswell | 8bff509 | 2003-06-11 13:55:44 +0000 | [diff] [blame^] | 599 | $(BUILD_OBJ_DIR)/Depend/%.d: $(SourceDir)%.c $(BUILD_OBJ_DIR)/Depend/.dir |
Chris Lattner | 694c5df | 2003-05-15 21:28:55 +0000 | [diff] [blame] | 600 | $(VERB) $(DependC) $< | sed 's|$*\.o *|Release/& Profile/& Debug/& Depend/$(@F)|g' > $@ |
| 601 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 602 | ifneq ($(SourceDepend),) |
Chris Lattner | ed03bc9 | 2002-10-25 14:32:42 +0000 | [diff] [blame] | 603 | -include $(SourceDepend) |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 604 | endif |