blob: efad0ec803475c6ebfeea951985e662b122ebd3f [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 Flack666a9862015-03-24 12:41:20 +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
Johnny Chen64a7e742012-01-17 00:58:08 +000020#
21# And test/functionalities/archives/Makefile:
22# MAKE_DSYM := NO
23# ARCHIVE_NAME := libfoo.a
24# ARCHIVE_C_SOURCES := a.c b.c
Johnny Chen9bc867a2010-08-23 23:56:08 +000025
26# Uncomment line below for debugging shell commands
27# SHELL = /bin/sh -x
28
Zachary Turnerc7826522014-08-13 17:44:53 +000029THIS_FILE_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/
30LLDB_BASE_DIR := $(THIS_FILE_DIR)../../
31
Johnny Chen9bc867a2010-08-23 23:56:08 +000032#----------------------------------------------------------------------
Peter Collingbourne518f03d2011-06-20 19:06:04 +000033# If OS is not defined, use 'uname -s' to determine the OS name.
Adrian McCarthyb4b8bb72015-04-15 23:38:23 +000034#
35# uname on Windows gives "windows32", but most environments standardize
36# on "Windows_NT", so we'll make it consistent here. When running
37# tests from Visual Studio, the environment variable isn't inherited
38# all the way down to the process spawned for make.
39#----------------------------------------------------------------------
40ifeq "$(OS)" ""
41 OS = $(shell uname -s)
42endif
43ifeq "$(OS)" "windows32"
44 OS = Windows_NT
45endif
46
47#----------------------------------------------------------------------
48# If ARCH is not defined, default to x86_64.
Johnny Chen6c17c082010-09-16 20:54:06 +000049#----------------------------------------------------------------------
50ifeq "$(ARCH)" ""
Zachary Turnere068d912014-12-01 23:13:41 +000051ifeq "$(OS)" "Windows_NT"
52 ARCH = x86
53else
Johnny Chen6c17c082010-09-16 20:54:06 +000054 ARCH = x86_64
55endif
Zachary Turnere068d912014-12-01 23:13:41 +000056endif
Johnny Chen6c17c082010-09-16 20:54:06 +000057
58#----------------------------------------------------------------------
Johnny Chen597cbbb2011-08-23 21:54:10 +000059# CC defaults to clang.
Johnny Chen4ab4a9b2011-08-24 18:12:53 +000060#
61# If you change the defaults of CC, be sure to also change it in the file
62# test/plugins/builder_base.py, which provides a Python way to return the
63# value of the make variable CC -- getCompiler().
64#
Johnny Chen6055b442011-01-14 20:55:13 +000065# See also these functions:
66# o cxx_compiler
67# o cxx_linker
Johnny Chend43e2082011-01-14 20:46:49 +000068#----------------------------------------------------------------------
Johnny Chen597cbbb2011-08-23 21:54:10 +000069CC ?= clang
Johnny Chend43e2082011-01-14 20:46:49 +000070ifeq "$(CC)" "cc"
Johnny Chen597cbbb2011-08-23 21:54:10 +000071 CC = clang
Johnny Chend43e2082011-01-14 20:46:49 +000072endif
73
74#----------------------------------------------------------------------
Daniel Malea2745d842013-01-25 00:31:48 +000075# ARCHFLAG is the flag used to tell the compiler which architecture
76# to compile for. The default is the flag that clang accepts.
77#----------------------------------------------------------------------
Tamas Berghammer23fc4b02015-04-15 09:28:31 +000078ARCHFLAG ?= "-arch "
Daniel Malea2745d842013-01-25 00:31:48 +000079
80#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +000081# Change any build/tool options needed
82#----------------------------------------------------------------------
Peter Collingbourne518f03d2011-06-20 19:06:04 +000083ifeq "$(OS)" "Darwin"
Greg Clayton82625d32014-07-29 20:10:59 +000084 DS := $(shell xcrun -find -toolchain default dsymutil)
Peter Collingbourne518f03d2011-06-20 19:06:04 +000085 DSFLAGS =
86 DSYM = $(EXE).dSYM
Johnny Chenfe141622012-01-12 23:09:42 +000087 AR := libtool
88 ARFLAGS := -static -o
Daniel Malea2745d842013-01-25 00:31:48 +000089else
90 # On non-Apple platforms, -arch becomes -m
91 ARCHFLAG := -m
92
Zachary Turnerc7826522014-08-13 17:44:53 +000093 # i386, i686, x86 -> 32
Zachary Turner7c1bc2b2014-07-31 21:07:41 +000094 # amd64, x86_64, x64 -> 64
Ed Maste4fe0aba2014-02-20 18:40:01 +000095 ifeq "$(ARCH)" "amd64"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +000096 override ARCH := $(subst amd64,64,$(ARCH))
Ed Maste4fe0aba2014-02-20 18:40:01 +000097 endif
Daniel Malea2745d842013-01-25 00:31:48 +000098 ifeq "$(ARCH)" "x86_64"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +000099 override ARCH := $(subst x86_64,64,$(ARCH))
100 endif
101 ifeq "$(ARCH)" "x64"
102 override ARCH := $(subst x64,64,$(ARCH))
Daniel Malea2745d842013-01-25 00:31:48 +0000103 endif
Zachary Turnerc7826522014-08-13 17:44:53 +0000104 ifeq "$(ARCH)" "x86"
105 override ARCH := $(subst x86,32,$(ARCH))
106 endif
Daniel Malea2745d842013-01-25 00:31:48 +0000107 ifeq "$(ARCH)" "i386"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +0000108 override ARCH := $(subst i386,32,$(ARCH))
109 endif
110 ifeq "$(ARCH)" "i686"
111 override ARCH := $(subst i686,32,$(ARCH))
Daniel Malea2745d842013-01-25 00:31:48 +0000112 endif
Justin Hibbits3cba1c22014-11-12 15:13:58 +0000113 ifeq "$(ARCH)" "powerpc"
114 override ARCH := $(subst powerpc,32,$(ARCH))
115 endif
116 ifeq "$(ARCH)" "powerpc64"
117 override ARCH := $(subst powerpc64,64,$(ARCH))
118 endif
Tamas Berghammer1e209fc2015-03-13 11:36:47 +0000119 ifeq "$(ARCH)" "aarch64"
120 override ARCH :=
121 override ARCHFLAG :=
122 endif
Michael Sartain802b0552013-07-02 18:13:13 +0000123
124 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
125 DSYM = $(EXE).debug
126 endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000127endif
128
Greg Claytone595c6b2013-02-28 18:47:39 +0000129CFLAGS ?= -g -O0
Tamas Berghammer23fc4b02015-04-15 09:28:31 +0000130CFLAGS += $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
Zachary Turner794e6a62015-03-13 21:51:11 +0000131CFLAGS += -include $(THIS_FILE_DIR)test_common.h
Daniel Malea2745d842013-01-25 00:31:48 +0000132
Jim Ingham4b4b2472014-03-13 02:47:14 +0000133# Use this one if you want to build one part of the result without debug information:
Tamas Berghammer23fc4b02015-04-15 09:28:31 +0000134CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS)
Jim Ingham4b4b2472014-03-13 02:47:14 +0000135
Zachary Turnerc7826522014-08-13 17:44:53 +0000136CXXFLAGS += -std=c++11
137CXXFLAGS += $(CFLAGS)
Johnny Chen53e2edb2011-08-09 20:07:16 +0000138LD = $(CC)
139LDFLAGS ?= $(CFLAGS)
Daniel Malea2745d842013-01-25 00:31:48 +0000140LDFLAGS += $(LD_EXTRAS)
Tamas Berghammer37099e82015-02-25 13:02:08 +0000141ifeq (,$(filter $(OS), Windows_NT Android))
Chaoren Linf4a92bd2015-04-13 18:21:31 +0000142 ifneq (,$(filter YES,$(ENABLE_THREADS) $(ENABLE_STD_THREADS)))
143 LDFLAGS += -lpthread
144 endif
Zachary Turnerc7826522014-08-13 17:44:53 +0000145endif
Johnny Chen53e2edb2011-08-09 20:07:16 +0000146OBJECTS =
147EXE ?= a.out
148
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000149ifneq "$(DYLIB_NAME)" ""
150 ifeq "$(OS)" "Darwin"
151 DYLIB_FILENAME = lib$(DYLIB_NAME).dylib
Chaoren Linf4a92bd2015-04-13 18:21:31 +0000152 else ifeq "$(OS)" "Windows_NT"
153 DYLIB_FILENAME = $(DYLIB_NAME).dll
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000154 else
155 DYLIB_FILENAME = lib$(DYLIB_NAME).so
156 endif
157endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000158
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000159# Function that returns the counterpart C++ compiler, given $(CC) as arg.
Shawn Best1ecb68d2014-11-11 17:34:58 +0000160cxx_compiler_notdir = $(if $(findstring clang,$(1)), \
161 $(subst clang,clang++,$(1)), \
162 $(if $(findstring icc,$(1)), \
163 $(subst icc,icpc,$(1)), \
164 $(if $(findstring llvm-gcc,$(1)), \
165 $(subst llvm-gcc,llvm-g++,$(1)), \
166 $(if $(findstring gcc,$(1)), \
167 $(subst gcc,g++,$(1)), \
168 $(subst cc,c++,$(1))))))
Greg Claytonb39751b2013-11-22 21:05:25 +0000169cxx_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 +0000170
171# Function that returns the C++ linker, given $(CC) as arg.
Shawn Best1ecb68d2014-11-11 17:34:58 +0000172cxx_linker_notdir = $(if $(findstring clang,$(1)), \
173 $(subst clang,clang++,$(1)), \
174 $(if $(findstring icc,$(1)), \
175 $(subst icc,icpc,$(1)), \
176 $(if $(findstring llvm-gcc,$(1)), \
177 $(subst llvm-gcc,llvm-g++,$(1)), \
178 $(if $(findstring gcc,$(1)), \
179 $(subst gcc,g++,$(1)), \
180 $(subst cc,c++,$(1))))))
Greg Claytonb39751b2013-11-22 21:05:25 +0000181cxx_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 +0000182
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000183OBJCOPY = objcopy
184
Johnny Chen9bc867a2010-08-23 23:56:08 +0000185#----------------------------------------------------------------------
Zachary Turnere068d912014-12-01 23:13:41 +0000186# Windows specific options
Zachary Turnerc7826522014-08-13 17:44:53 +0000187#----------------------------------------------------------------------
188ifeq "$(OS)" "Windows_NT"
189 ifneq (,$(findstring clang,$(CC)))
Zachary Turnere068d912014-12-01 23:13:41 +0000190 # Clang for Windows doesn't support C++ Exceptions
Zachary Turnerc7826522014-08-13 17:44:53 +0000191 CXXFLAGS += -fno-exceptions
Zachary Turnerc7826522014-08-13 17:44:53 +0000192 CXXFLAGS += -D_HAS_EXCEPTIONS=0
Zachary Turnere068d912014-12-01 23:13:41 +0000193 # The MSVC linker doesn't understand long section names
194 # generated by the clang compiler.
195 LDFLAGS += -fuse-ld=lld
Zachary Turnerc7826522014-08-13 17:44:53 +0000196 endif
197endif
198
199#----------------------------------------------------------------------
Tamas Berghammer37099e82015-02-25 13:02:08 +0000200# Android specific options
201#----------------------------------------------------------------------
202ifeq "$(OS)" "Android"
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000203 objcopy_notdir = $(if $(findstring clang,$(1)), \
204 $(subst clang,objcopy,$(1)), \
205 $(if $(findstring gcc,$(1)), \
206 $(subst gcc,objcopy,$(1)), \
207 $(subst cc,objcopy,$(1))))))
208 objcopy = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call objcopy_notdir,$(notdir $(1)))),$(call objcopy_notdir,$(1)))
209
210 LDFLAGS += -pie
211 OBJCOPY = $(call objcopy $(CC))
Tamas Berghammer37099e82015-02-25 13:02:08 +0000212endif
213
214#----------------------------------------------------------------------
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000215# C++ standard library options
216#----------------------------------------------------------------------
217ifeq (1,$(USE_LIBSTDCPP))
218 # Clang requires an extra flag: -stdlib=libstdc++
219 ifneq (,$(findstring clang,$(CC)))
Enrico Granataa1acb492013-06-07 01:58:52 +0000220 CXXFLAGS += -stdlib=libstdc++
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000221 LDFLAGS += -stdlib=libstdc++
222 endif
223endif
224
Greg Clayton1767a732013-06-13 21:27:14 +0000225ifeq (1,$(USE_LIBCPP))
226 # Clang requires an extra flag: -stdlib=libstdc++
227 ifneq (,$(findstring clang,$(CC)))
228 CXXFLAGS += -stdlib=libc++
229 LDFLAGS += -stdlib=libc++
230 endif
231endif
232
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000233#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000234# dylib settings
235#----------------------------------------------------------------------
236ifneq "$(strip $(DYLIB_C_SOURCES))" ""
237 DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
238endif
239
Sean Callanan72772842012-02-22 23:57:45 +0000240ifneq "$(strip $(DYLIB_OBJC_SOURCES))" ""
241 DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o))
242endif
243
Greg Claytond50d2382012-01-10 00:00:15 +0000244ifneq "$(strip $(DYLIB_CXX_SOURCES))" ""
245 DYLIB_OBJECTS +=$(strip $(DYLIB_CXX_SOURCES:.cpp=.o))
246 CXX = $(call cxx_compiler,$(CC))
247 LD = $(call cxx_linker,$(CC))
248endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000249
250#----------------------------------------------------------------------
251# Check if we have any C source files
252#----------------------------------------------------------------------
253ifneq "$(strip $(C_SOURCES))" ""
254 OBJECTS +=$(strip $(C_SOURCES:.c=.o))
255endif
256
257#----------------------------------------------------------------------
258# Check if we have any C++ source files
259#----------------------------------------------------------------------
260ifneq "$(strip $(CXX_SOURCES))" ""
261 OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
Johnny Chen832d2332010-09-30 01:22:34 +0000262 CXX = $(call cxx_compiler,$(CC))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000263 LD = $(call cxx_linker,$(CC))
Johnny Chen9bc867a2010-08-23 23:56:08 +0000264endif
265
266#----------------------------------------------------------------------
267# Check if we have any ObjC source files
268#----------------------------------------------------------------------
269ifneq "$(strip $(OBJC_SOURCES))" ""
270 OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o))
271 LDFLAGS +=-lobjc
272endif
273
274#----------------------------------------------------------------------
275# Check if we have any ObjC++ source files
276#----------------------------------------------------------------------
277ifneq "$(strip $(OBJCXX_SOURCES))" ""
278 OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
Johnny Chen832d2332010-09-30 01:22:34 +0000279 CXX = $(call cxx_compiler,$(CC))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000280 LD = $(call cxx_linker,$(CC))
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000281 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
Johnny Chen9bc867a2010-08-23 23:56:08 +0000282 LDFLAGS +=-lobjc
283 endif
284endif
285
Johnny Chenfe141622012-01-12 23:09:42 +0000286#----------------------------------------------------------------------
287# Check if we have any C source files for archive
288#----------------------------------------------------------------------
289ifneq "$(strip $(ARCHIVE_C_SOURCES))" ""
290 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_C_SOURCES:.c=.o))
291endif
292
293#----------------------------------------------------------------------
294# Check if we have any C++ source files for archive
295#----------------------------------------------------------------------
296ifneq "$(strip $(ARCHIVE_CXX_SOURCES))" ""
297 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_CXX_SOURCES:.cpp=.o))
298 CXX = $(call cxx_compiler,$(CC))
299 LD = $(call cxx_linker,$(CC))
300endif
301
302#----------------------------------------------------------------------
303# Check if we have any ObjC source files for archive
304#----------------------------------------------------------------------
305ifneq "$(strip $(ARCHIVE_OBJC_SOURCES))" ""
306 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJC_SOURCES:.m=.o))
307 LDFLAGS +=-lobjc
308endif
309
310#----------------------------------------------------------------------
311# Check if we have any ObjC++ source files for archive
312#----------------------------------------------------------------------
313ifneq "$(strip $(ARCHIVE_OBJCXX_SOURCES))" ""
314 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJCXX_SOURCES:.mm=.o))
315 CXX = $(call cxx_compiler,$(CC))
316 LD = $(call cxx_linker,$(CC))
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000317 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
Johnny Chenfe141622012-01-12 23:09:42 +0000318 LDFLAGS +=-lobjc
319 endif
320endif
321
Matt Kopecf2430f52013-07-24 21:39:24 +0000322#----------------------------------------------------------------------
323# Check if we are compiling with gcc 4.6
324#----------------------------------------------------------------------
325ifneq (,$(filter g++,$(CXX)))
326 CXXVERSION = $(shell g++ -dumpversion | cut -b 1-3)
327 ifeq "$(CXXVERSION)" "4.6"
328 # GCC 4.6 cannot handle -std=c++11, so replace it with -std=c++0x
329 # instead. FIXME: remove once GCC version is upgraded.
330 override CXXFLAGS := $(subst -std=c++11,-std=c++0x,$(CXXFLAGS))
331 endif
332endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000333
334#----------------------------------------------------------------------
Johnny Chenbeac8f92012-01-10 00:41:11 +0000335# DYLIB_ONLY variable can be used to skip the building of a.out.
336# See the sections below regarding dSYM file as well as the building of
337# EXE from all the objects.
338#----------------------------------------------------------------------
339
340#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000341# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO"
342#----------------------------------------------------------------------
Matt Kopec7663b3a2013-09-25 17:44:00 +0000343ifneq "$(DYLIB_ONLY)" "YES"
Michael Sartain802b0552013-07-02 18:13:13 +0000344$(DSYM) : $(EXE)
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000345ifeq "$(OS)" "Darwin"
Johnny Chen91016392011-06-20 20:08:26 +0000346ifneq "$(MAKE_DSYM)" "NO"
Enrico Granata489af082014-11-18 22:47:33 +0000347 "$(DS)" $(DSFLAGS) -o "$(DSYM)" "$(EXE)"
Johnny Chen91016392011-06-20 20:08:26 +0000348endif
Michael Sartain802b0552013-07-02 18:13:13 +0000349else
350ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000351 $(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
352 $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
Michael Sartain802b0552013-07-02 18:13:13 +0000353endif
354endif
Johnny Chenbeac8f92012-01-10 00:41:11 +0000355endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000356
357#----------------------------------------------------------------------
358# Compile the executable from all the objects.
359#----------------------------------------------------------------------
Johnny Chenbeac8f92012-01-10 00:41:11 +0000360ifneq "$(DYLIB_NAME)" ""
361ifeq "$(DYLIB_ONLY)" ""
Johnny Chenfe141622012-01-12 23:09:42 +0000362$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME)
Richard Mittonec8b2822013-10-17 20:09:33 +0000363 $(LD) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)"
Johnny Chenbeac8f92012-01-10 00:41:11 +0000364else
365EXE = $(DYLIB_FILENAME)
366endif
367else
Johnny Chenfe141622012-01-12 23:09:42 +0000368$(EXE) : $(OBJECTS) $(ARCHIVE_NAME)
Daniel Malea2745d842013-01-25 00:31:48 +0000369 $(LD) $(OBJECTS) $(LDFLAGS) $(ARCHIVE_NAME) -o "$(EXE)"
Johnny Chenfe141622012-01-12 23:09:42 +0000370endif
371
372#----------------------------------------------------------------------
373# Make the archive
374#----------------------------------------------------------------------
375ifneq "$(ARCHIVE_NAME)" ""
376ifeq "$(OS)" "Darwin"
377$(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS)
378 $(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
379 $(RM) $(ARCHIVE_OBJECTS)
380else
381$(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj)))
382endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000383endif
384
385#----------------------------------------------------------------------
386# Make the dylib
387#----------------------------------------------------------------------
Zachary Turner794e6a62015-03-13 21:51:11 +0000388$(DYLIB_OBJECTS) : CFLAGS += -DCOMPILING_LLDB_TEST_DLL
389
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000390$(DYLIB_FILENAME) : $(DYLIB_OBJECTS)
391ifeq "$(OS)" "Darwin"
392 $(LD) $(LDFLAGS) $(DYLIB_OBJECTS) -install_name "@executable_path/$(DYLIB_FILENAME)" -dynamiclib -o "$(DYLIB_FILENAME)"
Greg Clayton0c9773c2012-09-20 21:43:11 +0000393ifneq "$(MAKE_DSYM)" "NO"
394ifneq "$(DS)" ""
Kate Stone2136ace2015-01-21 19:30:00 +0000395 "$(DS)" $(DSFLAGS) "$(DYLIB_FILENAME)"
Greg Clayton0c9773c2012-09-20 21:43:11 +0000396endif
397endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000398else
399 $(LD) $(LDFLAGS) $(DYLIB_OBJECTS) -shared -o "$(DYLIB_FILENAME)"
Michael Sartain802b0552013-07-02 18:13:13 +0000400ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000401 $(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
402 $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
Michael Sartain802b0552013-07-02 18:13:13 +0000403endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000404endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000405
406#----------------------------------------------------------------------
407# Automatic variables based on items already entered. Below we create
Zachary Turner794e6a62015-03-13 21:51:11 +0000408# an object's lists from the list of sources by replacing all entries
Johnny Chen9bc867a2010-08-23 23:56:08 +0000409# that end with .c with .o, and we also create a list of prerequisite
410# files by replacing all .c files with .d.
411#----------------------------------------------------------------------
412PREREQS := $(OBJECTS:.o=.d)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000413ifneq "$(DYLIB_NAME)" ""
414 DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d)
415endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000416
417#----------------------------------------------------------------------
418# Rule for Generating Prerequisites Automatically using .d files and
419# the compiler -MM option. The -M option will list all system headers,
420# and the -MM option will list all non-system dependencies.
421#----------------------------------------------------------------------
Zachary Turner794e6a62015-03-13 21:51:11 +0000422ifeq "$(OS)" "Windows_NT"
423 JOIN_CMD = &
424 QUOTE = "
425else
426 JOIN_CMD = ;
427 QUOTE = '
428endif
429
Johnny Chen9bc867a2010-08-23 23:56:08 +0000430%.d: %.c
Zachary Turner794e6a62015-03-13 21:51:11 +0000431 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000432 $(CC) -M $(CFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000433 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000434 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000435
436%.d: %.cpp
Zachary Turner794e6a62015-03-13 21:51:11 +0000437 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000438 $(CXX) -M $(CXXFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000439 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000440 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000441
442%.d: %.m
Zachary Turner794e6a62015-03-13 21:51:11 +0000443 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000444 $(CC) -M $(CFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000445 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000446 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000447
448%.d: %.mm
Zachary Turner794e6a62015-03-13 21:51:11 +0000449 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000450 $(CXX) -M $(CXXFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000451 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000452 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000453
454#----------------------------------------------------------------------
455# Include all of the makefiles for each source file so we don't have
456# to manually track all of the prerequisites for each source file.
457#----------------------------------------------------------------------
458sinclude $(PREREQS)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000459ifneq "$(DYLIB_NAME)" ""
460 sinclude $(DYLIB_PREREQS)
461endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000462
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000463# Define a suffix rule for .mm -> .o
464.SUFFIXES: .mm .o
465.mm.o:
466 $(CXX) $(CXXFLAGS) -c $<
467
Johnny Chen9bc867a2010-08-23 23:56:08 +0000468.PHONY: clean
469dsym: $(DSYM)
470all: $(EXE) $(DSYM)
Johnny Chene1030cd2010-09-27 20:44:46 +0000471clean::
Pavel Labathf81ed472015-02-05 09:52:42 +0000472 $(RM) "$(EXE)" $(OBJECTS) $(PREREQS) $(PREREQS:.d=.d.tmp) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
Ed Maste0990e052014-03-07 17:20:50 +0000473ifneq "$(DYLIB_NAME)" ""
Jason Molenda53b8ea12014-03-08 01:53:27 +0000474 $(RM) -r $(DYLIB_FILENAME).dSYM
Pavel Labathf81ed472015-02-05 09:52:42 +0000475 $(RM) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_PREREQS:.d=.d.tmp) $(DYLIB_FILENAME) $(DYLIB_FILENAME).debug
Johnny Chen9bc867a2010-08-23 23:56:08 +0000476endif
Ed Maste0990e052014-03-07 17:20:50 +0000477ifneq "$(DSYM)" ""
Jason Molenda53b8ea12014-03-08 01:53:27 +0000478 $(RM) -r "$(DSYM)"
Ed Maste0990e052014-03-07 17:20:50 +0000479endif
Zachary Turner3e9ca3a2014-12-16 16:48:19 +0000480ifeq "$(OS)" "Windows_NT"
Zachary Turner65fe1eb2015-03-26 16:43:25 +0000481 $(RM) $(wildcard *.manifest *.pdb *.ilk)
Zachary Turner794e6a62015-03-13 21:51:11 +0000482 ifneq "$(DYLIB_NAME)" ""
Zachary Turner65fe1eb2015-03-26 16:43:25 +0000483 $(RM) $(DYLIB_NAME).lib $(DYLIB_NAME).exp
Zachary Turner794e6a62015-03-13 21:51:11 +0000484 endif
Zachary Turner3e9ca3a2014-12-16 16:48:19 +0000485endif
Johnny Chenfa380412011-01-14 21:18:12 +0000486
487#----------------------------------------------------------------------
488# From http://blog.melski.net/tag/debugging-makefiles/
489#
490# Usage: make print-CC print-CXX print-LD
491#----------------------------------------------------------------------
492print-%:
493 @echo '$*=$($*)'
494 @echo ' origin = $(origin $*)'
495 @echo ' flavor = $(flavor $*)'
496 @echo ' value = $(value $*)'
Johnny Chen8b2c3212011-01-28 17:22:29 +0000497
Johnny Chen8b2c3212011-01-28 17:22:29 +0000498### Local Variables: ###
499### mode:makefile ###
500### End: ###