blob: 87c291e4623e2b14708c5306f431775c8df41ed4 [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)" ""
37 ARCH = x86_64
38endif
39
Peter Collingbourne518f03d2011-06-20 19:06:04 +000040ifeq "$(OS)" ""
41 OS = $(shell uname -s)
42endif
43
Johnny Chen6c17c082010-09-16 20:54:06 +000044#----------------------------------------------------------------------
Johnny Chen597cbbb2011-08-23 21:54:10 +000045# CC defaults to clang.
Johnny Chen4ab4a9b2011-08-24 18:12:53 +000046#
47# If you change the defaults of CC, be sure to also change it in the file
48# test/plugins/builder_base.py, which provides a Python way to return the
49# value of the make variable CC -- getCompiler().
50#
Johnny Chen6055b442011-01-14 20:55:13 +000051# See also these functions:
52# o cxx_compiler
53# o cxx_linker
Johnny Chend43e2082011-01-14 20:46:49 +000054#----------------------------------------------------------------------
Johnny Chen597cbbb2011-08-23 21:54:10 +000055CC ?= clang
Johnny Chend43e2082011-01-14 20:46:49 +000056ifeq "$(CC)" "cc"
Johnny Chen597cbbb2011-08-23 21:54:10 +000057 CC = clang
Johnny Chend43e2082011-01-14 20:46:49 +000058endif
59
60#----------------------------------------------------------------------
Daniel Malea2745d842013-01-25 00:31:48 +000061# ARCHFLAG is the flag used to tell the compiler which architecture
62# to compile for. The default is the flag that clang accepts.
63#----------------------------------------------------------------------
64ARCHFLAG ?= -arch
65
66#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +000067# Change any build/tool options needed
68#----------------------------------------------------------------------
Peter Collingbourne518f03d2011-06-20 19:06:04 +000069ifeq "$(OS)" "Darwin"
Greg Clayton82625d32014-07-29 20:10:59 +000070 DS := $(shell xcrun -find -toolchain default dsymutil)
Peter Collingbourne518f03d2011-06-20 19:06:04 +000071 DSFLAGS =
72 DSYM = $(EXE).dSYM
Johnny Chenfe141622012-01-12 23:09:42 +000073 AR := libtool
74 ARFLAGS := -static -o
Daniel Malea2745d842013-01-25 00:31:48 +000075else
76 # On non-Apple platforms, -arch becomes -m
77 ARCHFLAG := -m
78
Zachary Turnerc7826522014-08-13 17:44:53 +000079 # i386, i686, x86 -> 32
Zachary Turner7c1bc2b2014-07-31 21:07:41 +000080 # amd64, x86_64, x64 -> 64
Ed Maste4fe0aba2014-02-20 18:40:01 +000081 ifeq "$(ARCH)" "amd64"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +000082 override ARCH := $(subst amd64,64,$(ARCH))
Ed Maste4fe0aba2014-02-20 18:40:01 +000083 endif
Daniel Malea2745d842013-01-25 00:31:48 +000084 ifeq "$(ARCH)" "x86_64"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +000085 override ARCH := $(subst x86_64,64,$(ARCH))
86 endif
87 ifeq "$(ARCH)" "x64"
88 override ARCH := $(subst x64,64,$(ARCH))
Daniel Malea2745d842013-01-25 00:31:48 +000089 endif
Zachary Turnerc7826522014-08-13 17:44:53 +000090 ifeq "$(ARCH)" "x86"
91 override ARCH := $(subst x86,32,$(ARCH))
92 endif
Daniel Malea2745d842013-01-25 00:31:48 +000093 ifeq "$(ARCH)" "i386"
Zachary Turner7c1bc2b2014-07-31 21:07:41 +000094 override ARCH := $(subst i386,32,$(ARCH))
95 endif
96 ifeq "$(ARCH)" "i686"
97 override ARCH := $(subst i686,32,$(ARCH))
Daniel Malea2745d842013-01-25 00:31:48 +000098 endif
Justin Hibbits3cba1c22014-11-12 15:13:58 +000099 ifeq "$(ARCH)" "powerpc"
100 override ARCH := $(subst powerpc,32,$(ARCH))
101 endif
102 ifeq "$(ARCH)" "powerpc64"
103 override ARCH := $(subst powerpc64,64,$(ARCH))
104 endif
Michael Sartain802b0552013-07-02 18:13:13 +0000105
106 ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
107 DSYM = $(EXE).debug
108 endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000109endif
110
Greg Claytone595c6b2013-02-28 18:47:39 +0000111CFLAGS ?= -g -O0
Zachary Turnerc7826522014-08-13 17:44:53 +0000112CFLAGS += $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
Daniel Malea2745d842013-01-25 00:31:48 +0000113
Jim Ingham4b4b2472014-03-13 02:47:14 +0000114# Use this one if you want to build one part of the result without debug information:
115CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS)
116
Zachary Turnerc7826522014-08-13 17:44:53 +0000117CXXFLAGS += -std=c++11
118CXXFLAGS += $(CFLAGS)
Johnny Chen53e2edb2011-08-09 20:07:16 +0000119LD = $(CC)
120LDFLAGS ?= $(CFLAGS)
Daniel Malea2745d842013-01-25 00:31:48 +0000121LDFLAGS += $(LD_EXTRAS)
Zachary Turnerc7826522014-08-13 17:44:53 +0000122ifneq "$(OS)" "Windows_NT"
Ed Maste6bc862d2014-08-13 18:27:12 +0000123 ifeq "$(ENABLE_THREADS)" "YES"
Zachary Turnerc7826522014-08-13 17:44:53 +0000124 LDFLAGS += -lpthread
125 endif
126endif
Johnny Chen53e2edb2011-08-09 20:07:16 +0000127OBJECTS =
128EXE ?= a.out
129
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000130ifneq "$(DYLIB_NAME)" ""
131 ifeq "$(OS)" "Darwin"
132 DYLIB_FILENAME = lib$(DYLIB_NAME).dylib
133 else
134 DYLIB_FILENAME = lib$(DYLIB_NAME).so
135 endif
136endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000137
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000138# Function that returns the counterpart C++ compiler, given $(CC) as arg.
Shawn Best1ecb68d2014-11-11 17:34:58 +0000139cxx_compiler_notdir = $(if $(findstring clang,$(1)), \
140 $(subst clang,clang++,$(1)), \
141 $(if $(findstring icc,$(1)), \
142 $(subst icc,icpc,$(1)), \
143 $(if $(findstring llvm-gcc,$(1)), \
144 $(subst llvm-gcc,llvm-g++,$(1)), \
145 $(if $(findstring gcc,$(1)), \
146 $(subst gcc,g++,$(1)), \
147 $(subst cc,c++,$(1))))))
Greg Claytonb39751b2013-11-22 21:05:25 +0000148cxx_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 +0000149
150# Function that returns the C++ linker, given $(CC) as arg.
Shawn Best1ecb68d2014-11-11 17:34:58 +0000151cxx_linker_notdir = $(if $(findstring clang,$(1)), \
152 $(subst clang,clang++,$(1)), \
153 $(if $(findstring icc,$(1)), \
154 $(subst icc,icpc,$(1)), \
155 $(if $(findstring llvm-gcc,$(1)), \
156 $(subst llvm-gcc,llvm-g++,$(1)), \
157 $(if $(findstring gcc,$(1)), \
158 $(subst gcc,g++,$(1)), \
159 $(subst cc,c++,$(1))))))
Greg Claytonb39751b2013-11-22 21:05:25 +0000160cxx_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 +0000161
Johnny Chen9bc867a2010-08-23 23:56:08 +0000162#----------------------------------------------------------------------
Zachary Turnerc7826522014-08-13 17:44:53 +0000163# Clang for Windows doesn't yet support exceptions
164#----------------------------------------------------------------------
165ifeq "$(OS)" "Windows_NT"
166 ifneq (,$(findstring clang,$(CC)))
167 CXXFLAGS += -fno-exceptions
168 CXXFLAGS += -include $(THIS_FILE_DIR)uncaught_exception.h
169 CXXFLAGS += -D_HAS_EXCEPTIONS=0
170 endif
171endif
172
173#----------------------------------------------------------------------
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000174# C++ standard library options
175#----------------------------------------------------------------------
176ifeq (1,$(USE_LIBSTDCPP))
177 # Clang requires an extra flag: -stdlib=libstdc++
178 ifneq (,$(findstring clang,$(CC)))
Enrico Granataa1acb492013-06-07 01:58:52 +0000179 CXXFLAGS += -stdlib=libstdc++
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000180 LDFLAGS += -stdlib=libstdc++
181 endif
182endif
183
Greg Clayton1767a732013-06-13 21:27:14 +0000184ifeq (1,$(USE_LIBCPP))
185 # Clang requires an extra flag: -stdlib=libstdc++
186 ifneq (,$(findstring clang,$(CC)))
187 CXXFLAGS += -stdlib=libc++
188 LDFLAGS += -stdlib=libc++
189 endif
190endif
191
Daniel Maleac7ffa7a2013-06-05 19:32:34 +0000192#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000193# dylib settings
194#----------------------------------------------------------------------
195ifneq "$(strip $(DYLIB_C_SOURCES))" ""
196 DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
197endif
198
Sean Callanan72772842012-02-22 23:57:45 +0000199ifneq "$(strip $(DYLIB_OBJC_SOURCES))" ""
200 DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o))
201endif
202
Greg Claytond50d2382012-01-10 00:00:15 +0000203ifneq "$(strip $(DYLIB_CXX_SOURCES))" ""
204 DYLIB_OBJECTS +=$(strip $(DYLIB_CXX_SOURCES:.cpp=.o))
205 CXX = $(call cxx_compiler,$(CC))
206 LD = $(call cxx_linker,$(CC))
207endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000208
209#----------------------------------------------------------------------
210# Check if we have any C source files
211#----------------------------------------------------------------------
212ifneq "$(strip $(C_SOURCES))" ""
213 OBJECTS +=$(strip $(C_SOURCES:.c=.o))
214endif
215
216#----------------------------------------------------------------------
217# Check if we have any C++ source files
218#----------------------------------------------------------------------
219ifneq "$(strip $(CXX_SOURCES))" ""
220 OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
Johnny Chen832d2332010-09-30 01:22:34 +0000221 CXX = $(call cxx_compiler,$(CC))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000222 LD = $(call cxx_linker,$(CC))
Johnny Chen9bc867a2010-08-23 23:56:08 +0000223endif
224
225#----------------------------------------------------------------------
226# Check if we have any ObjC source files
227#----------------------------------------------------------------------
228ifneq "$(strip $(OBJC_SOURCES))" ""
229 OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o))
230 LDFLAGS +=-lobjc
231endif
232
233#----------------------------------------------------------------------
234# Check if we have any ObjC++ source files
235#----------------------------------------------------------------------
236ifneq "$(strip $(OBJCXX_SOURCES))" ""
237 OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
Johnny Chen832d2332010-09-30 01:22:34 +0000238 CXX = $(call cxx_compiler,$(CC))
Johnny Chenbdb4efc2011-01-14 18:19:53 +0000239 LD = $(call cxx_linker,$(CC))
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000240 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
Johnny Chen9bc867a2010-08-23 23:56:08 +0000241 LDFLAGS +=-lobjc
242 endif
243endif
244
Johnny Chenfe141622012-01-12 23:09:42 +0000245#----------------------------------------------------------------------
246# Check if we have any C source files for archive
247#----------------------------------------------------------------------
248ifneq "$(strip $(ARCHIVE_C_SOURCES))" ""
249 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_C_SOURCES:.c=.o))
250endif
251
252#----------------------------------------------------------------------
253# Check if we have any C++ source files for archive
254#----------------------------------------------------------------------
255ifneq "$(strip $(ARCHIVE_CXX_SOURCES))" ""
256 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_CXX_SOURCES:.cpp=.o))
257 CXX = $(call cxx_compiler,$(CC))
258 LD = $(call cxx_linker,$(CC))
259endif
260
261#----------------------------------------------------------------------
262# Check if we have any ObjC source files for archive
263#----------------------------------------------------------------------
264ifneq "$(strip $(ARCHIVE_OBJC_SOURCES))" ""
265 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJC_SOURCES:.m=.o))
266 LDFLAGS +=-lobjc
267endif
268
269#----------------------------------------------------------------------
270# Check if we have any ObjC++ source files for archive
271#----------------------------------------------------------------------
272ifneq "$(strip $(ARCHIVE_OBJCXX_SOURCES))" ""
273 ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJCXX_SOURCES:.mm=.o))
274 CXX = $(call cxx_compiler,$(CC))
275 LD = $(call cxx_linker,$(CC))
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000276 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
Johnny Chenfe141622012-01-12 23:09:42 +0000277 LDFLAGS +=-lobjc
278 endif
279endif
280
Matt Kopecf2430f52013-07-24 21:39:24 +0000281#----------------------------------------------------------------------
282# Check if we are compiling with gcc 4.6
283#----------------------------------------------------------------------
284ifneq (,$(filter g++,$(CXX)))
285 CXXVERSION = $(shell g++ -dumpversion | cut -b 1-3)
286 ifeq "$(CXXVERSION)" "4.6"
287 # GCC 4.6 cannot handle -std=c++11, so replace it with -std=c++0x
288 # instead. FIXME: remove once GCC version is upgraded.
289 override CXXFLAGS := $(subst -std=c++11,-std=c++0x,$(CXXFLAGS))
290 endif
291endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000292
293#----------------------------------------------------------------------
Johnny Chenbeac8f92012-01-10 00:41:11 +0000294# DYLIB_ONLY variable can be used to skip the building of a.out.
295# See the sections below regarding dSYM file as well as the building of
296# EXE from all the objects.
297#----------------------------------------------------------------------
298
299#----------------------------------------------------------------------
Johnny Chen9bc867a2010-08-23 23:56:08 +0000300# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO"
301#----------------------------------------------------------------------
Matt Kopec7663b3a2013-09-25 17:44:00 +0000302ifneq "$(DYLIB_ONLY)" "YES"
Michael Sartain802b0552013-07-02 18:13:13 +0000303$(DSYM) : $(EXE)
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000304ifeq "$(OS)" "Darwin"
Johnny Chen91016392011-06-20 20:08:26 +0000305ifneq "$(MAKE_DSYM)" "NO"
Johnny Chen9bc867a2010-08-23 23:56:08 +0000306 $(DS) $(DSFLAGS) -o "$(DSYM)" "$(EXE)"
Johnny Chen91016392011-06-20 20:08:26 +0000307endif
Michael Sartain802b0552013-07-02 18:13:13 +0000308else
309ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
Michael Sartain802b0552013-07-02 18:13:13 +0000310 objcopy --only-keep-debug "$(EXE)" "$(DSYM)"
311 objcopy --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
312endif
313endif
Johnny Chenbeac8f92012-01-10 00:41:11 +0000314endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000315
316#----------------------------------------------------------------------
317# Compile the executable from all the objects.
318#----------------------------------------------------------------------
Johnny Chenbeac8f92012-01-10 00:41:11 +0000319ifneq "$(DYLIB_NAME)" ""
320ifeq "$(DYLIB_ONLY)" ""
Johnny Chenfe141622012-01-12 23:09:42 +0000321$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME)
Richard Mittonec8b2822013-10-17 20:09:33 +0000322 $(LD) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)"
Johnny Chenbeac8f92012-01-10 00:41:11 +0000323else
324EXE = $(DYLIB_FILENAME)
325endif
326else
Johnny Chenfe141622012-01-12 23:09:42 +0000327$(EXE) : $(OBJECTS) $(ARCHIVE_NAME)
Daniel Malea2745d842013-01-25 00:31:48 +0000328 $(LD) $(OBJECTS) $(LDFLAGS) $(ARCHIVE_NAME) -o "$(EXE)"
Johnny Chenfe141622012-01-12 23:09:42 +0000329endif
330
331#----------------------------------------------------------------------
332# Make the archive
333#----------------------------------------------------------------------
334ifneq "$(ARCHIVE_NAME)" ""
335ifeq "$(OS)" "Darwin"
336$(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS)
337 $(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
338 $(RM) $(ARCHIVE_OBJECTS)
339else
340$(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj)))
341endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000342endif
343
344#----------------------------------------------------------------------
345# Make the dylib
346#----------------------------------------------------------------------
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000347$(DYLIB_FILENAME) : $(DYLIB_OBJECTS)
348ifeq "$(OS)" "Darwin"
349 $(LD) $(LDFLAGS) $(DYLIB_OBJECTS) -install_name "@executable_path/$(DYLIB_FILENAME)" -dynamiclib -o "$(DYLIB_FILENAME)"
Greg Clayton0c9773c2012-09-20 21:43:11 +0000350ifneq "$(MAKE_DSYM)" "NO"
351ifneq "$(DS)" ""
352 $(DS) $(DSFLAGS) "$(DYLIB_FILENAME)"
353endif
354endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000355else
356 $(LD) $(LDFLAGS) $(DYLIB_OBJECTS) -shared -o "$(DYLIB_FILENAME)"
Michael Sartain802b0552013-07-02 18:13:13 +0000357ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
358 objcopy --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
359 objcopy --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
360endif
Peter Collingbourne518f03d2011-06-20 19:06:04 +0000361endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000362
363#----------------------------------------------------------------------
364# Automatic variables based on items already entered. Below we create
365# an objects lists from the list of sources by replacing all entries
366# that end with .c with .o, and we also create a list of prerequisite
367# files by replacing all .c files with .d.
368#----------------------------------------------------------------------
369PREREQS := $(OBJECTS:.o=.d)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000370ifneq "$(DYLIB_NAME)" ""
371 DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d)
372endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000373
374#----------------------------------------------------------------------
375# Rule for Generating Prerequisites Automatically using .d files and
376# the compiler -MM option. The -M option will list all system headers,
377# and the -MM option will list all non-system dependencies.
378#----------------------------------------------------------------------
379%.d: %.c
380 @set -e; rm -f $@; \
Johnny Chen189bff12011-08-04 20:44:56 +0000381 $(CC) -M $(CFLAGS) $< > $@.$$$$; \
Johnny Chen9bc867a2010-08-23 23:56:08 +0000382 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
383 rm -f $@.$$$$
384
385%.d: %.cpp
386 @set -e; rm -f $@; \
Stefanus Du Toitf1620ef2013-07-30 17:33:30 +0000387 $(CXX) -M $(CXXFLAGS) $< > $@.$$$$; \
Johnny Chen9bc867a2010-08-23 23:56:08 +0000388 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
389 rm -f $@.$$$$
390
391%.d: %.m
392 @set -e; rm -f $@; \
Johnny Chen189bff12011-08-04 20:44:56 +0000393 $(CC) -M $(CFLAGS) $< > $@.$$$$; \
Johnny Chen9bc867a2010-08-23 23:56:08 +0000394 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
395 rm -f $@.$$$$
396
397%.d: %.mm
398 @set -e; rm -f $@; \
Stefanus Du Toitf1620ef2013-07-30 17:33:30 +0000399 $(CXX) -M $(CXXFLAGS) $< > $@.$$$$; \
Johnny Chen9bc867a2010-08-23 23:56:08 +0000400 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
401 rm -f $@.$$$$
402
403#----------------------------------------------------------------------
404# Include all of the makefiles for each source file so we don't have
405# to manually track all of the prerequisites for each source file.
406#----------------------------------------------------------------------
407sinclude $(PREREQS)
Johnny Chene3dc0f02010-08-24 16:35:00 +0000408ifneq "$(DYLIB_NAME)" ""
409 sinclude $(DYLIB_PREREQS)
410endif
Johnny Chen9bc867a2010-08-23 23:56:08 +0000411
Johnny Chen8da4ddf2012-04-24 23:05:07 +0000412# Define a suffix rule for .mm -> .o
413.SUFFIXES: .mm .o
414.mm.o:
415 $(CXX) $(CXXFLAGS) -c $<
416
Johnny Chen9bc867a2010-08-23 23:56:08 +0000417.PHONY: clean
418dsym: $(DSYM)
419all: $(EXE) $(DSYM)
Johnny Chene1030cd2010-09-27 20:44:46 +0000420clean::
Ed Mastec5a3c9f2014-03-07 19:11:00 +0000421 $(RM) "$(EXE)" $(OBJECTS) $(PREREQS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
Zachary Turner7d186c02014-07-31 21:03:11 +0000422 $(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 +0000423ifneq "$(DYLIB_NAME)" ""
Jason Molenda53b8ea12014-03-08 01:53:27 +0000424 $(RM) -r $(DYLIB_FILENAME).dSYM
425 $(RM) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).debug
Johnny Chen9bc867a2010-08-23 23:56:08 +0000426endif
Ed Maste0990e052014-03-07 17:20:50 +0000427ifneq "$(DSYM)" ""
Jason Molenda53b8ea12014-03-08 01:53:27 +0000428 $(RM) -r "$(DSYM)"
Ed Maste0990e052014-03-07 17:20:50 +0000429endif
430
Johnny Chenfa380412011-01-14 21:18:12 +0000431
432#----------------------------------------------------------------------
433# From http://blog.melski.net/tag/debugging-makefiles/
434#
435# Usage: make print-CC print-CXX print-LD
436#----------------------------------------------------------------------
437print-%:
438 @echo '$*=$($*)'
439 @echo ' origin = $(origin $*)'
440 @echo ' flavor = $(flavor $*)'
441 @echo ' value = $(value $*)'
Johnny Chen8b2c3212011-01-28 17:22:29 +0000442
443
444### Local Variables: ###
445### mode:makefile ###
446### End: ###