# SPLIT_DEBUG_SYMBOLS := YES
# CROSS_COMPILE :=
# USE_PRIVATE_MODULE_CACHE := YES
- #
- # And test/functionalities/archives/Makefile:
- # MAKE_DSYM := NO
- # ARCHIVE_NAME := libfoo.a
- # ARCHIVE_C_SOURCES := a.c b.c
+# DWZ := YES
# Uncomment line below for debugging shell commands
# SHELL = /bin/sh -x
+ # Suppress built-in suffix rules. We explicitly define rules for %.o.
+ .SUFFIXES:
+
SRCDIR := $(shell dirname $(firstword $(MAKEFILE_LIST)))
BUILDDIR := $(shell pwd)
MAKEFILE_RULES := $(lastword $(MAKEFILE_LIST))
# When running tests from Visual Studio, the environment variable isn't
# inherited all the way down to the process spawned for make.
#----------------------------------------------------------------------
- HOST_OS = $(shell uname -s)
+ HOST_OS := $(shell uname -s)
ifneq (,$(findstring windows32,$(HOST_OS)))
- HOST_OS = Windows_NT
+ HOST_OS := Windows_NT
endif
ifeq "$(OS)" ""
- OS = $(HOST_OS)
+ OS := $(HOST_OS)
endif
#----------------------------------------------------------------------
override ARCHFLAG := -
endif
- ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
- DSYM = $(EXE).debug
+ ifeq "$(DWZ)" "YES"
+ # DWZ always does SPLIT_DEBUG_SYMBOLS (as otherwise the dwz command fails)
+ else
+ ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
+ DSYM = $(EXE).debug
+ endif
endif
endif
endif
#----------------------------------------------------------------------
+# Make the DWZ symbol file from the executable if $(DWZ) = "YES"
+# The dwz retry without -m is there because:
+# dwz -m still succeeds even for no debug info present (missing -g):
+# dwz: $(1).debug: .debug_info section not present
+# But dwz -m fails if there is some debug info but none if it is big enough
+# to be shared from the the common file $(1).debug.dwz:
+# dwz: $(1).debug.dwz: .debug_info section not present
+#----------------------------------------------------------------------
+ifeq "$(DWZ)" "YES"
+ dwz_strip = \
+ eu-strip --remove-comment -f "$(1).debug" "$(1)" \
+ && cp "$(1).debug" "$(1).debug.dup" \
+ && (dwz -m "$(1).debug.dwz" -M $$(basename "$(1).debug.dwz") "$(1).debug" "$(1).debug.dup" \
+ || dwz "$(1).debug") \
+ && /usr/lib/rpm/sepdebugcrcfix . "$$(realpath --relative-to=$$PWD "$(1)")"
+else
+ dwz_strip =
+endif
+
+#----------------------------------------------------------------------
# Windows specific options
#----------------------------------------------------------------------
ifeq "$(OS)" "Windows_NT"
endif
endif
- #----------------------------------------------------------------------
- # Check if we have any C source files for archive
- #----------------------------------------------------------------------
- ifneq "$(strip $(ARCHIVE_C_SOURCES))" ""
- ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_C_SOURCES:.c=.o))
- endif
-
- #----------------------------------------------------------------------
- # Check if we have any C++ source files for archive
- #----------------------------------------------------------------------
- ifneq "$(strip $(ARCHIVE_CXX_SOURCES))" ""
- ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_CXX_SOURCES:.cpp=.o))
- CXX = $(call cxx_compiler,$(CC))
- LD = $(call cxx_linker,$(CC))
- endif
-
- #----------------------------------------------------------------------
- # Check if we have any ObjC source files for archive
- #----------------------------------------------------------------------
- ifneq "$(strip $(ARCHIVE_OBJC_SOURCES))" ""
- ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJC_SOURCES:.m=.o))
- LDFLAGS +=-lobjc
- endif
-
- #----------------------------------------------------------------------
- # Check if we have any ObjC++ source files for archive
- #----------------------------------------------------------------------
- ifneq "$(strip $(ARCHIVE_OBJCXX_SOURCES))" ""
- ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJCXX_SOURCES:.mm=.o))
- CXX = $(call cxx_compiler,$(CC))
- LD = $(call cxx_linker,$(CC))
- ifeq "$(findstring lobjc,$(LDFLAGS))" ""
- LDFLAGS +=-lobjc
- endif
- endif
-
- #----------------------------------------------------------------------
- # Check if we are compiling with gcc 4.6
- #----------------------------------------------------------------------
- ifneq "$(strip $(CXX_SOURCES) $(OBJCXX_SOURCES))" ""
- ifneq "$(filter g++,$(CXX))" ""
- CXXVERSION = $(shell $(CXX) -dumpversion | cut -b 1-3)
- ifeq "$(CXXVERSION)" "4.6"
- # GCC 4.6 cannot handle -std=c++11, so replace it with -std=c++0x
- # instead. FIXME: remove once GCC version is upgraded.
- override CXXFLAGS := $(subst -std=c++11,-std=c++0x,$(CXXFLAGS))
- endif
- endif
- endif
-
ifeq ($(findstring clang, $(CXX)), clang)
CXXFLAGS += --driver-mode=g++
endif
#----------------------------------------------------------------------
ifneq "$(DYLIB_NAME)" ""
ifeq "$(DYLIB_ONLY)" ""
- $(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME)
- $(LD) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)"
+ $(EXE) : $(OBJECTS) $(DYLIB_FILENAME)
+ $(LD) $(OBJECTS) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)"
+ $(call dwz_strip,$(EXE))
ifneq "$(CODESIGN)" ""
$(CODESIGN) -s - "$(EXE)"
endif
EXE = $(DYLIB_FILENAME)
endif
else
- $(EXE) : $(OBJECTS) $(ARCHIVE_NAME)
- $(LD) $(OBJECTS) $(LDFLAGS) $(ARCHIVE_NAME) -o "$(EXE)"
+ $(EXE) : $(OBJECTS)
+ $(LD) $(OBJECTS) $(LDFLAGS) -o "$(EXE)"
+ $(call dwz_strip,$(EXE))
ifneq "$(CODESIGN)" ""
$(CODESIGN) -s - "$(EXE)"
endif
endif
#----------------------------------------------------------------------
- # Make the archive
- #----------------------------------------------------------------------
- ifneq "$(ARCHIVE_NAME)" ""
- ifeq "$(OS)" "Darwin"
- $(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS)
- $(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
- $(RM) $(ARCHIVE_OBJECTS)
- else
- $(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj)))
- endif
- endif
-
- #----------------------------------------------------------------------
# Make the dylib
#----------------------------------------------------------------------
$(DYLIB_OBJECTS) : CFLAGS += -DCOMPILING_LLDB_TEST_DLL
endif
else
$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
+ifeq "$(DWZ)" "YES"
+ # DWZ always does SPLIT_DEBUG_SYMBOLS (as otherwise the dwz command fails)
+ $(call dwz_strip,$(DYLIB_FILENAME))
+else
ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
$(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
endif
endif
+endif
#----------------------------------------------------------------------
# Make the precompiled header and compile C++ sources against it
#----------------------------------------------------------------------
- #ifneq "$(PCH_OUTPUT)" ""
+ ifneq "$(PCH_OUTPUT)" ""
$(PCH_OUTPUT) : $(PCH_CXX_SOURCE)
$(CXX) $(CXXFLAGS) -x c++-header -o $@ $<
- %.o : %.cpp $(PCH_OUTPUT)
- $(CXX) $(PCHFLAGS) $(CXXFLAGS) -c -o $@ $<
- #endif
+ endif
+
+ %.o: %.c %.d
+ $(CC) $(CFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
+
+ %.o: %.cpp %.d $(PCH_OUTPUT)
+ $(CXX) $(PCHFLAGS) $(CXXFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
+
+ %.o: %.m %.d
+ $(CC) $(CFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
+
+ %.o: %.mm %.d
+ $(CXX) $(CXXFLAGS) -MT $@ -MD -MP -MF $*.d -c -o $@ $<
#----------------------------------------------------------------------
# Automatic variables based on items already entered. Below we create
# files by replacing all .c files with .d.
#----------------------------------------------------------------------
PREREQS := $(OBJECTS:.o=.d)
- DWOS := $(OBJECTS:.o=.dwo) $(ARCHIVE_OBJECTS:.o=.dwo)
+ DWOS := $(OBJECTS:.o=.dwo)
ifneq "$(DYLIB_NAME)" ""
DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d)
DYLIB_DWOS := $(DYLIB_OBJECTS:.o=.dwo)
endif
- #----------------------------------------------------------------------
- # Rule for Generating Prerequisites Automatically using .d files and
- # the compiler -MM option. The -M option will list all system headers,
- # and the -MM option will list all non-system dependencies.
- #----------------------------------------------------------------------
- %.d: %.c
- $(CC) -M $(CFLAGS) $< -MF $@ -MT $@ -MT $*.o
-
- %.d: %.cpp
- @$(CXX) -M $(CXXFLAGS) $< -MF $@ -MT $@ -MT $*.o
-
- %.d: %.m
- @$(CC) -M $(CFLAGS) $< -MF $@ -MT $@ -MT $*.o
-
- %.d: %.mm
- @$(CXX) -M $(CXXFLAGS) $< -MF $@ -MT $@ -MT $*.o
+ # Don't error if a .d file is deleted.
+ $(PREREQS) $(DYLIB_PREREQS): ;
#----------------------------------------------------------------------
# Include all of the makefiles for each source file so we don't have
# to manually track all of the prerequisites for each source file.
#----------------------------------------------------------------------
- sinclude $(PREREQS)
- ifneq "$(DYLIB_NAME)" ""
- sinclude $(DYLIB_PREREQS)
- endif
-
- # Define a suffix rule for .mm -> .o
- .SUFFIXES: .mm .o
- .mm.o:
- $(CXX) $(CXXFLAGS) -c $<
+ include $(wildcard $(PREREQS) $(DYLIB_PREREQS))
.PHONY: clean
dsym: $(DSYM)