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_OBJC_SOURCES :=
10# DYLIB_CXX_SOURCES :=
11#
12# Specifying DYLIB_ONLY has the effect of building dylib only, skipping
13# the building of the a.out executable program.  For example,
14# DYLIB_ONLY := YES
15#
16# Specifying FRAMEWORK and its variants has the effect of building a NeXT-style
17# framework.
18# FRAMEWORK := "Foo"
19# FRAMEWORK_HEADERS := "Foo.h"
20# FRAMEWORK_MODULES := "module.modulemap"
21#
22# Also might be of interest:
23# FRAMEWORK_INCLUDES (Darwin only) :=
24# CFLAGS_EXTRAS :=
25# LD_EXTRAS :=
26# SPLIT_DEBUG_SYMBOLS := YES
27# CROSS_COMPILE :=
28# USE_PRIVATE_MODULE_CACHE := YES
29
30# Uncomment line below for debugging shell commands
31# SHELL = /bin/sh -x
32
33# Suppress built-in suffix rules. We explicitly define rules for %.o.
34.SUFFIXES:
35
36SRCDIR := $(shell dirname $(firstword $(MAKEFILE_LIST)))
37BUILDDIR := $(shell pwd)
38MAKEFILE_RULES := $(lastword $(MAKEFILE_LIST))
39THIS_FILE_DIR := $(shell dirname $(MAKEFILE_RULES))
40LLDB_BASE_DIR := $(THIS_FILE_DIR)/../../../../../
41
42# The test harness invokes the test Makefiles with an explicit 'all'
43# target, but its handy to be able to recursively call this Makefile
44# without specifying a goal. You almost certainly want to build 'all',
45# and not only the first target defined in this file (which might vary
46# according to variable values).
47.DEFAULT_GOAL := all
48
49#----------------------------------------------------------------------
50# If OS is not defined, use 'uname -s' to determine the OS name.
51#
52# uname on Windows gives "windows32" or "server version windows32", but most
53# environments standardize on "Windows_NT", so we'll make it consistent here.
54# When running tests from Visual Studio, the environment variable isn't
55# inherited all the way down to the process spawned for make.
56#----------------------------------------------------------------------
57HOST_OS := $(shell uname -s)
58ifneq (,$(findstring windows32,$(HOST_OS)))
59	HOST_OS := Windows_NT
60endif
61ifeq "$(OS)" ""
62	OS := $(HOST_OS)
63endif
64
65#----------------------------------------------------------------------
66# If OS is Windows, force SHELL to be cmd
67#
68# Some versions of make on Windows will search for other shells such as
69# C:\cygwin\bin\sh.exe. This shell fails for numerous different reasons
70# so default to using cmd.exe.
71#----------------------------------------------------------------------
72ifeq "$(OS)" "Windows_NT"
73	SHELL = $(WINDIR)\system32\cmd.exe
74endif
75
76#----------------------------------------------------------------------
77# If the OS is Windows use double-quotes in commands
78#
79# For other operating systems, single-quotes work fine, but on Windows
80# we strictly required double-quotes
81#----------------------------------------------------------------------
82ifeq "$(HOST_OS)" "Windows_NT"
83	QUOTE = "
84	FIXUP_SYNTAX_HIGHLIGHTING_IN_MY_EDITOR = "
85else
86	QUOTE = '
87	FIXUP_SYNTAX_HIGHLIGHTING_IN_MY_EDITOR = '
88endif
89
90#----------------------------------------------------------------------
91# If TRIPLE is not defined try to set the ARCH, CC, CFLAGS, and more
92# from the triple alone
93#----------------------------------------------------------------------
94ARCH_CFLAGS :=
95ifeq "$(OS)" "Android"
96	include $(THIS_FILE_DIR)/Android.rules
97endif
98
99#----------------------------------------------------------------------
100# If ARCH is not defined, default to x86_64.
101#----------------------------------------------------------------------
102ifeq "$(ARCH)" ""
103ifeq "$(OS)" "Windows_NT"
104	ARCH = x86
105else
106	ARCH = x86_64
107endif
108endif
109
110#----------------------------------------------------------------------
111# CC defaults to clang.
112#
113# If you change the defaults of CC, be sure to also change it in the file
114# test/builders/builder_base.py, which provides a Python way to return the
115# value of the make variable CC -- getCompiler().
116#
117# See also these functions:
118#   o cxx_compiler
119#   o cxx_linker
120#----------------------------------------------------------------------
121ifeq "$(CC)" ""
122$(error "C compiler is not specified. Please run tests through lldb-dotest or lit")
123endif
124
125#----------------------------------------------------------------------
126# Handle SDKROOT on Darwin
127#----------------------------------------------------------------------
128
129ifeq "$(OS)" "Darwin"
130    ifeq "$(SDKROOT)" ""
131	# We haven't otherwise set the SDKROOT, so set it now to macosx
132	SDKROOT := $(shell xcrun --sdk macosx --show-sdk-path)
133    endif
134endif
135
136#----------------------------------------------------------------------
137# ARCHFLAG is the flag used to tell the compiler which architecture
138# to compile for. The default is the flag that clang accepts.
139#----------------------------------------------------------------------
140ARCHFLAG ?= -arch
141
142#----------------------------------------------------------------------
143# Change any build/tool options needed
144#----------------------------------------------------------------------
145ifeq "$(OS)" "Darwin"
146	DS := $(DSYMUTIL)
147	DSFLAGS =
148	DSYM = $(EXE).dSYM
149	AR := $(CROSS_COMPILE)libtool
150	ARFLAGS := -static -o
151else
152	AR := $(CROSS_COMPILE)ar
153	# On non-Apple platforms, -arch becomes -m
154	ARCHFLAG := -m
155
156	# i386, i686, x86 -> 32
157	# amd64, x86_64, x64 -> 64
158	ifeq "$(ARCH)" "amd64"
159		override ARCH := $(subst amd64,64,$(ARCH))
160	endif
161	ifeq "$(ARCH)" "x86_64"
162		override ARCH := $(subst x86_64,64,$(ARCH))
163	endif
164	ifeq "$(ARCH)" "x64"
165		override ARCH := $(subst x64,64,$(ARCH))
166	endif
167	ifeq "$(ARCH)" "x86"
168		override ARCH := $(subst x86,32,$(ARCH))
169	endif
170	ifeq "$(ARCH)" "i386"
171		override ARCH := $(subst i386,32,$(ARCH))
172	endif
173	ifeq "$(ARCH)" "i686"
174		override ARCH := $(subst i686,32,$(ARCH))
175	endif
176	ifeq "$(ARCH)" "powerpc"
177		override ARCH := $(subst powerpc,32,$(ARCH))
178	endif
179	ifeq "$(ARCH)" "powerpc64"
180		override ARCH := $(subst powerpc64,64,$(ARCH))
181	endif
182	ifeq "$(ARCH)" "powerpc64le"
183		override ARCH := $(subst powerpc64le,64,$(ARCH))
184	endif
185	ifeq "$(ARCH)" "aarch64"
186		override ARCH :=
187		override ARCHFLAG :=
188	endif
189	ifeq "$(findstring arm,$(ARCH))" "arm"
190		override ARCH :=
191		override ARCHFLAG :=
192	endif
193	ifeq "$(ARCH)" "s390x"
194		override ARCH :=
195		override ARCHFLAG :=
196	endif
197	ifeq "$(findstring mips,$(ARCH))" "mips"
198		override ARCHFLAG := -
199	endif
200
201	ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
202		DSYM = $(EXE).debug
203	endif
204endif
205
206LIMIT_DEBUG_INFO_FLAGS =
207NO_LIMIT_DEBUG_INFO_FLAGS =
208MODULE_DEBUG_INFO_FLAGS =
209ifneq (,$(findstring clang,$(CC)))
210   LIMIT_DEBUG_INFO_FLAGS += -flimit-debug-info
211   NO_LIMIT_DEBUG_INFO_FLAGS += -fno-limit-debug-info
212   MODULE_DEBUG_INFO_FLAGS += -gmodules
213endif
214
215# If the OS is Windows, we need to pass -gdwarf to clang, otherwise it will build
216# with codeview by default but all the tests rely on dwarf.
217ifeq "$(OS)" "Windows_NT"
218	DEBUG_INFO_FLAG ?= -gdwarf
219endif
220
221DEBUG_INFO_FLAG ?= -g
222
223CFLAGS ?= $(DEBUG_INFO_FLAG) -O0
224
225ifeq "$(OS)" "Darwin"
226	ifneq "$(SDKROOT)" ""
227		CFLAGS += -isysroot "$(SDKROOT)"
228	endif
229endif
230
231ifeq "$(OS)" "Darwin"
232	CFLAGS += $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) -I$(LLDB_BASE_DIR)include
233else
234	CFLAGS += $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) -I$(LLDB_BASE_DIR)include
235endif
236
237CFLAGS += -I$(SRCDIR) -I$(THIS_FILE_DIR)
238
239ifndef NO_TEST_COMMON_H
240  CFLAGS += -include $(THIS_FILE_DIR)/test_common.h
241endif
242
243CFLAGS += $(NO_LIMIT_DEBUG_INFO_FLAGS) $(ARCH_CFLAGS)
244
245# Use this one if you want to build one part of the result without debug information:
246ifeq "$(OS)" "Darwin"
247	CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) -isysroot "$(SDKROOT)"
248else
249	CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS)
250endif
251
252ifeq "$(MAKE_DWO)" "YES"
253	CFLAGS += -gsplit-dwarf
254endif
255
256ifeq "$(USE_PRIVATE_MODULE_CACHE)" "YES"
257THE_CLANG_MODULE_CACHE_DIR := $(BUILDDIR)/private-module-cache
258else
259THE_CLANG_MODULE_CACHE_DIR := $(CLANG_MODULE_CACHE_DIR)
260endif
261
262MODULE_BASE_FLAGS := -fmodules -gmodules -fmodules-cache-path=$(THE_CLANG_MODULE_CACHE_DIR)
263MANDATORY_MODULE_BUILD_CFLAGS := $(MODULE_BASE_FLAGS) -gmodules
264# Build flags for building with C++ modules.
265# -glldb is necessary for emitting information about what modules were imported.
266MANDATORY_CXXMODULE_BUILD_CFLAGS := $(MODULE_BASE_FLAGS) -fcxx-modules -glldb
267
268ifeq "$(OS)" "Darwin"
269	MANDATORY_MODULE_BUILD_CFLAGS += -fcxx-modules
270endif
271
272ifeq "$(MAKE_GMODULES)" "YES"
273	CFLAGS += $(MANDATORY_MODULE_BUILD_CFLAGS)
274	CXXFLAGS += $(MANDATORY_MODULE_BUILD_CFLAGS)
275endif
276
277CFLAGS += $(CFLAGS_EXTRAS)
278CXXFLAGS += -std=c++11 $(CFLAGS) $(ARCH_CXXFLAGS)
279LD = $(CC)
280LDFLAGS ?= $(CFLAGS)
281LDFLAGS += $(LD_EXTRAS) $(ARCH_LDFLAGS)
282ifeq (,$(filter $(OS), Windows_NT Android Darwin))
283	ifneq (,$(filter YES,$(ENABLE_THREADS)))
284		LDFLAGS += -pthread
285	endif
286endif
287OBJECTS =
288EXE ?= a.out
289
290ifneq "$(FRAMEWORK)" ""
291	DYLIB_NAME ?= $(FRAMEWORK).framework/Versions/A/$(FRAMEWORK)
292	DYLIB_FILENAME ?= $(FRAMEWORK).framework/Versions/A/$(FRAMEWORK)
293endif
294
295ifneq "$(DYLIB_NAME)" ""
296	ifeq "$(OS)" "Darwin"
297		ifneq "$(FRAMEWORK)" ""
298			DYLIB_INSTALL_NAME ?= @executable_path/$(FRAMEWORK).framework/Versions/A/$(FRAMEWORK)
299		else
300			DYLIB_FILENAME = lib$(DYLIB_NAME).dylib
301			DYLIB_INSTALL_NAME ?= @executable_path/$(DYLIB_FILENAME)
302		endif
303	else ifeq "$(OS)" "Windows_NT"
304		DYLIB_FILENAME = $(DYLIB_NAME).dll
305	else
306		DYLIB_FILENAME = lib$(DYLIB_NAME).so
307	endif
308endif
309
310# Function that returns the counterpart C++ compiler, given $(CC) as arg.
311cxx_compiler_notdir = $(if $(findstring icc,$(1)), \
312			$(subst icc,icpc,$(1)), \
313			$(if $(findstring llvm-gcc,$(1)), \
314				$(subst llvm-gcc,llvm-g++,$(1)), \
315				$(if $(findstring gcc,$(1)), \
316					$(subst gcc,g++,$(1)), \
317					$(subst cc,c++,$(1)))))
318cxx_compiler = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call cxx_compiler_notdir,$(notdir $(1)))),$(call cxx_compiler_notdir,$(1)))
319
320# Function that returns the C++ linker, given $(CC) as arg.
321cxx_linker_notdir = $(if $(findstring icc,$(1)), \
322			$(subst icc,icpc,$(1)), \
323			$(if $(findstring llvm-gcc,$(1)), \
324				$(subst llvm-gcc,llvm-g++,$(1)), \
325				$(if $(findstring gcc,$(1)), \
326					$(subst gcc,g++,$(1)), \
327					$(subst cc,c++,$(1)))))
328cxx_linker = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call cxx_linker_notdir,$(notdir $(1)))),$(call cxx_linker_notdir,$(1)))
329
330ifneq "$(OS)" "Darwin"
331	CLANG_OR_GCC := $(strip $(if $(findstring clang,$(CC)), \
332				$(findstring clang,$(CC)), \
333				$(if $(findstring gcc,$(CC)), \
334					$(findstring gcc,$(CC)), \
335					cc)))
336
337	CC_LASTWORD := $(strip $(lastword $(subst -, ,$(CC))))
338
339	replace_with = $(strip $(if $(findstring $(3),$(CC_LASTWORD)), \
340			$(subst $(3),$(1),$(2)), \
341			$(subst $(3),$(1),$(subst -$(CC_LASTWORD),,$(2)))))
342
343	ifeq "$(notdir $(CC))" "$(CC)"
344		replace_cc_with = $(call replace_with,$(1),$(CC),$(CLANG_OR_GCC))
345	else
346		replace_cc_with = $(join $(dir $(CC)),$(call replace_with,$(1),$(notdir $(CC)),$(CLANG_OR_GCC)))
347	endif
348
349	OBJCOPY ?= $(call replace_cc_with,objcopy)
350	ARCHIVER ?= $(call replace_cc_with,ar)
351	override AR = $(ARCHIVER)
352endif
353
354ifdef PIE
355	LDFLAGS += -pie
356endif
357
358#----------------------------------------------------------------------
359# Windows specific options
360#----------------------------------------------------------------------
361ifeq "$(OS)" "Windows_NT"
362	ifneq (,$(findstring clang,$(CC)))
363		# Clang for Windows doesn't support C++ Exceptions
364		CXXFLAGS += -fno-exceptions
365		CXXFLAGS += -D_HAS_EXCEPTIONS=0
366
367		# MSVC 2015 or higher is required, which depends on c++14, so
368		# append these values unconditionally.
369		CXXFLAGS += -fms-compatibility-version=19.0
370		CXXFLAGS += -std=c++14
371
372		# The MSVC linker doesn't understand long section names
373		# generated by the clang compiler.
374		LDFLAGS += -fuse-ld=lld
375	endif
376endif
377
378#----------------------------------------------------------------------
379# C++ standard library options
380#----------------------------------------------------------------------
381ifeq (1,$(USE_LIBSTDCPP))
382	# Clang requires an extra flag: -stdlib=libstdc++
383	ifneq (,$(findstring clang,$(CC)))
384		CXXFLAGS += -stdlib=libstdc++ -DLLDB_USING_LIBSTDCPP
385		LDFLAGS += -stdlib=libstdc++
386	endif
387endif
388
389ifeq (1,$(USE_LIBCPP))
390	# TODO: Teach LLDB to handle ABI tags in libc++ namespaces.
391	CXXFLAGS += -DLLDB_USING_LIBCPP -D_LIBCPP_NO_ABI_TAG
392	ifeq "$(OS)" "Android"
393		# Nothing to do, this is already handled in
394		# Android.rules.
395	else
396		CXXFLAGS += -stdlib=libc++
397		LDFLAGS += -stdlib=libc++
398	endif
399	ifneq (,$(filter $(OS), FreeBSD Linux NetBSD))
400		ifneq (,$(LLVM_LIBS_DIR))
401			LDFLAGS += -Wl,-rpath,$(LLVM_LIBS_DIR)
402		endif
403	endif
404endif
405
406#----------------------------------------------------------------------
407# Additional system libraries
408#----------------------------------------------------------------------
409ifeq (1,$(USE_LIBDL))
410	ifeq (,$(filter $(OS), NetBSD Windows_NT))
411		LDFLAGS += -ldl
412	endif
413endif
414
415CXXFLAGS += $(CXXFLAGS_EXTRAS)
416
417#----------------------------------------------------------------------
418# dylib settings
419#----------------------------------------------------------------------
420
421DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
422DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o))
423ifneq "$(strip $(DYLIB_CXX_SOURCES))" ""
424	DYLIB_OBJECTS +=$(strip $(patsubst %.mm, %.o, $(DYLIB_CXX_SOURCES:.cpp=.o)))
425	CXX = $(call cxx_compiler,$(CC))
426	LD = $(call cxx_linker,$(CC))
427endif
428
429#----------------------------------------------------------------------
430# Check if we have a precompiled header
431#----------------------------------------------------------------------
432ifneq "$(strip $(PCH_CXX_SOURCE))" ""
433	PCH_OUTPUT = $(PCH_CXX_SOURCE:.h=.h.pch)
434	PCHFLAGS = -include $(PCH_CXX_SOURCE)
435endif
436
437#----------------------------------------------------------------------
438# Check if we have any C source files
439#----------------------------------------------------------------------
440ifneq "$(strip $(C_SOURCES))" ""
441	OBJECTS +=$(strip $(C_SOURCES:.c=.o))
442endif
443
444#----------------------------------------------------------------------
445# Check if we have any C++ source files
446#----------------------------------------------------------------------
447ifneq "$(strip $(CXX_SOURCES))" ""
448	OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
449	CXX = $(call cxx_compiler,$(CC))
450	LD = $(call cxx_linker,$(CC))
451endif
452
453#----------------------------------------------------------------------
454# Check if we have any ObjC source files
455#----------------------------------------------------------------------
456ifneq "$(strip $(OBJC_SOURCES))" ""
457	OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o))
458	LDFLAGS +=-lobjc
459endif
460
461#----------------------------------------------------------------------
462# Check if we have any ObjC++ source files
463#----------------------------------------------------------------------
464ifneq "$(strip $(OBJCXX_SOURCES))" ""
465	OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
466	CXX = $(call cxx_compiler,$(CC))
467	LD = $(call cxx_linker,$(CC))
468	ifeq "$(findstring lobjc,$(LDFLAGS))" ""
469		LDFLAGS +=-lobjc
470	endif
471endif
472
473ifeq ($(findstring clang, $(CXX)), clang)
474	CXXFLAGS += --driver-mode=g++
475endif
476
477ifneq "$(CXX)" ""
478	ifeq ($(findstring clang, $(LD)), clang)
479		LDFLAGS += --driver-mode=g++
480	endif
481endif
482
483#----------------------------------------------------------------------
484# DYLIB_ONLY variable can be used to skip the building of a.out.
485# See the sections below regarding dSYM file as well as the building of
486# EXE from all the objects.
487#----------------------------------------------------------------------
488
489#----------------------------------------------------------------------
490# Compile the executable from all the objects.
491#----------------------------------------------------------------------
492ifneq "$(DYLIB_NAME)" ""
493ifeq "$(DYLIB_ONLY)" ""
494$(EXE) : $(OBJECTS) $(DYLIB_FILENAME)
495	$(LD) $(OBJECTS) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)"
496ifneq "$(CODESIGN)" ""
497	$(CODESIGN) -s - "$(EXE)"
498endif
499else
500EXE = $(DYLIB_FILENAME)
501endif
502else
503$(EXE) : $(OBJECTS)
504	$(LD) $(OBJECTS) $(LDFLAGS) -o "$(EXE)"
505ifneq "$(CODESIGN)" ""
506	$(CODESIGN) -s - "$(EXE)"
507endif
508endif
509
510#----------------------------------------------------------------------
511# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO"
512#----------------------------------------------------------------------
513$(DSYM) : $(EXE)
514ifeq "$(OS)" "Darwin"
515ifneq "$(MAKE_DSYM)" "NO"
516	"$(DS)" $(DSFLAGS) -o "$(DSYM)" "$(EXE)"
517else
518endif
519else
520ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
521	$(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
522	$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
523endif
524endif
525
526#----------------------------------------------------------------------
527# Make the dylib
528#----------------------------------------------------------------------
529$(DYLIB_OBJECTS) : CFLAGS += -DCOMPILING_LLDB_TEST_DLL
530
531ifneq "$(OS)" "Windows_NT"
532$(DYLIB_OBJECTS) : CFLAGS += -fPIC
533$(DYLIB_OBJECTS) : CXXFLAGS += -fPIC
534endif
535
536$(DYLIB_FILENAME) : $(DYLIB_OBJECTS)
537ifeq "$(OS)" "Darwin"
538ifneq "$(FRAMEWORK)" ""
539	mkdir -p $(FRAMEWORK).framework/Versions/A/Headers
540	mkdir -p $(FRAMEWORK).framework/Versions/A/Modules
541	mkdir -p $(FRAMEWORK).framework/Versions/A/Resources
542ifneq "$(FRAMEWORK_MODULES)" ""
543	cp -r $(FRAMEWORK_MODULES) $(FRAMEWORK).framework/Versions/A/Modules
544endif
545ifneq "$(FRAMEWORK_HEADERS)" ""
546	cp -r $(FRAMEWORK_HEADERS) $(FRAMEWORK).framework/Versions/A/Headers
547endif
548	(cd $(FRAMEWORK).framework/Versions; ln -sf A Current)
549	(cd $(FRAMEWORK).framework/; ln -sf Versions/A/Headers Headers)
550	(cd $(FRAMEWORK).framework/; ln -sf Versions/A/Modules Modules)
551	(cd $(FRAMEWORK).framework/; ln -sf Versions/A/Resources Resources)
552	(cd $(FRAMEWORK).framework/; ln -sf Versions/A/$(FRAMEWORK) $(FRAMEWORK))
553endif
554	$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -install_name "$(DYLIB_INSTALL_NAME)" -dynamiclib -o "$(DYLIB_FILENAME)"
555ifneq "$(CODESIGN)" ""
556	$(CODESIGN) -s - "$(DYLIB_FILENAME)"
557endif
558ifneq "$(MAKE_DSYM)" "NO"
559ifneq "$(DS)" ""
560	"$(DS)" $(DSFLAGS) "$(DYLIB_FILENAME)"
561endif
562endif
563else
564	$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
565ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
566	$(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
567	$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
568endif
569endif
570
571#----------------------------------------------------------------------
572# Make the precompiled header and compile C++ sources against it
573#----------------------------------------------------------------------
574
575ifneq "$(PCH_OUTPUT)" ""
576$(PCH_OUTPUT) : $(PCH_CXX_SOURCE)
577	$(CXX) $(CXXFLAGS) -x c++-header -o $@ $<
578endif
579
580%.o: %.c %.d
581	$(CC) $(CFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
582
583%.o: %.cpp %.d $(PCH_OUTPUT)
584	$(CXX) $(PCHFLAGS) $(CXXFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
585
586%.o: %.m %.d
587	$(CC) $(CFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
588
589%.o: %.mm %.d
590	$(CXX) $(CXXFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
591
592#----------------------------------------------------------------------
593# Automatic variables based on items already entered. Below we create
594# an object's lists from the list of sources by replacing all entries
595# that end with .c with .o, and we also create a list of prerequisite
596# files by replacing all .c files with .d.
597#----------------------------------------------------------------------
598PREREQS := $(OBJECTS:.o=.d)
599DWOS := $(OBJECTS:.o=.dwo)
600ifneq "$(DYLIB_NAME)" ""
601	DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d)
602	DYLIB_DWOS := $(DYLIB_OBJECTS:.o=.dwo)
603endif
604
605# Don't error if a .d file is deleted.
606$(PREREQS) $(DYLIB_PREREQS): ;
607
608#----------------------------------------------------------------------
609# Include all of the makefiles for each source file so we don't have
610# to manually track all of the prerequisites for each source file.
611#----------------------------------------------------------------------
612include $(wildcard $(PREREQS) $(DYLIB_PREREQS))
613
614.PHONY: clean
615dsym:	$(DSYM)
616all:	$(EXE) $(DSYM)
617clean::
618ifeq "$(findstring lldb-test-build.noindex, $(BUILDDIR))" ""
619	$(error Trying to invoke the clean rule, but not using the default build tree layout)
620else
621	$(RM) -r $(wildcard $(BUILDDIR)/*)
622endif
623
624#----------------------------------------------------------------------
625# From http://blog.melski.net/tag/debugging-makefiles/
626#
627# Usage: make print-CC print-CXX print-LD
628#----------------------------------------------------------------------
629print-%:
630	@echo '$*=$($*)'
631	@echo '  origin = $(origin $*)'
632	@echo '  flavor = $(flavor $*)'
633	@echo '   value = $(value  $*)'
634
635### Local Variables: ###
636### mode:makefile ###
637### End: ###
638