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