summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2016-12-16 21:50:36 +0100
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2016-12-16 21:50:36 +0100
commit3ee79724f6fb033d50e26ef37b33d3f8cedf0c5b (patch)
tree2f43456d1697ec695015e926f05a2eedd9b4d9eb
parent78cb7f0cf037a06ed64de747cb30b4122a9c24e7 (diff)
downloadrockbox-3ee79724f6fb033d50e26ef37b33d3f8cedf0c5b.tar.gz
rockbox-3ee79724f6fb033d50e26ef37b33d3f8cedf0c5b.zip
Fix linking with C++ files.
When linking with C++ files the linker also needs to link against the C++ libraries. This is done automatically when invoking the compiler upon linking. Since we don't want C++ dependencies on C-only projects we check if we actually have C++ files and use either the C or C++ compiler. Rename CFLAGS since it's now used for both C and C++ compiler and add dedicated CFLAGS, CXXFLAGS and LDFLAGS variables. Change-Id: I9cc068a8038f21e8fd96b20173a8f790e6ab4b6e
-rw-r--r--rbutil/libtools.make26
1 files changed, 17 insertions, 9 deletions
diff --git a/rbutil/libtools.make b/rbutil/libtools.make
index ab936f81bc..5534d5b00c 100644
--- a/rbutil/libtools.make
+++ b/rbutil/libtools.make
@@ -31,25 +31,33 @@ endif
# overwrite for releases
APPVERSION ?= $(shell $(TOP)/../tools/version.sh $(TOP)/..)
-CFLAGS += -DVERSION=\"$(APPVERSION)\"
+GCCFLAGS += -DVERSION=\"$(APPVERSION)\"
TARGET_DIR ?= $(abspath .)/
CC := gcc
CXX := g++
+# use either CC or CXX to link: this makes sure the compiler knows about its
+# internal dependencies. Use CXX if we have at least one c++ file, since we
+# then need to link the c++ standard library (which CXX does for us).
+ifeq ($(strip $(filter %.cpp,$(SOURCES) $(LIBSOURCES))),)
+LD := $(CC)
+else
+LD := $(CXX)
+endif
CPPDEFINES := $(shell echo foo | $(CROSS)$(CC) -dM -E -)
BINARY = $(OUTPUT)
# when building a Windows binary add the correct file suffix
ifeq ($(findstring CYGWIN,$(CPPDEFINES)),CYGWIN)
BINARY = $(OUTPUT).exe
-CFLAGS+=-mno-cygwin
+GCCFLAGS += -mno-cygwin
COMPILETARGET = cygwin
else
ifeq ($(findstring MINGW,$(CPPDEFINES)),MINGW)
BINARY = $(OUTPUT).exe
COMPILETARGET = mingw
# use POSIX/C99 printf on windows
-CFLAGS += -D__USE_MINGW_ANSI_STDIO=1
+GCCFLAGS += -D__USE_MINGW_ANSI_STDIO=1
else
ifeq ($(findstring APPLE,$(CPPDEFINES)),APPLE)
COMPILETARGET = darwin
@@ -66,7 +74,7 @@ ifeq ($(findstring APPLE,$(CPPDEFINES)),APPLE)
# When building for 10.4+ we need to use gcc. Otherwise clang is used, so use
# that to determine if we need to set arch and isysroot.
ifeq ($(findstring __clang__,$(CPPDEFINES)),__clang__)
-CFLAGS += -mmacosx-version-min=10.5
+GCCFLAGS += -mmacosx-version-min=10.5
else
# when building libs for OS X 10.4+ build for both i386 and ppc at the same time.
# This creates fat objects, and ar can only create the archive but not operate
@@ -75,7 +83,7 @@ ARCHFLAGS += -arch ppc -arch i386
# building against SDK 10.4 is not compatible with gcc-4.2 (default on newer Xcode)
# might need adjustment for older Xcode.
CC = gcc-4.0
-CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
+GCCFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
endif
endif
@@ -106,7 +114,7 @@ $(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) $(TARGET_
$(info LD $@)
$(SILENT)$(call mkdir,$(dir $@))
# EXTRADEPS need to be built into OBJDIR.
- $(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) -o $(BINARY) \
+ $(SILENT)$(CROSS)$(LD) $(ARCHFLAGS) $(LDFLAGS) -o $(BINARY) \
$(OBJS) $(addprefix $(OBJDIR),$(EXTRADEPS)) \
$(addprefix $(OBJDIR),$(EXTRALIBOBJS)) lib$(OUTPUT).a $(addprefix $(OBJDIR),$(EXTRADEPS)) $(LDOPTS)
@@ -114,12 +122,12 @@ $(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) $(TARGET_
$(OBJDIR)%.c.o:
$(info CC $<)
$(SILENT)$(call mkdir,$(dir $@))
- $(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) -MMD -c -o $@ $<
+ $(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(GCCFLAGS) $(CFLAGS) -MMD -c -o $@ $<
$(OBJDIR)%.cpp.o:
$(info CXX $<)
$(SILENT)$(call mkdir,$(dir $@))
- $(SILENT)$(CROSS)$(CXX) $(ARCHFLAGS) $(CFLAGS) -MMD -c -o $@ $<
+ $(SILENT)$(CROSS)$(CXX) $(ARCHFLAGS) $(GCCFLAGS) $(CXXFLAGS) -MMD -c -o $@ $<
# lib rules
lib$(OUTPUT).a: $(TARGET_DIR)lib$(OUTPUT).a
@@ -133,7 +141,7 @@ $(OUTPUT).dll: $(TARGET_DIR)$(OUTPUT).dll
$(TARGET_DIR)$(OUTPUT).dll: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
$(info DLL $(notdir $@))
$(SILENT)$(call mkdir,$(dir $@))
- $(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) -shared -o $@ $^ \
+ $(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(GCCFLAGS) -shared -o $@ $^ \
-Wl,--output-def,$(TARGET_DIR)$(OUTPUT).def
# create lib file from objects