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