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
215DEBUG_INFO_FLAG ?= -g
216
217CFLAGS ?= $(DEBUG_INFO_FLAG) -O0
218
219ifeq "$(OS)" "Darwin"
220	ifneq "$(SDKROOT)" ""
221		CFLAGS += -isysroot "$(SDKROOT)"
222	endif
223endif
224
225ifeq "$(OS)" "Darwin"
226	CFLAGS += $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) -I$(LLDB_BASE_DIR)include
227else
228	CFLAGS += $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) -I$(LLDB_BASE_DIR)include
229endif
230
231CFLAGS += -I$(SRCDIR) -I$(THIS_FILE_DIR)
232
233ifndef NO_TEST_COMMON_H
234  CFLAGS += -include $(THIS_FILE_DIR)/test_common.h
235endif
236
237CFLAGS += $(NO_LIMIT_DEBUG_INFO_FLAGS) $(ARCH_CFLAGS)
238
239# If the OS is Windows, we need to pass -gdwarf to clang, otherwise it will build
240# with codeview by default but all the tests rely on dwarf.
241ifeq "$(OS)" "Windows_NT"
242	CFLAGS += -gdwarf
243endif
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	CXXFLAGS += -DLLDB_USING_LIBCPP
391	ifeq "$(OS)" "Android"
392		# Nothing to do, this is already handled in
393		# Android.rules.
394	else
395		CXXFLAGS += -stdlib=libc++
396		LDFLAGS += -stdlib=libc++
397	endif
398	ifneq (,$(filter $(OS), FreeBSD Linux NetBSD))
399		ifneq (,$(LLVM_LIBS_DIR))
400			LDFLAGS += -Wl,-rpath,$(LLVM_LIBS_DIR)
401		endif
402	endif
403endif
404
405#----------------------------------------------------------------------
406# Additional system libraries
407#----------------------------------------------------------------------
408ifeq (1,$(USE_LIBDL))
409	ifeq (,$(filter $(OS), NetBSD Windows_NT))
410		LDFLAGS += -ldl
411	endif
412endif
413
414CXXFLAGS += $(CXXFLAGS_EXTRAS)
415
416#----------------------------------------------------------------------
417# dylib settings
418#----------------------------------------------------------------------
419
420DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
421DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o))
422ifneq "$(strip $(DYLIB_CXX_SOURCES))" ""
423	DYLIB_OBJECTS +=$(strip $(patsubst %.mm, %.o, $(DYLIB_CXX_SOURCES:.cpp=.o)))
424	CXX = $(call cxx_compiler,$(CC))
425	LD = $(call cxx_linker,$(CC))
426endif
427
428#----------------------------------------------------------------------
429# Check if we have a precompiled header
430#----------------------------------------------------------------------
431ifneq "$(strip $(PCH_CXX_SOURCE))" ""
432	PCH_OUTPUT = $(PCH_CXX_SOURCE:.h=.h.pch)
433	PCHFLAGS = -include $(PCH_CXX_SOURCE)
434endif
435
436#----------------------------------------------------------------------
437# Check if we have any C source files
438#----------------------------------------------------------------------
439ifneq "$(strip $(C_SOURCES))" ""
440	OBJECTS +=$(strip $(C_SOURCES:.c=.o))
441endif
442
443#----------------------------------------------------------------------
444# Check if we have any C++ source files
445#----------------------------------------------------------------------
446ifneq "$(strip $(CXX_SOURCES))" ""
447	OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
448	CXX = $(call cxx_compiler,$(CC))
449	LD = $(call cxx_linker,$(CC))
450endif
451
452#----------------------------------------------------------------------
453# Check if we have any ObjC source files
454#----------------------------------------------------------------------
455ifneq "$(strip $(OBJC_SOURCES))" ""
456	OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o))
457	LDFLAGS +=-lobjc
458endif
459
460#----------------------------------------------------------------------
461# Check if we have any ObjC++ source files
462#----------------------------------------------------------------------
463ifneq "$(strip $(OBJCXX_SOURCES))" ""
464	OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
465	CXX = $(call cxx_compiler,$(CC))
466	LD = $(call cxx_linker,$(CC))
467	ifeq "$(findstring lobjc,$(LDFLAGS))" ""
468		LDFLAGS +=-lobjc
469	endif
470endif
471
472ifeq ($(findstring clang, $(CXX)), clang)
473	CXXFLAGS += --driver-mode=g++
474endif
475
476ifneq "$(CXX)" ""
477	ifeq ($(findstring clang, $(LD)), clang)
478		LDFLAGS += --driver-mode=g++
479	endif
480endif
481
482#----------------------------------------------------------------------
483# DYLIB_ONLY variable can be used to skip the building of a.out.
484# See the sections below regarding dSYM file as well as the building of
485# EXE from all the objects.
486#----------------------------------------------------------------------
487
488#----------------------------------------------------------------------
489# Compile the executable from all the objects.
490#----------------------------------------------------------------------
491ifneq "$(DYLIB_NAME)" ""
492ifeq "$(DYLIB_ONLY)" ""
493$(EXE) : $(OBJECTS) $(DYLIB_FILENAME)
494	$(LD) $(OBJECTS) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)"
495ifneq "$(CODESIGN)" ""
496	$(CODESIGN) -s - "$(EXE)"
497endif
498else
499EXE = $(DYLIB_FILENAME)
500endif
501else
502$(EXE) : $(OBJECTS)
503	$(LD) $(OBJECTS) $(LDFLAGS) -o "$(EXE)"
504ifneq "$(CODESIGN)" ""
505	$(CODESIGN) -s - "$(EXE)"
506endif
507endif
508
509#----------------------------------------------------------------------
510# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO"
511#----------------------------------------------------------------------
512$(DSYM) : $(EXE)
513ifeq "$(OS)" "Darwin"
514ifneq "$(MAKE_DSYM)" "NO"
515	"$(DS)" $(DSFLAGS) -o "$(DSYM)" "$(EXE)"
516else
517endif
518else
519ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
520	$(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
521	$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
522endif
523endif
524
525#----------------------------------------------------------------------
526# Make the dylib
527#----------------------------------------------------------------------
528$(DYLIB_OBJECTS) : CFLAGS += -DCOMPILING_LLDB_TEST_DLL
529
530ifneq "$(OS)" "Windows_NT"
531$(DYLIB_OBJECTS) : CFLAGS += -fPIC
532$(DYLIB_OBJECTS) : CXXFLAGS += -fPIC
533endif
534
535$(DYLIB_FILENAME) : $(DYLIB_OBJECTS)
536ifeq "$(OS)" "Darwin"
537ifneq "$(FRAMEWORK)" ""
538	mkdir -p $(FRAMEWORK).framework/Versions/A/Headers
539	mkdir -p $(FRAMEWORK).framework/Versions/A/Modules
540	mkdir -p $(FRAMEWORK).framework/Versions/A/Resources
541ifneq "$(FRAMEWORK_MODULES)" ""
542	cp -r $(FRAMEWORK_MODULES) $(FRAMEWORK).framework/Versions/A/Modules
543endif
544ifneq "$(FRAMEWORK_HEADERS)" ""
545	cp -r $(FRAMEWORK_HEADERS) $(FRAMEWORK).framework/Versions/A/Headers
546endif
547	(cd $(FRAMEWORK).framework/Versions; ln -sf A Current)
548	(cd $(FRAMEWORK).framework/; ln -sf Versions/A/Headers Headers)
549	(cd $(FRAMEWORK).framework/; ln -sf Versions/A/Modules Modules)
550	(cd $(FRAMEWORK).framework/; ln -sf Versions/A/Resources Resources)
551	(cd $(FRAMEWORK).framework/; ln -sf Versions/A/$(FRAMEWORK) $(FRAMEWORK))
552endif
553	$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -install_name "$(DYLIB_INSTALL_NAME)" -dynamiclib -o "$(DYLIB_FILENAME)"
554ifneq "$(CODESIGN)" ""
555	$(CODESIGN) -s - "$(DYLIB_FILENAME)"
556endif
557ifneq "$(MAKE_DSYM)" "NO"
558ifneq "$(DS)" ""
559	"$(DS)" $(DSFLAGS) "$(DYLIB_FILENAME)"
560endif
561endif
562else
563	$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
564ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
565	$(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
566	$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
567endif
568endif
569
570#----------------------------------------------------------------------
571# Make the precompiled header and compile C++ sources against it
572#----------------------------------------------------------------------
573
574ifneq "$(PCH_OUTPUT)" ""
575$(PCH_OUTPUT) : $(PCH_CXX_SOURCE)
576	$(CXX) $(CXXFLAGS) -x c++-header -o $@ $<
577endif
578
579%.o: %.c %.d
580	$(CC) $(CFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
581
582%.o: %.cpp %.d $(PCH_OUTPUT)
583	$(CXX) $(PCHFLAGS) $(CXXFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
584
585%.o: %.m %.d
586	$(CC) $(CFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
587
588%.o: %.mm %.d
589	$(CXX) $(CXXFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
590
591#----------------------------------------------------------------------
592# Automatic variables based on items already entered. Below we create
593# an object's lists from the list of sources by replacing all entries
594# that end with .c with .o, and we also create a list of prerequisite
595# files by replacing all .c files with .d.
596#----------------------------------------------------------------------
597PREREQS := $(OBJECTS:.o=.d)
598DWOS := $(OBJECTS:.o=.dwo)
599ifneq "$(DYLIB_NAME)" ""
600	DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d)
601	DYLIB_DWOS := $(DYLIB_OBJECTS:.o=.dwo)
602endif
603
604# Don't error if a .d file is deleted.
605$(PREREQS) $(DYLIB_PREREQS): ;
606
607#----------------------------------------------------------------------
608# Include all of the makefiles for each source file so we don't have
609# to manually track all of the prerequisites for each source file.
610#----------------------------------------------------------------------
611include $(wildcard $(PREREQS) $(DYLIB_PREREQS))
612
613.PHONY: clean
614dsym:	$(DSYM)
615all:	$(EXE) $(DSYM)
616clean::
617ifeq "$(findstring lldb-test-build.noindex, $(BUILDDIR))" ""
618	$(error Trying to invoke the clean rule, but not using the default build tree layout)
619else
620	$(RM) -r $(wildcard $(BUILDDIR)/*)
621endif
622
623#----------------------------------------------------------------------
624# From http://blog.melski.net/tag/debugging-makefiles/
625#
626# Usage: make print-CC print-CXX print-LD
627#----------------------------------------------------------------------
628print-%:
629	@echo '$*=$($*)'
630	@echo '  origin = $(origin $*)'
631	@echo '  flavor = $(flavor $*)'
632	@echo '   value = $(value  $*)'
633
634### Local Variables: ###
635### mode:makefile ###
636### End: ###
637