blob: e72b2d0931e8dc2ba848531350119743b96ddd27 [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
Siva Chandra27e33a82015-10-07 22:11:52 +0000173LIMIT_DEBUG_INFO_FLAGS =
174ifneq (,$(findstring clang,$(CC)))
175 LIMIT_DEBUG_INFO_FLAGS += -flimit-debug-info
176endif
177
Ilia Kfeda0b72015-05-12 12:13:12 +0000178CFLAGS ?= -g -O0 -fno-builtin
Greg Clayton2c93b802015-04-16 01:18:05 +0000179ifeq "$(OS)" "Darwin"
180 CFLAGS += $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
181else
182 CFLAGS += $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
183endif
Greg Clayton315b88d2015-06-02 21:38:10 +0000184CFLAGS += -include $(THIS_FILE_DIR)test_common.h $(TRIPLE_CFLAGS)
Daniel Malea2745d842013-01-25 00:31:48 +0000185
Jim Ingham4b4b2472014-03-13 02:47:14 +0000186# Use this one if you want to build one part of the result without debug information:
Greg Clayton2c93b802015-04-16 01:18:05 +0000187ifeq "$(OS)" "Darwin"
Greg Clayton315b88d2015-06-02 21:38:10 +0000188 CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) $(TRIPLE_CFLAGS)
Greg Clayton2c93b802015-04-16 01:18:05 +0000189else
Greg Clayton315b88d2015-06-02 21:38:10 +0000190 CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) $(TRIPLE_CFLAGS)
Greg Clayton2c93b802015-04-16 01:18:05 +0000191endif
Jim Ingham4b4b2472014-03-13 02:47:14 +0000192
Tamas Berghammer4c0c7a72015-10-07 10:02:17 +0000193ifeq "$(MAKE_DWO)" "YES"
194 CFLAGS += -gsplit-dwarf
195endif
196
Zachary Turnerc7826522014-08-13 17:44:53 +0000197CXXFLAGS += -std=c++11
198CXXFLAGS += $(CFLAGS)
Johnny Chen53e2edb2011-08-09 20:07:16 +0000199LD = $(CC)
200LDFLAGS ?= $(CFLAGS)
Daniel Malea2745d842013-01-25 00:31:48 +0000201LDFLAGS += $(LD_EXTRAS)
Tamas Berghammer37099e82015-02-25 13:02:08 +0000202ifeq (,$(filter $(OS), Windows_NT Android))
Chaoren Linf4a92bd2015-04-13 18:21:31 +0000203 ifneq (,$(filter YES,$(ENABLE_THREADS) $(ENABLE_STD_THREADS)))
Chaoren Lin36758cf2015-05-21 00:19:15 +0000204 LDFLAGS += -pthread
Chaoren Linf4a92bd2015-04-13 18:21:31 +0000205 endif
Zachary Turnerc7826522014-08-13 17:44:53 +0000206endif
Johnny Chen53e2edb2011-08-09 20:07:16 +0000207OBJECTS =
208EXE ?= a.out
209
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000210ifneq "$(DYLIB_NAME)" ""
211 ifeq "$(OS)" "Darwin"
212 DYLIB_FILENAME = lib$(DYLIB_NAME).dylib
Chaoren Lin29449152015-07-21 17:50:16 +0000213 DYLIB_EXECUTABLE_PATH ?= @executable_path
Chaoren Linf4a92bd2015-04-13 18:21:31 +0000214 else ifeq "$(OS)" "Windows_NT"
215 DYLIB_FILENAME = $(DYLIB_NAME).dll
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000216 else
217 DYLIB_FILENAME = lib$(DYLIB_NAME).so
218 endif
219endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000220
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000221# Function that returns the counterpart C++ compiler, given $(CC) as arg.
Shawn Best1ecb68d2014-11-11 17:34:58 +0000222cxx_compiler_notdir = $(if $(findstring clang,$(1)), \
223 $(subst clang,clang++,$(1)), \
224 $(if $(findstring icc,$(1)), \
225 $(subst icc,icpc,$(1)), \
226 $(if $(findstring llvm-gcc,$(1)), \
227 $(subst llvm-gcc,llvm-g++,$(1)), \
228 $(if $(findstring gcc,$(1)), \
229 $(subst gcc,g++,$(1)), \
230 $(subst cc,c++,$(1))))))
Greg Claytonb39751b2013-11-22 21:05:25 +0000231cxx_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 +0000232
233# Function that returns the C++ linker, given $(CC) as arg.
Shawn Best1ecb68d2014-11-11 17:34:58 +0000234cxx_linker_notdir = $(if $(findstring clang,$(1)), \
235 $(subst clang,clang++,$(1)), \
236 $(if $(findstring icc,$(1)), \
237 $(subst icc,icpc,$(1)), \
238 $(if $(findstring llvm-gcc,$(1)), \
239 $(subst llvm-gcc,llvm-g++,$(1)), \
240 $(if $(findstring gcc,$(1)), \
241 $(subst gcc,g++,$(1)), \
242 $(subst cc,c++,$(1))))))
Greg Claytonb39751b2013-11-22 21:05:25 +0000243cxx_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 +0000244
Robert Flackfa8aa172015-04-20 18:07:55 +0000245OBJCOPY := $(CROSS_COMPILE)objcopy
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000246
Johnny Chen9bc867a2010-08-23 23:56:08 +0000247#----------------------------------------------------------------------
Zachary Turnere068d912014-12-01 23:13:41 +0000248# Windows specific options
Zachary Turnerc7826522014-08-13 17:44:53 +0000249#----------------------------------------------------------------------
250ifeq "$(OS)" "Windows_NT"
251 ifneq (,$(findstring clang,$(CC)))
Zachary Turnere068d912014-12-01 23:13:41 +0000252 # Clang for Windows doesn't support C++ Exceptions
Zachary Turnerc7826522014-08-13 17:44:53 +0000253 CXXFLAGS += -fno-exceptions
Zachary Turnerc7826522014-08-13 17:44:53 +0000254 CXXFLAGS += -D_HAS_EXCEPTIONS=0
Zachary Turnere068d912014-12-01 23:13:41 +0000255 # The MSVC linker doesn't understand long section names
256 # generated by the clang compiler.
257 LDFLAGS += -fuse-ld=lld
Zachary Turnerc7826522014-08-13 17:44:53 +0000258 endif
259endif
260
261#----------------------------------------------------------------------
Tamas Berghammer37099e82015-02-25 13:02:08 +0000262# Android specific options
263#----------------------------------------------------------------------
264ifeq "$(OS)" "Android"
Chaoren Lin9070f532015-07-17 22:13:29 +0000265 ifdef PIE
266 LDFLAGS += -pie
267 endif
Chaoren Lin7d76a132015-06-02 16:43:19 +0000268 replace_with = $(if $(findstring clang,$(1)), \
269 $(subst clang,$(2),$(1)), \
270 $(if $(findstring gcc,$(1)), \
271 $(subst gcc,$(2),$(1)), \
272 $(subst cc,$(2),$(1))))
273 ifeq "$(notdir $(CC))" "$(CC)"
274 replace_cc_with = $(call replace_with,$(CC),$(1))
275 else
276 replace_cc_with = $(join $(dir $(CC)),$(call replace_with,$(notdir $(CC)),$(1)))
277 endif
278 OBJCOPY = $(call replace_cc_with,objcopy)
279 AR = $(call replace_cc_with,ar)
Tamas Berghammer37099e82015-02-25 13:02:08 +0000280endif
281
282#----------------------------------------------------------------------
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000283# C++ standard library options
284#----------------------------------------------------------------------
285ifeq (1,$(USE_LIBSTDCPP))
286 # Clang requires an extra flag: -stdlib=libstdc++
287 ifneq (,$(findstring clang,$(CC)))
Enrico Granataa1acb492013-06-07 01:58:52 +0000288 CXXFLAGS += -stdlib=libstdc++
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000289 LDFLAGS += -stdlib=libstdc++
290 endif
291endif
292
Greg Clayton1767a732013-06-13 21:27:14 +0000293ifeq (1,$(USE_LIBCPP))
294 # Clang requires an extra flag: -stdlib=libstdc++
295 ifneq (,$(findstring clang,$(CC)))
Vince Harronf2e37602015-05-04 02:56:32 +0000296 ifeq "$(OS)" "Linux"
297 # This is the default install location on Ubuntu 14.04
Enrico Granataf6fe3022015-09-18 22:26:34 +0000298 ifneq ($(wildcard /usr/include/c++/v1/.),)
Todd Fiala82ffb8e2015-10-22 00:23:38 +0000299 CXXFLAGS += -stdlib=libc++ -DLLDB_USING_LIBCPP
Enrico Granataf6fe3022015-09-18 22:26:34 +0000300 LDFLAGS += -stdlib=libc++
301 CXXFLAGS += -I/usr/include/c++/v1
302 endif
303 else
Todd Fiala82ffb8e2015-10-22 00:23:38 +0000304 CXXFLAGS += -stdlib=libc++ -DLLDB_USING_LIBCPP
Enrico Granataf6fe3022015-09-18 22:26:34 +0000305 LDFLAGS += -stdlib=libc++
306 endif
Greg Clayton1767a732013-06-13 21:27:14 +0000307 endif
308endif
309
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000310#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000311# dylib settings
312#----------------------------------------------------------------------
313ifneq "$(strip $(DYLIB_C_SOURCES))" ""
314 DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
315endif
316
Sean Callanan72772842012-02-22 23:57:45 +0000317ifneq "$(strip $(DYLIB_OBJC_SOURCES))" ""
318 DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o))
319endif
320
Greg Claytond50d2382012-01-10 00:00:15 +0000321ifneq "$(strip $(DYLIB_CXX_SOURCES))" ""
322 DYLIB_OBJECTS +=$(strip $(DYLIB_CXX_SOURCES:.cpp=.o))
323 CXX = $(call cxx_compiler,$(CC))
324 LD = $(call cxx_linker,$(CC))
325endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000326
327#----------------------------------------------------------------------
328# Check if we have any C source files
329#----------------------------------------------------------------------
330ifneq "$(strip $(C_SOURCES))" ""
331 OBJECTS +=$(strip $(C_SOURCES:.c=.o))
332endif
333
334#----------------------------------------------------------------------
335# Check if we have any C++ source files
336#----------------------------------------------------------------------
337ifneq "$(strip $(CXX_SOURCES))" ""
338 OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
Johnny Chen832d2332010-09-30 01:22:34 +0000339 CXX = $(call cxx_compiler,$(CC))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000340 LD = $(call cxx_linker,$(CC))
Johnny Chen9bc867a2010-08-23 23:56:08 +0000341endif
342
343#----------------------------------------------------------------------
344# Check if we have any ObjC source files
345#----------------------------------------------------------------------
346ifneq "$(strip $(OBJC_SOURCES))" ""
347 OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o))
348 LDFLAGS +=-lobjc
349endif
350
351#----------------------------------------------------------------------
352# Check if we have any ObjC++ source files
353#----------------------------------------------------------------------
354ifneq "$(strip $(OBJCXX_SOURCES))" ""
355 OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
Johnny Chen832d2332010-09-30 01:22:34 +0000356 CXX = $(call cxx_compiler,$(CC))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000357 LD = $(call cxx_linker,$(CC))
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000358 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
Johnny Chen9bc867a2010-08-23 23:56:08 +0000359 LDFLAGS +=-lobjc
360 endif
361endif
362
Johnny Chenfe141622012-01-12 23:09:42 +0000363#----------------------------------------------------------------------
364# Check if we have any C source files for archive
365#----------------------------------------------------------------------
366ifneq "$(strip $(ARCHIVE_C_SOURCES))" ""
367 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_C_SOURCES:.c=.o))
368endif
369
370#----------------------------------------------------------------------
371# Check if we have any C++ source files for archive
372#----------------------------------------------------------------------
373ifneq "$(strip $(ARCHIVE_CXX_SOURCES))" ""
374 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_CXX_SOURCES:.cpp=.o))
375 CXX = $(call cxx_compiler,$(CC))
376 LD = $(call cxx_linker,$(CC))
377endif
378
379#----------------------------------------------------------------------
380# Check if we have any ObjC source files for archive
381#----------------------------------------------------------------------
382ifneq "$(strip $(ARCHIVE_OBJC_SOURCES))" ""
383 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJC_SOURCES:.m=.o))
384 LDFLAGS +=-lobjc
385endif
386
387#----------------------------------------------------------------------
388# Check if we have any ObjC++ source files for archive
389#----------------------------------------------------------------------
390ifneq "$(strip $(ARCHIVE_OBJCXX_SOURCES))" ""
391 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJCXX_SOURCES:.mm=.o))
392 CXX = $(call cxx_compiler,$(CC))
393 LD = $(call cxx_linker,$(CC))
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000394 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
Johnny Chenfe141622012-01-12 23:09:42 +0000395 LDFLAGS +=-lobjc
396 endif
397endif
398
Matt Kopecf2430f52013-07-24 21:39:24 +0000399#----------------------------------------------------------------------
400# Check if we are compiling with gcc 4.6
401#----------------------------------------------------------------------
Ed Maste375432e2015-05-29 19:52:02 +0000402ifneq "$(strip $(CXX_SOURCES) $(OBJCXX_SOURCES))" ""
403ifneq "$(filter g++,$(CXX))" ""
404 CXXVERSION = $(shell $(CXX) -dumpversion | cut -b 1-3)
Matt Kopecf2430f52013-07-24 21:39:24 +0000405 ifeq "$(CXXVERSION)" "4.6"
406 # GCC 4.6 cannot handle -std=c++11, so replace it with -std=c++0x
407 # instead. FIXME: remove once GCC version is upgraded.
408 override CXXFLAGS := $(subst -std=c++11,-std=c++0x,$(CXXFLAGS))
409 endif
410endif
Ed Maste375432e2015-05-29 19:52:02 +0000411endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000412
413#----------------------------------------------------------------------
Johnny Chenbeac8f92012-01-10 00:41:11 +0000414# DYLIB_ONLY variable can be used to skip the building of a.out.
415# See the sections below regarding dSYM file as well as the building of
416# EXE from all the objects.
417#----------------------------------------------------------------------
418
419#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000420# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO"
421#----------------------------------------------------------------------
Matt Kopec7663b3a2013-09-25 17:44:00 +0000422ifneq "$(DYLIB_ONLY)" "YES"
Michael Sartain802b0552013-07-02 18:13:13 +0000423$(DSYM) : $(EXE)
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000424ifeq "$(OS)" "Darwin"
Johnny Chen91016392011-06-20 20:08:26 +0000425ifneq "$(MAKE_DSYM)" "NO"
Enrico Granata489af082014-11-18 22:47:33 +0000426 "$(DS)" $(DSFLAGS) -o "$(DSYM)" "$(EXE)"
Johnny Chen91016392011-06-20 20:08:26 +0000427endif
Michael Sartain802b0552013-07-02 18:13:13 +0000428else
429ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000430 $(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
431 $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
Michael Sartain802b0552013-07-02 18:13:13 +0000432endif
433endif
Johnny Chenbeac8f92012-01-10 00:41:11 +0000434endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000435
436#----------------------------------------------------------------------
437# Compile the executable from all the objects.
438#----------------------------------------------------------------------
Johnny Chenbeac8f92012-01-10 00:41:11 +0000439ifneq "$(DYLIB_NAME)" ""
440ifeq "$(DYLIB_ONLY)" ""
Johnny Chenfe141622012-01-12 23:09:42 +0000441$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME)
Richard Mittonec8b2822013-10-17 20:09:33 +0000442 $(LD) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)"
Johnny Chenbeac8f92012-01-10 00:41:11 +0000443else
444EXE = $(DYLIB_FILENAME)
445endif
446else
Johnny Chenfe141622012-01-12 23:09:42 +0000447$(EXE) : $(OBJECTS) $(ARCHIVE_NAME)
Daniel Malea2745d842013-01-25 00:31:48 +0000448 $(LD) $(OBJECTS) $(LDFLAGS) $(ARCHIVE_NAME) -o "$(EXE)"
Johnny Chenfe141622012-01-12 23:09:42 +0000449endif
450
451#----------------------------------------------------------------------
452# Make the archive
453#----------------------------------------------------------------------
454ifneq "$(ARCHIVE_NAME)" ""
455ifeq "$(OS)" "Darwin"
456$(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS)
457 $(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
458 $(RM) $(ARCHIVE_OBJECTS)
459else
460$(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj)))
461endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000462endif
463
464#----------------------------------------------------------------------
465# Make the dylib
466#----------------------------------------------------------------------
Zachary Turner794e6a62015-03-13 21:51:11 +0000467$(DYLIB_OBJECTS) : CFLAGS += -DCOMPILING_LLDB_TEST_DLL
468
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000469$(DYLIB_FILENAME) : $(DYLIB_OBJECTS)
470ifeq "$(OS)" "Darwin"
Chaoren Lin29449152015-07-21 17:50:16 +0000471 $(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -install_name "$(DYLIB_EXECUTABLE_PATH)/$(DYLIB_FILENAME)" -dynamiclib -o "$(DYLIB_FILENAME)"
Greg Clayton0c9773c2012-09-20 21:43:11 +0000472ifneq "$(MAKE_DSYM)" "NO"
473ifneq "$(DS)" ""
Kate Stone2136ace2015-01-21 19:30:00 +0000474 "$(DS)" $(DSFLAGS) "$(DYLIB_FILENAME)"
Greg Clayton0c9773c2012-09-20 21:43:11 +0000475endif
476endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000477else
Chaoren Lin54fff4c2015-04-16 22:03:43 +0000478 $(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
Michael Sartain802b0552013-07-02 18:13:13 +0000479ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000480 $(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
481 $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
Michael Sartain802b0552013-07-02 18:13:13 +0000482endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000483endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000484
485#----------------------------------------------------------------------
486# Automatic variables based on items already entered. Below we create
Zachary Turner794e6a62015-03-13 21:51:11 +0000487# an object's lists from the list of sources by replacing all entries
Johnny Chen9bc867a2010-08-23 23:56:08 +0000488# that end with .c with .o, and we also create a list of prerequisite
489# files by replacing all .c files with .d.
490#----------------------------------------------------------------------
491PREREQS := $(OBJECTS:.o=.d)
Pavel Labathbaf54a82015-10-21 12:56:37 +0000492DWOS := $(OBJECTS:.o=.dwo) $(ARCHIVE_OBJECTS:.o=.dwo)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000493ifneq "$(DYLIB_NAME)" ""
494 DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d)
Tamas Berghammer1535beb2015-09-09 10:20:30 +0000495 DYLIB_DWOS := $(DYLIB_OBJECTS:.o=.dwo)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000496endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000497
498#----------------------------------------------------------------------
499# Rule for Generating Prerequisites Automatically using .d files and
500# the compiler -MM option. The -M option will list all system headers,
501# and the -MM option will list all non-system dependencies.
502#----------------------------------------------------------------------
Chaoren Lind761a952015-09-16 21:51:51 +0000503ifeq "$(HOST_OS)" "Windows_NT"
Zachary Turner794e6a62015-03-13 21:51:11 +0000504 JOIN_CMD = &
505 QUOTE = "
506else
507 JOIN_CMD = ;
508 QUOTE = '
509endif
510
Johnny Chen9bc867a2010-08-23 23:56:08 +0000511%.d: %.c
Zachary Turner794e6a62015-03-13 21:51:11 +0000512 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000513 $(CC) -M $(CFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000514 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000515 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000516
517%.d: %.cpp
Zachary Turner794e6a62015-03-13 21:51:11 +0000518 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000519 $(CXX) -M $(CXXFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000520 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000521 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000522
523%.d: %.m
Zachary Turner794e6a62015-03-13 21:51:11 +0000524 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000525 $(CC) -M $(CFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000526 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000527 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000528
529%.d: %.mm
Zachary Turner794e6a62015-03-13 21:51:11 +0000530 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000531 $(CXX) -M $(CXXFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000532 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000533 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000534
535#----------------------------------------------------------------------
536# Include all of the makefiles for each source file so we don't have
537# to manually track all of the prerequisites for each source file.
538#----------------------------------------------------------------------
539sinclude $(PREREQS)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000540ifneq "$(DYLIB_NAME)" ""
541 sinclude $(DYLIB_PREREQS)
542endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000543
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000544# Define a suffix rule for .mm -> .o
545.SUFFIXES: .mm .o
546.mm.o:
547 $(CXX) $(CXXFLAGS) -c $<
548
Johnny Chen9bc867a2010-08-23 23:56:08 +0000549.PHONY: clean
550dsym: $(DSYM)
551all: $(EXE) $(DSYM)
Johnny Chene1030cd2010-09-27 20:44:46 +0000552clean::
Tamas Berghammer1535beb2015-09-09 10:20:30 +0000553 $(RM) $(OBJECTS) $(PREREQS) $(PREREQS:.d=.d.tmp) $(DWOS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
Ed Maste0990e052014-03-07 17:20:50 +0000554ifneq "$(DYLIB_NAME)" ""
Jason Molenda53b8ea12014-03-08 01:53:27 +0000555 $(RM) -r $(DYLIB_FILENAME).dSYM
Tamas Berghammer1535beb2015-09-09 10:20:30 +0000556 $(RM) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_PREREQS:.d=.d.tmp) $(DYLIB_DWOS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).debug
Johnny Chen9bc867a2010-08-23 23:56:08 +0000557endif
Ed Maste0990e052014-03-07 17:20:50 +0000558ifneq "$(DSYM)" ""
Jason Molenda53b8ea12014-03-08 01:53:27 +0000559 $(RM) -r "$(DSYM)"
Ed Maste0990e052014-03-07 17:20:50 +0000560endif
Zachary Turner3e9ca3a2014-12-16 16:48:19 +0000561ifeq "$(OS)" "Windows_NT"
Zachary Turner0844d8d2015-08-26 19:44:45 +0000562# http://llvm.org/pr24589
563 IF EXIST "$(EXE)" del "$(EXE)"
Zachary Turner65fe1eb2015-03-26 16:43:25 +0000564 $(RM) $(wildcard *.manifest *.pdb *.ilk)
Zachary Turner0844d8d2015-08-26 19:44:45 +0000565ifneq "$(DYLIB_NAME)" ""
Zachary Turner65fe1eb2015-03-26 16:43:25 +0000566 $(RM) $(DYLIB_NAME).lib $(DYLIB_NAME).exp
Zachary Turner0844d8d2015-08-26 19:44:45 +0000567endif
568else
569 $(RM) "$(EXE)"
Zachary Turner3e9ca3a2014-12-16 16:48:19 +0000570endif
Johnny Chenfa380412011-01-14 21:18:12 +0000571
572#----------------------------------------------------------------------
573# From http://blog.melski.net/tag/debugging-makefiles/
574#
575# Usage: make print-CC print-CXX print-LD
576#----------------------------------------------------------------------
577print-%:
578 @echo '$*=$($*)'
579 @echo ' origin = $(origin $*)'
580 @echo ' flavor = $(flavor $*)'
581 @echo ' value = $(value $*)'
Johnny Chen8b2c3212011-01-28 17:22:29 +0000582
Johnny Chen8b2c3212011-01-28 17:22:29 +0000583### Local Variables: ###
584### mode:makefile ###
585### End: ###