From c8c5866a86c8d4a3e80d8708d14a06776fb683d1 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Wed, 30 Nov 2011 10:59:40 +0000 Subject: [PATCH] Makefile fixes for systems with $CXX other than g++. - Makefile: Use $(CXX) for compiling C++ files, don't override the environment's value of $CXX - build_detect_platform: use $CXX instead of g++. Based on bug report from Theo Schlossnagle: http://code.google.com/p/leveldb/issues/detail?id=46 (Sync with uptream at 25807040.) --- Makefile | 49 +++++++++++++++++++++++++------------------------ build_detect_platform | 10 +++++++--- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 8385d44..d337905 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. See the AUTHORS file for names of contributors. -CC = g++ +CXX ?= g++ +CC ?= gcc #----------------------------------------------- # Uncomment exactly one of the lines labelled (A), (B), and (C) below @@ -120,68 +121,68 @@ $(LIBRARY): $(LIBOBJECTS) $(AR) -rs $@ $(LIBOBJECTS) db_bench: db/db_bench.o $(LIBOBJECTS) $(TESTUTIL) - $(CC) $(LDFLAGS) db/db_bench.o $(LIBOBJECTS) $(TESTUTIL) -o $@ + $(CXX) $(LDFLAGS) db/db_bench.o $(LIBOBJECTS) $(TESTUTIL) -o $@ db_bench_sqlite3: doc/bench/db_bench_sqlite3.o $(LIBOBJECTS) $(TESTUTIL) - $(CC) $(LDFLAGS) -lsqlite3 doc/bench/db_bench_sqlite3.o $(LIBOBJECTS) $(TESTUTIL) -o $@ + $(CXX) $(LDFLAGS) -lsqlite3 doc/bench/db_bench_sqlite3.o $(LIBOBJECTS) $(TESTUTIL) -o $@ db_bench_tree_db: doc/bench/db_bench_tree_db.o $(LIBOBJECTS) $(TESTUTIL) - $(CC) $(LDFLAGS) -lkyotocabinet doc/bench/db_bench_tree_db.o $(LIBOBJECTS) $(TESTUTIL) -o $@ + $(CXX) $(LDFLAGS) -lkyotocabinet doc/bench/db_bench_tree_db.o $(LIBOBJECTS) $(TESTUTIL) -o $@ arena_test: util/arena_test.o $(LIBOBJECTS) $(TESTHARNESS) - $(CC) $(LDFLAGS) util/arena_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) util/arena_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ c_test: db/c_test.o $(LIBOBJECTS) $(TESTHARNESS) - $(CC) $(LDFLAGS) db/c_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) db/c_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ cache_test: util/cache_test.o $(LIBOBJECTS) $(TESTHARNESS) - $(CC) $(LDFLAGS) util/cache_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) util/cache_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ coding_test: util/coding_test.o $(LIBOBJECTS) $(TESTHARNESS) - $(CC) $(LDFLAGS) util/coding_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) util/coding_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ corruption_test: db/corruption_test.o $(LIBOBJECTS) $(TESTHARNESS) - $(CC) $(LDFLAGS) db/corruption_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) db/corruption_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ crc32c_test: util/crc32c_test.o $(LIBOBJECTS) $(TESTHARNESS) - $(CC) $(LDFLAGS) util/crc32c_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) util/crc32c_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ db_test: db/db_test.o $(LIBOBJECTS) $(TESTHARNESS) - $(CC) $(LDFLAGS) db/db_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) db/db_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ dbformat_test: db/dbformat_test.o $(LIBOBJECTS) $(TESTHARNESS) - $(CC) $(LDFLAGS) db/dbformat_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) db/dbformat_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ env_test: util/env_test.o $(LIBOBJECTS) $(TESTHARNESS) - $(CC) $(LDFLAGS) util/env_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) util/env_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ filename_test: db/filename_test.o $(LIBOBJECTS) $(TESTHARNESS) - $(CC) $(LDFLAGS) db/filename_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) db/filename_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ log_test: db/log_test.o $(LIBOBJECTS) $(TESTHARNESS) - $(CC) $(LDFLAGS) db/log_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) db/log_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ table_test: table/table_test.o $(LIBOBJECTS) $(TESTHARNESS) - $(CC) $(LDFLAGS) table/table_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) table/table_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ skiplist_test: db/skiplist_test.o $(LIBOBJECTS) $(TESTHARNESS) - $(CC) $(LDFLAGS) db/skiplist_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) db/skiplist_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ version_edit_test: db/version_edit_test.o $(LIBOBJECTS) $(TESTHARNESS) - $(CC) $(LDFLAGS) db/version_edit_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) db/version_edit_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ version_set_test: db/version_set_test.o $(LIBOBJECTS) $(TESTHARNESS) - $(CC) $(LDFLAGS) db/version_set_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) db/version_set_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ write_batch_test: db/write_batch_test.o $(LIBOBJECTS) $(TESTHARNESS) - $(CC) $(LDFLAGS) db/write_batch_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) db/write_batch_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(MEMENVLIBRARY) : helpers/memenv/memenv.o rm -f $@ $(AR) -rs $@ helpers/memenv/memenv.o memenv_test : helpers/memenv/memenv_test.o $(MEMENVLIBRARY) $(LIBRARY) $(TESTHARNESS) - $(CC) $(LDFLAGS) helpers/memenv/memenv_test.o $(MEMENVLIBRARY) $(LIBRARY) $(TESTHARNESS) -o $@ + $(CXX) $(LDFLAGS) helpers/memenv/memenv_test.o $(MEMENVLIBRARY) $(LIBRARY) $(TESTHARNESS) -o $@ ifeq ($(PLATFORM), IOS) # For iOS, create universal object files to be used on both the simulator and @@ -192,9 +193,9 @@ IOSVERSION=$(shell defaults read /Developer/Platforms/iPhoneOS.platform/version .cc.o: mkdir -p ios-x86/$(dir $@) - $(SIMULATORROOT)/usr/bin/$(CC) $(CFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 $< -o ios-x86/$@ + $(SIMULATORROOT)/usr/bin/$(CXX) $(CFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 $< -o ios-x86/$@ mkdir -p ios-arm/$(dir $@) - $(DEVICEROOT)/usr/bin/$(CC) $(CFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 $< -o ios-arm/$@ + $(DEVICEROOT)/usr/bin/$(CXX) $(CFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 $< -o ios-arm/$@ lipo ios-x86/$@ ios-arm/$@ -create -output $@ .c.o: @@ -206,7 +207,7 @@ IOSVERSION=$(shell defaults read /Developer/Platforms/iPhoneOS.platform/version else .cc.o: - $(CC) $(CFLAGS) $< -o $@ + $(CXX) $(CFLAGS) $< -o $@ .c.o: $(CC) $(CFLAGS) $< -o $@ diff --git a/build_detect_platform b/build_detect_platform index d1804e0..5ab15ef 100644 --- a/build_detect_platform +++ b/build_detect_platform @@ -13,6 +13,10 @@ # Delete existing build_config.mk rm -f build_config.mk +if test -z "$CXX"; then + CXX=g++ +fi + # Detect OS case `uname -s` in Darwin) @@ -48,8 +52,8 @@ PORT_CFLAGS="-fno-builtin-memcmp" # Detect C++0x -- this determines whether we'll use port_noatomic.h # or port_posix.h by: # 1. Rrying to compile with -std=c++0x and including . -# 2. If g++ returns error code, we know to use port_posix.h -g++ $CFLAGS -std=c++0x -x c++ - -o /dev/null 2>/dev/null </dev/null < int main() {} EOF @@ -61,7 +65,7 @@ fi # Test whether Snappy library is installed # http://code.google.com/p/snappy/ -g++ $CFLAGS -x c++ - -o /dev/null 2>/dev/null </dev/null < int main() {} EOF