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