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