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