Makefile: support Mingw + more cross-compilation
Tested on an Ubuntu 20.04 host, targeting: - Linux ARM64, using aarch64-linux-gnu-g++ - macOS AMD64 and ARM64, using https://github.com/tpoechtrager/osxcross - Windows AMD64, using Mingw-w64 from https://github.com/mxe/mxe "build_tools/build_detect_platform" and "Makefile" have been partially cleaned, in the process. There is more stuff left to clean there. The Makefile now passes more command line arguments to the detection script via environment variables.
This commit is contained in:
parent
d583d23d86
commit
d35dfeba58
@ -3,6 +3,10 @@
|
|||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
* Fixed a race condition when 2PC is disabled and WAL tracking in the MANIFEST is enabled. The race condition is between two background flush threads trying to install flush results, causing a WAL deletion not tracked in the MANIFEST. A future DB open may fail.
|
* Fixed a race condition when 2PC is disabled and WAL tracking in the MANIFEST is enabled. The race condition is between two background flush threads trying to install flush results, causing a WAL deletion not tracked in the MANIFEST. A future DB open may fail.
|
||||||
|
|
||||||
|
### New Features
|
||||||
|
* Support Mingw when using the Makefile.
|
||||||
|
* Support more cross-compilation scenarios when using the Makefile.
|
||||||
|
|
||||||
## 7.1.0 (03/23/2022)
|
## 7.1.0 (03/23/2022)
|
||||||
### New Features
|
### New Features
|
||||||
* Allow WriteBatchWithIndex to index a WriteBatch that includes keys with user-defined timestamps. The index itself does not have timestamp.
|
* Allow WriteBatchWithIndex to index a WriteBatch that includes keys with user-defined timestamps. The index itself does not have timestamp.
|
||||||
|
16
INSTALL.md
16
INSTALL.md
@ -27,6 +27,22 @@ CPU supports it. To print a warning if your CPU does not support SSE4.2, build w
|
|||||||
to build a portable binary, add `PORTABLE=1` before your make commands, like this:
|
to build a portable binary, add `PORTABLE=1` before your make commands, like this:
|
||||||
`PORTABLE=1 make static_lib`.
|
`PORTABLE=1 make static_lib`.
|
||||||
|
|
||||||
|
* When cross-compiling, you may want to disable dependency and CPU feature
|
||||||
|
autodetection. You do that by setting `CROSS_COMPILE=true`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Target macOS on Apple M1, from a Linux host, using https://github.com/tpoechtrager/osxcross
|
||||||
|
make -j $(nproc) \
|
||||||
|
CROSS_COMPILE=true \
|
||||||
|
PORTABLE=1 \
|
||||||
|
DISABLE_WARNING_AS_ERROR=1 \
|
||||||
|
TARGET_OS=Darwin \
|
||||||
|
TARGET_ARCHITECTURE=arm64 \
|
||||||
|
CXX=oa64-clang++ \
|
||||||
|
AR=arm64-apple-darwin20.4-ar \
|
||||||
|
static_lib
|
||||||
|
```
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
* You can link RocksDB with following compression libraries:
|
* You can link RocksDB with following compression libraries:
|
||||||
|
83
Makefile
83
Makefile
@ -118,16 +118,19 @@ OPT += -momit-leaf-frame-pointer
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq (,$(shell $(CXX) -fsyntax-only -maltivec -xc /dev/null 2>&1))
|
# A cross-compiler can support PPC, even though that's not our target.
|
||||||
CXXFLAGS += -DHAS_ALTIVEC
|
ifneq ($(CROSS_COMPILE), true)
|
||||||
CFLAGS += -DHAS_ALTIVEC
|
ifeq (,$(shell $(CXX) -fsyntax-only -maltivec -xc /dev/null 2>&1))
|
||||||
HAS_ALTIVEC=1
|
CXXFLAGS += -DHAS_ALTIVEC
|
||||||
endif
|
CFLAGS += -DHAS_ALTIVEC
|
||||||
|
HAS_ALTIVEC=1
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq (,$(shell $(CXX) -fsyntax-only -mcpu=power8 -xc /dev/null 2>&1))
|
ifeq (,$(shell $(CXX) -fsyntax-only -mcpu=power8 -xc /dev/null 2>&1))
|
||||||
CXXFLAGS += -DHAVE_POWER8
|
CXXFLAGS += -DHAVE_POWER8
|
||||||
CFLAGS += -DHAVE_POWER8
|
CFLAGS += -DHAVE_POWER8
|
||||||
HAVE_POWER8=1
|
HAVE_POWER8=1
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# if we're compiling for shared libraries, add the shared flags
|
# if we're compiling for shared libraries, add the shared flags
|
||||||
@ -136,34 +139,31 @@ CXXFLAGS += $(PLATFORM_SHARED_CFLAGS) -DROCKSDB_DLL
|
|||||||
CFLAGS += $(PLATFORM_SHARED_CFLAGS) -DROCKSDB_DLL
|
CFLAGS += $(PLATFORM_SHARED_CFLAGS) -DROCKSDB_DLL
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# if we're compiling for release, compile without debug code (-DNDEBUG)
|
ifeq ($(DEBUG_LEVEL),0) # release build
|
||||||
ifeq ($(DEBUG_LEVEL),0)
|
# if we're compiling for release, compile without debug code (-DNDEBUG)
|
||||||
OPT += -DNDEBUG
|
OPT += -DNDEBUG
|
||||||
|
USE_RTTI := 0
|
||||||
|
else # debug build
|
||||||
|
USE_RTTI := 1
|
||||||
|
|
||||||
ifneq ($(USE_RTTI), 1)
|
ifdef ASSERT_STATUS_CHECKED
|
||||||
CXXFLAGS += -fno-rtti
|
# For ASC, turn off constructor elision, preventing the case where a constructor returned
|
||||||
else
|
# by a method may pass the ASC check if the status is checked in the inner method. Forcing
|
||||||
CXXFLAGS += -DROCKSDB_USE_RTTI
|
# the copy constructor to be invoked disables the optimization and will cause the calling method
|
||||||
endif
|
# to check the status in order to prevent an error from being raised.
|
||||||
else
|
PLATFORM_CXXFLAGS += -fno-elide-constructors
|
||||||
ifneq ($(USE_RTTI), 0)
|
ifeq ($(filter -DROCKSDB_ASSERT_STATUS_CHECKED,$(OPT)),)
|
||||||
CXXFLAGS += -DROCKSDB_USE_RTTI
|
OPT += -DROCKSDB_ASSERT_STATUS_CHECKED
|
||||||
else
|
endif
|
||||||
CXXFLAGS += -fno-rtti
|
endif
|
||||||
endif
|
|
||||||
|
|
||||||
ifdef ASSERT_STATUS_CHECKED
|
$(warning Warning: Compiling in debug mode. Don't use the resulting binary in production)
|
||||||
# For ASC, turn off constructor elision, preventing the case where a constructor returned
|
endif # DEBUG_LEVEL
|
||||||
# by a method may pass the ASC check if the status is checked in the inner method. Forcing
|
|
||||||
# the copy constructor to be invoked disables the optimization and will cause the calling method
|
|
||||||
# to check the status in order to prevent an error from being raised.
|
|
||||||
PLATFORM_CXXFLAGS += -fno-elide-constructors
|
|
||||||
ifeq ($(filter -DROCKSDB_ASSERT_STATUS_CHECKED,$(OPT)),)
|
|
||||||
OPT += -DROCKSDB_ASSERT_STATUS_CHECKED
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
$(warning Warning: Compiling in debug mode. Don't use the resulting binary in production)
|
ifeq ($(USE_RTTI), 0)
|
||||||
|
CXXFLAGS += -fno-rtti
|
||||||
|
else
|
||||||
|
CXXFLAGS += -DROCKSDB_USE_RTTI
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# `USE_LTO=1` enables link-time optimizations. Among other things, this enables
|
# `USE_LTO=1` enables link-time optimizations. Among other things, this enables
|
||||||
@ -217,12 +217,18 @@ AM_SHARE = $(AM_V_CCLD) $(CXX) $(PLATFORM_SHARED_LDFLAGS)$@ -L. $(patsubst lib%.
|
|||||||
# Export some common variables that might have been passed as Make variables
|
# Export some common variables that might have been passed as Make variables
|
||||||
# instead of environment variables.
|
# instead of environment variables.
|
||||||
dummy := $(shell (export ROCKSDB_ROOT="$(CURDIR)"; \
|
dummy := $(shell (export ROCKSDB_ROOT="$(CURDIR)"; \
|
||||||
export CXXFLAGS="$(EXTRA_CXXFLAGS)"; \
|
export CC="$(CC)"; \
|
||||||
export LDFLAGS="$(EXTRA_LDFLAGS)"; \
|
export CXX="$(CXX)"; \
|
||||||
|
export AR="$(AR)"; \
|
||||||
|
export CFLAGS="$(CFLAGS)"; \
|
||||||
|
export CXXFLAGS="$(CXXFLAGS)"; \
|
||||||
export COMPILE_WITH_ASAN="$(COMPILE_WITH_ASAN)"; \
|
export COMPILE_WITH_ASAN="$(COMPILE_WITH_ASAN)"; \
|
||||||
export COMPILE_WITH_TSAN="$(COMPILE_WITH_TSAN)"; \
|
export COMPILE_WITH_TSAN="$(COMPILE_WITH_TSAN)"; \
|
||||||
export COMPILE_WITH_UBSAN="$(COMPILE_WITH_UBSAN)"; \
|
export COMPILE_WITH_UBSAN="$(COMPILE_WITH_UBSAN)"; \
|
||||||
export PORTABLE="$(PORTABLE)"; \
|
export PORTABLE="$(PORTABLE)"; \
|
||||||
|
export CROSS_COMPILE="$(CROSS_COMPILE)"; \
|
||||||
|
export TARGET_OS="$(TARGET_OS)"; \
|
||||||
|
export TARGET_ARCHITECTURE="$(TARGET_ARCHITECTURE)"; \
|
||||||
export ROCKSDB_NO_FBCODE="$(ROCKSDB_NO_FBCODE)"; \
|
export ROCKSDB_NO_FBCODE="$(ROCKSDB_NO_FBCODE)"; \
|
||||||
export USE_CLANG="$(USE_CLANG)"; \
|
export USE_CLANG="$(USE_CLANG)"; \
|
||||||
export LIB_MODE="$(LIB_MODE)"; \
|
export LIB_MODE="$(LIB_MODE)"; \
|
||||||
@ -504,6 +510,11 @@ ifeq ($(NO_THREEWAY_CRC32C), 1)
|
|||||||
CXXFLAGS += -DNO_THREEWAY_CRC32C
|
CXXFLAGS += -DNO_THREEWAY_CRC32C
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# The original CFLAGS and CXXFLAGS have already been included in
|
||||||
|
# PLATFORM_CCFLAGS and PLATFORM_CXXFLAGS, but we can't avoid the duplication
|
||||||
|
# here because more parameters have been appended in the mean time.
|
||||||
|
# TODO: move all the new flags to PLATFORM_* after "make_config.mk" is
|
||||||
|
# included, so we can := instead of += here.
|
||||||
CFLAGS += $(C_WARNING_FLAGS) $(WARNING_FLAGS) -I. -I./include $(PLATFORM_CCFLAGS) $(OPT)
|
CFLAGS += $(C_WARNING_FLAGS) $(WARNING_FLAGS) -I. -I./include $(PLATFORM_CCFLAGS) $(OPT)
|
||||||
CXXFLAGS += $(WARNING_FLAGS) -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT) -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers
|
CXXFLAGS += $(WARNING_FLAGS) -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT) -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers
|
||||||
|
|
||||||
|
@ -45,16 +45,15 @@ if test -z "$OUTPUT"; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS ${CXXFLAGS}"
|
||||||
|
|
||||||
# we depend on C++17, but should be compatible with newer standards
|
# we depend on C++17, but should be compatible with newer standards
|
||||||
if [ "$ROCKSDB_CXX_STANDARD" ]; then
|
if [ "$ROCKSDB_CXX_STANDARD" ]; then
|
||||||
PLATFORM_CXXFLAGS="-std=$ROCKSDB_CXX_STANDARD"
|
PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS -std=$ROCKSDB_CXX_STANDARD"
|
||||||
else
|
else
|
||||||
PLATFORM_CXXFLAGS="-std=c++17"
|
PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS -std=c++17"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# we currently depend on POSIX platform
|
|
||||||
COMMON_FLAGS="-DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX"
|
|
||||||
|
|
||||||
# Default to fbcode gcc on internal fb machines
|
# Default to fbcode gcc on internal fb machines
|
||||||
if [ -z "$ROCKSDB_NO_FBCODE" -a -d /mnt/gvfs/third-party ]; then
|
if [ -z "$ROCKSDB_NO_FBCODE" -a -d /mnt/gvfs/third-party ]; then
|
||||||
FBCODE_BUILD="true"
|
FBCODE_BUILD="true"
|
||||||
@ -136,10 +135,11 @@ if test -z "$WATCH"; then
|
|||||||
WATCH=watch
|
WATCH=watch
|
||||||
fi
|
fi
|
||||||
|
|
||||||
COMMON_FLAGS="$COMMON_FLAGS ${CFLAGS}"
|
if [[ ! "$TARGET_OS" =~ MINGW ]]; then
|
||||||
CROSS_COMPILE=
|
COMMON_FLAGS="-DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX"
|
||||||
PLATFORM_CCFLAGS=
|
fi
|
||||||
PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS"
|
|
||||||
|
PLATFORM_CCFLAGS="${CFLAGS}"
|
||||||
PLATFORM_SHARED_EXT="so"
|
PLATFORM_SHARED_EXT="so"
|
||||||
PLATFORM_SHARED_LDFLAGS="-Wl,--no-as-needed -shared -Wl,-soname -Wl,"
|
PLATFORM_SHARED_LDFLAGS="-Wl,--no-as-needed -shared -Wl,-soname -Wl,"
|
||||||
PLATFORM_SHARED_CFLAGS="-fPIC"
|
PLATFORM_SHARED_CFLAGS="-fPIC"
|
||||||
@ -249,7 +249,7 @@ EOF
|
|||||||
Cygwin)
|
Cygwin)
|
||||||
PLATFORM=CYGWIN
|
PLATFORM=CYGWIN
|
||||||
PLATFORM_SHARED_CFLAGS=""
|
PLATFORM_SHARED_CFLAGS=""
|
||||||
PLATFORM_CXXFLAGS="-std=gnu++11"
|
#PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS -std=gnu++11"
|
||||||
COMMON_FLAGS="$COMMON_FLAGS -DCYGWIN"
|
COMMON_FLAGS="$COMMON_FLAGS -DCYGWIN"
|
||||||
if [ -z "$USE_CLANG" ]; then
|
if [ -z "$USE_CLANG" ]; then
|
||||||
COMMON_FLAGS="$COMMON_FLAGS -fno-builtin-memcmp"
|
COMMON_FLAGS="$COMMON_FLAGS -fno-builtin-memcmp"
|
||||||
@ -259,6 +259,10 @@ EOF
|
|||||||
PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lpthread -lrt"
|
PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lpthread -lrt"
|
||||||
# PORT_FILES=port/linux/linux_specific.cc
|
# PORT_FILES=port/linux/linux_specific.cc
|
||||||
;;
|
;;
|
||||||
|
MINGW*)
|
||||||
|
PLATFORM=MINGW
|
||||||
|
COMMON_FLAGS="$COMMON_FLAGS -DWIN32 -DOS_WIN -D_MBCS -DWIN64 -DNOMINMAX -D_WIN32_WINNT=_WIN32_WINNT_VISTA -D_POSIX_C_SOURCE=1"
|
||||||
|
;;
|
||||||
OS_ANDROID_CROSSCOMPILE)
|
OS_ANDROID_CROSSCOMPILE)
|
||||||
PLATFORM=OS_ANDROID
|
PLATFORM=OS_ANDROID
|
||||||
COMMON_FLAGS="$COMMON_FLAGS -fno-builtin-memcmp -D_REENTRANT -DOS_ANDROID -DROCKSDB_PLATFORM_POSIX"
|
COMMON_FLAGS="$COMMON_FLAGS -fno-builtin-memcmp -D_REENTRANT -DOS_ANDROID -DROCKSDB_PLATFORM_POSIX"
|
||||||
@ -271,7 +275,6 @@ EOF
|
|||||||
exit 1
|
exit 1
|
||||||
esac
|
esac
|
||||||
|
|
||||||
PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS ${CXXFLAGS}"
|
|
||||||
JAVA_LDFLAGS="$PLATFORM_LDFLAGS"
|
JAVA_LDFLAGS="$PLATFORM_LDFLAGS"
|
||||||
JAVA_STATIC_LDFLAGS="$PLATFORM_LDFLAGS"
|
JAVA_STATIC_LDFLAGS="$PLATFORM_LDFLAGS"
|
||||||
JAVAC_ARGS="-source 8"
|
JAVAC_ARGS="-source 8"
|
||||||
@ -416,7 +419,7 @@ EOF
|
|||||||
|
|
||||||
if ! test $ROCKSDB_DISABLE_TBB; then
|
if ! test $ROCKSDB_DISABLE_TBB; then
|
||||||
# Test whether tbb is available
|
# Test whether tbb is available
|
||||||
$CXX $PLATFORM_CXXFLAGS $LDFLAGS -x c++ - -o test.o -ltbb 2>/dev/null <<EOF
|
$CXX $PLATFORM_CXXFLAGS -x c++ - -o test.o -ltbb 2>/dev/null <<EOF
|
||||||
#include <tbb/tbb.h>
|
#include <tbb/tbb.h>
|
||||||
int main() {}
|
int main() {}
|
||||||
EOF
|
EOF
|
||||||
@ -667,13 +670,13 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${PLATFORM}" == "OS_MACOSX" ]]; then
|
if [[ "${PLATFORM}" == "OS_MACOSX" ]]; then
|
||||||
# For portability compile for macOS 10.12 (2016) or newer
|
# For portability compile for macOS 10.14 (2018) or newer
|
||||||
COMMON_FLAGS="$COMMON_FLAGS -mmacosx-version-min=10.12"
|
COMMON_FLAGS="$COMMON_FLAGS -mmacosx-version-min=10.14"
|
||||||
PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -mmacosx-version-min=10.12"
|
PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -mmacosx-version-min=10.14"
|
||||||
# -mmacosx-version-min must come first here.
|
# -mmacosx-version-min must come first here.
|
||||||
PLATFORM_SHARED_LDFLAGS="-mmacosx-version-min=10.12 $PLATFORM_SHARED_LDFLAGS"
|
PLATFORM_SHARED_LDFLAGS="-mmacosx-version-min=10.14 $PLATFORM_SHARED_LDFLAGS"
|
||||||
PLATFORM_CMAKE_FLAGS="-DCMAKE_OSX_DEPLOYMENT_TARGET=10.12"
|
PLATFORM_CMAKE_FLAGS="-DCMAKE_OSX_DEPLOYMENT_TARGET=10.14"
|
||||||
JAVA_STATIC_DEPS_COMMON_FLAGS="-mmacosx-version-min=10.12"
|
JAVA_STATIC_DEPS_COMMON_FLAGS="-mmacosx-version-min=10.14"
|
||||||
JAVA_STATIC_DEPS_LDFLAGS="$JAVA_STATIC_DEPS_COMMON_FLAGS"
|
JAVA_STATIC_DEPS_LDFLAGS="$JAVA_STATIC_DEPS_COMMON_FLAGS"
|
||||||
JAVA_STATIC_DEPS_CCFLAGS="$JAVA_STATIC_DEPS_COMMON_FLAGS"
|
JAVA_STATIC_DEPS_CCFLAGS="$JAVA_STATIC_DEPS_COMMON_FLAGS"
|
||||||
JAVA_STATIC_DEPS_CXXFLAGS="$JAVA_STATIC_DEPS_COMMON_FLAGS"
|
JAVA_STATIC_DEPS_CXXFLAGS="$JAVA_STATIC_DEPS_COMMON_FLAGS"
|
||||||
|
Loading…
Reference in New Issue
Block a user