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 "$(findstring mips,$(ARCH))" "mips"
172		override ARCHFLAG := -
173	endif
174
175	ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
176		DSYM = $(EXE).debug
177	endif
178endif
179
180LIMIT_DEBUG_INFO_FLAGS =
181ifneq (,$(findstring clang,$(CC)))
182   LIMIT_DEBUG_INFO_FLAGS += -flimit-debug-info
183endif
184
185CFLAGS ?= -g -O0 -fno-builtin
186ifeq "$(OS)" "Darwin"
187	CFLAGS += $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
188else
189	CFLAGS += $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) -I$(LLDB_BASE_DIR)include
190endif
191
192CFLAGS += -include $(THIS_FILE_DIR)test_common.h $(TRIPLE_CFLAGS)
193
194# Use this one if you want to build one part of the result without debug information:
195ifeq "$(OS)" "Darwin"
196	CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) $(TRIPLE_CFLAGS)
197else
198	CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS) $(TRIPLE_CFLAGS)
199endif
200
201ifeq "$(MAKE_DWO)" "YES"
202	CFLAGS += -gsplit-dwarf
203endif
204
205CXXFLAGS += -std=c++11
206CXXFLAGS += $(CFLAGS)
207LD = $(CC)
208LDFLAGS ?= $(CFLAGS)
209LDFLAGS += $(LD_EXTRAS)
210ifeq (,$(filter $(OS), Windows_NT Android))
211	ifneq (,$(filter YES,$(ENABLE_THREADS) $(ENABLE_STD_THREADS)))
212		LDFLAGS += -pthread
213	endif
214endif
215OBJECTS =
216EXE ?= a.out
217
218ifneq "$(DYLIB_NAME)" ""
219	ifeq "$(OS)" "Darwin"
220		DYLIB_FILENAME = lib$(DYLIB_NAME).dylib
221		DYLIB_EXECUTABLE_PATH ?= @executable_path
222	else ifeq "$(OS)" "Windows_NT"
223		DYLIB_FILENAME = $(DYLIB_NAME).dll
224	else
225		DYLIB_FILENAME = lib$(DYLIB_NAME).so
226	endif
227endif
228
229# Function that returns the counterpart C++ compiler, given $(CC) as arg.
230cxx_compiler_notdir = $(if $(findstring clang,$(1)), \
231                           $(subst clang,clang++,$(1)), \
232                           $(if $(findstring icc,$(1)), \
233                                $(subst icc,icpc,$(1)), \
234                                $(if $(findstring llvm-gcc,$(1)), \
235                                     $(subst llvm-gcc,llvm-g++,$(1)), \
236                                     $(if $(findstring gcc,$(1)), \
237                                          $(subst gcc,g++,$(1)), \
238                                          $(subst cc,c++,$(1))))))
239cxx_compiler = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call cxx_compiler_notdir,$(notdir $(1)))),$(call cxx_compiler_notdir,$(1)))
240
241# Function that returns the C++ linker, given $(CC) as arg.
242cxx_linker_notdir = $(if $(findstring clang,$(1)), \
243                         $(subst clang,clang++,$(1)), \
244                         $(if $(findstring icc,$(1)), \
245                              $(subst icc,icpc,$(1)), \
246                              $(if $(findstring llvm-gcc,$(1)), \
247                                   $(subst llvm-gcc,llvm-g++,$(1)), \
248                                   $(if $(findstring gcc,$(1)), \
249                                        $(subst gcc,g++,$(1)), \
250                                        $(subst cc,c++,$(1))))))
251cxx_linker = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call cxx_linker_notdir,$(notdir $(1)))),$(call cxx_linker_notdir,$(1)))
252
253OBJCOPY := $(CROSS_COMPILE)objcopy
254
255#----------------------------------------------------------------------
256# Windows specific options
257#----------------------------------------------------------------------
258ifeq "$(OS)" "Windows_NT"
259	ifneq (,$(findstring clang,$(CC)))
260		# Clang for Windows doesn't support C++ Exceptions
261		CXXFLAGS += -fno-exceptions
262		CXXFLAGS += -D_HAS_EXCEPTIONS=0
263		ifeq "$(VisualStudioVersion)" "14.0"
264			CXXFLAGS += -fms-compatibility-version=19.0
265		endif
266		# The MSVC linker doesn't understand long section names
267		# generated by the clang compiler.
268		LDFLAGS += -fuse-ld=lld
269	endif
270endif
271
272#----------------------------------------------------------------------
273# Android specific options
274#----------------------------------------------------------------------
275ifeq "$(OS)" "Android"
276    ifdef PIE
277        LDFLAGS += -pie
278    endif
279    replace_with = $(if $(findstring clang,$(1)), \
280                        $(subst clang,$(2),$(1)), \
281                        $(if $(findstring gcc,$(1)), \
282                             $(subst gcc,$(2),$(1)), \
283                             $(subst cc,$(2),$(1))))
284    ifeq "$(notdir $(CC))" "$(CC)"
285        replace_cc_with = $(call replace_with,$(CC),$(1))
286    else
287        replace_cc_with = $(join $(dir $(CC)),$(call replace_with,$(notdir $(CC)),$(1)))
288    endif
289    OBJCOPY = $(call replace_cc_with,objcopy)
290    AR = $(call replace_cc_with,ar)
291endif
292
293#----------------------------------------------------------------------
294# C++ standard library options
295#----------------------------------------------------------------------
296ifeq (1,$(USE_LIBSTDCPP))
297	# Clang requires an extra flag: -stdlib=libstdc++
298	ifneq (,$(findstring clang,$(CC)))
299		CXXFLAGS += -stdlib=libstdc++
300		LDFLAGS += -stdlib=libstdc++
301	endif
302endif
303
304ifeq (1,$(USE_LIBCPP))
305	# Clang requires an extra flag: -stdlib=libstdc++
306	ifneq (,$(findstring clang,$(CC)))
307		ifeq "$(OS)" "Linux"
308			# This is the default install location on Ubuntu 14.04
309			ifneq ($(wildcard /usr/include/c++/v1/.),)
310				CXXFLAGS += -stdlib=libc++ -DLLDB_USING_LIBCPP
311				LDFLAGS += -stdlib=libc++
312				CXXFLAGS += -I/usr/include/c++/v1
313			endif
314		else
315			CXXFLAGS += -stdlib=libc++ -DLLDB_USING_LIBCPP
316			LDFLAGS += -stdlib=libc++
317		endif
318	endif
319endif
320
321#----------------------------------------------------------------------
322# dylib settings
323#----------------------------------------------------------------------
324ifneq "$(strip $(DYLIB_C_SOURCES))" ""
325	DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
326endif
327
328ifneq "$(strip $(DYLIB_OBJC_SOURCES))" ""
329	DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o))
330endif
331
332ifneq "$(strip $(DYLIB_CXX_SOURCES))" ""
333    DYLIB_OBJECTS +=$(strip $(DYLIB_CXX_SOURCES:.cpp=.o))
334    CXX = $(call cxx_compiler,$(CC))
335    LD = $(call cxx_linker,$(CC))
336endif
337
338#----------------------------------------------------------------------
339# Check if we have any C source files
340#----------------------------------------------------------------------
341ifneq "$(strip $(C_SOURCES))" ""
342	OBJECTS +=$(strip $(C_SOURCES:.c=.o))
343endif
344
345#----------------------------------------------------------------------
346# Check if we have any C++ source files
347#----------------------------------------------------------------------
348ifneq "$(strip $(CXX_SOURCES))" ""
349	OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
350	CXX = $(call cxx_compiler,$(CC))
351	LD = $(call cxx_linker,$(CC))
352endif
353
354#----------------------------------------------------------------------
355# Check if we have any ObjC source files
356#----------------------------------------------------------------------
357ifneq "$(strip $(OBJC_SOURCES))" ""
358	OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o))
359	LDFLAGS +=-lobjc
360endif
361
362#----------------------------------------------------------------------
363# Check if we have any ObjC++ source files
364#----------------------------------------------------------------------
365ifneq "$(strip $(OBJCXX_SOURCES))" ""
366	OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
367	CXX = $(call cxx_compiler,$(CC))
368	LD = $(call cxx_linker,$(CC))
369	ifeq "$(findstring lobjc,$(LDFLAGS))" ""
370		LDFLAGS +=-lobjc
371	endif
372endif
373
374#----------------------------------------------------------------------
375# Check if we have any C source files for archive
376#----------------------------------------------------------------------
377ifneq "$(strip $(ARCHIVE_C_SOURCES))" ""
378	ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_C_SOURCES:.c=.o))
379endif
380
381#----------------------------------------------------------------------
382# Check if we have any C++ source files for archive
383#----------------------------------------------------------------------
384ifneq "$(strip $(ARCHIVE_CXX_SOURCES))" ""
385	ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_CXX_SOURCES:.cpp=.o))
386	CXX = $(call cxx_compiler,$(CC))
387	LD = $(call cxx_linker,$(CC))
388endif
389
390#----------------------------------------------------------------------
391# Check if we have any ObjC source files for archive
392#----------------------------------------------------------------------
393ifneq "$(strip $(ARCHIVE_OBJC_SOURCES))" ""
394	ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJC_SOURCES:.m=.o))
395	LDFLAGS +=-lobjc
396endif
397
398#----------------------------------------------------------------------
399# Check if we have any ObjC++ source files for archive
400#----------------------------------------------------------------------
401ifneq "$(strip $(ARCHIVE_OBJCXX_SOURCES))" ""
402	ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJCXX_SOURCES:.mm=.o))
403	CXX = $(call cxx_compiler,$(CC))
404	LD = $(call cxx_linker,$(CC))
405	ifeq "$(findstring lobjc,$(LDFLAGS))" ""
406		LDFLAGS +=-lobjc
407	endif
408endif
409
410#----------------------------------------------------------------------
411# Check if we are compiling with gcc 4.6
412#----------------------------------------------------------------------
413ifneq "$(strip $(CXX_SOURCES) $(OBJCXX_SOURCES))" ""
414ifneq "$(filter g++,$(CXX))" ""
415	CXXVERSION = $(shell $(CXX) -dumpversion | cut -b 1-3)
416	ifeq "$(CXXVERSION)" "4.6"
417                # GCC 4.6 cannot handle -std=c++11, so replace it with -std=c++0x
418                # instead. FIXME: remove once GCC version is upgraded.
419		override CXXFLAGS := $(subst -std=c++11,-std=c++0x,$(CXXFLAGS))
420	endif
421endif
422endif
423
424#----------------------------------------------------------------------
425# DYLIB_ONLY variable can be used to skip the building of a.out.
426# See the sections below regarding dSYM file as well as the building of
427# EXE from all the objects.
428#----------------------------------------------------------------------
429
430#----------------------------------------------------------------------
431# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO"
432#----------------------------------------------------------------------
433ifneq "$(DYLIB_ONLY)" "YES"
434$(DSYM) : $(EXE)
435ifeq "$(OS)" "Darwin"
436ifneq "$(MAKE_DSYM)" "NO"
437	"$(DS)" $(DSFLAGS) -o "$(DSYM)" "$(EXE)"
438endif
439else
440ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
441	$(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
442	$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
443endif
444endif
445endif
446
447#----------------------------------------------------------------------
448# Compile the executable from all the objects.
449#----------------------------------------------------------------------
450ifneq "$(DYLIB_NAME)" ""
451ifeq "$(DYLIB_ONLY)" ""
452$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME)
453	$(LD) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)"
454else
455EXE = $(DYLIB_FILENAME)
456endif
457else
458$(EXE) : $(OBJECTS) $(ARCHIVE_NAME)
459	$(LD) $(OBJECTS) $(LDFLAGS) $(ARCHIVE_NAME) -o "$(EXE)"
460endif
461
462#----------------------------------------------------------------------
463# Make the archive
464#----------------------------------------------------------------------
465ifneq "$(ARCHIVE_NAME)" ""
466ifeq "$(OS)" "Darwin"
467$(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS)
468	$(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
469	$(RM) $(ARCHIVE_OBJECTS)
470else
471$(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj)))
472endif
473endif
474
475#----------------------------------------------------------------------
476# Make the dylib
477#----------------------------------------------------------------------
478$(DYLIB_OBJECTS) : CFLAGS += -DCOMPILING_LLDB_TEST_DLL
479
480$(DYLIB_FILENAME) : $(DYLIB_OBJECTS)
481ifeq "$(OS)" "Darwin"
482	$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -install_name "$(DYLIB_EXECUTABLE_PATH)/$(DYLIB_FILENAME)" -dynamiclib -o "$(DYLIB_FILENAME)"
483ifneq "$(MAKE_DSYM)" "NO"
484ifneq "$(DS)" ""
485	"$(DS)" $(DSFLAGS) "$(DYLIB_FILENAME)"
486endif
487endif
488else
489	$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
490ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
491	$(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
492	$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
493endif
494endif
495
496#----------------------------------------------------------------------
497# Automatic variables based on items already entered. Below we create
498# an object's lists from the list of sources by replacing all entries
499# that end with .c with .o, and we also create a list of prerequisite
500# files by replacing all .c files with .d.
501#----------------------------------------------------------------------
502PREREQS := $(OBJECTS:.o=.d)
503DWOS := $(OBJECTS:.o=.dwo) $(ARCHIVE_OBJECTS:.o=.dwo)
504ifneq "$(DYLIB_NAME)" ""
505	DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d)
506	DYLIB_DWOS := $(DYLIB_OBJECTS:.o=.dwo)
507endif
508
509#----------------------------------------------------------------------
510# Rule for Generating Prerequisites Automatically using .d files and
511# the compiler -MM option. The -M option will list all system headers,
512# and the -MM option will list all non-system dependencies.
513#----------------------------------------------------------------------
514ifeq "$(HOST_OS)" "Windows_NT"
515	JOIN_CMD = &
516	QUOTE = "
517else
518	JOIN_CMD = ;
519	QUOTE = '
520endif
521
522%.d: %.c
523	@rm -f $@ $(JOIN_CMD) \
524	$(CC) -M $(CFLAGS) $< > [email protected] && \
525	sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < [email protected] > $@ $(JOIN_CMD) \
526	rm -f [email protected]
527
528%.d: %.cpp
529	@rm -f $@ $(JOIN_CMD) \
530	$(CXX) -M $(CXXFLAGS) $< > [email protected] && \
531	sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < [email protected] > $@ $(JOIN_CMD) \
532	rm -f [email protected]
533
534%.d: %.m
535	@rm -f $@ $(JOIN_CMD) \
536	$(CC) -M $(CFLAGS) $< > [email protected] && \
537	sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < [email protected] > $@ $(JOIN_CMD) \
538	rm -f [email protected]
539
540%.d: %.mm
541	@rm -f $@ $(JOIN_CMD) \
542	$(CXX) -M $(CXXFLAGS) $< > [email protected] && \
543	sed $(QUOTE)s,\($*\)\.o[ :]*,\1.o $@ : ,g$(QUOTE) < [email protected] > $@ $(JOIN_CMD) \
544	rm -f [email protected]
545
546#----------------------------------------------------------------------
547# Include all of the makefiles for each source file so we don't have
548# to manually track all of the prerequisites for each source file.
549#----------------------------------------------------------------------
550sinclude $(PREREQS)
551ifneq "$(DYLIB_NAME)" ""
552	sinclude $(DYLIB_PREREQS)
553endif
554
555# Define a suffix rule for .mm -> .o
556.SUFFIXES: .mm .o
557.mm.o:
558	$(CXX) $(CXXFLAGS) -c $<
559
560.PHONY: clean
561dsym:	$(DSYM)
562all:	$(EXE) $(DSYM)
563clean::
564	$(RM) $(OBJECTS) $(PREREQS) $(PREREQS:.d=.d.tmp) $(DWOS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
565ifneq "$(DYLIB_NAME)" ""
566	$(RM) -r $(DYLIB_FILENAME).dSYM
567	$(RM) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_PREREQS:.d=.d.tmp) $(DYLIB_DWOS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).debug
568endif
569ifneq "$(DSYM)" ""
570	$(RM) -r "$(DSYM)"
571endif
572ifeq "$(OS)" "Windows_NT"
573# http://llvm.org/pr24589
574	IF EXIST "$(EXE)" del "$(EXE)"
575	$(RM) $(wildcard *.manifest *.pdb *.ilk)
576ifneq "$(DYLIB_NAME)" ""
577	$(RM) $(DYLIB_NAME).lib $(DYLIB_NAME).exp
578endif
579else
580	$(RM) "$(EXE)"
581endif
582
583#----------------------------------------------------------------------
584# From http://blog.melski.net/tag/debugging-makefiles/
585#
586# Usage: make print-CC print-CXX print-LD
587#----------------------------------------------------------------------
588print-%:
589	@echo '$*=$($*)'
590	@echo '  origin = $(origin $*)'
591	@echo '  flavor = $(flavor $*)'
592	@echo '   value = $(value  $*)'
593
594### Local Variables: ###
595### mode:makefile ###
596### End: ###
597