blob: 691503053b8b0b89be52e3f0153f4e2377af678d [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) :=
17# CFLAGS_EXTRAS :=
18# 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
Michael Sartain802b0552013-07-02 18:13:13 +0000109
110 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
111 DSYM = $(EXE).debug
112 endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000113endif
114
Greg Claytone595c6b2013-02-28 18:47:39 +0000115CFLAGS ?= -g -O0
Zachary Turnerc7826522014-08-13 17:44:53 +0000116CFLAGS += $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
Daniel Malea2745d842013-01-25 00:31:48 +0000117
Jim Ingham4b4b2472014-03-13 02:47:14 +0000118# Use this one if you want to build one part of the result without debug information:
119CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS)
120
Zachary Turnerc7826522014-08-13 17:44:53 +0000121CXXFLAGS += -std=c++11
122CXXFLAGS += $(CFLAGS)
Johnny Chen53e2edb2011-08-09 20:07:16 +0000123LD = $(CC)
124LDFLAGS ?= $(CFLAGS)
Daniel Malea2745d842013-01-25 00:31:48 +0000125LDFLAGS += $(LD_EXTRAS)
Zachary Turnerc7826522014-08-13 17:44:53 +0000126ifneq "$(OS)" "Windows_NT"
Shawn Best954eae02014-11-14 19:41:33 +0000127 ifeq "$(ENABLE_THREADS)" "YES"
128 LDFLAGS += -lpthread
129 else
130 ifeq "$(ENABLE_STD_THREADS)" "YES"
131 # with the specific combination of Linux, g++, std=c++11, adding the
132 # linker flag -lpthread, will cause a program to hang when a std::conditional_variable
133 # is used in a program that links lldb (see bugzilla 21553)
134 ifeq "$(OS)" "Linux"
135 ifeq (,$(findstring gcc,$(CC)))
136 # Linux, but not gcc
137 LDFLAGS += -lpthread
138 endif
139 else
140 LDFLAGS += -lpthread
141 endif
142 endif
143 endif
Zachary Turnerc7826522014-08-13 17:44:53 +0000144endif
Johnny Chen53e2edb2011-08-09 20:07:16 +0000145OBJECTS =
146EXE ?= a.out
147
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000148ifneq "$(DYLIB_NAME)" ""
149 ifeq "$(OS)" "Darwin"
150 DYLIB_FILENAME = lib$(DYLIB_NAME).dylib
151 else
152 DYLIB_FILENAME = lib$(DYLIB_NAME).so
153 endif
154endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000155
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000156# Function that returns the counterpart C++ compiler, given $(CC) as arg.
Shawn Best1ecb68d2014-11-11 17:34:58 +0000157cxx_compiler_notdir = $(if $(findstring clang,$(1)), \
158 $(subst clang,clang++,$(1)), \
159 $(if $(findstring icc,$(1)), \
160 $(subst icc,icpc,$(1)), \
161 $(if $(findstring llvm-gcc,$(1)), \
162 $(subst llvm-gcc,llvm-g++,$(1)), \
163 $(if $(findstring gcc,$(1)), \
164 $(subst gcc,g++,$(1)), \
165 $(subst cc,c++,$(1))))))
Greg Claytonb39751b2013-11-22 21:05:25 +0000166cxx_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 +0000167
168# Function that returns the C++ linker, given $(CC) as arg.
Shawn Best1ecb68d2014-11-11 17:34:58 +0000169cxx_linker_notdir = $(if $(findstring clang,$(1)), \
170 $(subst clang,clang++,$(1)), \
171 $(if $(findstring icc,$(1)), \
172 $(subst icc,icpc,$(1)), \
173 $(if $(findstring llvm-gcc,$(1)), \
174 $(subst llvm-gcc,llvm-g++,$(1)), \
175 $(if $(findstring gcc,$(1)), \
176 $(subst gcc,g++,$(1)), \
177 $(subst cc,c++,$(1))))))
Greg Claytonb39751b2013-11-22 21:05:25 +0000178cxx_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 +0000179
Johnny Chen9bc867a2010-08-23 23:56:08 +0000180#----------------------------------------------------------------------
Zachary Turnere068d912014-12-01 23:13:41 +0000181# Windows specific options
Zachary Turnerc7826522014-08-13 17:44:53 +0000182#----------------------------------------------------------------------
183ifeq "$(OS)" "Windows_NT"
184 ifneq (,$(findstring clang,$(CC)))
Zachary Turnere068d912014-12-01 23:13:41 +0000185 # Clang for Windows doesn't support C++ Exceptions
Zachary Turnerc7826522014-08-13 17:44:53 +0000186 CXXFLAGS += -fno-exceptions
187 CXXFLAGS += -include $(THIS_FILE_DIR)uncaught_exception.h
188 CXXFLAGS += -D_HAS_EXCEPTIONS=0
Zachary Turnere068d912014-12-01 23:13:41 +0000189 # The MSVC linker doesn't understand long section names
190 # generated by the clang compiler.
191 LDFLAGS += -fuse-ld=lld
Zachary Turnerc7826522014-08-13 17:44:53 +0000192 endif
193endif
194
195#----------------------------------------------------------------------
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000196# C++ standard library options
197#----------------------------------------------------------------------
198ifeq (1,$(USE_LIBSTDCPP))
199 # Clang requires an extra flag: -stdlib=libstdc++
200 ifneq (,$(findstring clang,$(CC)))
Enrico Granataa1acb492013-06-07 01:58:52 +0000201 CXXFLAGS += -stdlib=libstdc++
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000202 LDFLAGS += -stdlib=libstdc++
203 endif
204endif
205
Greg Clayton1767a732013-06-13 21:27:14 +0000206ifeq (1,$(USE_LIBCPP))
207 # Clang requires an extra flag: -stdlib=libstdc++
208 ifneq (,$(findstring clang,$(CC)))
209 CXXFLAGS += -stdlib=libc++
210 LDFLAGS += -stdlib=libc++
211 endif
212endif
213
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000214#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000215# dylib settings
216#----------------------------------------------------------------------
217ifneq "$(strip $(DYLIB_C_SOURCES))" ""
218 DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
219endif
220
Sean Callanan72772842012-02-22 23:57:45 +0000221ifneq "$(strip $(DYLIB_OBJC_SOURCES))" ""
222 DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o))
223endif
224
Greg Claytond50d2382012-01-10 00:00:15 +0000225ifneq "$(strip $(DYLIB_CXX_SOURCES))" ""
226 DYLIB_OBJECTS +=$(strip $(DYLIB_CXX_SOURCES:.cpp=.o))
227 CXX = $(call cxx_compiler,$(CC))
228 LD = $(call cxx_linker,$(CC))
229endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000230
231#----------------------------------------------------------------------
232# Check if we have any C source files
233#----------------------------------------------------------------------
234ifneq "$(strip $(C_SOURCES))" ""
235 OBJECTS +=$(strip $(C_SOURCES:.c=.o))
236endif
237
238#----------------------------------------------------------------------
239# Check if we have any C++ source files
240#----------------------------------------------------------------------
241ifneq "$(strip $(CXX_SOURCES))" ""
242 OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
Johnny Chen832d2332010-09-30 01:22:34 +0000243 CXX = $(call cxx_compiler,$(CC))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000244 LD = $(call cxx_linker,$(CC))
Johnny Chen9bc867a2010-08-23 23:56:08 +0000245endif
246
247#----------------------------------------------------------------------
248# Check if we have any ObjC source files
249#----------------------------------------------------------------------
250ifneq "$(strip $(OBJC_SOURCES))" ""
251 OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o))
252 LDFLAGS +=-lobjc
253endif
254
255#----------------------------------------------------------------------
256# Check if we have any ObjC++ source files
257#----------------------------------------------------------------------
258ifneq "$(strip $(OBJCXX_SOURCES))" ""
259 OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
Johnny Chen832d2332010-09-30 01:22:34 +0000260 CXX = $(call cxx_compiler,$(CC))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000261 LD = $(call cxx_linker,$(CC))
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000262 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
Johnny Chen9bc867a2010-08-23 23:56:08 +0000263 LDFLAGS +=-lobjc
264 endif
265endif
266
Johnny Chenfe141622012-01-12 23:09:42 +0000267#----------------------------------------------------------------------
268# Check if we have any C source files for archive
269#----------------------------------------------------------------------
270ifneq "$(strip $(ARCHIVE_C_SOURCES))" ""
271 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_C_SOURCES:.c=.o))
272endif
273
274#----------------------------------------------------------------------
275# Check if we have any C++ source files for archive
276#----------------------------------------------------------------------
277ifneq "$(strip $(ARCHIVE_CXX_SOURCES))" ""
278 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_CXX_SOURCES:.cpp=.o))
279 CXX = $(call cxx_compiler,$(CC))
280 LD = $(call cxx_linker,$(CC))
281endif
282
283#----------------------------------------------------------------------
284# Check if we have any ObjC source files for archive
285#----------------------------------------------------------------------
286ifneq "$(strip $(ARCHIVE_OBJC_SOURCES))" ""
287 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJC_SOURCES:.m=.o))
288 LDFLAGS +=-lobjc
289endif
290
291#----------------------------------------------------------------------
292# Check if we have any ObjC++ source files for archive
293#----------------------------------------------------------------------
294ifneq "$(strip $(ARCHIVE_OBJCXX_SOURCES))" ""
295 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJCXX_SOURCES:.mm=.o))
296 CXX = $(call cxx_compiler,$(CC))
297 LD = $(call cxx_linker,$(CC))
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000298 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
Johnny Chenfe141622012-01-12 23:09:42 +0000299 LDFLAGS +=-lobjc
300 endif
301endif
302
Matt Kopecf2430f52013-07-24 21:39:24 +0000303#----------------------------------------------------------------------
304# Check if we are compiling with gcc 4.6
305#----------------------------------------------------------------------
306ifneq (,$(filter g++,$(CXX)))
307 CXXVERSION = $(shell g++ -dumpversion | cut -b 1-3)
308 ifeq "$(CXXVERSION)" "4.6"
309 # GCC 4.6 cannot handle -std=c++11, so replace it with -std=c++0x
310 # instead. FIXME: remove once GCC version is upgraded.
311 override CXXFLAGS := $(subst -std=c++11,-std=c++0x,$(CXXFLAGS))
312 endif
313endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000314
315#----------------------------------------------------------------------
Johnny Chenbeac8f92012-01-10 00:41:11 +0000316# DYLIB_ONLY variable can be used to skip the building of a.out.
317# See the sections below regarding dSYM file as well as the building of
318# EXE from all the objects.
319#----------------------------------------------------------------------
320
321#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000322# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO"
323#----------------------------------------------------------------------
Matt Kopec7663b3a2013-09-25 17:44:00 +0000324ifneq "$(DYLIB_ONLY)" "YES"
Michael Sartain802b0552013-07-02 18:13:13 +0000325$(DSYM) : $(EXE)
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000326ifeq "$(OS)" "Darwin"
Johnny Chen91016392011-06-20 20:08:26 +0000327ifneq "$(MAKE_DSYM)" "NO"
Enrico Granata489af082014-11-18 22:47:33 +0000328 "$(DS)" $(DSFLAGS) -o "$(DSYM)" "$(EXE)"
Johnny Chen91016392011-06-20 20:08:26 +0000329endif
Michael Sartain802b0552013-07-02 18:13:13 +0000330else
331ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
Michael Sartain802b0552013-07-02 18:13:13 +0000332 objcopy --only-keep-debug "$(EXE)" "$(DSYM)"
333 objcopy --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
334endif
335endif
Johnny Chenbeac8f92012-01-10 00:41:11 +0000336endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000337
338#----------------------------------------------------------------------
339# Compile the executable from all the objects.
340#----------------------------------------------------------------------
Johnny Chenbeac8f92012-01-10 00:41:11 +0000341ifneq "$(DYLIB_NAME)" ""
342ifeq "$(DYLIB_ONLY)" ""
Johnny Chenfe141622012-01-12 23:09:42 +0000343$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME)
Richard Mittonec8b2822013-10-17 20:09:33 +0000344 $(LD) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)"
Johnny Chenbeac8f92012-01-10 00:41:11 +0000345else
346EXE = $(DYLIB_FILENAME)
347endif
348else
Johnny Chenfe141622012-01-12 23:09:42 +0000349$(EXE) : $(OBJECTS) $(ARCHIVE_NAME)
Daniel Malea2745d842013-01-25 00:31:48 +0000350 $(LD) $(OBJECTS) $(LDFLAGS) $(ARCHIVE_NAME) -o "$(EXE)"
Johnny Chenfe141622012-01-12 23:09:42 +0000351endif
352
353#----------------------------------------------------------------------
354# Make the archive
355#----------------------------------------------------------------------
356ifneq "$(ARCHIVE_NAME)" ""
357ifeq "$(OS)" "Darwin"
358$(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS)
359 $(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
360 $(RM) $(ARCHIVE_OBJECTS)
361else
362$(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj)))
363endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000364endif
365
366#----------------------------------------------------------------------
367# Make the dylib
368#----------------------------------------------------------------------
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000369$(DYLIB_FILENAME) : $(DYLIB_OBJECTS)
370ifeq "$(OS)" "Darwin"
371 $(LD) $(LDFLAGS) $(DYLIB_OBJECTS) -install_name "@executable_path/$(DYLIB_FILENAME)" -dynamiclib -o "$(DYLIB_FILENAME)"
Greg Clayton0c9773c2012-09-20 21:43:11 +0000372ifneq "$(MAKE_DSYM)" "NO"
373ifneq "$(DS)" ""
374 $(DS) $(DSFLAGS) "$(DYLIB_FILENAME)"
375endif
376endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000377else
378 $(LD) $(LDFLAGS) $(DYLIB_OBJECTS) -shared -o "$(DYLIB_FILENAME)"
Michael Sartain802b0552013-07-02 18:13:13 +0000379ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
380 objcopy --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
381 objcopy --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
382endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000383endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000384
385#----------------------------------------------------------------------
386# Automatic variables based on items already entered. Below we create
387# an objects lists from the list of sources by replacing all entries
388# that end with .c with .o, and we also create a list of prerequisite
389# files by replacing all .c files with .d.
390#----------------------------------------------------------------------
391PREREQS := $(OBJECTS:.o=.d)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000392ifneq "$(DYLIB_NAME)" ""
393 DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d)
394endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000395
396#----------------------------------------------------------------------
397# Rule for Generating Prerequisites Automatically using .d files and
398# the compiler -MM option. The -M option will list all system headers,
399# and the -MM option will list all non-system dependencies.
400#----------------------------------------------------------------------
401%.d: %.c
402 @set -e; rm -f $@; \
Johnny Chen189bff12011-08-04 20:44:56 +0000403 $(CC) -M $(CFLAGS) $< > $@.$$$$; \
Johnny Chen9bc867a2010-08-23 23:56:08 +0000404 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
405 rm -f $@.$$$$
406
407%.d: %.cpp
408 @set -e; rm -f $@; \
Stefanus Du Toitf1620ef2013-07-30 17:33:30 +0000409 $(CXX) -M $(CXXFLAGS) $< > $@.$$$$; \
Johnny Chen9bc867a2010-08-23 23:56:08 +0000410 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
411 rm -f $@.$$$$
412
413%.d: %.m
414 @set -e; rm -f $@; \
Johnny Chen189bff12011-08-04 20:44:56 +0000415 $(CC) -M $(CFLAGS) $< > $@.$$$$; \
Johnny Chen9bc867a2010-08-23 23:56:08 +0000416 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
417 rm -f $@.$$$$
418
419%.d: %.mm
420 @set -e; rm -f $@; \
Stefanus Du Toitf1620ef2013-07-30 17:33:30 +0000421 $(CXX) -M $(CXXFLAGS) $< > $@.$$$$; \
Johnny Chen9bc867a2010-08-23 23:56:08 +0000422 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
423 rm -f $@.$$$$
424
425#----------------------------------------------------------------------
426# Include all of the makefiles for each source file so we don't have
427# to manually track all of the prerequisites for each source file.
428#----------------------------------------------------------------------
429sinclude $(PREREQS)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000430ifneq "$(DYLIB_NAME)" ""
431 sinclude $(DYLIB_PREREQS)
432endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000433
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000434# Define a suffix rule for .mm -> .o
435.SUFFIXES: .mm .o
436.mm.o:
437 $(CXX) $(CXXFLAGS) -c $<
438
Johnny Chen9bc867a2010-08-23 23:56:08 +0000439.PHONY: clean
440dsym: $(DSYM)
441all: $(EXE) $(DSYM)
Johnny Chene1030cd2010-09-27 20:44:46 +0000442clean::
Ed Mastec5a3c9f2014-03-07 19:11:00 +0000443 $(RM) "$(EXE)" $(OBJECTS) $(PREREQS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
Zachary Turner7d186c02014-07-31 21:03:11 +0000444 $(RM) -r $(wildcard *.d.[0-9] *.d.[0-9][0-9] *.d.[0-9][0-9][0-9] *.d.[0-9][0-9][0-9][0-9] *.d.[0-9][0-9][0-9][0-9][0-9])
Ed Maste0990e052014-03-07 17:20:50 +0000445ifneq "$(DYLIB_NAME)" ""
Jason Molenda53b8ea12014-03-08 01:53:27 +0000446 $(RM) -r $(DYLIB_FILENAME).dSYM
447 $(RM) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).debug
Johnny Chen9bc867a2010-08-23 23:56:08 +0000448endif
Ed Maste0990e052014-03-07 17:20:50 +0000449ifneq "$(DSYM)" ""
Jason Molenda53b8ea12014-03-08 01:53:27 +0000450 $(RM) -r "$(DSYM)"
Ed Maste0990e052014-03-07 17:20:50 +0000451endif
Zachary Turner3e9ca3a2014-12-16 16:48:19 +0000452ifeq "$(OS)" "Windows_NT"
453 $(RM) "$(EXE).manifest" $(wildcard *.pdb *.ilk)
454endif
Johnny Chenfa380412011-01-14 21:18:12 +0000455
456#----------------------------------------------------------------------
457# From http://blog.melski.net/tag/debugging-makefiles/
458#
459# Usage: make print-CC print-CXX print-LD
460#----------------------------------------------------------------------
461print-%:
462 @echo '$*=$($*)'
463 @echo ' origin = $(origin $*)'
464 @echo ' flavor = $(flavor $*)'
465 @echo ' value = $(value $*)'
Johnny Chen8b2c3212011-01-28 17:22:29 +0000466
467
468### Local Variables: ###
469### mode:makefile ###
470### End: ###