blob: f533a24c7cdc172036b99c2167d2fb4f82f347dd [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#----------------------------------------------------------------------
Johnny Chen6c17c082010-09-16 20:54:06 +000033# If ARCH is not defined, default to x86_64.
Peter Collingbourne518f03d2011-06-20 19:06:04 +000034# If OS is not defined, use 'uname -s' to determine the OS name.
Johnny Chen6c17c082010-09-16 20:54:06 +000035#----------------------------------------------------------------------
36ifeq "$(ARCH)" ""
Zachary Turnere068d912014-12-01 23:13:41 +000037ifeq "$(OS)" "Windows_NT"
38 ARCH = x86
39else
Johnny Chen6c17c082010-09-16 20:54:06 +000040 ARCH = x86_64
41endif
Zachary Turnere068d912014-12-01 23:13:41 +000042endif
Johnny Chen6c17c082010-09-16 20:54:06 +000043
Peter Collingbourne518f03d2011-06-20 19:06:04 +000044ifeq "$(OS)" ""
45 OS = $(shell uname -s)
46endif
47
Johnny Chen6c17c082010-09-16 20:54:06 +000048#----------------------------------------------------------------------
Johnny Chen597cbbb2011-08-23 21:54:10 +000049# CC defaults to clang.
Johnny Chen4ab4a9b2011-08-24 18:12:53 +000050#
51# If you change the defaults of CC, be sure to also change it in the file
52# test/plugins/builder_base.py, which provides a Python way to return the
53# value of the make variable CC -- getCompiler().
54#
Johnny Chen6055b442011-01-14 20:55:13 +000055# See also these functions:
56# o cxx_compiler
57# o cxx_linker
Johnny Chend43e2082011-01-14 20:46:49 +000058#----------------------------------------------------------------------
Johnny Chen597cbbb2011-08-23 21:54:10 +000059CC ?= clang
Johnny Chend43e2082011-01-14 20:46:49 +000060ifeq "$(CC)" "cc"
Johnny Chen597cbbb2011-08-23 21:54:10 +000061 CC = clang
Johnny Chend43e2082011-01-14 20:46:49 +000062endif
63
64#----------------------------------------------------------------------
Daniel Malea2745d842013-01-25 00:31:48 +000065# ARCHFLAG is the flag used to tell the compiler which architecture
66# to compile for. The default is the flag that clang accepts.
67#----------------------------------------------------------------------
68ARCHFLAG ?= -arch
69
70#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +000071# Change any build/tool options needed
72#----------------------------------------------------------------------
Peter Collingbourne518f03d2011-06-20 19:06:04 +000073ifeq "$(OS)" "Darwin"
Greg Clayton82625d32014-07-29 20:10:59 +000074 DS := $(shell xcrun -find -toolchain default dsymutil)
Peter Collingbourne518f03d2011-06-20 19:06:04 +000075 DSFLAGS =
76 DSYM = $(EXE).dSYM
Johnny Chenfe141622012-01-12 23:09:42 +000077 AR := libtool
78 ARFLAGS := -static -o
Daniel Malea2745d842013-01-25 00:31:48 +000079else
80 # On non-Apple platforms, -arch becomes -m
81 ARCHFLAG := -m
82
Zachary Turnerc7826522014-08-13 17:44:53 +000083 # i386, i686, x86 -> 32
Zachary Turner7c1bc2b2014-07-31 21:07:41 +000084 # amd64, x86_64, x64 -> 64
Ed Maste4fe0aba2014-02-20 18:40:01 +000085 ifeq "$(ARCH)" "amd64"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +000086 override ARCH := $(subst amd64,64,$(ARCH))
Ed Maste4fe0aba2014-02-20 18:40:01 +000087 endif
Daniel Malea2745d842013-01-25 00:31:48 +000088 ifeq "$(ARCH)" "x86_64"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +000089 override ARCH := $(subst x86_64,64,$(ARCH))
90 endif
91 ifeq "$(ARCH)" "x64"
92 override ARCH := $(subst x64,64,$(ARCH))
Daniel Malea2745d842013-01-25 00:31:48 +000093 endif
Zachary Turnerc7826522014-08-13 17:44:53 +000094 ifeq "$(ARCH)" "x86"
95 override ARCH := $(subst x86,32,$(ARCH))
96 endif
Daniel Malea2745d842013-01-25 00:31:48 +000097 ifeq "$(ARCH)" "i386"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +000098 override ARCH := $(subst i386,32,$(ARCH))
99 endif
100 ifeq "$(ARCH)" "i686"
101 override ARCH := $(subst i686,32,$(ARCH))
Daniel Malea2745d842013-01-25 00:31:48 +0000102 endif
Justin Hibbits3cba1c22014-11-12 15:13:58 +0000103 ifeq "$(ARCH)" "powerpc"
104 override ARCH := $(subst powerpc,32,$(ARCH))
105 endif
106 ifeq "$(ARCH)" "powerpc64"
107 override ARCH := $(subst powerpc64,64,$(ARCH))
108 endif
Tamas Berghammer1e209fc2015-03-13 11:36:47 +0000109 ifeq "$(ARCH)" "aarch64"
110 override ARCH :=
111 override ARCHFLAG :=
112 endif
Michael Sartain802b0552013-07-02 18:13:13 +0000113
114 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
115 DSYM = $(EXE).debug
116 endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000117endif
118
Greg Claytone595c6b2013-02-28 18:47:39 +0000119CFLAGS ?= -g -O0
Zachary Turnerc7826522014-08-13 17:44:53 +0000120CFLAGS += $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
Zachary Turner794e6a62015-03-13 21:51:11 +0000121CFLAGS += -include $(THIS_FILE_DIR)test_common.h
Daniel Malea2745d842013-01-25 00:31:48 +0000122
Jim Ingham4b4b2472014-03-13 02:47:14 +0000123# Use this one if you want to build one part of the result without debug information:
124CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS)
125
Zachary Turnerc7826522014-08-13 17:44:53 +0000126CXXFLAGS += -std=c++11
127CXXFLAGS += $(CFLAGS)
Johnny Chen53e2edb2011-08-09 20:07:16 +0000128LD = $(CC)
129LDFLAGS ?= $(CFLAGS)
Daniel Malea2745d842013-01-25 00:31:48 +0000130LDFLAGS += $(LD_EXTRAS)
Tamas Berghammer37099e82015-02-25 13:02:08 +0000131ifeq (,$(filter $(OS), Windows_NT Android))
Shawn Best954eae02014-11-14 19:41:33 +0000132 ifeq "$(ENABLE_THREADS)" "YES"
133 LDFLAGS += -lpthread
Tamas Berghammer37099e82015-02-25 13:02:08 +0000134 else
Shawn Best954eae02014-11-14 19:41:33 +0000135 ifeq "$(ENABLE_STD_THREADS)" "YES"
136 # with the specific combination of Linux, g++, std=c++11, adding the
137 # linker flag -lpthread, will cause a program to hang when a std::conditional_variable
138 # is used in a program that links lldb (see bugzilla 21553)
139 ifeq "$(OS)" "Linux"
140 ifeq (,$(findstring gcc,$(CC)))
141 # Linux, but not gcc
142 LDFLAGS += -lpthread
143 endif
144 else
145 LDFLAGS += -lpthread
146 endif
147 endif
148 endif
Zachary Turnerc7826522014-08-13 17:44:53 +0000149endif
Johnny Chen53e2edb2011-08-09 20:07:16 +0000150OBJECTS =
151EXE ?= a.out
152
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000153ifneq "$(DYLIB_NAME)" ""
154 ifeq "$(OS)" "Darwin"
155 DYLIB_FILENAME = lib$(DYLIB_NAME).dylib
Zachary Turner794e6a62015-03-13 21:51:11 +0000156 else ifeq "$(OS)" "Windows_NT"
157 DYLIB_FILENAME = $(DYLIB_NAME).dll
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000158 else
159 DYLIB_FILENAME = lib$(DYLIB_NAME).so
160 endif
161endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000162
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000163# Function that returns the counterpart C++ compiler, given $(CC) as arg.
Shawn Best1ecb68d2014-11-11 17:34:58 +0000164cxx_compiler_notdir = $(if $(findstring clang,$(1)), \
165 $(subst clang,clang++,$(1)), \
166 $(if $(findstring icc,$(1)), \
167 $(subst icc,icpc,$(1)), \
168 $(if $(findstring llvm-gcc,$(1)), \
169 $(subst llvm-gcc,llvm-g++,$(1)), \
170 $(if $(findstring gcc,$(1)), \
171 $(subst gcc,g++,$(1)), \
172 $(subst cc,c++,$(1))))))
Greg Claytonb39751b2013-11-22 21:05:25 +0000173cxx_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 +0000174
175# Function that returns the C++ linker, given $(CC) as arg.
Shawn Best1ecb68d2014-11-11 17:34:58 +0000176cxx_linker_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_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 +0000186
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000187OBJCOPY = objcopy
188
Johnny Chen9bc867a2010-08-23 23:56:08 +0000189#----------------------------------------------------------------------
Zachary Turnere068d912014-12-01 23:13:41 +0000190# Windows specific options
Zachary Turnerc7826522014-08-13 17:44:53 +0000191#----------------------------------------------------------------------
192ifeq "$(OS)" "Windows_NT"
193 ifneq (,$(findstring clang,$(CC)))
Zachary Turnere068d912014-12-01 23:13:41 +0000194 # Clang for Windows doesn't support C++ Exceptions
Zachary Turnerc7826522014-08-13 17:44:53 +0000195 CXXFLAGS += -fno-exceptions
Zachary Turnerc7826522014-08-13 17:44:53 +0000196 CXXFLAGS += -D_HAS_EXCEPTIONS=0
Zachary Turnere068d912014-12-01 23:13:41 +0000197 # The MSVC linker doesn't understand long section names
198 # generated by the clang compiler.
199 LDFLAGS += -fuse-ld=lld
Zachary Turnerc7826522014-08-13 17:44:53 +0000200 endif
201endif
202
203#----------------------------------------------------------------------
Tamas Berghammer37099e82015-02-25 13:02:08 +0000204# Android specific options
205#----------------------------------------------------------------------
206ifeq "$(OS)" "Android"
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000207 objcopy_notdir = $(if $(findstring clang,$(1)), \
208 $(subst clang,objcopy,$(1)), \
209 $(if $(findstring gcc,$(1)), \
210 $(subst gcc,objcopy,$(1)), \
211 $(subst cc,objcopy,$(1))))))
212 objcopy = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call objcopy_notdir,$(notdir $(1)))),$(call objcopy_notdir,$(1)))
213
214 LDFLAGS += -pie
215 OBJCOPY = $(call objcopy $(CC))
Tamas Berghammer37099e82015-02-25 13:02:08 +0000216endif
217
218#----------------------------------------------------------------------
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000219# C++ standard library options
220#----------------------------------------------------------------------
221ifeq (1,$(USE_LIBSTDCPP))
222 # Clang requires an extra flag: -stdlib=libstdc++
223 ifneq (,$(findstring clang,$(CC)))
Enrico Granataa1acb492013-06-07 01:58:52 +0000224 CXXFLAGS += -stdlib=libstdc++
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000225 LDFLAGS += -stdlib=libstdc++
226 endif
227endif
228
Greg Clayton1767a732013-06-13 21:27:14 +0000229ifeq (1,$(USE_LIBCPP))
230 # Clang requires an extra flag: -stdlib=libstdc++
231 ifneq (,$(findstring clang,$(CC)))
232 CXXFLAGS += -stdlib=libc++
233 LDFLAGS += -stdlib=libc++
234 endif
235endif
236
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000237#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000238# dylib settings
239#----------------------------------------------------------------------
240ifneq "$(strip $(DYLIB_C_SOURCES))" ""
241 DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
242endif
243
Sean Callanan72772842012-02-22 23:57:45 +0000244ifneq "$(strip $(DYLIB_OBJC_SOURCES))" ""
245 DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o))
246endif
247
Greg Claytond50d2382012-01-10 00:00:15 +0000248ifneq "$(strip $(DYLIB_CXX_SOURCES))" ""
249 DYLIB_OBJECTS +=$(strip $(DYLIB_CXX_SOURCES:.cpp=.o))
250 CXX = $(call cxx_compiler,$(CC))
251 LD = $(call cxx_linker,$(CC))
252endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000253
254#----------------------------------------------------------------------
255# Check if we have any C source files
256#----------------------------------------------------------------------
257ifneq "$(strip $(C_SOURCES))" ""
258 OBJECTS +=$(strip $(C_SOURCES:.c=.o))
259endif
260
261#----------------------------------------------------------------------
262# Check if we have any C++ source files
263#----------------------------------------------------------------------
264ifneq "$(strip $(CXX_SOURCES))" ""
265 OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
Johnny Chen832d2332010-09-30 01:22:34 +0000266 CXX = $(call cxx_compiler,$(CC))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000267 LD = $(call cxx_linker,$(CC))
Johnny Chen9bc867a2010-08-23 23:56:08 +0000268endif
269
270#----------------------------------------------------------------------
271# Check if we have any ObjC source files
272#----------------------------------------------------------------------
273ifneq "$(strip $(OBJC_SOURCES))" ""
274 OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o))
275 LDFLAGS +=-lobjc
276endif
277
278#----------------------------------------------------------------------
279# Check if we have any ObjC++ source files
280#----------------------------------------------------------------------
281ifneq "$(strip $(OBJCXX_SOURCES))" ""
282 OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
Johnny Chen832d2332010-09-30 01:22:34 +0000283 CXX = $(call cxx_compiler,$(CC))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000284 LD = $(call cxx_linker,$(CC))
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000285 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
Johnny Chen9bc867a2010-08-23 23:56:08 +0000286 LDFLAGS +=-lobjc
287 endif
288endif
289
Johnny Chenfe141622012-01-12 23:09:42 +0000290#----------------------------------------------------------------------
291# Check if we have any C source files for archive
292#----------------------------------------------------------------------
293ifneq "$(strip $(ARCHIVE_C_SOURCES))" ""
294 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_C_SOURCES:.c=.o))
295endif
296
297#----------------------------------------------------------------------
298# Check if we have any C++ source files for archive
299#----------------------------------------------------------------------
300ifneq "$(strip $(ARCHIVE_CXX_SOURCES))" ""
301 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_CXX_SOURCES:.cpp=.o))
302 CXX = $(call cxx_compiler,$(CC))
303 LD = $(call cxx_linker,$(CC))
304endif
305
306#----------------------------------------------------------------------
307# Check if we have any ObjC source files for archive
308#----------------------------------------------------------------------
309ifneq "$(strip $(ARCHIVE_OBJC_SOURCES))" ""
310 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJC_SOURCES:.m=.o))
311 LDFLAGS +=-lobjc
312endif
313
314#----------------------------------------------------------------------
315# Check if we have any ObjC++ source files for archive
316#----------------------------------------------------------------------
317ifneq "$(strip $(ARCHIVE_OBJCXX_SOURCES))" ""
318 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJCXX_SOURCES:.mm=.o))
319 CXX = $(call cxx_compiler,$(CC))
320 LD = $(call cxx_linker,$(CC))
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000321 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
Johnny Chenfe141622012-01-12 23:09:42 +0000322 LDFLAGS +=-lobjc
323 endif
324endif
325
Matt Kopecf2430f52013-07-24 21:39:24 +0000326#----------------------------------------------------------------------
327# Check if we are compiling with gcc 4.6
328#----------------------------------------------------------------------
329ifneq (,$(filter g++,$(CXX)))
330 CXXVERSION = $(shell g++ -dumpversion | cut -b 1-3)
331 ifeq "$(CXXVERSION)" "4.6"
332 # GCC 4.6 cannot handle -std=c++11, so replace it with -std=c++0x
333 # instead. FIXME: remove once GCC version is upgraded.
334 override CXXFLAGS := $(subst -std=c++11,-std=c++0x,$(CXXFLAGS))
335 endif
336endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000337
338#----------------------------------------------------------------------
Johnny Chenbeac8f92012-01-10 00:41:11 +0000339# DYLIB_ONLY variable can be used to skip the building of a.out.
340# See the sections below regarding dSYM file as well as the building of
341# EXE from all the objects.
342#----------------------------------------------------------------------
343
344#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000345# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO"
346#----------------------------------------------------------------------
Matt Kopec7663b3a2013-09-25 17:44:00 +0000347ifneq "$(DYLIB_ONLY)" "YES"
Michael Sartain802b0552013-07-02 18:13:13 +0000348$(DSYM) : $(EXE)
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000349ifeq "$(OS)" "Darwin"
Johnny Chen91016392011-06-20 20:08:26 +0000350ifneq "$(MAKE_DSYM)" "NO"
Enrico Granata489af082014-11-18 22:47:33 +0000351 "$(DS)" $(DSFLAGS) -o "$(DSYM)" "$(EXE)"
Johnny Chen91016392011-06-20 20:08:26 +0000352endif
Michael Sartain802b0552013-07-02 18:13:13 +0000353else
354ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000355 $(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
356 $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
Michael Sartain802b0552013-07-02 18:13:13 +0000357endif
358endif
Johnny Chenbeac8f92012-01-10 00:41:11 +0000359endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000360
361#----------------------------------------------------------------------
362# Compile the executable from all the objects.
363#----------------------------------------------------------------------
Johnny Chenbeac8f92012-01-10 00:41:11 +0000364ifneq "$(DYLIB_NAME)" ""
365ifeq "$(DYLIB_ONLY)" ""
Johnny Chenfe141622012-01-12 23:09:42 +0000366$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME)
Richard Mittonec8b2822013-10-17 20:09:33 +0000367 $(LD) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)"
Johnny Chenbeac8f92012-01-10 00:41:11 +0000368else
369EXE = $(DYLIB_FILENAME)
370endif
371else
Johnny Chenfe141622012-01-12 23:09:42 +0000372$(EXE) : $(OBJECTS) $(ARCHIVE_NAME)
Daniel Malea2745d842013-01-25 00:31:48 +0000373 $(LD) $(OBJECTS) $(LDFLAGS) $(ARCHIVE_NAME) -o "$(EXE)"
Johnny Chenfe141622012-01-12 23:09:42 +0000374endif
375
376#----------------------------------------------------------------------
377# Make the archive
378#----------------------------------------------------------------------
379ifneq "$(ARCHIVE_NAME)" ""
380ifeq "$(OS)" "Darwin"
381$(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS)
382 $(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
383 $(RM) $(ARCHIVE_OBJECTS)
384else
385$(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj)))
386endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000387endif
388
389#----------------------------------------------------------------------
390# Make the dylib
391#----------------------------------------------------------------------
Zachary Turner794e6a62015-03-13 21:51:11 +0000392$(DYLIB_OBJECTS) : CFLAGS += -DCOMPILING_LLDB_TEST_DLL
393
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000394$(DYLIB_FILENAME) : $(DYLIB_OBJECTS)
395ifeq "$(OS)" "Darwin"
396 $(LD) $(LDFLAGS) $(DYLIB_OBJECTS) -install_name "@executable_path/$(DYLIB_FILENAME)" -dynamiclib -o "$(DYLIB_FILENAME)"
Greg Clayton0c9773c2012-09-20 21:43:11 +0000397ifneq "$(MAKE_DSYM)" "NO"
398ifneq "$(DS)" ""
Kate Stone2136ace2015-01-21 19:30:00 +0000399 "$(DS)" $(DSFLAGS) "$(DYLIB_FILENAME)"
Greg Clayton0c9773c2012-09-20 21:43:11 +0000400endif
401endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000402else
403 $(LD) $(LDFLAGS) $(DYLIB_OBJECTS) -shared -o "$(DYLIB_FILENAME)"
Michael Sartain802b0552013-07-02 18:13:13 +0000404ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
Tamas Berghammerdcc8e592015-04-02 11:09:28 +0000405 $(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
406 $(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
Michael Sartain802b0552013-07-02 18:13:13 +0000407endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000408endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000409
410#----------------------------------------------------------------------
411# Automatic variables based on items already entered. Below we create
Zachary Turner794e6a62015-03-13 21:51:11 +0000412# an object's lists from the list of sources by replacing all entries
Johnny Chen9bc867a2010-08-23 23:56:08 +0000413# that end with .c with .o, and we also create a list of prerequisite
414# files by replacing all .c files with .d.
415#----------------------------------------------------------------------
416PREREQS := $(OBJECTS:.o=.d)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000417ifneq "$(DYLIB_NAME)" ""
418 DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d)
419endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000420
421#----------------------------------------------------------------------
422# Rule for Generating Prerequisites Automatically using .d files and
423# the compiler -MM option. The -M option will list all system headers,
424# and the -MM option will list all non-system dependencies.
425#----------------------------------------------------------------------
Zachary Turner794e6a62015-03-13 21:51:11 +0000426ifeq "$(OS)" "Windows_NT"
427 JOIN_CMD = &
428 QUOTE = "
429else
430 JOIN_CMD = ;
431 QUOTE = '
432endif
433
Johnny Chen9bc867a2010-08-23 23:56:08 +0000434%.d: %.c
Zachary Turner794e6a62015-03-13 21:51:11 +0000435 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000436 $(CC) -M $(CFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000437 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000438 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000439
440%.d: %.cpp
Zachary Turner794e6a62015-03-13 21:51:11 +0000441 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000442 $(CXX) -M $(CXXFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000443 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000444 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000445
446%.d: %.m
Zachary Turner794e6a62015-03-13 21:51:11 +0000447 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000448 $(CC) -M $(CFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000449 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000450 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000451
452%.d: %.mm
Zachary Turner794e6a62015-03-13 21:51:11 +0000453 @rm -f $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000454 $(CXX) -M $(CXXFLAGS) $< > $@.tmp && \
Zachary Turner794e6a62015-03-13 21:51:11 +0000455 sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < $@.tmp > $@ $(JOIN_CMD) \
Pavel Labathf81ed472015-02-05 09:52:42 +0000456 rm -f $@.tmp
Johnny Chen9bc867a2010-08-23 23:56:08 +0000457
458#----------------------------------------------------------------------
459# Include all of the makefiles for each source file so we don't have
460# to manually track all of the prerequisites for each source file.
461#----------------------------------------------------------------------
462sinclude $(PREREQS)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000463ifneq "$(DYLIB_NAME)" ""
464 sinclude $(DYLIB_PREREQS)
465endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000466
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000467# Define a suffix rule for .mm -> .o
468.SUFFIXES: .mm .o
469.mm.o:
470 $(CXX) $(CXXFLAGS) -c $<
471
Johnny Chen9bc867a2010-08-23 23:56:08 +0000472.PHONY: clean
473dsym: $(DSYM)
474all: $(EXE) $(DSYM)
Johnny Chene1030cd2010-09-27 20:44:46 +0000475clean::
Pavel Labathf81ed472015-02-05 09:52:42 +0000476 $(RM) "$(EXE)" $(OBJECTS) $(PREREQS) $(PREREQS:.d=.d.tmp) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
Ed Maste0990e052014-03-07 17:20:50 +0000477ifneq "$(DYLIB_NAME)" ""
Jason Molenda53b8ea12014-03-08 01:53:27 +0000478 $(RM) -r $(DYLIB_FILENAME).dSYM
Pavel Labathf81ed472015-02-05 09:52:42 +0000479 $(RM) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_PREREQS:.d=.d.tmp) $(DYLIB_FILENAME) $(DYLIB_FILENAME).debug
Johnny Chen9bc867a2010-08-23 23:56:08 +0000480endif
Ed Maste0990e052014-03-07 17:20:50 +0000481ifneq "$(DSYM)" ""
Jason Molenda53b8ea12014-03-08 01:53:27 +0000482 $(RM) -r "$(DSYM)"
Ed Maste0990e052014-03-07 17:20:50 +0000483endif
Zachary Turner3e9ca3a2014-12-16 16:48:19 +0000484ifeq "$(OS)" "Windows_NT"
Zachary Turner65fe1eb2015-03-26 16:43:25 +0000485 $(RM) $(wildcard *.manifest *.pdb *.ilk)
Zachary Turner794e6a62015-03-13 21:51:11 +0000486 ifneq "$(DYLIB_NAME)" ""
Zachary Turner65fe1eb2015-03-26 16:43:25 +0000487 $(RM) $(DYLIB_NAME).lib $(DYLIB_NAME).exp
Zachary Turner794e6a62015-03-13 21:51:11 +0000488 endif
Zachary Turner3e9ca3a2014-12-16 16:48:19 +0000489endif
Johnny Chenfa380412011-01-14 21:18:12 +0000490
491#----------------------------------------------------------------------
492# From http://blog.melski.net/tag/debugging-makefiles/
493#
494# Usage: make print-CC print-CXX print-LD
495#----------------------------------------------------------------------
496print-%:
497 @echo '$*=$($*)'
498 @echo ' origin = $(origin $*)'
499 @echo ' flavor = $(flavor $*)'
500 @echo ' value = $(value $*)'
Johnny Chen8b2c3212011-01-28 17:22:29 +0000501
502
503### Local Variables: ###
504### mode:makefile ###
505### End: ###