blob: c7118b73e2d5adfdd33093830d99d67a66e51518 [file] [log] [blame]
Johnny Chen9bc867a2010-08-23 23:56:08 +00001#----------------------------------------------------------------------
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 Chene9f97702012-01-11 01:42:58 +00009# 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 Chen64a7e742012-01-17 00:58:08 +000015# Also might be of interest:
Johnny Chen4876b5f2012-01-11 01:59:55 +000016# FRAMEWORK_INCLUDES (Darwin only) :=
Robert Flackfa8aa172015-04-20 18:07:55 +000017# CFLAGS_EXTRAS :=
Johnny Chen4876b5f2012-01-11 01:59:55 +000018# LD_EXTRAS :=
Michael Sartain802b0552013-07-02 18:13:13 +000019# SPLIT_DEBUG_SYMBOLS := YES
Robert Flackfa8aa172015-04-20 18:07:55 +000020# CROSS_COMPILE :=
Johnny Chen64a7e742012-01-17 00:58:08 +000021#
22# And test/functionalities/archives/Makefile:
23# MAKE_DSYM := NO
24# ARCHIVE_NAME := libfoo.a
25# ARCHIVE_C_SOURCES := a.c b.c
Johnny Chen9bc867a2010-08-23 23:56:08 +000026
27# Uncomment line below for debugging shell commands
28# SHELL = /bin/sh -x
29
Zachary Turnerc7826522014-08-13 17:44:53 +000030THIS_FILE_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/
31LLDB_BASE_DIR := $(THIS_FILE_DIR)../../
32
Greg Clayton315b88d2015-06-02 21:38:10 +000033
34#----------------------------------------------------------------------
35# If TRIPLE is not defined try to set the ARCH, CC, CFLAGS, and more
36# from the triple alone
37#----------------------------------------------------------------------
38TRIPLE_CFLAGS :=
39ifneq "$(TRIPLE)" ""
40 triple_space = $(subst -, ,$(TRIPLE))
41 ARCH =$(word 1, $(triple_space))
42 TRIPLE_VENDOR =$(word 2, $(triple_space))
43 triple_os_and_version =$(shell echo $(word 3, $(triple_space)) | sed -e 's/\(.*\)\([0-9]\.[0-9]\).*/\1 \2/')
44 TRIPLE_OS =$(word 1, $(triple_os_and_version))
45 TRIPLE_VERSION =$(word 2, $(triple_os_and_version))
Greg Clayton315b88d2015-06-02 21:38:10 +000046 ifeq "$(TRIPLE_VENDOR)" "apple"
47 ifeq "$(TRIPLE_OS)" "ios"
48 ifeq "$(SDKROOT)" ""
49 # Set SDKROOT if it wasn't set
50 ifneq (,$(findstring arm,$(ARCH)))
51 SDKROOT = $(shell xcrun --sdk iphoneos --show-sdk-path)
Greg Clayton5e3f20d2015-06-02 21:42:31 +000052 ifeq "$(TRIPLE_VERSION)" ""
53 TRIPLE_VERSION =$(shell echo $(notdir $(SDKROOT)) | sed -e 's/.*\([0-9]\.[0-9]\).*/\1/')
54 endif
Greg Clayton315b88d2015-06-02 21:38:10 +000055 TRIPLE_CFLAGS :=-mios-version-min=$(TRIPLE_VERSION) -isysroot "$(SDKROOT)"
56 else
57 SDKROOT = $(shell xcrun --sdk iphonesimulator --show-sdk-path)
Greg Clayton5e3f20d2015-06-02 21:42:31 +000058 ifeq "$(TRIPLE_VERSION)" ""
59 TRIPLE_VERSION =$(shell echo $(notdir $(SDKROOT)) | sed -e 's/.*\([0-9]\.[0-9]\).*/\1/')
60 endif
Greg Clayton315b88d2015-06-02 21:38:10 +000061 TRIPLE_CFLAGS :=-mios-simulator-version-min=$(TRIPLE_VERSION) -isysroot "$(SDKROOT)"
62 endif
63 endif
Greg Clayton315b88d2015-06-02 21:38:10 +000064 endif
65 endif
66endif
67
Johnny Chen9bc867a2010-08-23 23:56:08 +000068#----------------------------------------------------------------------
Peter Collingbourne518f03d2011-06-20 19:06:04 +000069# If OS is not defined, use 'uname -s' to determine the OS name.
Adrian McCarthyb4b8bb72015-04-15 23:38:23 +000070#
71# uname on Windows gives "windows32", but most environments standardize
72# on "Windows_NT", so we'll make it consistent here. When running
73# tests from Visual Studio, the environment variable isn't inherited
74# all the way down to the process spawned for make.
75#----------------------------------------------------------------------
Chaoren Lind761a952015-09-16 21:51:51 +000076HOST_OS = $(shell uname -s)
77ifeq "$(HOST_OS)" "windows32"
78 HOST_OS = Windows_NT
Adrian McCarthyb4b8bb72015-04-15 23:38:23 +000079endif
Chaoren Lind761a952015-09-16 21:51:51 +000080ifeq "$(OS)" ""
81 OS = $(HOST_OS)
Adrian McCarthyb4b8bb72015-04-15 23:38:23 +000082endif
83
84#----------------------------------------------------------------------
85# If ARCH is not defined, default to x86_64.
Johnny Chen6c17c082010-09-16 20:54:06 +000086#----------------------------------------------------------------------
87ifeq "$(ARCH)" ""
Zachary Turnere068d912014-12-01 23:13:41 +000088ifeq "$(OS)" "Windows_NT"
89 ARCH = x86
90else
Johnny Chen6c17c082010-09-16 20:54:06 +000091 ARCH = x86_64
92endif
Zachary Turnere068d912014-12-01 23:13:41 +000093endif
Johnny Chen6c17c082010-09-16 20:54:06 +000094
95#----------------------------------------------------------------------
Johnny Chen597cbbb2011-08-23 21:54:10 +000096# CC defaults to clang.
Johnny Chen4ab4a9b2011-08-24 18:12:53 +000097#
98# If you change the defaults of CC, be sure to also change it in the file
99# test/plugins/builder_base.py, which provides a Python way to return the
100# value of the make variable CC -- getCompiler().
101#
Johnny Chen6055b442011-01-14 20:55:13 +0000102# See also these functions:
103# o cxx_compiler
104# o cxx_linker
Johnny Chend43e2082011-01-14 20:46:49 +0000105#----------------------------------------------------------------------
Johnny Chen597cbbb2011-08-23 21:54:10 +0000106CC ?= clang
Johnny Chend43e2082011-01-14 20:46:49 +0000107ifeq "$(CC)" "cc"
Vince Harron847e2612015-05-27 04:42:54 +0000108 ifneq "$(shell which clang)" ""
109 CC = clang
110 else ifneq "$(shell which clang-3.5)" ""
111 CC = clang-3.5
112 else ifneq "$(shell which gcc)" ""
113 CC = gcc
114 endif
Johnny Chend43e2082011-01-14 20:46:49 +0000115endif
116
117#----------------------------------------------------------------------
Daniel Malea2745d842013-01-25 00:31:48 +0000118# ARCHFLAG is the flag used to tell the compiler which architecture
119# to compile for. The default is the flag that clang accepts.
120#----------------------------------------------------------------------
Greg Clayton2c93b802015-04-16 01:18:05 +0000121ARCHFLAG ?= -arch
Daniel Malea2745d842013-01-25 00:31:48 +0000122
123#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000124# Change any build/tool options needed
125#----------------------------------------------------------------------
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000126ifeq "$(OS)" "Darwin"
Greg Clayton82625d32014-07-29 20:10:59 +0000127 DS := $(shell xcrun -find -toolchain default dsymutil)
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000128 DSFLAGS =
129 DSYM = $(EXE).dSYM
Robert Flackfa8aa172015-04-20 18:07:55 +0000130 AR := $(CROSS_COMPILE)libtool
Johnny Chenfe141622012-01-12 23:09:42 +0000131 ARFLAGS := -static -o
Daniel Malea2745d842013-01-25 00:31:48 +0000132else
Robert Flackfa8aa172015-04-20 18:07:55 +0000133 AR := $(CROSS_COMPILE)ar
Daniel Malea2745d842013-01-25 00:31:48 +0000134 # On non-Apple platforms, -arch becomes -m
135 ARCHFLAG := -m
136
Zachary Turnerc7826522014-08-13 17:44:53 +0000137 # i386, i686, x86 -> 32
Zachary Turner7c1bc2b2014-07-31 21:07:41 +0000138 # amd64, x86_64, x64 -> 64
Ed Maste4fe0aba2014-02-20 18:40:01 +0000139 ifeq "$(ARCH)" "amd64"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +0000140 override ARCH := $(subst amd64,64,$(ARCH))
Ed Maste4fe0aba2014-02-20 18:40:01 +0000141 endif
Daniel Malea2745d842013-01-25 00:31:48 +0000142 ifeq "$(ARCH)" "x86_64"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +0000143 override ARCH := $(subst x86_64,64,$(ARCH))
144 endif
145 ifeq "$(ARCH)" "x64"
146 override ARCH := $(subst x64,64,$(ARCH))
Daniel Malea2745d842013-01-25 00:31:48 +0000147 endif
Zachary Turnerc7826522014-08-13 17:44:53 +0000148 ifeq "$(ARCH)" "x86"
149 override ARCH := $(subst x86,32,$(ARCH))
150 endif
Daniel Malea2745d842013-01-25 00:31:48 +0000151 ifeq "$(ARCH)" "i386"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +0000152 override ARCH := $(subst i386,32,$(ARCH))
153 endif
154 ifeq "$(ARCH)" "i686"
155 override ARCH := $(subst i686,32,$(ARCH))
Daniel Malea2745d842013-01-25 00:31:48 +0000156 endif
Justin Hibbits3cba1c22014-11-12 15:13:58 +0000157 ifeq "$(ARCH)" "powerpc"
158 override ARCH := $(subst powerpc,32,$(ARCH))
159 endif
160 ifeq "$(ARCH)" "powerpc64"
161 override ARCH := $(subst powerpc64,64,$(ARCH))
162 endif
Tamas Berghammer1e209fc2015-03-13 11:36:47 +0000163 ifeq "$(ARCH)" "aarch64"
164 override ARCH :=
165 override ARCHFLAG :=
166 endif
Michael Sartain802b0552013-07-02 18:13:13 +0000167
168 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
169 DSYM = $(EXE).debug
170 endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000171endif
172
Ilia Kfeda0b72015-05-12 12:13:12 +0000173CFLAGS ?= -g -O0 -fno-builtin
Greg Clayton2c93b802015-04-16 01:18:05 +0000174ifeq "$(OS)" "Darwin"
175 CFLAGS += $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
176else
177 CFLAGS += $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
178endif
Greg Clayton315b88d2015-06-02 21:38:10 +0000179CFLAGS += -include $(THIS_FILE_DIR)test_common.h $(TRIPLE_CFLAGS)
Daniel Malea2745d842013-01-25 00:31:48 +0000180
Jim Ingham4b4b2472014-03-13 02:47:14 +0000181# Use this one if you want to build one part of the result without debug information:
Greg Clayton2c93b802015-04-16 01:18:05 +0000182ifeq "$(OS)" "Darwin"
Greg Clayton315b88d2015-06-02 21:38:10 +0000183 CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) $(TRIPLE_CFLAGS)
Greg Clayton2c93b802015-04-16 01:18:05 +0000184else
Greg Clayton315b88d2015-06-02 21:38:10 +0000185 CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) $(TRIPLE_CFLAGS)
Greg Clayton2c93b802015-04-16 01:18:05 +0000186endif
Jim Ingham4b4b2472014-03-13 02:47:14 +0000187
Zachary Turnerc7826522014-08-13 17:44:53 +0000188CXXFLAGS += -std=c++11
189CXXFLAGS += $(CFLAGS)
Johnny Chen53e2edb2011-08-09 20:07:16 +0000190LD = $(CC)
191LDFLAGS ?= $(CFLAGS)
Daniel Malea2745d842013-01-25 00:31:48 +0000192LDFLAGS += $(LD_EXTRAS)
Tamas Berghammer37099e82015-02-25 13:02:08 +0000193ifeq (,$(filter $(OS), Windows_NT Android))
Chaoren Linf4a92bd2015-04-13 18:21:31 +0000194 ifneq (,$(filter YES,$(ENABLE_THREADS) $(ENABLE_STD_THREADS)))
Chaoren Lin36758cf2015-05-21 00:19:15 +0000195 LDFLAGS += -pthread
Chaoren Linf4a92bd2015-04-13 18:21:31 +0000196 endif
Zachary Turnerc7826522014-08-13 17:44:53 +0000197endif
Johnny Chen53e2edb2011-08-09 20:07:16 +0000198OBJECTS =
199EXE ?= a.out
200
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000201ifneq "$(DYLIB_NAME)" ""
202 ifeq "$(OS)" "Darwin"
203 DYLIB_FILENAME = lib$(DYLIB_NAME).dylib
Chaoren Lin29449152015-07-21 17:50:16 +0000204 DYLIB_EXECUTABLE_PATH ?= @executable_path
Chaoren Linf4a92bd2015-04-13 18:21:31 +0000205 else ifeq "$(OS)" "Windows_NT"
206 DYLIB_FILENAME = $(DYLIB_NAME).dll
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000207 else
208 DYLIB_FILENAME = lib$(DYLIB_NAME).so
209 endif
210endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000211
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000212# Function that returns the counterpart C++ compiler, given $(CC) as arg.
Shawn Best1ecb68d2014-11-11 17:34:58 +0000213cxx_compiler_notdir = $(if $(findstring clang,$(1)), \
214 $(subst clang,clang++,$(1)), \
215 $(if $(findstring icc,$(1)), \
216 $(subst icc,icpc,$(1)), \
217 $(if $(findstring llvm-gcc,$(1)), \
218 $(subst llvm-gcc,llvm-g++,$(1)), \
219 $(if $(findstring gcc,$(1)), \
220 $(subst gcc,g++,$(1)), \
221 $(subst cc,c++,$(1))))))
Greg Claytonb39751b2013-11-22 21:05:25 +0000222cxx_compiler = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call cxx_compiler_notdir,$(notdir $(1)))),$(call cxx_compiler_notdir,$(1)))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000223
224# Function that returns the C++ linker, given $(CC) as arg.
Shawn Best1ecb68d2014-11-11 17:34:58 +0000225cxx_linker_notdir = $(if $(findstring clang,$(1)), \
226 $(subst clang,clang++,$(1)), \
227 $(if $(findstring icc,$(1)), \
228 $(subst icc,icpc,$(1)), \
229 $(if $(findstring llvm-gcc,$(1)), \
230 $(subst llvm-gcc,llvm-g++,$(1)), \
231 $(if $(findstring gcc,$(1)), \
232 $(subst gcc,g++,$(1)), \
233 $(subst cc,c++,$(1))))))
Greg Claytonb39751b2013-11-22 21:05:25 +0000234cxx_linker = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call cxx_linker_notdir,$(notdir $(1)))),$(call cxx_linker_notdir,$(1)))
Johnny Chen832d2332010-09-30 01:22:34 +0000235
Robert Flackfa8aa172015-04-20 18:07:55 +0000236OBJCOPY := $(CROSS_COMPILE)objcopy
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000237
Johnny Chen9bc867a2010-08-23 23:56:08 +0000238#----------------------------------------------------------------------
Zachary Turnere068d912014-12-01 23:13:41 +0000239# Windows specific options
Zachary Turnerc7826522014-08-13 17:44:53 +0000240#----------------------------------------------------------------------
241ifeq "$(OS)" "Windows_NT"
242 ifneq (,$(findstring clang,$(CC)))
Zachary Turnere068d912014-12-01 23:13:41 +0000243 # Clang for Windows doesn't support C++ Exceptions
Zachary Turnerc7826522014-08-13 17:44:53 +0000244 CXXFLAGS += -fno-exceptions
Zachary Turnerc7826522014-08-13 17:44:53 +0000245 CXXFLAGS += -D_HAS_EXCEPTIONS=0
Zachary Turnere068d912014-12-01 23:13:41 +0000246 # The MSVC linker doesn't understand long section names
247 # generated by the clang compiler.
248 LDFLAGS += -fuse-ld=lld
Zachary Turnerc7826522014-08-13 17:44:53 +0000249 endif
250endif
251
252#----------------------------------------------------------------------
Tamas Berghammer37099e82015-02-25 13:02:08 +0000253# Android specific options
254#----------------------------------------------------------------------
255ifeq "$(OS)" "Android"
Chaoren Lin9070f532015-07-17 22:13:29 +0000256 ifdef PIE
257 LDFLAGS += -pie
258 endif
Chaoren Lin7d76a132015-06-02 16:43:19 +0000259 replace_with = $(if $(findstring clang,$(1)), \
260 $(subst clang,$(2),$(1)), \
261 $(if $(findstring gcc,$(1)), \
262 $(subst gcc,$(2),$(1)), \
263 $(subst cc,$(2),$(1))))
264 ifeq "$(notdir $(CC))" "$(CC)"
265 replace_cc_with = $(call replace_with,$(CC),$(1))
266 else
267 replace_cc_with = $(join $(dir $(CC)),$(call replace_with,$(notdir $(CC)),$(1)))
268 endif
269 OBJCOPY = $(call replace_cc_with,objcopy)
270 AR = $(call replace_cc_with,ar)
Tamas Berghammer37099e82015-02-25 13:02:08 +0000271endif
272
273#----------------------------------------------------------------------
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000274# C++ standard library options
275#----------------------------------------------------------------------
276ifeq (1,$(USE_LIBSTDCPP))
277 # Clang requires an extra flag: -stdlib=libstdc++
278 ifneq (,$(findstring clang,$(CC)))
Enrico Granataa1acb492013-06-07 01:58:52 +0000279 CXXFLAGS += -stdlib=libstdc++
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000280 LDFLAGS += -stdlib=libstdc++
281 endif
282endif
283
Greg Clayton1767a732013-06-13 21:27:14 +0000284ifeq (1,$(USE_LIBCPP))
285 # Clang requires an extra flag: -stdlib=libstdc++
286 ifneq (,$(findstring clang,$(CC)))
Vince Harronf2e37602015-05-04 02:56:32 +0000287 ifeq "$(OS)" "Linux"
288 # This is the default install location on Ubuntu 14.04
Enrico Granataf6fe3022015-09-18 22:26:34 +0000289 ifneq ($(wildcard /usr/include/c++/v1/.),)
290 CXXFLAGS += -stdlib=libc++
291 LDFLAGS += -stdlib=libc++
292 CXXFLAGS += -I/usr/include/c++/v1
293 endif
294 else
295 CXXFLAGS += -stdlib=libc++
296 LDFLAGS += -stdlib=libc++
297 endif
Greg Clayton1767a732013-06-13 21:27:14 +0000298 endif
299endif
300
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000301#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000302# dylib settings
303#----------------------------------------------------------------------
304ifneq "$(strip $(DYLIB_C_SOURCES))" ""
305 DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
306endif
307
Sean Callanan72772842012-02-22 23:57:45 +0000308ifneq "$(strip $(DYLIB_OBJC_SOURCES))" ""
309 DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o))
310endif
311
Greg Claytond50d2382012-01-10 00:00:15 +0000312ifneq "$(strip $(DYLIB_CXX_SOURCES))" ""
313 DYLIB_OBJECTS +=$(strip $(DYLIB_CXX_SOURCES:.cpp=.o))
314 CXX = $(call cxx_compiler,$(CC))
315 LD = $(call cxx_linker,$(CC))
316endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000317
318#----------------------------------------------------------------------
319# Check if we have any C source files
320#----------------------------------------------------------------------
321ifneq "$(strip $(C_SOURCES))" ""
322 OBJECTS +=$(strip $(C_SOURCES:.c=.o))
323endif
324
325#----------------------------------------------------------------------
326# Check if we have any C++ source files
327#----------------------------------------------------------------------
328ifneq "$(strip $(CXX_SOURCES))" ""
329 OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
Johnny Chen832d2332010-09-30 01:22:34 +0000330 CXX = $(call cxx_compiler,$(CC))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000331 LD = $(call cxx_linker,$(CC))
Johnny Chen9bc867a2010-08-23 23:56:08 +0000332endif
333
334#----------------------------------------------------------------------
335# Check if we have any ObjC source files
336#----------------------------------------------------------------------
337ifneq "$(strip $(OBJC_SOURCES))" ""
338 OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o))
339 LDFLAGS +=-lobjc
340endif
341
342#----------------------------------------------------------------------
343# Check if we have any ObjC++ source files
344#----------------------------------------------------------------------
345ifneq "$(strip $(OBJCXX_SOURCES))" ""
346 OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
Johnny Chen832d2332010-09-30 01:22:34 +0000347 CXX = $(call cxx_compiler,$(CC))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000348 LD = $(call cxx_linker,$(CC))
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000349 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
Johnny Chen9bc867a2010-08-23 23:56:08 +0000350 LDFLAGS +=-lobjc
351 endif
352endif
353
Johnny Chenfe141622012-01-12 23:09:42 +0000354#----------------------------------------------------------------------
355# Check if we have any C source files for archive
356#----------------------------------------------------------------------
357ifneq "$(strip $(ARCHIVE_C_SOURCES))" ""
358 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_C_SOURCES:.c=.o))
359endif
360
361#----------------------------------------------------------------------
362# Check if we have any C++ source files for archive
363#----------------------------------------------------------------------
364ifneq "$(strip $(ARCHIVE_CXX_SOURCES))" ""
365 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_CXX_SOURCES:.cpp=.o))
366 CXX = $(call cxx_compiler,$(CC))
367 LD = $(call cxx_linker,$(CC))
368endif
369
370#----------------------------------------------------------------------
371# Check if we have any ObjC source files for archive
372#----------------------------------------------------------------------
373ifneq "$(strip $(ARCHIVE_OBJC_SOURCES))" ""
374 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJC_SOURCES:.m=.o))
375 LDFLAGS +=-lobjc
376endif
377
378#----------------------------------------------------------------------
379# Check if we have any ObjC++ source files for archive
380#----------------------------------------------------------------------
381ifneq "$(strip $(ARCHIVE_OBJCXX_SOURCES))" ""
382 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJCXX_SOURCES:.mm=.o))
383 CXX = $(call cxx_compiler,$(CC))
384 LD = $(call cxx_linker,$(CC))
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000385 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
Johnny Chenfe141622012-01-12 23:09:42 +0000386 LDFLAGS +=-lobjc
387 endif
388endif
389
Matt Kopecf2430f52013-07-24 21:39:24 +0000390#----------------------------------------------------------------------
391# Check if we are compiling with gcc 4.6
392#----------------------------------------------------------------------
Ed Maste375432e2015-05-29 19:52:02 +0000393ifneq "$(strip $(CXX_SOURCES) $(OBJCXX_SOURCES))" ""
394ifneq "$(filter g++,$(CXX))" ""
395 CXXVERSION = $(shell $(CXX) -dumpversion | cut -b 1-3)
Matt Kopecf2430f52013-07-24 21:39:24 +0000396 ifeq "$(CXXVERSION)" "4.6"
397 # GCC 4.6 cannot handle -std=c++11, so replace it with -std=c++0x
398 # instead. FIXME: remove once GCC version is upgraded.
399 override CXXFLAGS := $(subst -std=c++11,-std=c++0x,$(CXXFLAGS))
400 endif
401endif
Ed Maste375432e2015-05-29 19:52:02 +0000402endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000403
404#----------------------------------------------------------------------
Johnny Chenbeac8f92012-01-10 00:41:11 +0000405# DYLIB_ONLY variable can be used to skip the building of a.out.
406# See the sections below regarding dSYM file as well as the building of
407# EXE from all the objects.
408#----------------------------------------------------------------------
409
410#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000411# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO"
412#----------------------------------------------------------------------
Matt Kopec7663b3a2013-09-25 17:44:00 +0000413ifneq "$(DYLIB_ONLY)" "YES"
Michael Sartain802b0552013-07-02 18:13:13 +0000414$(DSYM) : $(EXE)
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000415ifeq "$(OS)" "Darwin"
Johnny Chen91016392011-06-20 20:08:26 +0000416ifneq "$(MAKE_DSYM)" "NO"
Enrico Granata489af082014-11-18 22:47:33 +0000417 "$(DS)" $(DSFLAGS) -o "$(DSYM)" "$(EXE)"
Johnny Chen91016392011-06-20 20:08:26 +0000418endif
Michael Sartain802b0552013-07-02 18:13:13 +0000419else
420ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000421 $(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
422 $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
Michael Sartain802b0552013-07-02 18:13:13 +0000423endif
424endif
Johnny Chenbeac8f92012-01-10 00:41:11 +0000425endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000426
427#----------------------------------------------------------------------
428# Compile the executable from all the objects.
429#----------------------------------------------------------------------
Johnny Chenbeac8f92012-01-10 00:41:11 +0000430ifneq "$(DYLIB_NAME)" ""
431ifeq "$(DYLIB_ONLY)" ""
Johnny Chenfe141622012-01-12 23:09:42 +0000432$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME)
Richard Mittonec8b2822013-10-17 20:09:33 +0000433 $(LD) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)"
Johnny Chenbeac8f92012-01-10 00:41:11 +0000434else
435EXE = $(DYLIB_FILENAME)
436endif
437else
Johnny Chenfe141622012-01-12 23:09:42 +0000438$(EXE) : $(OBJECTS) $(ARCHIVE_NAME)
Daniel Malea2745d842013-01-25 00:31:48 +0000439 $(LD) $(OBJECTS) $(LDFLAGS) $(ARCHIVE_NAME) -o "$(EXE)"
Johnny Chenfe141622012-01-12 23:09:42 +0000440endif
441
442#----------------------------------------------------------------------
443# Make the archive
444#----------------------------------------------------------------------
445ifneq "$(ARCHIVE_NAME)" ""
446ifeq "$(OS)" "Darwin"
447$(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS)
448 $(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
449 $(RM) $(ARCHIVE_OBJECTS)
450else
451$(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj)))
452endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000453endif
454
455#----------------------------------------------------------------------
456# Make the dylib
457#----------------------------------------------------------------------
Zachary Turner794e6a62015-03-13 21:51:11 +0000458$(DYLIB_OBJECTS) : CFLAGS += -DCOMPILING_LLDB_TEST_DLL
459
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000460$(DYLIB_FILENAME) : $(DYLIB_OBJECTS)
461ifeq "$(OS)" "Darwin"
Chaoren Lin29449152015-07-21 17:50:16 +0000462 $(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -install_name "$(DYLIB_EXECUTABLE_PATH)/$(DYLIB_FILENAME)" -dynamiclib -o "$(DYLIB_FILENAME)"
Greg Clayton0c9773c2012-09-20 21:43:11 +0000463ifneq "$(MAKE_DSYM)" "NO"
464ifneq "$(DS)" ""
Kate Stone2136ace2015-01-21 19:30:00 +0000465 "$(DS)" $(DSFLAGS) "$(DYLIB_FILENAME)"
Greg Clayton0c9773c2012-09-20 21:43:11 +0000466endif
467endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000468else
Chaoren Lin54fff4c2015-04-16 22:03:43 +0000469 $(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
Michael Sartain802b0552013-07-02 18:13:13 +0000470ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000471 $(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
472 $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
Michael Sartain802b0552013-07-02 18:13:13 +0000473endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000474endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000475
476#----------------------------------------------------------------------
477# Automatic variables based on items already entered. Below we create
Zachary Turner794e6a62015-03-13 21:51:11 +0000478# an object's lists from the list of sources by replacing all entries
Johnny Chen9bc867a2010-08-23 23:56:08 +0000479# that end with .c with .o, and we also create a list of prerequisite
480# files by replacing all .c files with .d.
481#----------------------------------------------------------------------
482PREREQS := $(OBJECTS:.o=.d)
Tamas Berghammer1535beb2015-09-09 10:20:30 +0000483DWOS := $(OBJECTS:.o=.dwo)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000484ifneq "$(DYLIB_NAME)" ""
485 DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d)
Tamas Berghammer1535beb2015-09-09 10:20:30 +0000486 DYLIB_DWOS := $(DYLIB_OBJECTS:.o=.dwo)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000487endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000488
489#----------------------------------------------------------------------
490# Rule for Generating Prerequisites Automatically using .d files and
491# the compiler -MM option. The -M option will list all system headers,
492# and the -MM option will list all non-system dependencies.
493#----------------------------------------------------------------------
Chaoren Lind761a952015-09-16 21:51:51 +0000494ifeq "$(HOST_OS)" "Windows_NT"
Zachary Turner794e6a62015-03-13 21:51:11 +0000495 JOIN_CMD = &
496 QUOTE = "
497else
498 JOIN_CMD = ;
499 QUOTE = '
500endif
501
Johnny Chen9bc867a2010-08-23 23:56:08 +0000502%.d: %.c
Zachary Turner794e6a62015-03-13 21:51:11 +0000503 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000504 $(CC) -M $(CFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000505 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000506 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000507
508%.d: %.cpp
Zachary Turner794e6a62015-03-13 21:51:11 +0000509 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000510 $(CXX) -M $(CXXFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000511 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000512 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000513
514%.d: %.m
Zachary Turner794e6a62015-03-13 21:51:11 +0000515 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000516 $(CC) -M $(CFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000517 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000518 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000519
520%.d: %.mm
Zachary Turner794e6a62015-03-13 21:51:11 +0000521 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000522 $(CXX) -M $(CXXFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000523 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000524 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000525
526#----------------------------------------------------------------------
527# Include all of the makefiles for each source file so we don't have
528# to manually track all of the prerequisites for each source file.
529#----------------------------------------------------------------------
530sinclude $(PREREQS)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000531ifneq "$(DYLIB_NAME)" ""
532 sinclude $(DYLIB_PREREQS)
533endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000534
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000535# Define a suffix rule for .mm -> .o
536.SUFFIXES: .mm .o
537.mm.o:
538 $(CXX) $(CXXFLAGS) -c $<
539
Johnny Chen9bc867a2010-08-23 23:56:08 +0000540.PHONY: clean
541dsym: $(DSYM)
542all: $(EXE) $(DSYM)
Johnny Chene1030cd2010-09-27 20:44:46 +0000543clean::
Tamas Berghammer1535beb2015-09-09 10:20:30 +0000544 $(RM) $(OBJECTS) $(PREREQS) $(PREREQS:.d=.d.tmp) $(DWOS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
Ed Maste0990e052014-03-07 17:20:50 +0000545ifneq "$(DYLIB_NAME)" ""
Jason Molenda53b8ea12014-03-08 01:53:27 +0000546 $(RM) -r $(DYLIB_FILENAME).dSYM
Tamas Berghammer1535beb2015-09-09 10:20:30 +0000547 $(RM) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_PREREQS:.d=.d.tmp) $(DYLIB_DWOS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).debug
Johnny Chen9bc867a2010-08-23 23:56:08 +0000548endif
Ed Maste0990e052014-03-07 17:20:50 +0000549ifneq "$(DSYM)" ""
Jason Molenda53b8ea12014-03-08 01:53:27 +0000550 $(RM) -r "$(DSYM)"
Ed Maste0990e052014-03-07 17:20:50 +0000551endif
Zachary Turner3e9ca3a2014-12-16 16:48:19 +0000552ifeq "$(OS)" "Windows_NT"
Zachary Turner0844d8d2015-08-26 19:44:45 +0000553# http://llvm.org/pr24589
554 IF EXIST "$(EXE)" del "$(EXE)"
Zachary Turner65fe1eb2015-03-26 16:43:25 +0000555 $(RM) $(wildcard *.manifest *.pdb *.ilk)
Zachary Turner0844d8d2015-08-26 19:44:45 +0000556ifneq "$(DYLIB_NAME)" ""
Zachary Turner65fe1eb2015-03-26 16:43:25 +0000557 $(RM) $(DYLIB_NAME).lib $(DYLIB_NAME).exp
Zachary Turner0844d8d2015-08-26 19:44:45 +0000558endif
559else
560 $(RM) "$(EXE)"
Zachary Turner3e9ca3a2014-12-16 16:48:19 +0000561endif
Johnny Chenfa380412011-01-14 21:18:12 +0000562
563#----------------------------------------------------------------------
564# From http://blog.melski.net/tag/debugging-makefiles/
565#
566# Usage: make print-CC print-CXX print-LD
567#----------------------------------------------------------------------
568print-%:
569 @echo '$*=$($*)'
570 @echo ' origin = $(origin $*)'
571 @echo ' flavor = $(flavor $*)'
572 @echo ' value = $(value $*)'
Johnny Chen8b2c3212011-01-28 17:22:29 +0000573
Johnny Chen8b2c3212011-01-28 17:22:29 +0000574### Local Variables: ###
575### mode:makefile ###
576### End: ###