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