summaryrefslogtreecommitdiff
path: root/rbutil/libtools.make
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 /rbutil/libtools.make
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
Diffstat (limited to 'rbutil/libtools.make')
-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
31 31
32# overwrite for releases 32# overwrite for releases
33APPVERSION ?= $(shell $(TOP)/../tools/version.sh $(TOP)/..) 33APPVERSION ?= $(shell $(TOP)/../tools/version.sh $(TOP)/..)
34CFLAGS += -DVERSION=\"$(APPVERSION)\" 34GCCFLAGS += -DVERSION=\"$(APPVERSION)\"
35TARGET_DIR ?= $(abspath .)/ 35TARGET_DIR ?= $(abspath .)/
36 36
37CC := gcc 37CC := gcc
38CXX := g++ 38CXX := g++
39# use either CC or CXX to link: this makes sure the compiler knows about its
40# internal dependencies. Use CXX if we have at least one c++ file, since we
41# then need to link the c++ standard library (which CXX does for us).
42ifeq ($(strip $(filter %.cpp,$(SOURCES) $(LIBSOURCES))),)
43LD := $(CC)
44else
45LD := $(CXX)
46endif
39CPPDEFINES := $(shell echo foo | $(CROSS)$(CC) -dM -E -) 47CPPDEFINES := $(shell echo foo | $(CROSS)$(CC) -dM -E -)
40 48
41BINARY = $(OUTPUT) 49BINARY = $(OUTPUT)
42# when building a Windows binary add the correct file suffix 50# when building a Windows binary add the correct file suffix
43ifeq ($(findstring CYGWIN,$(CPPDEFINES)),CYGWIN) 51ifeq ($(findstring CYGWIN,$(CPPDEFINES)),CYGWIN)
44BINARY = $(OUTPUT).exe 52BINARY = $(OUTPUT).exe
45CFLAGS+=-mno-cygwin 53GCCFLAGS += -mno-cygwin
46COMPILETARGET = cygwin 54COMPILETARGET = cygwin
47else 55else
48ifeq ($(findstring MINGW,$(CPPDEFINES)),MINGW) 56ifeq ($(findstring MINGW,$(CPPDEFINES)),MINGW)
49BINARY = $(OUTPUT).exe 57BINARY = $(OUTPUT).exe
50COMPILETARGET = mingw 58COMPILETARGET = mingw
51# use POSIX/C99 printf on windows 59# use POSIX/C99 printf on windows
52CFLAGS += -D__USE_MINGW_ANSI_STDIO=1 60GCCFLAGS += -D__USE_MINGW_ANSI_STDIO=1
53else 61else
54ifeq ($(findstring APPLE,$(CPPDEFINES)),APPLE) 62ifeq ($(findstring APPLE,$(CPPDEFINES)),APPLE)
55COMPILETARGET = darwin 63COMPILETARGET = darwin
@@ -66,7 +74,7 @@ ifeq ($(findstring APPLE,$(CPPDEFINES)),APPLE)
66# When building for 10.4+ we need to use gcc. Otherwise clang is used, so use 74# When building for 10.4+ we need to use gcc. Otherwise clang is used, so use
67# that to determine if we need to set arch and isysroot. 75# that to determine if we need to set arch and isysroot.
68ifeq ($(findstring __clang__,$(CPPDEFINES)),__clang__) 76ifeq ($(findstring __clang__,$(CPPDEFINES)),__clang__)
69CFLAGS += -mmacosx-version-min=10.5 77GCCFLAGS += -mmacosx-version-min=10.5
70else 78else
71# when building libs for OS X 10.4+ build for both i386 and ppc at the same time. 79# when building libs for OS X 10.4+ build for both i386 and ppc at the same time.
72# This creates fat objects, and ar can only create the archive but not operate 80# This creates fat objects, and ar can only create the archive but not operate
@@ -75,7 +83,7 @@ ARCHFLAGS += -arch ppc -arch i386
75# building against SDK 10.4 is not compatible with gcc-4.2 (default on newer Xcode) 83# building against SDK 10.4 is not compatible with gcc-4.2 (default on newer Xcode)
76# might need adjustment for older Xcode. 84# might need adjustment for older Xcode.
77CC = gcc-4.0 85CC = gcc-4.0
78CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 86GCCFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
79endif 87endif
80endif 88endif
81 89
@@ -106,7 +114,7 @@ $(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) $(TARGET_
106 $(info LD $@) 114 $(info LD $@)
107 $(SILENT)$(call mkdir,$(dir $@)) 115 $(SILENT)$(call mkdir,$(dir $@))
108# EXTRADEPS need to be built into OBJDIR. 116# EXTRADEPS need to be built into OBJDIR.
109 $(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) -o $(BINARY) \ 117 $(SILENT)$(CROSS)$(LD) $(ARCHFLAGS) $(LDFLAGS) -o $(BINARY) \
110 $(OBJS) $(addprefix $(OBJDIR),$(EXTRADEPS)) \ 118 $(OBJS) $(addprefix $(OBJDIR),$(EXTRADEPS)) \
111 $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) lib$(OUTPUT).a $(addprefix $(OBJDIR),$(EXTRADEPS)) $(LDOPTS) 119 $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) lib$(OUTPUT).a $(addprefix $(OBJDIR),$(EXTRADEPS)) $(LDOPTS)
112 120
@@ -114,12 +122,12 @@ $(BINARY): $(OBJS) $(EXTRADEPS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) $(TARGET_
114$(OBJDIR)%.c.o: 122$(OBJDIR)%.c.o:
115 $(info CC $<) 123 $(info CC $<)
116 $(SILENT)$(call mkdir,$(dir $@)) 124 $(SILENT)$(call mkdir,$(dir $@))
117 $(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) -MMD -c -o $@ $< 125 $(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(GCCFLAGS) $(CFLAGS) -MMD -c -o $@ $<
118 126
119$(OBJDIR)%.cpp.o: 127$(OBJDIR)%.cpp.o:
120 $(info CXX $<) 128 $(info CXX $<)
121 $(SILENT)$(call mkdir,$(dir $@)) 129 $(SILENT)$(call mkdir,$(dir $@))
122 $(SILENT)$(CROSS)$(CXX) $(ARCHFLAGS) $(CFLAGS) -MMD -c -o $@ $< 130 $(SILENT)$(CROSS)$(CXX) $(ARCHFLAGS) $(GCCFLAGS) $(CXXFLAGS) -MMD -c -o $@ $<
123 131
124# lib rules 132# lib rules
125lib$(OUTPUT).a: $(TARGET_DIR)lib$(OUTPUT).a 133lib$(OUTPUT).a: $(TARGET_DIR)lib$(OUTPUT).a
@@ -133,7 +141,7 @@ $(OUTPUT).dll: $(TARGET_DIR)$(OUTPUT).dll
133$(TARGET_DIR)$(OUTPUT).dll: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS)) 141$(TARGET_DIR)$(OUTPUT).dll: $(LIBOBJS) $(addprefix $(OBJDIR),$(EXTRALIBOBJS))
134 $(info DLL $(notdir $@)) 142 $(info DLL $(notdir $@))
135 $(SILENT)$(call mkdir,$(dir $@)) 143 $(SILENT)$(call mkdir,$(dir $@))
136 $(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(CFLAGS) -shared -o $@ $^ \ 144 $(SILENT)$(CROSS)$(CC) $(ARCHFLAGS) $(GCCFLAGS) -shared -o $@ $^ \
137 -Wl,--output-def,$(TARGET_DIR)$(OUTPUT).def 145 -Wl,--output-def,$(TARGET_DIR)$(OUTPUT).def
138 146
139# create lib file from objects 147# create lib file from objects