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