blob: fcb67adffeae69a68fec249ce0bdaa26be968c02 [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
Johnny Chen9bc867a2010-08-23 23:56:08 +000033#----------------------------------------------------------------------
Peter Collingbourne518f03d2011-06-20 19:06:04 +000034# If OS is not defined, use 'uname -s' to determine the OS name.
Adrian McCarthyb4b8bb72015-04-15 23:38:23 +000035#
36# uname on Windows gives "windows32", but most environments standardize
37# on "Windows_NT", so we'll make it consistent here. When running
38# tests from Visual Studio, the environment variable isn't inherited
39# all the way down to the process spawned for make.
40#----------------------------------------------------------------------
41ifeq "$(OS)" ""
42 OS = $(shell uname -s)
43endif
44ifeq "$(OS)" "windows32"
45 OS = Windows_NT
46endif
47
48#----------------------------------------------------------------------
49# If ARCH is not defined, default to x86_64.
Johnny Chen6c17c082010-09-16 20:54:06 +000050#----------------------------------------------------------------------
51ifeq "$(ARCH)" ""
Zachary Turnere068d912014-12-01 23:13:41 +000052ifeq "$(OS)" "Windows_NT"
53 ARCH = x86
54else
Johnny Chen6c17c082010-09-16 20:54:06 +000055 ARCH = x86_64
56endif
Zachary Turnere068d912014-12-01 23:13:41 +000057endif
Johnny Chen6c17c082010-09-16 20:54:06 +000058
59#----------------------------------------------------------------------
Johnny Chen597cbbb2011-08-23 21:54:10 +000060# CC defaults to clang.
Johnny Chen4ab4a9b2011-08-24 18:12:53 +000061#
62# If you change the defaults of CC, be sure to also change it in the file
63# test/plugins/builder_base.py, which provides a Python way to return the
64# value of the make variable CC -- getCompiler().
65#
Johnny Chen6055b442011-01-14 20:55:13 +000066# See also these functions:
67# o cxx_compiler
68# o cxx_linker
Johnny Chend43e2082011-01-14 20:46:49 +000069#----------------------------------------------------------------------
Johnny Chen597cbbb2011-08-23 21:54:10 +000070CC ?= clang
Johnny Chend43e2082011-01-14 20:46:49 +000071ifeq "$(CC)" "cc"
Vince Harron847e2612015-05-27 04:42:54 +000072 ifneq "$(shell which clang)" ""
73 CC = clang
74 else ifneq "$(shell which clang-3.5)" ""
75 CC = clang-3.5
76 else ifneq "$(shell which gcc)" ""
77 CC = gcc
78 endif
Johnny Chend43e2082011-01-14 20:46:49 +000079endif
80
81#----------------------------------------------------------------------
Daniel Malea2745d842013-01-25 00:31:48 +000082# ARCHFLAG is the flag used to tell the compiler which architecture
83# to compile for. The default is the flag that clang accepts.
84#----------------------------------------------------------------------
Greg Clayton2c93b802015-04-16 01:18:05 +000085ARCHFLAG ?= -arch
Daniel Malea2745d842013-01-25 00:31:48 +000086
87#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +000088# Change any build/tool options needed
89#----------------------------------------------------------------------
Peter Collingbourne518f03d2011-06-20 19:06:04 +000090ifeq "$(OS)" "Darwin"
Greg Clayton82625d32014-07-29 20:10:59 +000091 DS := $(shell xcrun -find -toolchain default dsymutil)
Peter Collingbourne518f03d2011-06-20 19:06:04 +000092 DSFLAGS =
93 DSYM = $(EXE).dSYM
Robert Flackfa8aa172015-04-20 18:07:55 +000094 AR := $(CROSS_COMPILE)libtool
Johnny Chenfe141622012-01-12 23:09:42 +000095 ARFLAGS := -static -o
Daniel Malea2745d842013-01-25 00:31:48 +000096else
Robert Flackfa8aa172015-04-20 18:07:55 +000097 AR := $(CROSS_COMPILE)ar
Daniel Malea2745d842013-01-25 00:31:48 +000098 # On non-Apple platforms, -arch becomes -m
99 ARCHFLAG := -m
100
Zachary Turnerc7826522014-08-13 17:44:53 +0000101 # i386, i686, x86 -> 32
Zachary Turner7c1bc2b2014-07-31 21:07:41 +0000102 # amd64, x86_64, x64 -> 64
Ed Maste4fe0aba2014-02-20 18:40:01 +0000103 ifeq "$(ARCH)" "amd64"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +0000104 override ARCH := $(subst amd64,64,$(ARCH))
Ed Maste4fe0aba2014-02-20 18:40:01 +0000105 endif
Daniel Malea2745d842013-01-25 00:31:48 +0000106 ifeq "$(ARCH)" "x86_64"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +0000107 override ARCH := $(subst x86_64,64,$(ARCH))
108 endif
109 ifeq "$(ARCH)" "x64"
110 override ARCH := $(subst x64,64,$(ARCH))
Daniel Malea2745d842013-01-25 00:31:48 +0000111 endif
Zachary Turnerc7826522014-08-13 17:44:53 +0000112 ifeq "$(ARCH)" "x86"
113 override ARCH := $(subst x86,32,$(ARCH))
114 endif
Daniel Malea2745d842013-01-25 00:31:48 +0000115 ifeq "$(ARCH)" "i386"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +0000116 override ARCH := $(subst i386,32,$(ARCH))
117 endif
118 ifeq "$(ARCH)" "i686"
119 override ARCH := $(subst i686,32,$(ARCH))
Daniel Malea2745d842013-01-25 00:31:48 +0000120 endif
Justin Hibbits3cba1c22014-11-12 15:13:58 +0000121 ifeq "$(ARCH)" "powerpc"
122 override ARCH := $(subst powerpc,32,$(ARCH))
123 endif
124 ifeq "$(ARCH)" "powerpc64"
125 override ARCH := $(subst powerpc64,64,$(ARCH))
126 endif
Tamas Berghammer1e209fc2015-03-13 11:36:47 +0000127 ifeq "$(ARCH)" "aarch64"
128 override ARCH :=
129 override ARCHFLAG :=
130 endif
Michael Sartain802b0552013-07-02 18:13:13 +0000131
132 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
133 DSYM = $(EXE).debug
134 endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000135endif
136
Ilia Kfeda0b72015-05-12 12:13:12 +0000137CFLAGS ?= -g -O0 -fno-builtin
Greg Clayton2c93b802015-04-16 01:18:05 +0000138ifeq "$(OS)" "Darwin"
139 CFLAGS += $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
140else
141 CFLAGS += $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
142endif
Zachary Turner794e6a62015-03-13 21:51:11 +0000143CFLAGS += -include $(THIS_FILE_DIR)test_common.h
Daniel Malea2745d842013-01-25 00:31:48 +0000144
Jim Ingham4b4b2472014-03-13 02:47:14 +0000145# Use this one if you want to build one part of the result without debug information:
Greg Clayton2c93b802015-04-16 01:18:05 +0000146ifeq "$(OS)" "Darwin"
147 CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS)
148else
149 CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS)
150endif
Jim Ingham4b4b2472014-03-13 02:47:14 +0000151
Zachary Turnerc7826522014-08-13 17:44:53 +0000152CXXFLAGS += -std=c++11
153CXXFLAGS += $(CFLAGS)
Johnny Chen53e2edb2011-08-09 20:07:16 +0000154LD = $(CC)
155LDFLAGS ?= $(CFLAGS)
Daniel Malea2745d842013-01-25 00:31:48 +0000156LDFLAGS += $(LD_EXTRAS)
Tamas Berghammer37099e82015-02-25 13:02:08 +0000157ifeq (,$(filter $(OS), Windows_NT Android))
Chaoren Linf4a92bd2015-04-13 18:21:31 +0000158 ifneq (,$(filter YES,$(ENABLE_THREADS) $(ENABLE_STD_THREADS)))
Chaoren Lin36758cf2015-05-21 00:19:15 +0000159 LDFLAGS += -pthread
Chaoren Linf4a92bd2015-04-13 18:21:31 +0000160 endif
Zachary Turnerc7826522014-08-13 17:44:53 +0000161endif
Johnny Chen53e2edb2011-08-09 20:07:16 +0000162OBJECTS =
163EXE ?= a.out
164
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000165ifneq "$(DYLIB_NAME)" ""
166 ifeq "$(OS)" "Darwin"
167 DYLIB_FILENAME = lib$(DYLIB_NAME).dylib
Chaoren Linf4a92bd2015-04-13 18:21:31 +0000168 else ifeq "$(OS)" "Windows_NT"
169 DYLIB_FILENAME = $(DYLIB_NAME).dll
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000170 else
171 DYLIB_FILENAME = lib$(DYLIB_NAME).so
172 endif
173endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000174
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000175# Function that returns the counterpart C++ compiler, given $(CC) as arg.
Shawn Best1ecb68d2014-11-11 17:34:58 +0000176cxx_compiler_notdir = $(if $(findstring clang,$(1)), \
177 $(subst clang,clang++,$(1)), \
178 $(if $(findstring icc,$(1)), \
179 $(subst icc,icpc,$(1)), \
180 $(if $(findstring llvm-gcc,$(1)), \
181 $(subst llvm-gcc,llvm-g++,$(1)), \
182 $(if $(findstring gcc,$(1)), \
183 $(subst gcc,g++,$(1)), \
184 $(subst cc,c++,$(1))))))
Greg Claytonb39751b2013-11-22 21:05:25 +0000185cxx_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 +0000186
187# Function that returns the C++ linker, given $(CC) as arg.
Shawn Best1ecb68d2014-11-11 17:34:58 +0000188cxx_linker_notdir = $(if $(findstring clang,$(1)), \
189 $(subst clang,clang++,$(1)), \
190 $(if $(findstring icc,$(1)), \
191 $(subst icc,icpc,$(1)), \
192 $(if $(findstring llvm-gcc,$(1)), \
193 $(subst llvm-gcc,llvm-g++,$(1)), \
194 $(if $(findstring gcc,$(1)), \
195 $(subst gcc,g++,$(1)), \
196 $(subst cc,c++,$(1))))))
Greg Claytonb39751b2013-11-22 21:05:25 +0000197cxx_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 +0000198
Robert Flackfa8aa172015-04-20 18:07:55 +0000199OBJCOPY := $(CROSS_COMPILE)objcopy
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000200
Johnny Chen9bc867a2010-08-23 23:56:08 +0000201#----------------------------------------------------------------------
Zachary Turnere068d912014-12-01 23:13:41 +0000202# Windows specific options
Zachary Turnerc7826522014-08-13 17:44:53 +0000203#----------------------------------------------------------------------
204ifeq "$(OS)" "Windows_NT"
205 ifneq (,$(findstring clang,$(CC)))
Zachary Turnere068d912014-12-01 23:13:41 +0000206 # Clang for Windows doesn't support C++ Exceptions
Zachary Turnerc7826522014-08-13 17:44:53 +0000207 CXXFLAGS += -fno-exceptions
Zachary Turnerc7826522014-08-13 17:44:53 +0000208 CXXFLAGS += -D_HAS_EXCEPTIONS=0
Zachary Turnere068d912014-12-01 23:13:41 +0000209 # The MSVC linker doesn't understand long section names
210 # generated by the clang compiler.
211 LDFLAGS += -fuse-ld=lld
Zachary Turnerc7826522014-08-13 17:44:53 +0000212 endif
213endif
214
215#----------------------------------------------------------------------
Tamas Berghammer37099e82015-02-25 13:02:08 +0000216# Android specific options
217#----------------------------------------------------------------------
218ifeq "$(OS)" "Android"
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000219 LDFLAGS += -pie
Chaoren Lin7d76a132015-06-02 16:43:19 +0000220 replace_with = $(if $(findstring clang,$(1)), \
221 $(subst clang,$(2),$(1)), \
222 $(if $(findstring gcc,$(1)), \
223 $(subst gcc,$(2),$(1)), \
224 $(subst cc,$(2),$(1))))
225 ifeq "$(notdir $(CC))" "$(CC)"
226 replace_cc_with = $(call replace_with,$(CC),$(1))
227 else
228 replace_cc_with = $(join $(dir $(CC)),$(call replace_with,$(notdir $(CC)),$(1)))
229 endif
230 OBJCOPY = $(call replace_cc_with,objcopy)
231 AR = $(call replace_cc_with,ar)
Tamas Berghammer37099e82015-02-25 13:02:08 +0000232endif
233
234#----------------------------------------------------------------------
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000235# C++ standard library options
236#----------------------------------------------------------------------
237ifeq (1,$(USE_LIBSTDCPP))
238 # Clang requires an extra flag: -stdlib=libstdc++
239 ifneq (,$(findstring clang,$(CC)))
Enrico Granataa1acb492013-06-07 01:58:52 +0000240 CXXFLAGS += -stdlib=libstdc++
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000241 LDFLAGS += -stdlib=libstdc++
242 endif
243endif
244
Greg Clayton1767a732013-06-13 21:27:14 +0000245ifeq (1,$(USE_LIBCPP))
246 # Clang requires an extra flag: -stdlib=libstdc++
247 ifneq (,$(findstring clang,$(CC)))
248 CXXFLAGS += -stdlib=libc++
249 LDFLAGS += -stdlib=libc++
Vince Harronf2e37602015-05-04 02:56:32 +0000250 ifeq "$(OS)" "Linux"
251 # This is the default install location on Ubuntu 14.04
252 CXXFLAGS += -I/usr/include/c++/v1
253 endif
Greg Clayton1767a732013-06-13 21:27:14 +0000254 endif
255endif
256
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000257#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000258# dylib settings
259#----------------------------------------------------------------------
260ifneq "$(strip $(DYLIB_C_SOURCES))" ""
261 DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
262endif
263
Sean Callanan72772842012-02-22 23:57:45 +0000264ifneq "$(strip $(DYLIB_OBJC_SOURCES))" ""
265 DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o))
266endif
267
Greg Claytond50d2382012-01-10 00:00:15 +0000268ifneq "$(strip $(DYLIB_CXX_SOURCES))" ""
269 DYLIB_OBJECTS +=$(strip $(DYLIB_CXX_SOURCES:.cpp=.o))
270 CXX = $(call cxx_compiler,$(CC))
271 LD = $(call cxx_linker,$(CC))
272endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000273
274#----------------------------------------------------------------------
275# Check if we have any C source files
276#----------------------------------------------------------------------
277ifneq "$(strip $(C_SOURCES))" ""
278 OBJECTS +=$(strip $(C_SOURCES:.c=.o))
279endif
280
281#----------------------------------------------------------------------
282# Check if we have any C++ source files
283#----------------------------------------------------------------------
284ifneq "$(strip $(CXX_SOURCES))" ""
285 OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
Johnny Chen832d2332010-09-30 01:22:34 +0000286 CXX = $(call cxx_compiler,$(CC))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000287 LD = $(call cxx_linker,$(CC))
Johnny Chen9bc867a2010-08-23 23:56:08 +0000288endif
289
290#----------------------------------------------------------------------
291# Check if we have any ObjC source files
292#----------------------------------------------------------------------
293ifneq "$(strip $(OBJC_SOURCES))" ""
294 OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o))
295 LDFLAGS +=-lobjc
296endif
297
298#----------------------------------------------------------------------
299# Check if we have any ObjC++ source files
300#----------------------------------------------------------------------
301ifneq "$(strip $(OBJCXX_SOURCES))" ""
302 OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
Johnny Chen832d2332010-09-30 01:22:34 +0000303 CXX = $(call cxx_compiler,$(CC))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000304 LD = $(call cxx_linker,$(CC))
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000305 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
Johnny Chen9bc867a2010-08-23 23:56:08 +0000306 LDFLAGS +=-lobjc
307 endif
308endif
309
Johnny Chenfe141622012-01-12 23:09:42 +0000310#----------------------------------------------------------------------
311# Check if we have any C source files for archive
312#----------------------------------------------------------------------
313ifneq "$(strip $(ARCHIVE_C_SOURCES))" ""
314 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_C_SOURCES:.c=.o))
315endif
316
317#----------------------------------------------------------------------
318# Check if we have any C++ source files for archive
319#----------------------------------------------------------------------
320ifneq "$(strip $(ARCHIVE_CXX_SOURCES))" ""
321 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_CXX_SOURCES:.cpp=.o))
322 CXX = $(call cxx_compiler,$(CC))
323 LD = $(call cxx_linker,$(CC))
324endif
325
326#----------------------------------------------------------------------
327# Check if we have any ObjC source files for archive
328#----------------------------------------------------------------------
329ifneq "$(strip $(ARCHIVE_OBJC_SOURCES))" ""
330 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJC_SOURCES:.m=.o))
331 LDFLAGS +=-lobjc
332endif
333
334#----------------------------------------------------------------------
335# Check if we have any ObjC++ source files for archive
336#----------------------------------------------------------------------
337ifneq "$(strip $(ARCHIVE_OBJCXX_SOURCES))" ""
338 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJCXX_SOURCES:.mm=.o))
339 CXX = $(call cxx_compiler,$(CC))
340 LD = $(call cxx_linker,$(CC))
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000341 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
Johnny Chenfe141622012-01-12 23:09:42 +0000342 LDFLAGS +=-lobjc
343 endif
344endif
345
Matt Kopecf2430f52013-07-24 21:39:24 +0000346#----------------------------------------------------------------------
347# Check if we are compiling with gcc 4.6
348#----------------------------------------------------------------------
Ed Maste375432e2015-05-29 19:52:02 +0000349ifneq "$(strip $(CXX_SOURCES) $(OBJCXX_SOURCES))" ""
350ifneq "$(filter g++,$(CXX))" ""
351 CXXVERSION = $(shell $(CXX) -dumpversion | cut -b 1-3)
Matt Kopecf2430f52013-07-24 21:39:24 +0000352 ifeq "$(CXXVERSION)" "4.6"
353 # GCC 4.6 cannot handle -std=c++11, so replace it with -std=c++0x
354 # instead. FIXME: remove once GCC version is upgraded.
355 override CXXFLAGS := $(subst -std=c++11,-std=c++0x,$(CXXFLAGS))
356 endif
357endif
Ed Maste375432e2015-05-29 19:52:02 +0000358endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000359
360#----------------------------------------------------------------------
Johnny Chenbeac8f92012-01-10 00:41:11 +0000361# DYLIB_ONLY variable can be used to skip the building of a.out.
362# See the sections below regarding dSYM file as well as the building of
363# EXE from all the objects.
364#----------------------------------------------------------------------
365
366#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000367# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO"
368#----------------------------------------------------------------------
Matt Kopec7663b3a2013-09-25 17:44:00 +0000369ifneq "$(DYLIB_ONLY)" "YES"
Michael Sartain802b0552013-07-02 18:13:13 +0000370$(DSYM) : $(EXE)
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000371ifeq "$(OS)" "Darwin"
Johnny Chen91016392011-06-20 20:08:26 +0000372ifneq "$(MAKE_DSYM)" "NO"
Enrico Granata489af082014-11-18 22:47:33 +0000373 "$(DS)" $(DSFLAGS) -o "$(DSYM)" "$(EXE)"
Johnny Chen91016392011-06-20 20:08:26 +0000374endif
Michael Sartain802b0552013-07-02 18:13:13 +0000375else
376ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000377 $(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
378 $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
Michael Sartain802b0552013-07-02 18:13:13 +0000379endif
380endif
Johnny Chenbeac8f92012-01-10 00:41:11 +0000381endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000382
383#----------------------------------------------------------------------
384# Compile the executable from all the objects.
385#----------------------------------------------------------------------
Johnny Chenbeac8f92012-01-10 00:41:11 +0000386ifneq "$(DYLIB_NAME)" ""
387ifeq "$(DYLIB_ONLY)" ""
Johnny Chenfe141622012-01-12 23:09:42 +0000388$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME)
Richard Mittonec8b2822013-10-17 20:09:33 +0000389 $(LD) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)"
Johnny Chenbeac8f92012-01-10 00:41:11 +0000390else
391EXE = $(DYLIB_FILENAME)
392endif
393else
Johnny Chenfe141622012-01-12 23:09:42 +0000394$(EXE) : $(OBJECTS) $(ARCHIVE_NAME)
Daniel Malea2745d842013-01-25 00:31:48 +0000395 $(LD) $(OBJECTS) $(LDFLAGS) $(ARCHIVE_NAME) -o "$(EXE)"
Johnny Chenfe141622012-01-12 23:09:42 +0000396endif
397
398#----------------------------------------------------------------------
399# Make the archive
400#----------------------------------------------------------------------
401ifneq "$(ARCHIVE_NAME)" ""
402ifeq "$(OS)" "Darwin"
403$(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS)
404 $(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
405 $(RM) $(ARCHIVE_OBJECTS)
406else
407$(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj)))
408endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000409endif
410
411#----------------------------------------------------------------------
412# Make the dylib
413#----------------------------------------------------------------------
Zachary Turner794e6a62015-03-13 21:51:11 +0000414$(DYLIB_OBJECTS) : CFLAGS += -DCOMPILING_LLDB_TEST_DLL
415
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000416$(DYLIB_FILENAME) : $(DYLIB_OBJECTS)
417ifeq "$(OS)" "Darwin"
Chaoren Lin54fff4c2015-04-16 22:03:43 +0000418 $(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -install_name "@executable_path/$(DYLIB_FILENAME)" -dynamiclib -o "$(DYLIB_FILENAME)"
Greg Clayton0c9773c2012-09-20 21:43:11 +0000419ifneq "$(MAKE_DSYM)" "NO"
420ifneq "$(DS)" ""
Kate Stone2136ace2015-01-21 19:30:00 +0000421 "$(DS)" $(DSFLAGS) "$(DYLIB_FILENAME)"
Greg Clayton0c9773c2012-09-20 21:43:11 +0000422endif
423endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000424else
Chaoren Lin54fff4c2015-04-16 22:03:43 +0000425 $(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
Michael Sartain802b0552013-07-02 18:13:13 +0000426ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000427 $(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
428 $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
Michael Sartain802b0552013-07-02 18:13:13 +0000429endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000430endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000431
432#----------------------------------------------------------------------
433# Automatic variables based on items already entered. Below we create
Zachary Turner794e6a62015-03-13 21:51:11 +0000434# an object's lists from the list of sources by replacing all entries
Johnny Chen9bc867a2010-08-23 23:56:08 +0000435# that end with .c with .o, and we also create a list of prerequisite
436# files by replacing all .c files with .d.
437#----------------------------------------------------------------------
438PREREQS := $(OBJECTS:.o=.d)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000439ifneq "$(DYLIB_NAME)" ""
440 DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d)
441endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000442
443#----------------------------------------------------------------------
444# Rule for Generating Prerequisites Automatically using .d files and
445# the compiler -MM option. The -M option will list all system headers,
446# and the -MM option will list all non-system dependencies.
447#----------------------------------------------------------------------
Zachary Turner794e6a62015-03-13 21:51:11 +0000448ifeq "$(OS)" "Windows_NT"
449 JOIN_CMD = &
450 QUOTE = "
451else
452 JOIN_CMD = ;
453 QUOTE = '
454endif
455
Johnny Chen9bc867a2010-08-23 23:56:08 +0000456%.d: %.c
Zachary Turner794e6a62015-03-13 21:51:11 +0000457 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000458 $(CC) -M $(CFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000459 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000460 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000461
462%.d: %.cpp
Zachary Turner794e6a62015-03-13 21:51:11 +0000463 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000464 $(CXX) -M $(CXXFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000465 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000466 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000467
468%.d: %.m
Zachary Turner794e6a62015-03-13 21:51:11 +0000469 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000470 $(CC) -M $(CFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000471 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000472 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000473
474%.d: %.mm
Zachary Turner794e6a62015-03-13 21:51:11 +0000475 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000476 $(CXX) -M $(CXXFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000477 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000478 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000479
480#----------------------------------------------------------------------
481# Include all of the makefiles for each source file so we don't have
482# to manually track all of the prerequisites for each source file.
483#----------------------------------------------------------------------
484sinclude $(PREREQS)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000485ifneq "$(DYLIB_NAME)" ""
486 sinclude $(DYLIB_PREREQS)
487endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000488
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000489# Define a suffix rule for .mm -> .o
490.SUFFIXES: .mm .o
491.mm.o:
492 $(CXX) $(CXXFLAGS) -c $<
493
Johnny Chen9bc867a2010-08-23 23:56:08 +0000494.PHONY: clean
495dsym: $(DSYM)
496all: $(EXE) $(DSYM)
Johnny Chene1030cd2010-09-27 20:44:46 +0000497clean::
Pavel Labathf81ed472015-02-05 09:52:42 +0000498 $(RM) "$(EXE)" $(OBJECTS) $(PREREQS) $(PREREQS:.d=.d.tmp) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
Ed Maste0990e052014-03-07 17:20:50 +0000499ifneq "$(DYLIB_NAME)" ""
Jason Molenda53b8ea12014-03-08 01:53:27 +0000500 $(RM) -r $(DYLIB_FILENAME).dSYM
Pavel Labathf81ed472015-02-05 09:52:42 +0000501 $(RM) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_PREREQS:.d=.d.tmp) $(DYLIB_FILENAME) $(DYLIB_FILENAME).debug
Johnny Chen9bc867a2010-08-23 23:56:08 +0000502endif
Ed Maste0990e052014-03-07 17:20:50 +0000503ifneq "$(DSYM)" ""
Jason Molenda53b8ea12014-03-08 01:53:27 +0000504 $(RM) -r "$(DSYM)"
Ed Maste0990e052014-03-07 17:20:50 +0000505endif
Zachary Turner3e9ca3a2014-12-16 16:48:19 +0000506ifeq "$(OS)" "Windows_NT"
Zachary Turner65fe1eb2015-03-26 16:43:25 +0000507 $(RM) $(wildcard *.manifest *.pdb *.ilk)
Zachary Turner794e6a62015-03-13 21:51:11 +0000508 ifneq "$(DYLIB_NAME)" ""
Zachary Turner65fe1eb2015-03-26 16:43:25 +0000509 $(RM) $(DYLIB_NAME).lib $(DYLIB_NAME).exp
Zachary Turner794e6a62015-03-13 21:51:11 +0000510 endif
Zachary Turner3e9ca3a2014-12-16 16:48:19 +0000511endif
Johnny Chenfa380412011-01-14 21:18:12 +0000512
513#----------------------------------------------------------------------
514# From http://blog.melski.net/tag/debugging-makefiles/
515#
516# Usage: make print-CC print-CXX print-LD
517#----------------------------------------------------------------------
518print-%:
519 @echo '$*=$($*)'
520 @echo ' origin = $(origin $*)'
521 @echo ' flavor = $(flavor $*)'
522 @echo ' value = $(value $*)'
Johnny Chen8b2c3212011-01-28 17:22:29 +0000523
Johnny Chen8b2c3212011-01-28 17:22:29 +0000524### Local Variables: ###
525### mode:makefile ###
526### End: ###