Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 1 | #---------------------------------------------------------------------- |
| 2 | # Clients fill in the source files to build |
| 3 | #---------------------------------------------------------------------- |
| 4 | # C_SOURCES := main.c |
| 5 | # CXX_SOURCES := |
| 6 | # OBJC_SOURCES := |
| 7 | # OBJCXX_SOURCES := |
| 8 | # DYLIB_C_SOURCES := |
Johnny Chen | e9f9770 | 2012-01-11 01:42:58 +0000 | [diff] [blame] | 9 | # DYLIB_CXX_SOURCES := |
| 10 | # |
| 11 | # Specifying DYLIB_ONLY has the effect of building dylib only, skipping |
| 12 | # the building of the a.out executable program. For example, |
| 13 | # DYLIB_ONLY := YES |
| 14 | # |
Johnny Chen | 64a7e74 | 2012-01-17 00:58:08 +0000 | [diff] [blame] | 15 | # Also might be of interest: |
Johnny Chen | 4876b5f | 2012-01-11 01:59:55 +0000 | [diff] [blame] | 16 | # FRAMEWORK_INCLUDES (Darwin only) := |
| 17 | # CFLAGS_EXTRAS := |
| 18 | # LD_EXTRAS := |
Johnny Chen | 64a7e74 | 2012-01-17 00:58:08 +0000 | [diff] [blame] | 19 | # |
| 20 | # And test/functionalities/archives/Makefile: |
| 21 | # MAKE_DSYM := NO |
| 22 | # ARCHIVE_NAME := libfoo.a |
| 23 | # ARCHIVE_C_SOURCES := a.c b.c |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 24 | |
| 25 | # Uncomment line below for debugging shell commands |
| 26 | # SHELL = /bin/sh -x |
| 27 | |
| 28 | #---------------------------------------------------------------------- |
Johnny Chen | 6c17c08 | 2010-09-16 20:54:06 +0000 | [diff] [blame] | 29 | # If ARCH is not defined, default to x86_64. |
Peter Collingbourne | 518f03d | 2011-06-20 19:06:04 +0000 | [diff] [blame] | 30 | # If OS is not defined, use 'uname -s' to determine the OS name. |
Johnny Chen | 6c17c08 | 2010-09-16 20:54:06 +0000 | [diff] [blame] | 31 | #---------------------------------------------------------------------- |
| 32 | ifeq "$(ARCH)" "" |
| 33 | ARCH = x86_64 |
| 34 | endif |
| 35 | |
Peter Collingbourne | 518f03d | 2011-06-20 19:06:04 +0000 | [diff] [blame] | 36 | ifeq "$(OS)" "" |
| 37 | OS = $(shell uname -s) |
| 38 | endif |
| 39 | |
Johnny Chen | 6c17c08 | 2010-09-16 20:54:06 +0000 | [diff] [blame] | 40 | #---------------------------------------------------------------------- |
Johnny Chen | 597cbbb | 2011-08-23 21:54:10 +0000 | [diff] [blame] | 41 | # CC defaults to clang. |
Johnny Chen | 4ab4a9b | 2011-08-24 18:12:53 +0000 | [diff] [blame] | 42 | # |
| 43 | # If you change the defaults of CC, be sure to also change it in the file |
| 44 | # test/plugins/builder_base.py, which provides a Python way to return the |
| 45 | # value of the make variable CC -- getCompiler(). |
| 46 | # |
Johnny Chen | 6055b44 | 2011-01-14 20:55:13 +0000 | [diff] [blame] | 47 | # See also these functions: |
| 48 | # o cxx_compiler |
| 49 | # o cxx_linker |
Johnny Chen | d43e208 | 2011-01-14 20:46:49 +0000 | [diff] [blame] | 50 | #---------------------------------------------------------------------- |
Johnny Chen | 597cbbb | 2011-08-23 21:54:10 +0000 | [diff] [blame] | 51 | CC ?= clang |
Johnny Chen | d43e208 | 2011-01-14 20:46:49 +0000 | [diff] [blame] | 52 | ifeq "$(CC)" "cc" |
Johnny Chen | 597cbbb | 2011-08-23 21:54:10 +0000 | [diff] [blame] | 53 | CC = clang |
Johnny Chen | d43e208 | 2011-01-14 20:46:49 +0000 | [diff] [blame] | 54 | endif |
| 55 | |
| 56 | #---------------------------------------------------------------------- |
Daniel Malea | 2745d84 | 2013-01-25 00:31:48 +0000 | [diff] [blame] | 57 | # ARCHFLAG is the flag used to tell the compiler which architecture |
| 58 | # to compile for. The default is the flag that clang accepts. |
| 59 | #---------------------------------------------------------------------- |
| 60 | ARCHFLAG ?= -arch |
| 61 | |
| 62 | #---------------------------------------------------------------------- |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 63 | # Change any build/tool options needed |
| 64 | #---------------------------------------------------------------------- |
Peter Collingbourne | 518f03d | 2011-06-20 19:06:04 +0000 | [diff] [blame] | 65 | ifeq "$(OS)" "Darwin" |
Greg Clayton | 3bffb08 | 2011-12-10 02:15:28 +0000 | [diff] [blame] | 66 | DS := dsymutil |
Peter Collingbourne | 518f03d | 2011-06-20 19:06:04 +0000 | [diff] [blame] | 67 | DSFLAGS = |
| 68 | DSYM = $(EXE).dSYM |
Johnny Chen | fe14162 | 2012-01-12 23:09:42 +0000 | [diff] [blame] | 69 | AR := libtool |
| 70 | ARFLAGS := -static -o |
Daniel Malea | 2745d84 | 2013-01-25 00:31:48 +0000 | [diff] [blame] | 71 | else |
| 72 | # On non-Apple platforms, -arch becomes -m |
| 73 | ARCHFLAG := -m |
| 74 | |
| 75 | # i386 becomes 32, and x86_64 becomes 64 |
| 76 | ifeq "$(ARCH)" "x86_64" |
| 77 | override ARCH := $(subst x86_64,64,$(ARCH)) |
| 78 | endif |
| 79 | ifeq "$(ARCH)" "i386" |
| 80 | override ARCH := $(subst i386,32,$(ARCH)) |
| 81 | endif |
Peter Collingbourne | 518f03d | 2011-06-20 19:06:04 +0000 | [diff] [blame] | 82 | endif |
| 83 | |
Greg Clayton | e595c6b | 2013-02-28 18:47:39 +0000 | [diff] [blame] | 84 | CFLAGS ?= -g -O0 |
Daniel Malea | 2745d84 | 2013-01-25 00:31:48 +0000 | [diff] [blame] | 85 | CFLAGS += $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) |
| 86 | |
Johnny Chen | 53e2edb | 2011-08-09 20:07:16 +0000 | [diff] [blame] | 87 | CXXFLAGS +=$(CFLAGS) |
| 88 | LD = $(CC) |
| 89 | LDFLAGS ?= $(CFLAGS) |
Daniel Malea | 2745d84 | 2013-01-25 00:31:48 +0000 | [diff] [blame] | 90 | LDFLAGS += $(LD_EXTRAS) |
Johnny Chen | 53e2edb | 2011-08-09 20:07:16 +0000 | [diff] [blame] | 91 | OBJECTS = |
| 92 | EXE ?= a.out |
| 93 | |
Daniel Malea | 2745d84 | 2013-01-25 00:31:48 +0000 | [diff] [blame] | 94 | ifneq (,$(findstring g++,$(CXX))) |
| 95 | # GCC 4.6 cannot handle -std=c++11, so replace it with -std=c++0x |
| 96 | # instead. FIXME: remove once GCC version is upgraded. |
| 97 | override CXXFLAGS := $(subst -std=c++11,-std=c++0x,$(CXXFLAGS)) |
| 98 | endif |
| 99 | |
Peter Collingbourne | 518f03d | 2011-06-20 19:06:04 +0000 | [diff] [blame] | 100 | ifneq "$(DYLIB_NAME)" "" |
| 101 | ifeq "$(OS)" "Darwin" |
| 102 | DYLIB_FILENAME = lib$(DYLIB_NAME).dylib |
| 103 | else |
| 104 | DYLIB_FILENAME = lib$(DYLIB_NAME).so |
| 105 | endif |
| 106 | endif |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 107 | |
Johnny Chen | bdb4efc | 2011-01-14 18:19:53 +0000 | [diff] [blame] | 108 | # Function that returns the counterpart C++ compiler, given $(CC) as arg. |
Matt Kopec | f99f0b8 | 2013-03-15 21:55:13 +0000 | [diff] [blame] | 109 | cxx_compiler = $(if $(findstring clang,$(1)), $(subst clang,clang++,$(1)), $(if $(findstring icc,$(1)), $(subst icc,icpc,$(1)), $(if $(findstring llvm-gcc,$(1)), $(subst llvm-gcc,llvm-g++,$(1)), $(subst gcc,g++,$(1))))) |
Johnny Chen | bdb4efc | 2011-01-14 18:19:53 +0000 | [diff] [blame] | 110 | |
| 111 | # Function that returns the C++ linker, given $(CC) as arg. |
Matt Kopec | f99f0b8 | 2013-03-15 21:55:13 +0000 | [diff] [blame] | 112 | cxx_linker = $(if $(findstring clang,$(1)), $(subst clang,clang++,$(1)), $(if $(findstring icc,$(1)), $(subst icc,icpc,$(1)), $(if $(findstring llvm-gcc,$(1)), $(subst llvm-gcc,llvm-g++,$(1)), $(subst gcc,g++,$(1))))) |
Johnny Chen | 832d233 | 2010-09-30 01:22:34 +0000 | [diff] [blame] | 113 | |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 114 | #---------------------------------------------------------------------- |
Daniel Malea | c7ffa7a | 2013-06-05 19:32:34 +0000 | [diff] [blame^] | 115 | # C++ standard library options |
| 116 | #---------------------------------------------------------------------- |
| 117 | ifeq (1,$(USE_LIBSTDCPP)) |
| 118 | # Clang requires an extra flag: -stdlib=libstdc++ |
| 119 | ifneq (,$(findstring clang,$(CC))) |
| 120 | CFLAGS += -stdlib=libstdc++ |
| 121 | LDFLAGS += -stdlib=libstdc++ |
| 122 | endif |
| 123 | endif |
| 124 | |
| 125 | #---------------------------------------------------------------------- |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 126 | # dylib settings |
| 127 | #---------------------------------------------------------------------- |
| 128 | ifneq "$(strip $(DYLIB_C_SOURCES))" "" |
| 129 | DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o)) |
| 130 | endif |
| 131 | |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 132 | ifneq "$(strip $(DYLIB_OBJC_SOURCES))" "" |
| 133 | DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o)) |
| 134 | endif |
| 135 | |
Greg Clayton | d50d238 | 2012-01-10 00:00:15 +0000 | [diff] [blame] | 136 | ifneq "$(strip $(DYLIB_CXX_SOURCES))" "" |
| 137 | DYLIB_OBJECTS +=$(strip $(DYLIB_CXX_SOURCES:.cpp=.o)) |
| 138 | CXX = $(call cxx_compiler,$(CC)) |
| 139 | LD = $(call cxx_linker,$(CC)) |
| 140 | endif |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 141 | |
| 142 | #---------------------------------------------------------------------- |
| 143 | # Check if we have any C source files |
| 144 | #---------------------------------------------------------------------- |
| 145 | ifneq "$(strip $(C_SOURCES))" "" |
| 146 | OBJECTS +=$(strip $(C_SOURCES:.c=.o)) |
| 147 | endif |
| 148 | |
| 149 | #---------------------------------------------------------------------- |
| 150 | # Check if we have any C++ source files |
| 151 | #---------------------------------------------------------------------- |
| 152 | ifneq "$(strip $(CXX_SOURCES))" "" |
| 153 | OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o)) |
Johnny Chen | 832d233 | 2010-09-30 01:22:34 +0000 | [diff] [blame] | 154 | CXX = $(call cxx_compiler,$(CC)) |
Johnny Chen | bdb4efc | 2011-01-14 18:19:53 +0000 | [diff] [blame] | 155 | LD = $(call cxx_linker,$(CC)) |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 156 | endif |
| 157 | |
| 158 | #---------------------------------------------------------------------- |
| 159 | # Check if we have any ObjC source files |
| 160 | #---------------------------------------------------------------------- |
| 161 | ifneq "$(strip $(OBJC_SOURCES))" "" |
| 162 | OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o)) |
| 163 | LDFLAGS +=-lobjc |
| 164 | endif |
| 165 | |
| 166 | #---------------------------------------------------------------------- |
| 167 | # Check if we have any ObjC++ source files |
| 168 | #---------------------------------------------------------------------- |
| 169 | ifneq "$(strip $(OBJCXX_SOURCES))" "" |
| 170 | OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o)) |
Johnny Chen | 832d233 | 2010-09-30 01:22:34 +0000 | [diff] [blame] | 171 | CXX = $(call cxx_compiler,$(CC)) |
Johnny Chen | bdb4efc | 2011-01-14 18:19:53 +0000 | [diff] [blame] | 172 | LD = $(call cxx_linker,$(CC)) |
Johnny Chen | 8da4ddf | 2012-04-24 23:05:07 +0000 | [diff] [blame] | 173 | ifeq "$(findstring lobjc,$(LDFLAGS))" "" |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 174 | LDFLAGS +=-lobjc |
| 175 | endif |
| 176 | endif |
| 177 | |
Johnny Chen | fe14162 | 2012-01-12 23:09:42 +0000 | [diff] [blame] | 178 | #---------------------------------------------------------------------- |
| 179 | # Check if we have any C source files for archive |
| 180 | #---------------------------------------------------------------------- |
| 181 | ifneq "$(strip $(ARCHIVE_C_SOURCES))" "" |
| 182 | ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_C_SOURCES:.c=.o)) |
| 183 | endif |
| 184 | |
| 185 | #---------------------------------------------------------------------- |
| 186 | # Check if we have any C++ source files for archive |
| 187 | #---------------------------------------------------------------------- |
| 188 | ifneq "$(strip $(ARCHIVE_CXX_SOURCES))" "" |
| 189 | ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_CXX_SOURCES:.cpp=.o)) |
| 190 | CXX = $(call cxx_compiler,$(CC)) |
| 191 | LD = $(call cxx_linker,$(CC)) |
| 192 | endif |
| 193 | |
| 194 | #---------------------------------------------------------------------- |
| 195 | # Check if we have any ObjC source files for archive |
| 196 | #---------------------------------------------------------------------- |
| 197 | ifneq "$(strip $(ARCHIVE_OBJC_SOURCES))" "" |
| 198 | ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJC_SOURCES:.m=.o)) |
| 199 | LDFLAGS +=-lobjc |
| 200 | endif |
| 201 | |
| 202 | #---------------------------------------------------------------------- |
| 203 | # Check if we have any ObjC++ source files for archive |
| 204 | #---------------------------------------------------------------------- |
| 205 | ifneq "$(strip $(ARCHIVE_OBJCXX_SOURCES))" "" |
| 206 | ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJCXX_SOURCES:.mm=.o)) |
| 207 | CXX = $(call cxx_compiler,$(CC)) |
| 208 | LD = $(call cxx_linker,$(CC)) |
Johnny Chen | 8da4ddf | 2012-04-24 23:05:07 +0000 | [diff] [blame] | 209 | ifeq "$(findstring lobjc,$(LDFLAGS))" "" |
Johnny Chen | fe14162 | 2012-01-12 23:09:42 +0000 | [diff] [blame] | 210 | LDFLAGS +=-lobjc |
| 211 | endif |
| 212 | endif |
| 213 | |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 214 | |
| 215 | #---------------------------------------------------------------------- |
Johnny Chen | beac8f9 | 2012-01-10 00:41:11 +0000 | [diff] [blame] | 216 | # DYLIB_ONLY variable can be used to skip the building of a.out. |
| 217 | # See the sections below regarding dSYM file as well as the building of |
| 218 | # EXE from all the objects. |
| 219 | #---------------------------------------------------------------------- |
| 220 | |
| 221 | #---------------------------------------------------------------------- |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 222 | # Make the dSYM file from the executable if $(MAKE_DSYM) != "NO" |
| 223 | #---------------------------------------------------------------------- |
Peter Collingbourne | 518f03d | 2011-06-20 19:06:04 +0000 | [diff] [blame] | 224 | ifeq "$(OS)" "Darwin" |
Johnny Chen | 9101639 | 2011-06-20 20:08:26 +0000 | [diff] [blame] | 225 | ifneq "$(MAKE_DSYM)" "NO" |
Johnny Chen | beac8f9 | 2012-01-10 00:41:11 +0000 | [diff] [blame] | 226 | ifeq "$(DYLIB_ONLY)" "" |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 227 | $(DSYM) : $(EXE) |
| 228 | $(DS) $(DSFLAGS) -o "$(DSYM)" "$(EXE)" |
Johnny Chen | 9101639 | 2011-06-20 20:08:26 +0000 | [diff] [blame] | 229 | endif |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 230 | endif |
Johnny Chen | beac8f9 | 2012-01-10 00:41:11 +0000 | [diff] [blame] | 231 | endif |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 232 | |
| 233 | #---------------------------------------------------------------------- |
| 234 | # Compile the executable from all the objects. |
| 235 | #---------------------------------------------------------------------- |
Johnny Chen | beac8f9 | 2012-01-10 00:41:11 +0000 | [diff] [blame] | 236 | ifneq "$(DYLIB_NAME)" "" |
| 237 | ifeq "$(DYLIB_ONLY)" "" |
Johnny Chen | fe14162 | 2012-01-12 23:09:42 +0000 | [diff] [blame] | 238 | $(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME) |
| 239 | $(LD) $(LDFLAGS) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) -o "$(EXE)" |
Johnny Chen | beac8f9 | 2012-01-10 00:41:11 +0000 | [diff] [blame] | 240 | else |
| 241 | EXE = $(DYLIB_FILENAME) |
| 242 | endif |
| 243 | else |
Johnny Chen | fe14162 | 2012-01-12 23:09:42 +0000 | [diff] [blame] | 244 | $(EXE) : $(OBJECTS) $(ARCHIVE_NAME) |
Daniel Malea | 2745d84 | 2013-01-25 00:31:48 +0000 | [diff] [blame] | 245 | $(LD) $(OBJECTS) $(LDFLAGS) $(ARCHIVE_NAME) -o "$(EXE)" |
Johnny Chen | fe14162 | 2012-01-12 23:09:42 +0000 | [diff] [blame] | 246 | endif |
| 247 | |
| 248 | #---------------------------------------------------------------------- |
| 249 | # Make the archive |
| 250 | #---------------------------------------------------------------------- |
| 251 | ifneq "$(ARCHIVE_NAME)" "" |
| 252 | ifeq "$(OS)" "Darwin" |
| 253 | $(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS) |
| 254 | $(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS) |
| 255 | $(RM) $(ARCHIVE_OBJECTS) |
| 256 | else |
| 257 | $(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj))) |
| 258 | endif |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 259 | endif |
| 260 | |
| 261 | #---------------------------------------------------------------------- |
| 262 | # Make the dylib |
| 263 | #---------------------------------------------------------------------- |
Peter Collingbourne | 518f03d | 2011-06-20 19:06:04 +0000 | [diff] [blame] | 264 | $(DYLIB_FILENAME) : $(DYLIB_OBJECTS) |
| 265 | ifeq "$(OS)" "Darwin" |
| 266 | $(LD) $(LDFLAGS) $(DYLIB_OBJECTS) -install_name "@executable_path/$(DYLIB_FILENAME)" -dynamiclib -o "$(DYLIB_FILENAME)" |
Greg Clayton | 0c9773c | 2012-09-20 21:43:11 +0000 | [diff] [blame] | 267 | ifneq "$(MAKE_DSYM)" "NO" |
| 268 | ifneq "$(DS)" "" |
| 269 | $(DS) $(DSFLAGS) "$(DYLIB_FILENAME)" |
| 270 | endif |
| 271 | endif |
Peter Collingbourne | 518f03d | 2011-06-20 19:06:04 +0000 | [diff] [blame] | 272 | else |
| 273 | $(LD) $(LDFLAGS) $(DYLIB_OBJECTS) -shared -o "$(DYLIB_FILENAME)" |
| 274 | endif |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 275 | |
| 276 | #---------------------------------------------------------------------- |
| 277 | # Automatic variables based on items already entered. Below we create |
| 278 | # an objects lists from the list of sources by replacing all entries |
| 279 | # that end with .c with .o, and we also create a list of prerequisite |
| 280 | # files by replacing all .c files with .d. |
| 281 | #---------------------------------------------------------------------- |
| 282 | PREREQS := $(OBJECTS:.o=.d) |
Johnny Chen | e3dc0f0 | 2010-08-24 16:35:00 +0000 | [diff] [blame] | 283 | ifneq "$(DYLIB_NAME)" "" |
| 284 | DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d) |
| 285 | endif |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 286 | |
| 287 | #---------------------------------------------------------------------- |
| 288 | # Rule for Generating Prerequisites Automatically using .d files and |
| 289 | # the compiler -MM option. The -M option will list all system headers, |
| 290 | # and the -MM option will list all non-system dependencies. |
| 291 | #---------------------------------------------------------------------- |
| 292 | %.d: %.c |
| 293 | @set -e; rm -f $@; \ |
Johnny Chen | 189bff1 | 2011-08-04 20:44:56 +0000 | [diff] [blame] | 294 | $(CC) -M $(CFLAGS) $< > $@.$$$$; \ |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 295 | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ |
| 296 | rm -f $@.$$$$ |
| 297 | |
| 298 | %.d: %.cpp |
| 299 | @set -e; rm -f $@; \ |
Johnny Chen | 189bff1 | 2011-08-04 20:44:56 +0000 | [diff] [blame] | 300 | $(CC) -M $(CXXFLAGS) $< > $@.$$$$; \ |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 301 | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ |
| 302 | rm -f $@.$$$$ |
| 303 | |
| 304 | %.d: %.m |
| 305 | @set -e; rm -f $@; \ |
Johnny Chen | 189bff1 | 2011-08-04 20:44:56 +0000 | [diff] [blame] | 306 | $(CC) -M $(CFLAGS) $< > $@.$$$$; \ |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 307 | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ |
| 308 | rm -f $@.$$$$ |
| 309 | |
| 310 | %.d: %.mm |
| 311 | @set -e; rm -f $@; \ |
Johnny Chen | 189bff1 | 2011-08-04 20:44:56 +0000 | [diff] [blame] | 312 | $(CC) -M $(CXXFLAGS) $< > $@.$$$$; \ |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 313 | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ |
| 314 | rm -f $@.$$$$ |
| 315 | |
| 316 | #---------------------------------------------------------------------- |
| 317 | # Include all of the makefiles for each source file so we don't have |
| 318 | # to manually track all of the prerequisites for each source file. |
| 319 | #---------------------------------------------------------------------- |
| 320 | sinclude $(PREREQS) |
Johnny Chen | e3dc0f0 | 2010-08-24 16:35:00 +0000 | [diff] [blame] | 321 | ifneq "$(DYLIB_NAME)" "" |
| 322 | sinclude $(DYLIB_PREREQS) |
| 323 | endif |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 324 | |
Johnny Chen | 8da4ddf | 2012-04-24 23:05:07 +0000 | [diff] [blame] | 325 | # Define a suffix rule for .mm -> .o |
| 326 | .SUFFIXES: .mm .o |
| 327 | .mm.o: |
| 328 | $(CXX) $(CXXFLAGS) -c $< |
| 329 | |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 330 | .PHONY: clean |
| 331 | dsym: $(DSYM) |
| 332 | all: $(EXE) $(DSYM) |
Johnny Chen | e1030cd | 2010-09-27 20:44:46 +0000 | [diff] [blame] | 333 | clean:: |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 334 | ifeq "$(DYLIB_NAME)" "" |
Johnny Chen | fe14162 | 2012-01-12 23:09:42 +0000 | [diff] [blame] | 335 | rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS) |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 336 | else |
Johnny Chen | fe14162 | 2012-01-12 23:09:42 +0000 | [diff] [blame] | 337 | rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).dSYM |
Johnny Chen | 9bc867a | 2010-08-23 23:56:08 +0000 | [diff] [blame] | 338 | endif |
Johnny Chen | fa38041 | 2011-01-14 21:18:12 +0000 | [diff] [blame] | 339 | |
| 340 | #---------------------------------------------------------------------- |
| 341 | # From http://blog.melski.net/tag/debugging-makefiles/ |
| 342 | # |
| 343 | # Usage: make print-CC print-CXX print-LD |
| 344 | #---------------------------------------------------------------------- |
| 345 | print-%: |
| 346 | @echo '$*=$($*)' |
| 347 | @echo ' origin = $(origin $*)' |
| 348 | @echo ' flavor = $(flavor $*)' |
| 349 | @echo ' value = $(value $*)' |
Johnny Chen | 8b2c321 | 2011-01-28 17:22:29 +0000 | [diff] [blame] | 350 | |
| 351 | |
| 352 | ### Local Variables: ### |
| 353 | ### mode:makefile ### |
| 354 | ### End: ### |