1#----------------------------------------------------------------------
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 :=
9# 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#
15# Also might be of interest:
16# FRAMEWORK_INCLUDES (Darwin only) :=
17# CFLAGS_EXTRAS :=
18# LD_EXTRAS :=
19# SPLIT_DEBUG_SYMBOLS := YES
20# CROSS_COMPILE :=
21#
22# And test/functionalities/archives/Makefile:
23# MAKE_DSYM := NO
24# ARCHIVE_NAME := libfoo.a
25# ARCHIVE_C_SOURCES := a.c b.c
26
27# Uncomment line below for debugging shell commands
28# SHELL = /bin/sh -x
29
30THIS_FILE_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/
31LLDB_BASE_DIR := $(THIS_FILE_DIR)../../../../../
32
33
34#----------------------------------------------------------------------
35# If TRIPLE is not defined try to set the ARCH, CC, CFLAGS, and more
36# from the triple alone
37#----------------------------------------------------------------------
38TRIPLE_CFLAGS :=
39ifneq "$(TRIPLE)" ""
40	triple_space = $(subst -, ,$(TRIPLE))
41	ARCH =$(word 1, $(triple_space))
42	TRIPLE_VENDOR =$(word 2, $(triple_space))
43	triple_os_and_version =$(shell echo $(word 3, $(triple_space)) | sed 's/\([a-z]*\)\(.*\)/\1 \2/')
44	TRIPLE_OS =$(word 1, $(triple_os_and_version))
45	TRIPLE_VERSION =$(word 2, $(triple_os_and_version))
46	ifeq "$(TRIPLE_VENDOR)" "apple"
47		ifeq "$(TRIPLE_OS)" "ios"
48		    ifeq "$(SDKROOT)" ""
49				# Set SDKROOT if it wasn't set
50				ifneq (,$(findstring arm,$(ARCH)))
51					SDKROOT = $(shell xcrun --sdk iphoneos --show-sdk-path)
52					ifeq "$(TRIPLE_VERSION)" ""
53						TRIPLE_VERSION =$(shell echo $(notdir $(SDKROOT)) | sed -e 's/.*\([0-9]\.[0-9]\).*/\1/')
54					endif
55					TRIPLE_CFLAGS :=-mios-version-min=$(TRIPLE_VERSION) -isysroot "$(SDKROOT)"
56				else
57					SDKROOT = $(shell xcrun --sdk iphonesimulator --show-sdk-path)
58					ifeq "$(TRIPLE_VERSION)" ""
59						TRIPLE_VERSION =$(shell echo $(notdir $(SDKROOT)) | sed -e 's/.*\([0-9]\.[0-9]\).*/\1/')
60					endif
61					TRIPLE_CFLAGS :=-mios-simulator-version-min=$(TRIPLE_VERSION) -isysroot "$(SDKROOT)"
62				endif
63			endif
64		endif
65	endif
66endif
67
68#----------------------------------------------------------------------
69# If OS is not defined, use 'uname -s' to determine the OS name.
70#
71# uname on Windows gives "windows32", but most environments standardize
72# on "Windows_NT", so we'll make it consistent here.  When running
73# tests from Visual Studio, the environment variable isn't inherited
74# all the way down to the process spawned for make.
75#----------------------------------------------------------------------
76HOST_OS = $(shell uname -s)
77ifeq "$(HOST_OS)" "windows32"
78	HOST_OS = Windows_NT
79endif
80ifeq "$(OS)" ""
81	OS = $(HOST_OS)
82endif
83
84#----------------------------------------------------------------------
85# If ARCH is not defined, default to x86_64.
86#----------------------------------------------------------------------
87ifeq "$(ARCH)" ""
88ifeq "$(OS)" "Windows_NT"
89	ARCH = x86
90else
91	ARCH = x86_64
92endif
93endif
94
95#----------------------------------------------------------------------
96# CC defaults to clang.
97#
98# If you change the defaults of CC, be sure to also change it in the file
99# test/plugins/builder_base.py, which provides a Python way to return the
100# value of the make variable CC -- getCompiler().
101#
102# See also these functions:
103#   o cxx_compiler
104#   o cxx_linker
105#----------------------------------------------------------------------
106CC ?= clang
107ifeq "$(CC)" "cc"
108	ifneq "$(shell which clang)" ""
109		CC = clang
110	else ifneq "$(shell which clang-3.5)" ""
111		CC = clang-3.5
112	else ifneq "$(shell which gcc)" ""
113		CC = gcc
114	endif
115endif
116
117#----------------------------------------------------------------------
118# ARCHFLAG is the flag used to tell the compiler which architecture
119# to compile for. The default is the flag that clang accepts.
120#----------------------------------------------------------------------
121ARCHFLAG ?= -arch
122
123#----------------------------------------------------------------------
124# Change any build/tool options needed
125#----------------------------------------------------------------------
126ifeq "$(OS)" "Darwin"
127	DS := $(shell xcrun -find -toolchain default dsymutil)
128	DSFLAGS =
129	DSYM = $(EXE).dSYM
130	AR := $(CROSS_COMPILE)libtool
131	ARFLAGS := -static -o
132else
133	AR := $(CROSS_COMPILE)ar
134	# On non-Apple platforms, -arch becomes -m
135	ARCHFLAG := -m
136
137	# i386, i686, x86 -> 32
138	# amd64, x86_64, x64 -> 64
139	ifeq "$(ARCH)" "amd64"
140		override ARCH := $(subst amd64,64,$(ARCH))
141	endif
142	ifeq "$(ARCH)" "x86_64"
143		override ARCH := $(subst x86_64,64,$(ARCH))
144	endif
145	ifeq "$(ARCH)" "x64"
146		override ARCH := $(subst x64,64,$(ARCH))
147	endif
148	ifeq "$(ARCH)" "x86"
149		override ARCH := $(subst x86,32,$(ARCH))
150	endif
151	ifeq "$(ARCH)" "i386"
152		override ARCH := $(subst i386,32,$(ARCH))
153	endif
154	ifeq "$(ARCH)" "i686"
155		override ARCH := $(subst i686,32,$(ARCH))
156	endif
157	ifeq "$(ARCH)" "powerpc"
158		override ARCH := $(subst powerpc,32,$(ARCH))
159	endif
160	ifeq "$(ARCH)" "powerpc64"
161		override ARCH := $(subst powerpc64,64,$(ARCH))
162	endif
163	ifeq "$(ARCH)" "aarch64"
164		override ARCH :=
165		override ARCHFLAG :=
166	endif
167	ifeq "$(ARCH)" "arm"
168		override ARCH :=
169		override ARCHFLAG :=
170	endif
171	ifeq "$(ARCH)" "s390x"
172		override ARCH :=
173		override ARCHFLAG :=
174	endif
175	ifeq "$(findstring mips,$(ARCH))" "mips"
176		override ARCHFLAG := -
177	endif
178
179	ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
180		DSYM = $(EXE).debug
181	endif
182endif
183
184LIMIT_DEBUG_INFO_FLAGS =
185NO_LIMIT_DEBUG_INFO_FLAGS =
186ifneq (,$(findstring clang,$(CC)))
187   LIMIT_DEBUG_INFO_FLAGS += -flimit-debug-info
188   NO_LIMIT_DEBUG_INFO_FLAGS += -fno-limit-debug-info
189endif
190
191DEBUG_INFO_FLAG ?= -g
192
193CFLAGS ?= $(DEBUG_INFO_FLAG) -O0 -fno-builtin
194ifeq "$(OS)" "Darwin"
195	CFLAGS += $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
196else
197	CFLAGS += $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
198endif
199
200CFLAGS += -include $(THIS_FILE_DIR)test_common.h $(TRIPLE_CFLAGS)
201
202# Use this one if you want to build one part of the result without debug information:
203ifeq "$(OS)" "Darwin"
204	CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) $(TRIPLE_CFLAGS)
205else
206	CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) $(TRIPLE_CFLAGS)
207endif
208
209ifeq "$(MAKE_DWO)" "YES"
210	CFLAGS += -gsplit-dwarf
211endif
212
213CXXFLAGS += -std=c++11
214CXXFLAGS += $(CFLAGS)
215LD = $(CC)
216LDFLAGS ?= $(CFLAGS)
217LDFLAGS += $(LD_EXTRAS)
218ifeq (,$(filter $(OS), Windows_NT Android))
219	ifneq (,$(filter YES,$(ENABLE_THREADS)))
220		LDFLAGS += -pthread
221	endif
222endif
223OBJECTS =
224EXE ?= a.out
225
226ifneq "$(DYLIB_NAME)" ""
227	ifeq "$(OS)" "Darwin"
228		DYLIB_FILENAME = lib$(DYLIB_NAME).dylib
229		DYLIB_EXECUTABLE_PATH ?= @executable_path
230	else ifeq "$(OS)" "Windows_NT"
231		DYLIB_FILENAME = $(DYLIB_NAME).dll
232	else
233		DYLIB_FILENAME = lib$(DYLIB_NAME).so
234	endif
235endif
236
237# Function that returns the counterpart C++ compiler, given $(CC) as arg.
238cxx_compiler_notdir = $(if $(findstring clang,$(1)), \
239                           $(subst clang,clang++,$(1)), \
240                           $(if $(findstring icc,$(1)), \
241                                $(subst icc,icpc,$(1)), \
242                                $(if $(findstring llvm-gcc,$(1)), \
243                                     $(subst llvm-gcc,llvm-g++,$(1)), \
244                                     $(if $(findstring gcc,$(1)), \
245                                          $(subst gcc,g++,$(1)), \
246                                          $(subst cc,c++,$(1))))))
247cxx_compiler = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call cxx_compiler_notdir,$(notdir $(1)))),$(call cxx_compiler_notdir,$(1)))
248
249# Function that returns the C++ linker, given $(CC) as arg.
250cxx_linker_notdir = $(if $(findstring clang,$(1)), \
251                         $(subst clang,clang++,$(1)), \
252                         $(if $(findstring icc,$(1)), \
253                              $(subst icc,icpc,$(1)), \
254                              $(if $(findstring llvm-gcc,$(1)), \
255                                   $(subst llvm-gcc,llvm-g++,$(1)), \
256                                   $(if $(findstring gcc,$(1)), \
257                                        $(subst gcc,g++,$(1)), \
258                                        $(subst cc,c++,$(1))))))
259cxx_linker = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call cxx_linker_notdir,$(notdir $(1)))),$(call cxx_linker_notdir,$(1)))
260
261OBJCOPY := $(CROSS_COMPILE)objcopy
262
263#----------------------------------------------------------------------
264# Windows specific options
265#----------------------------------------------------------------------
266ifeq "$(OS)" "Windows_NT"
267	ifneq (,$(findstring clang,$(CC)))
268		# Clang for Windows doesn't support C++ Exceptions
269		CXXFLAGS += -fno-exceptions
270		CXXFLAGS += -D_HAS_EXCEPTIONS=0
271		ifeq "$(VisualStudioVersion)" "14.0"
272			CXXFLAGS += -fms-compatibility-version=19.0
273		endif
274		# The MSVC linker doesn't understand long section names
275		# generated by the clang compiler.
276		LDFLAGS += -fuse-ld=lld
277	endif
278endif
279
280#----------------------------------------------------------------------
281# Android specific options
282#----------------------------------------------------------------------
283ifeq "$(OS)" "Android"
284    ifdef PIE
285        LDFLAGS += -pie
286    endif
287    replace_with = $(if $(findstring clang,$(1)), \
288                        $(subst clang,$(2),$(1)), \
289                        $(if $(findstring gcc,$(1)), \
290                             $(subst gcc,$(2),$(1)), \
291                             $(subst cc,$(2),$(1))))
292    ifeq "$(notdir $(CC))" "$(CC)"
293        replace_cc_with = $(call replace_with,$(CC),$(1))
294    else
295        replace_cc_with = $(join $(dir $(CC)),$(call replace_with,$(notdir $(CC)),$(1)))
296    endif
297    OBJCOPY = $(call replace_cc_with,objcopy)
298    AR = $(call replace_cc_with,ar)
299endif
300
301#----------------------------------------------------------------------
302# C++ standard library options
303#----------------------------------------------------------------------
304ifeq (1,$(USE_LIBSTDCPP))
305	# Clang requires an extra flag: -stdlib=libstdc++
306	ifneq (,$(findstring clang,$(CC)))
307		CXXFLAGS += -stdlib=libstdc++
308		LDFLAGS += -stdlib=libstdc++
309	endif
310endif
311
312ifeq (1,$(USE_LIBCPP))
313	# Clang requires an extra flag: -stdlib=libstdc++
314	ifneq (,$(findstring clang,$(CC)))
315		ifeq "$(OS)" "Linux"
316			# This is the default install location on Ubuntu 14.04
317			ifneq ($(wildcard /usr/include/c++/v1/.),)
318				CXXFLAGS += -stdlib=libc++ -DLLDB_USING_LIBCPP
319				LDFLAGS += -stdlib=libc++
320				CXXFLAGS += -I/usr/include/c++/v1
321			endif
322		else
323			CXXFLAGS += -stdlib=libc++ -DLLDB_USING_LIBCPP
324			LDFLAGS += -stdlib=libc++
325		endif
326	endif
327endif
328
329#----------------------------------------------------------------------
330# dylib settings
331#----------------------------------------------------------------------
332ifneq "$(strip $(DYLIB_C_SOURCES))" ""
333	DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
334endif
335
336ifneq "$(strip $(DYLIB_OBJC_SOURCES))" ""
337	DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o))
338endif
339
340ifneq "$(strip $(DYLIB_CXX_SOURCES))" ""
341    DYLIB_OBJECTS +=$(strip $(DYLIB_CXX_SOURCES:.cpp=.o))
342    CXX = $(call cxx_compiler,$(CC))
343    LD = $(call cxx_linker,$(CC))
344endif
345
346#----------------------------------------------------------------------
347# Check if we have any C source files
348#----------------------------------------------------------------------
349ifneq "$(strip $(C_SOURCES))" ""
350	OBJECTS +=$(strip $(C_SOURCES:.c=.o))
351endif
352
353#----------------------------------------------------------------------
354# Check if we have any C++ source files
355#----------------------------------------------------------------------
356ifneq "$(strip $(CXX_SOURCES))" ""
357	OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
358	CXX = $(call cxx_compiler,$(CC))
359	LD = $(call cxx_linker,$(CC))
360endif
361
362#----------------------------------------------------------------------
363# Check if we have any ObjC source files
364#----------------------------------------------------------------------
365ifneq "$(strip $(OBJC_SOURCES))" ""
366	OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o))
367	LDFLAGS +=-lobjc
368endif
369
370#----------------------------------------------------------------------
371# Check if we have any ObjC++ source files
372#----------------------------------------------------------------------
373ifneq "$(strip $(OBJCXX_SOURCES))" ""
374	OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
375	CXX = $(call cxx_compiler,$(CC))
376	LD = $(call cxx_linker,$(CC))
377	ifeq "$(findstring lobjc,$(LDFLAGS))" ""
378		LDFLAGS +=-lobjc
379	endif
380endif
381
382#----------------------------------------------------------------------
383# Check if we have any C source files for archive
384#----------------------------------------------------------------------
385ifneq "$(strip $(ARCHIVE_C_SOURCES))" ""
386	ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_C_SOURCES:.c=.o))
387endif
388
389#----------------------------------------------------------------------
390# Check if we have any C++ source files for archive
391#----------------------------------------------------------------------
392ifneq "$(strip $(ARCHIVE_CXX_SOURCES))" ""
393	ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_CXX_SOURCES:.cpp=.o))
394	CXX = $(call cxx_compiler,$(CC))
395	LD = $(call cxx_linker,$(CC))
396endif
397
398#----------------------------------------------------------------------
399# Check if we have any ObjC source files for archive
400#----------------------------------------------------------------------
401ifneq "$(strip $(ARCHIVE_OBJC_SOURCES))" ""
402	ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJC_SOURCES:.m=.o))
403	LDFLAGS +=-lobjc
404endif
405
406#----------------------------------------------------------------------
407# Check if we have any ObjC++ source files for archive
408#----------------------------------------------------------------------
409ifneq "$(strip $(ARCHIVE_OBJCXX_SOURCES))" ""
410	ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJCXX_SOURCES:.mm=.o))
411	CXX = $(call cxx_compiler,$(CC))
412	LD = $(call cxx_linker,$(CC))
413	ifeq "$(findstring lobjc,$(LDFLAGS))" ""
414		LDFLAGS +=-lobjc
415	endif
416endif
417
418#----------------------------------------------------------------------
419# Check if we are compiling with gcc 4.6
420#----------------------------------------------------------------------
421ifneq "$(strip $(CXX_SOURCES) $(OBJCXX_SOURCES))" ""
422ifneq "$(filter g++,$(CXX))" ""
423	CXXVERSION = $(shell $(CXX) -dumpversion | cut -b 1-3)
424	ifeq "$(CXXVERSION)" "4.6"
425                # GCC 4.6 cannot handle -std=c++11, so replace it with -std=c++0x
426                # instead. FIXME: remove once GCC version is upgraded.
427		override CXXFLAGS := $(subst -std=c++11,-std=c++0x,$(CXXFLAGS))
428	endif
429endif
430endif
431
432#----------------------------------------------------------------------
433# DYLIB_ONLY variable can be used to skip the building of a.out.
434# See the sections below regarding dSYM file as well as the building of
435# EXE from all the objects.
436#----------------------------------------------------------------------
437
438#----------------------------------------------------------------------
439# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO"
440#----------------------------------------------------------------------
441ifneq "$(DYLIB_ONLY)" "YES"
442$(DSYM) : $(EXE)
443ifeq "$(OS)" "Darwin"
444ifneq "$(MAKE_DSYM)" "NO"
445	"$(DS)" $(DSFLAGS) -o "$(DSYM)" "$(EXE)"
446endif
447else
448ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
449	$(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
450	$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
451endif
452endif
453endif
454
455#----------------------------------------------------------------------
456# Compile the executable from all the objects.
457#----------------------------------------------------------------------
458ifneq "$(DYLIB_NAME)" ""
459ifeq "$(DYLIB_ONLY)" ""
460$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME)
461	$(LD) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)"
462else
463EXE = $(DYLIB_FILENAME)
464endif
465else
466$(EXE) : $(OBJECTS) $(ARCHIVE_NAME)
467	$(LD) $(OBJECTS) $(LDFLAGS) $(ARCHIVE_NAME) -o "$(EXE)"
468endif
469
470#----------------------------------------------------------------------
471# Make the archive
472#----------------------------------------------------------------------
473ifneq "$(ARCHIVE_NAME)" ""
474ifeq "$(OS)" "Darwin"
475$(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS)
476	$(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
477	$(RM) $(ARCHIVE_OBJECTS)
478else
479$(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj)))
480endif
481endif
482
483#----------------------------------------------------------------------
484# Make the dylib
485#----------------------------------------------------------------------
486$(DYLIB_OBJECTS) : CFLAGS += -DCOMPILING_LLDB_TEST_DLL
487
488$(DYLIB_FILENAME) : $(DYLIB_OBJECTS)
489ifeq "$(OS)" "Darwin"
490	$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -install_name "$(DYLIB_EXECUTABLE_PATH)/$(DYLIB_FILENAME)" -dynamiclib -o "$(DYLIB_FILENAME)"
491ifneq "$(MAKE_DSYM)" "NO"
492ifneq "$(DS)" ""
493	"$(DS)" $(DSFLAGS) "$(DYLIB_FILENAME)"
494endif
495endif
496else
497	$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
498ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
499	$(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
500	$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
501endif
502endif
503
504#----------------------------------------------------------------------
505# Automatic variables based on items already entered. Below we create
506# an object's lists from the list of sources by replacing all entries
507# that end with .c with .o, and we also create a list of prerequisite
508# files by replacing all .c files with .d.
509#----------------------------------------------------------------------
510PREREQS := $(OBJECTS:.o=.d)
511DWOS := $(OBJECTS:.o=.dwo) $(ARCHIVE_OBJECTS:.o=.dwo)
512ifneq "$(DYLIB_NAME)" ""
513	DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d)
514	DYLIB_DWOS := $(DYLIB_OBJECTS:.o=.dwo)
515endif
516
517#----------------------------------------------------------------------
518# Rule for Generating Prerequisites Automatically using .d files and
519# the compiler -MM option. The -M option will list all system headers,
520# and the -MM option will list all non-system dependencies.
521#----------------------------------------------------------------------
522ifeq "$(HOST_OS)" "Windows_NT"
523	JOIN_CMD = &
524	QUOTE = "
525else
526	JOIN_CMD = ;
527	QUOTE = '
528endif
529
530%.d: %.c
531	@rm -f $@ $(JOIN_CMD) \
532	$(CC) -M $(CFLAGS) $< > [email protected] && \
533	sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < [email protected] > $@ $(JOIN_CMD) \
534	rm -f [email protected]
535
536%.d: %.cpp
537	@rm -f $@ $(JOIN_CMD) \
538	$(CXX) -M $(CXXFLAGS) $< > [email protected] && \
539	sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < [email protected] > $@ $(JOIN_CMD) \
540	rm -f [email protected]
541
542%.d: %.m
543	@rm -f $@ $(JOIN_CMD) \
544	$(CC) -M $(CFLAGS) $< > [email protected] && \
545	sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < [email protected] > $@ $(JOIN_CMD) \
546	rm -f [email protected]
547
548%.d: %.mm
549	@rm -f $@ $(JOIN_CMD) \
550	$(CXX) -M $(CXXFLAGS) $< > [email protected] && \
551	sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < [email protected] > $@ $(JOIN_CMD) \
552	rm -f [email protected]
553
554#----------------------------------------------------------------------
555# Include all of the makefiles for each source file so we don't have
556# to manually track all of the prerequisites for each source file.
557#----------------------------------------------------------------------
558sinclude $(PREREQS)
559ifneq "$(DYLIB_NAME)" ""
560	sinclude $(DYLIB_PREREQS)
561endif
562
563# Define a suffix rule for .mm -> .o
564.SUFFIXES: .mm .o
565.mm.o:
566	$(CXX) $(CXXFLAGS) -c $<
567
568.PHONY: clean
569dsym:	$(DSYM)
570all:	$(EXE) $(DSYM)
571clean::
572	$(RM) $(OBJECTS) $(PREREQS) $(PREREQS:.d=.d.tmp) $(DWOS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
573ifneq "$(DYLIB_NAME)" ""
574	$(RM) -r $(DYLIB_FILENAME).dSYM
575	$(RM) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_PREREQS:.d=.d.tmp) $(DYLIB_DWOS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).debug
576endif
577ifneq "$(DSYM)" ""
578	$(RM) -r "$(DSYM)"
579endif
580ifeq "$(OS)" "Windows_NT"
581# http://llvm.org/pr24589
582	IF EXIST "$(EXE)" del "$(EXE)"
583	$(RM) $(wildcard *.manifest *.pdb *.ilk)
584ifneq "$(DYLIB_NAME)" ""
585	$(RM) $(DYLIB_NAME).lib $(DYLIB_NAME).exp
586endif
587else
588	$(RM) "$(EXE)"
589endif
590
591#----------------------------------------------------------------------
592# From http://blog.melski.net/tag/debugging-makefiles/
593#
594# Usage: make print-CC print-CXX print-LD
595#----------------------------------------------------------------------
596print-%:
597	@echo '$*=$($*)'
598	@echo '  origin = $(origin $*)'
599	@echo '  flavor = $(flavor $*)'
600	@echo '   value = $(value  $*)'
601
602### Local Variables: ###
603### mode:makefile ###
604### End: ###
605