diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2016-12-16 21:50:36 +0100 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2016-12-16 21:50:36 +0100 |
commit | 3ee79724f6fb033d50e26ef37b33d3f8cedf0c5b (patch) | |
tree | 2f43456d1697ec695015e926f05a2eedd9b4d9eb | |
parent | 78cb7f0cf037a06ed64de747cb30b4122a9c24e7 (diff) | |
download | rockbox-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.make | 26 |
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 |
33 | APPVERSION ?= $(shell $(TOP)/../tools/version.sh $(TOP)/..) | 33 | APPVERSION ?= $(shell $(TOP)/../tools/version.sh $(TOP)/..) |
34 | CFLAGS += -DVERSION=\"$(APPVERSION)\" | 34 | GCCFLAGS += -DVERSION=\"$(APPVERSION)\" |
35 | TARGET_DIR ?= $(abspath .)/ | 35 | TARGET_DIR ?= $(abspath .)/ |
36 | 36 | ||
37 | CC := gcc | 37 | CC := gcc |
38 | CXX := g++ | 38 | CXX := 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). | ||
42 | ifeq ($(strip $(filter %.cpp,$(SOURCES) $(LIBSOURCES))),) | ||
43 | LD := $(CC) | ||
44 | else | ||
45 | LD := $(CXX) | ||
46 | endif | ||
39 | CPPDEFINES := $(shell echo foo | $(CROSS)$(CC) -dM -E -) | 47 | CPPDEFINES := $(shell echo foo | $(CROSS)$(CC) -dM -E -) |
40 | 48 | ||
41 | BINARY = $(OUTPUT) | 49 | BINARY = $(OUTPUT) |
42 | # when building a Windows binary add the correct file suffix | 50 | # when building a Windows binary add the correct file suffix |
43 | ifeq ($(findstring CYGWIN,$(CPPDEFINES)),CYGWIN) | 51 | ifeq ($(findstring CYGWIN,$(CPPDEFINES)),CYGWIN) |
44 | BINARY = $(OUTPUT).exe | 52 | BINARY = $(OUTPUT).exe |
45 | CFLAGS+=-mno-cygwin | 53 | GCCFLAGS += -mno-cygwin |
46 | COMPILETARGET = cygwin | 54 | COMPILETARGET = cygwin |
47 | else | 55 | else |
48 | ifeq ($(findstring MINGW,$(CPPDEFINES)),MINGW) | 56 | ifeq ($(findstring MINGW,$(CPPDEFINES)),MINGW) |
49 | BINARY = $(OUTPUT).exe | 57 | BINARY = $(OUTPUT).exe |
50 | COMPILETARGET = mingw | 58 | COMPILETARGET = mingw |
51 | # use POSIX/C99 printf on windows | 59 | # use POSIX/C99 printf on windows |
52 | CFLAGS += -D__USE_MINGW_ANSI_STDIO=1 | 60 | GCCFLAGS += -D__USE_MINGW_ANSI_STDIO=1 |
53 | else | 61 | else |
54 | ifeq ($(findstring APPLE,$(CPPDEFINES)),APPLE) | 62 | ifeq ($(findstring APPLE,$(CPPDEFINES)),APPLE) |
55 | COMPILETARGET = darwin | 63 | COMPILETARGET = 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. |
68 | ifeq ($(findstring __clang__,$(CPPDEFINES)),__clang__) | 76 | ifeq ($(findstring __clang__,$(CPPDEFINES)),__clang__) |
69 | CFLAGS += -mmacosx-version-min=10.5 | 77 | GCCFLAGS += -mmacosx-version-min=10.5 |
70 | else | 78 | else |
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. |
77 | CC = gcc-4.0 | 85 | CC = gcc-4.0 |
78 | CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 | 86 | GCCFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 |
79 | endif | 87 | endif |
80 | endif | 88 | endif |
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 |
125 | lib$(OUTPUT).a: $(TARGET_DIR)lib$(OUTPUT).a | 133 | lib$(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 |