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