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