blob: a73ab3f3e0fe9b360078525b60f3ae111fbd63dc [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#----------------------------------------------------------------------
76ifeq "$(OS)" ""
77 OS = $(shell uname -s)
78endif
79ifeq "$(OS)" "windows32"
80 OS = Windows_NT
81endif
82
83#----------------------------------------------------------------------
84# If ARCH is not defined, default to x86_64.
Johnny Chen6c17c082010-09-16 20:54:06 +000085#----------------------------------------------------------------------
86ifeq "$(ARCH)" ""
Zachary Turnere068d912014-12-01 23:13:41 +000087ifeq "$(OS)" "Windows_NT"
88 ARCH = x86
89else
Johnny Chen6c17c082010-09-16 20:54:06 +000090 ARCH = x86_64
91endif
Zachary Turnere068d912014-12-01 23:13:41 +000092endif
Johnny Chen6c17c082010-09-16 20:54:06 +000093
94#----------------------------------------------------------------------
Johnny Chen597cbbb2011-08-23 21:54:10 +000095# CC defaults to clang.
Johnny Chen4ab4a9b2011-08-24 18:12:53 +000096#
97# If you change the defaults of CC, be sure to also change it in the file
98# test/plugins/builder_base.py, which provides a Python way to return the
99# value of the make variable CC -- getCompiler().
100#
Johnny Chen6055b442011-01-14 20:55:13 +0000101# See also these functions:
102# o cxx_compiler
103# o cxx_linker
Johnny Chend43e2082011-01-14 20:46:49 +0000104#----------------------------------------------------------------------
Johnny Chen597cbbb2011-08-23 21:54:10 +0000105CC ?= clang
Johnny Chend43e2082011-01-14 20:46:49 +0000106ifeq "$(CC)" "cc"
Vince Harron847e2612015-05-27 04:42:54 +0000107 ifneq "$(shell which clang)" ""
108 CC = clang
109 else ifneq "$(shell which clang-3.5)" ""
110 CC = clang-3.5
111 else ifneq "$(shell which gcc)" ""
112 CC = gcc
113 endif
Johnny Chend43e2082011-01-14 20:46:49 +0000114endif
115
116#----------------------------------------------------------------------
Daniel Malea2745d842013-01-25 00:31:48 +0000117# ARCHFLAG is the flag used to tell the compiler which architecture
118# to compile for. The default is the flag that clang accepts.
119#----------------------------------------------------------------------
Greg Clayton2c93b802015-04-16 01:18:05 +0000120ARCHFLAG ?= -arch
Daniel Malea2745d842013-01-25 00:31:48 +0000121
122#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000123# Change any build/tool options needed
124#----------------------------------------------------------------------
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000125ifeq "$(OS)" "Darwin"
Greg Clayton82625d32014-07-29 20:10:59 +0000126 DS := $(shell xcrun -find -toolchain default dsymutil)
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000127 DSFLAGS =
128 DSYM = $(EXE).dSYM
Robert Flackfa8aa172015-04-20 18:07:55 +0000129 AR := $(CROSS_COMPILE)libtool
Johnny Chenfe141622012-01-12 23:09:42 +0000130 ARFLAGS := -static -o
Daniel Malea2745d842013-01-25 00:31:48 +0000131else
Robert Flackfa8aa172015-04-20 18:07:55 +0000132 AR := $(CROSS_COMPILE)ar
Daniel Malea2745d842013-01-25 00:31:48 +0000133 # On non-Apple platforms, -arch becomes -m
134 ARCHFLAG := -m
135
Zachary Turnerc7826522014-08-13 17:44:53 +0000136 # i386, i686, x86 -> 32
Zachary Turner7c1bc2b2014-07-31 21:07:41 +0000137 # amd64, x86_64, x64 -> 64
Ed Maste4fe0aba2014-02-20 18:40:01 +0000138 ifeq "$(ARCH)" "amd64"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +0000139 override ARCH := $(subst amd64,64,$(ARCH))
Ed Maste4fe0aba2014-02-20 18:40:01 +0000140 endif
Daniel Malea2745d842013-01-25 00:31:48 +0000141 ifeq "$(ARCH)" "x86_64"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +0000142 override ARCH := $(subst x86_64,64,$(ARCH))
143 endif
144 ifeq "$(ARCH)" "x64"
145 override ARCH := $(subst x64,64,$(ARCH))
Daniel Malea2745d842013-01-25 00:31:48 +0000146 endif
Zachary Turnerc7826522014-08-13 17:44:53 +0000147 ifeq "$(ARCH)" "x86"
148 override ARCH := $(subst x86,32,$(ARCH))
149 endif
Daniel Malea2745d842013-01-25 00:31:48 +0000150 ifeq "$(ARCH)" "i386"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +0000151 override ARCH := $(subst i386,32,$(ARCH))
152 endif
153 ifeq "$(ARCH)" "i686"
154 override ARCH := $(subst i686,32,$(ARCH))
Daniel Malea2745d842013-01-25 00:31:48 +0000155 endif
Justin Hibbits3cba1c22014-11-12 15:13:58 +0000156 ifeq "$(ARCH)" "powerpc"
157 override ARCH := $(subst powerpc,32,$(ARCH))
158 endif
159 ifeq "$(ARCH)" "powerpc64"
160 override ARCH := $(subst powerpc64,64,$(ARCH))
161 endif
Tamas Berghammer1e209fc2015-03-13 11:36:47 +0000162 ifeq "$(ARCH)" "aarch64"
163 override ARCH :=
164 override ARCHFLAG :=
165 endif
Michael Sartain802b0552013-07-02 18:13:13 +0000166
167 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
168 DSYM = $(EXE).debug
169 endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000170endif
171
Ilia Kfeda0b72015-05-12 12:13:12 +0000172CFLAGS ?= -g -O0 -fno-builtin
Greg Clayton2c93b802015-04-16 01:18:05 +0000173ifeq "$(OS)" "Darwin"
174 CFLAGS += $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
175else
176 CFLAGS += $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
177endif
Greg Clayton315b88d2015-06-02 21:38:10 +0000178CFLAGS += -include $(THIS_FILE_DIR)test_common.h $(TRIPLE_CFLAGS)
Daniel Malea2745d842013-01-25 00:31:48 +0000179
Jim Ingham4b4b2472014-03-13 02:47:14 +0000180# Use this one if you want to build one part of the result without debug information:
Greg Clayton2c93b802015-04-16 01:18:05 +0000181ifeq "$(OS)" "Darwin"
Greg Clayton315b88d2015-06-02 21:38:10 +0000182 CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) $(TRIPLE_CFLAGS)
Greg Clayton2c93b802015-04-16 01:18:05 +0000183else
Greg Clayton315b88d2015-06-02 21:38:10 +0000184 CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) $(TRIPLE_CFLAGS)
Greg Clayton2c93b802015-04-16 01:18:05 +0000185endif
Jim Ingham4b4b2472014-03-13 02:47:14 +0000186
Zachary Turnerc7826522014-08-13 17:44:53 +0000187CXXFLAGS += -std=c++11
188CXXFLAGS += $(CFLAGS)
Johnny Chen53e2edb2011-08-09 20:07:16 +0000189LD = $(CC)
190LDFLAGS ?= $(CFLAGS)
Daniel Malea2745d842013-01-25 00:31:48 +0000191LDFLAGS += $(LD_EXTRAS)
Tamas Berghammer37099e82015-02-25 13:02:08 +0000192ifeq (,$(filter $(OS), Windows_NT Android))
Chaoren Linf4a92bd2015-04-13 18:21:31 +0000193 ifneq (,$(filter YES,$(ENABLE_THREADS) $(ENABLE_STD_THREADS)))
Chaoren Lin36758cf2015-05-21 00:19:15 +0000194 LDFLAGS += -pthread
Chaoren Linf4a92bd2015-04-13 18:21:31 +0000195 endif
Zachary Turnerc7826522014-08-13 17:44:53 +0000196endif
Johnny Chen53e2edb2011-08-09 20:07:16 +0000197OBJECTS =
198EXE ?= a.out
199
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000200ifneq "$(DYLIB_NAME)" ""
201 ifeq "$(OS)" "Darwin"
202 DYLIB_FILENAME = lib$(DYLIB_NAME).dylib
Chaoren Lin29449152015-07-21 17:50:16 +0000203 DYLIB_EXECUTABLE_PATH ?= @executable_path
Chaoren Linf4a92bd2015-04-13 18:21:31 +0000204 else ifeq "$(OS)" "Windows_NT"
205 DYLIB_FILENAME = $(DYLIB_NAME).dll
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000206 else
207 DYLIB_FILENAME = lib$(DYLIB_NAME).so
208 endif
209endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000210
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000211# Function that returns the counterpart C++ compiler, given $(CC) as arg.
Shawn Best1ecb68d2014-11-11 17:34:58 +0000212cxx_compiler_notdir = $(if $(findstring clang,$(1)), \
213 $(subst clang,clang++,$(1)), \
214 $(if $(findstring icc,$(1)), \
215 $(subst icc,icpc,$(1)), \
216 $(if $(findstring llvm-gcc,$(1)), \
217 $(subst llvm-gcc,llvm-g++,$(1)), \
218 $(if $(findstring gcc,$(1)), \
219 $(subst gcc,g++,$(1)), \
220 $(subst cc,c++,$(1))))))
Greg Claytonb39751b2013-11-22 21:05:25 +0000221cxx_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 +0000222
223# Function that returns the C++ linker, given $(CC) as arg.
Shawn Best1ecb68d2014-11-11 17:34:58 +0000224cxx_linker_notdir = $(if $(findstring clang,$(1)), \
225 $(subst clang,clang++,$(1)), \
226 $(if $(findstring icc,$(1)), \
227 $(subst icc,icpc,$(1)), \
228 $(if $(findstring llvm-gcc,$(1)), \
229 $(subst llvm-gcc,llvm-g++,$(1)), \
230 $(if $(findstring gcc,$(1)), \
231 $(subst gcc,g++,$(1)), \
232 $(subst cc,c++,$(1))))))
Greg Claytonb39751b2013-11-22 21:05:25 +0000233cxx_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 +0000234
Robert Flackfa8aa172015-04-20 18:07:55 +0000235OBJCOPY := $(CROSS_COMPILE)objcopy
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000236
Johnny Chen9bc867a2010-08-23 23:56:08 +0000237#----------------------------------------------------------------------
Zachary Turnere068d912014-12-01 23:13:41 +0000238# Windows specific options
Zachary Turnerc7826522014-08-13 17:44:53 +0000239#----------------------------------------------------------------------
240ifeq "$(OS)" "Windows_NT"
241 ifneq (,$(findstring clang,$(CC)))
Zachary Turnere068d912014-12-01 23:13:41 +0000242 # Clang for Windows doesn't support C++ Exceptions
Zachary Turnerc7826522014-08-13 17:44:53 +0000243 CXXFLAGS += -fno-exceptions
Zachary Turnerc7826522014-08-13 17:44:53 +0000244 CXXFLAGS += -D_HAS_EXCEPTIONS=0
Zachary Turnere068d912014-12-01 23:13:41 +0000245 # The MSVC linker doesn't understand long section names
246 # generated by the clang compiler.
247 LDFLAGS += -fuse-ld=lld
Zachary Turnerc7826522014-08-13 17:44:53 +0000248 endif
249endif
250
251#----------------------------------------------------------------------
Tamas Berghammer37099e82015-02-25 13:02:08 +0000252# Android specific options
253#----------------------------------------------------------------------
254ifeq "$(OS)" "Android"
Chaoren Lin9070f532015-07-17 22:13:29 +0000255 ifdef PIE
256 LDFLAGS += -pie
257 endif
Chaoren Lin7d76a132015-06-02 16:43:19 +0000258 replace_with = $(if $(findstring clang,$(1)), \
259 $(subst clang,$(2),$(1)), \
260 $(if $(findstring gcc,$(1)), \
261 $(subst gcc,$(2),$(1)), \
262 $(subst cc,$(2),$(1))))
263 ifeq "$(notdir $(CC))" "$(CC)"
264 replace_cc_with = $(call replace_with,$(CC),$(1))
265 else
266 replace_cc_with = $(join $(dir $(CC)),$(call replace_with,$(notdir $(CC)),$(1)))
267 endif
268 OBJCOPY = $(call replace_cc_with,objcopy)
269 AR = $(call replace_cc_with,ar)
Tamas Berghammer37099e82015-02-25 13:02:08 +0000270endif
271
272#----------------------------------------------------------------------
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000273# C++ standard library options
274#----------------------------------------------------------------------
275ifeq (1,$(USE_LIBSTDCPP))
276 # Clang requires an extra flag: -stdlib=libstdc++
277 ifneq (,$(findstring clang,$(CC)))
Enrico Granataa1acb492013-06-07 01:58:52 +0000278 CXXFLAGS += -stdlib=libstdc++
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000279 LDFLAGS += -stdlib=libstdc++
280 endif
281endif
282
Greg Clayton1767a732013-06-13 21:27:14 +0000283ifeq (1,$(USE_LIBCPP))
284 # Clang requires an extra flag: -stdlib=libstdc++
285 ifneq (,$(findstring clang,$(CC)))
286 CXXFLAGS += -stdlib=libc++
287 LDFLAGS += -stdlib=libc++
Vince Harronf2e37602015-05-04 02:56:32 +0000288 ifeq "$(OS)" "Linux"
289 # This is the default install location on Ubuntu 14.04
290 CXXFLAGS += -I/usr/include/c++/v1
291 endif
Greg Clayton1767a732013-06-13 21:27:14 +0000292 endif
293endif
294
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000295#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000296# dylib settings
297#----------------------------------------------------------------------
298ifneq "$(strip $(DYLIB_C_SOURCES))" ""
299 DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
300endif
301
Sean Callanan72772842012-02-22 23:57:45 +0000302ifneq "$(strip $(DYLIB_OBJC_SOURCES))" ""
303 DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o))
304endif
305
Greg Claytond50d2382012-01-10 00:00:15 +0000306ifneq "$(strip $(DYLIB_CXX_SOURCES))" ""
307 DYLIB_OBJECTS +=$(strip $(DYLIB_CXX_SOURCES:.cpp=.o))
308 CXX = $(call cxx_compiler,$(CC))
309 LD = $(call cxx_linker,$(CC))
310endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000311
312#----------------------------------------------------------------------
313# Check if we have any C source files
314#----------------------------------------------------------------------
315ifneq "$(strip $(C_SOURCES))" ""
316 OBJECTS +=$(strip $(C_SOURCES:.c=.o))
317endif
318
319#----------------------------------------------------------------------
320# Check if we have any C++ source files
321#----------------------------------------------------------------------
322ifneq "$(strip $(CXX_SOURCES))" ""
323 OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
Johnny Chen832d2332010-09-30 01:22:34 +0000324 CXX = $(call cxx_compiler,$(CC))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000325 LD = $(call cxx_linker,$(CC))
Johnny Chen9bc867a2010-08-23 23:56:08 +0000326endif
327
328#----------------------------------------------------------------------
329# Check if we have any ObjC source files
330#----------------------------------------------------------------------
331ifneq "$(strip $(OBJC_SOURCES))" ""
332 OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o))
333 LDFLAGS +=-lobjc
334endif
335
336#----------------------------------------------------------------------
337# Check if we have any ObjC++ source files
338#----------------------------------------------------------------------
339ifneq "$(strip $(OBJCXX_SOURCES))" ""
340 OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
Johnny Chen832d2332010-09-30 01:22:34 +0000341 CXX = $(call cxx_compiler,$(CC))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000342 LD = $(call cxx_linker,$(CC))
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000343 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
Johnny Chen9bc867a2010-08-23 23:56:08 +0000344 LDFLAGS +=-lobjc
345 endif
346endif
347
Johnny Chenfe141622012-01-12 23:09:42 +0000348#----------------------------------------------------------------------
349# Check if we have any C source files for archive
350#----------------------------------------------------------------------
351ifneq "$(strip $(ARCHIVE_C_SOURCES))" ""
352 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_C_SOURCES:.c=.o))
353endif
354
355#----------------------------------------------------------------------
356# Check if we have any C++ source files for archive
357#----------------------------------------------------------------------
358ifneq "$(strip $(ARCHIVE_CXX_SOURCES))" ""
359 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_CXX_SOURCES:.cpp=.o))
360 CXX = $(call cxx_compiler,$(CC))
361 LD = $(call cxx_linker,$(CC))
362endif
363
364#----------------------------------------------------------------------
365# Check if we have any ObjC source files for archive
366#----------------------------------------------------------------------
367ifneq "$(strip $(ARCHIVE_OBJC_SOURCES))" ""
368 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJC_SOURCES:.m=.o))
369 LDFLAGS +=-lobjc
370endif
371
372#----------------------------------------------------------------------
373# Check if we have any ObjC++ source files for archive
374#----------------------------------------------------------------------
375ifneq "$(strip $(ARCHIVE_OBJCXX_SOURCES))" ""
376 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJCXX_SOURCES:.mm=.o))
377 CXX = $(call cxx_compiler,$(CC))
378 LD = $(call cxx_linker,$(CC))
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000379 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
Johnny Chenfe141622012-01-12 23:09:42 +0000380 LDFLAGS +=-lobjc
381 endif
382endif
383
Matt Kopecf2430f52013-07-24 21:39:24 +0000384#----------------------------------------------------------------------
385# Check if we are compiling with gcc 4.6
386#----------------------------------------------------------------------
Ed Maste375432e2015-05-29 19:52:02 +0000387ifneq "$(strip $(CXX_SOURCES) $(OBJCXX_SOURCES))" ""
388ifneq "$(filter g++,$(CXX))" ""
389 CXXVERSION = $(shell $(CXX) -dumpversion | cut -b 1-3)
Matt Kopecf2430f52013-07-24 21:39:24 +0000390 ifeq "$(CXXVERSION)" "4.6"
391 # GCC 4.6 cannot handle -std=c++11, so replace it with -std=c++0x
392 # instead. FIXME: remove once GCC version is upgraded.
393 override CXXFLAGS := $(subst -std=c++11,-std=c++0x,$(CXXFLAGS))
394 endif
395endif
Ed Maste375432e2015-05-29 19:52:02 +0000396endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000397
398#----------------------------------------------------------------------
Johnny Chenbeac8f92012-01-10 00:41:11 +0000399# DYLIB_ONLY variable can be used to skip the building of a.out.
400# See the sections below regarding dSYM file as well as the building of
401# EXE from all the objects.
402#----------------------------------------------------------------------
403
404#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000405# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO"
406#----------------------------------------------------------------------
Matt Kopec7663b3a2013-09-25 17:44:00 +0000407ifneq "$(DYLIB_ONLY)" "YES"
Michael Sartain802b0552013-07-02 18:13:13 +0000408$(DSYM) : $(EXE)
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000409ifeq "$(OS)" "Darwin"
Johnny Chen91016392011-06-20 20:08:26 +0000410ifneq "$(MAKE_DSYM)" "NO"
Enrico Granata489af082014-11-18 22:47:33 +0000411 "$(DS)" $(DSFLAGS) -o "$(DSYM)" "$(EXE)"
Johnny Chen91016392011-06-20 20:08:26 +0000412endif
Michael Sartain802b0552013-07-02 18:13:13 +0000413else
414ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000415 $(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
416 $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
Michael Sartain802b0552013-07-02 18:13:13 +0000417endif
418endif
Johnny Chenbeac8f92012-01-10 00:41:11 +0000419endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000420
421#----------------------------------------------------------------------
422# Compile the executable from all the objects.
423#----------------------------------------------------------------------
Johnny Chenbeac8f92012-01-10 00:41:11 +0000424ifneq "$(DYLIB_NAME)" ""
425ifeq "$(DYLIB_ONLY)" ""
Johnny Chenfe141622012-01-12 23:09:42 +0000426$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME)
Richard Mittonec8b2822013-10-17 20:09:33 +0000427 $(LD) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)"
Johnny Chenbeac8f92012-01-10 00:41:11 +0000428else
429EXE = $(DYLIB_FILENAME)
430endif
431else
Johnny Chenfe141622012-01-12 23:09:42 +0000432$(EXE) : $(OBJECTS) $(ARCHIVE_NAME)
Daniel Malea2745d842013-01-25 00:31:48 +0000433 $(LD) $(OBJECTS) $(LDFLAGS) $(ARCHIVE_NAME) -o "$(EXE)"
Johnny Chenfe141622012-01-12 23:09:42 +0000434endif
435
436#----------------------------------------------------------------------
437# Make the archive
438#----------------------------------------------------------------------
439ifneq "$(ARCHIVE_NAME)" ""
440ifeq "$(OS)" "Darwin"
441$(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS)
442 $(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
443 $(RM) $(ARCHIVE_OBJECTS)
444else
445$(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj)))
446endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000447endif
448
449#----------------------------------------------------------------------
450# Make the dylib
451#----------------------------------------------------------------------
Zachary Turner794e6a62015-03-13 21:51:11 +0000452$(DYLIB_OBJECTS) : CFLAGS += -DCOMPILING_LLDB_TEST_DLL
453
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000454$(DYLIB_FILENAME) : $(DYLIB_OBJECTS)
455ifeq "$(OS)" "Darwin"
Chaoren Lin29449152015-07-21 17:50:16 +0000456 $(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -install_name "$(DYLIB_EXECUTABLE_PATH)/$(DYLIB_FILENAME)" -dynamiclib -o "$(DYLIB_FILENAME)"
Greg Clayton0c9773c2012-09-20 21:43:11 +0000457ifneq "$(MAKE_DSYM)" "NO"
458ifneq "$(DS)" ""
Kate Stone2136ace2015-01-21 19:30:00 +0000459 "$(DS)" $(DSFLAGS) "$(DYLIB_FILENAME)"
Greg Clayton0c9773c2012-09-20 21:43:11 +0000460endif
461endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000462else
Chaoren Lin54fff4c2015-04-16 22:03:43 +0000463 $(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
Michael Sartain802b0552013-07-02 18:13:13 +0000464ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000465 $(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
466 $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
Michael Sartain802b0552013-07-02 18:13:13 +0000467endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000468endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000469
470#----------------------------------------------------------------------
471# Automatic variables based on items already entered. Below we create
Zachary Turner794e6a62015-03-13 21:51:11 +0000472# an object's lists from the list of sources by replacing all entries
Johnny Chen9bc867a2010-08-23 23:56:08 +0000473# that end with .c with .o, and we also create a list of prerequisite
474# files by replacing all .c files with .d.
475#----------------------------------------------------------------------
476PREREQS := $(OBJECTS:.o=.d)
Tamas Berghammer1535beb2015-09-09 10:20:30 +0000477DWOS := $(OBJECTS:.o=.dwo)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000478ifneq "$(DYLIB_NAME)" ""
479 DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d)
Tamas Berghammer1535beb2015-09-09 10:20:30 +0000480 DYLIB_DWOS := $(DYLIB_OBJECTS:.o=.dwo)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000481endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000482
483#----------------------------------------------------------------------
484# Rule for Generating Prerequisites Automatically using .d files and
485# the compiler -MM option. The -M option will list all system headers,
486# and the -MM option will list all non-system dependencies.
487#----------------------------------------------------------------------
Zachary Turner794e6a62015-03-13 21:51:11 +0000488ifeq "$(OS)" "Windows_NT"
489 JOIN_CMD = &
490 QUOTE = "
491else
492 JOIN_CMD = ;
493 QUOTE = '
494endif
495
Johnny Chen9bc867a2010-08-23 23:56:08 +0000496%.d: %.c
Zachary Turner794e6a62015-03-13 21:51:11 +0000497 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000498 $(CC) -M $(CFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000499 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000500 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000501
502%.d: %.cpp
Zachary Turner794e6a62015-03-13 21:51:11 +0000503 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000504 $(CXX) -M $(CXXFLAGS) $< > $@.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: %.m
Zachary Turner794e6a62015-03-13 21:51:11 +0000509 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000510 $(CC) -M $(CFLAGS) $< > $@.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: %.mm
Zachary Turner794e6a62015-03-13 21:51:11 +0000515 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000516 $(CXX) -M $(CXXFLAGS) $< > $@.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#----------------------------------------------------------------------
521# Include all of the makefiles for each source file so we don't have
522# to manually track all of the prerequisites for each source file.
523#----------------------------------------------------------------------
524sinclude $(PREREQS)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000525ifneq "$(DYLIB_NAME)" ""
526 sinclude $(DYLIB_PREREQS)
527endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000528
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000529# Define a suffix rule for .mm -> .o
530.SUFFIXES: .mm .o
531.mm.o:
532 $(CXX) $(CXXFLAGS) -c $<
533
Johnny Chen9bc867a2010-08-23 23:56:08 +0000534.PHONY: clean
535dsym: $(DSYM)
536all: $(EXE) $(DSYM)
Johnny Chene1030cd2010-09-27 20:44:46 +0000537clean::
Tamas Berghammer1535beb2015-09-09 10:20:30 +0000538 $(RM) $(OBJECTS) $(PREREQS) $(PREREQS:.d=.d.tmp) $(DWOS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
Ed Maste0990e052014-03-07 17:20:50 +0000539ifneq "$(DYLIB_NAME)" ""
Jason Molenda53b8ea12014-03-08 01:53:27 +0000540 $(RM) -r $(DYLIB_FILENAME).dSYM
Tamas Berghammer1535beb2015-09-09 10:20:30 +0000541 $(RM) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_PREREQS:.d=.d.tmp) $(DYLIB_DWOS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).debug
Johnny Chen9bc867a2010-08-23 23:56:08 +0000542endif
Ed Maste0990e052014-03-07 17:20:50 +0000543ifneq "$(DSYM)" ""
Jason Molenda53b8ea12014-03-08 01:53:27 +0000544 $(RM) -r "$(DSYM)"
Ed Maste0990e052014-03-07 17:20:50 +0000545endif
Zachary Turner3e9ca3a2014-12-16 16:48:19 +0000546ifeq "$(OS)" "Windows_NT"
Zachary Turner0844d8d2015-08-26 19:44:45 +0000547# http://llvm.org/pr24589
548 IF EXIST "$(EXE)" del "$(EXE)"
Zachary Turner65fe1eb2015-03-26 16:43:25 +0000549 $(RM) $(wildcard *.manifest *.pdb *.ilk)
Zachary Turner0844d8d2015-08-26 19:44:45 +0000550ifneq "$(DYLIB_NAME)" ""
Zachary Turner65fe1eb2015-03-26 16:43:25 +0000551 $(RM) $(DYLIB_NAME).lib $(DYLIB_NAME).exp
Zachary Turner0844d8d2015-08-26 19:44:45 +0000552endif
553else
554 $(RM) "$(EXE)"
Zachary Turner3e9ca3a2014-12-16 16:48:19 +0000555endif
Johnny Chenfa380412011-01-14 21:18:12 +0000556
557#----------------------------------------------------------------------
558# From http://blog.melski.net/tag/debugging-makefiles/
559#
560# Usage: make print-CC print-CXX print-LD
561#----------------------------------------------------------------------
562print-%:
563 @echo '$*=$($*)'
564 @echo ' origin = $(origin $*)'
565 @echo ' flavor = $(flavor $*)'
566 @echo ' value = $(value $*)'
Johnny Chen8b2c3212011-01-28 17:22:29 +0000567
Johnny Chen8b2c3212011-01-28 17:22:29 +0000568### Local Variables: ###
569### mode:makefile ###
570### End: ###