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