From ae7743f22688f10efd8bd5a8ef1871890f8a7ee1 Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Mon, 21 Jul 2014 22:41:54 -0700 Subject: [PATCH] Fixed some make and linking issues of RocksDBJava Summary: Fixed some make and linking issues of RocksDBJava. Specifically: * Add JAVA_LDFLAGS, which does not include gflags * rocksdbjava library now uses JAVA_LDFLAGS instead of LDFLAGS * java/Makefile now includes build_config.mk * rearrange make rocksdbjava workflow to ensure the library file is correctly included in the jar file. Test Plan: make rocksdbjava make jdb_bench java/jdb_bench.sh Reviewers: dhruba, swapnilghike, zzbennett, rsumbaly, ankgup87 Reviewed By: ankgup87 Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D20289 --- Makefile | 9 +++++---- build_tools/build_detect_platform | 11 +++++++++++ java/Makefile | 6 ------ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index a87c79241..a63dc381e 100644 --- a/Makefile +++ b/Makefile @@ -448,18 +448,19 @@ ldb: tools/ldb.o $(LIBOBJECTS) JNI_NATIVE_SOURCES = ./java/rocksjni/*.cc JAVA_INCLUDE = -I$(JAVA_HOME)/include/ -I$(JAVA_HOME)/include/linux -ROCKSDBJNILIB = ./java/librocksdbjni.so +ROCKSDBJNILIB = librocksdbjni.so ifeq ($(PLATFORM), OS_MACOSX) -ROCKSDBJNILIB = ./java/librocksdbjni.jnilib +ROCKSDBJNILIB = librocksdbjni.jnilib JAVA_INCLUDE = -I/System/Library/Frameworks/JavaVM.framework/Headers/ endif rocksdbjava: OPT="-fPIC -DNDEBUG -O2" $(MAKE) $(LIBRARY) -j32 cd java;$(MAKE) java; - rm -f $(ROCKSDBJNILIB) - $(CXX) $(CXXFLAGS) -I./java/. $(JAVA_INCLUDE) -shared -fPIC -o $(ROCKSDBJNILIB) $(JNI_NATIVE_SOURCES) $(LIBOBJECTS) $(LDFLAGS) $(COVERAGEFLAGS) + rm -f ./java/$(ROCKSDBJNILIB) + $(CXX) $(CXXFLAGS) -I./java/. $(JAVA_INCLUDE) -shared -fPIC -o ./java/$(ROCKSDBJNILIB) $(JNI_NATIVE_SOURCES) $(LIBOBJECTS) $(JAVA_LDFLAGS) $(COVERAGEFLAGS) + cd java;jar -cf $(ROCKSDB_JAR) org/rocksdb/*.class org/rocksdb/util/*.class HISTORY*.md $(ROCKSDBJNILIB) jclean: cd java;$(MAKE) clean; diff --git a/build_tools/build_detect_platform b/build_tools/build_detect_platform index 6ea1a63d0..3389d2851 100755 --- a/build_tools/build_detect_platform +++ b/build_tools/build_detect_platform @@ -7,6 +7,7 @@ # CC C Compiler path # CXX C++ Compiler path # PLATFORM_LDFLAGS Linker flags +# JAVA_LDFLAGS Linker flags for RocksDBJava # PLATFORM_SHARED_EXT Extension for shared libraries # PLATFORM_SHARED_LDFLAGS Flags for building shared library # PLATFORM_SHARED_CFLAGS Flags for compiling objects for shared library @@ -157,6 +158,8 @@ case "$TARGET_OS" in exit 1 esac +JAVA_LDFLAGS="$PLATFORM_LDFLAGS" + if test -z "$DO_NOT_RUN_BUILD_DETECT_VERSION"; then "$PWD/build_tools/build_detect_version" fi @@ -215,6 +218,7 @@ EOF if [ "$?" = 0 ]; then COMMON_FLAGS="$COMMON_FLAGS -DSNAPPY" PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lsnappy" + JAVA_LDFLAGS="$JAVA_LDFLAGS -lsnappy" fi @@ -250,6 +254,7 @@ EOF if [ "$?" = 0 ]; then COMMON_FLAGS="$COMMON_FLAGS -DZLIB" PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lz" + JAVA_LDFLAGS="$JAVA_LDFLAGS -lz" fi # Test whether bzip library is installed @@ -260,6 +265,7 @@ EOF if [ "$?" = 0 ]; then COMMON_FLAGS="$COMMON_FLAGS -DBZIP2" PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lbz2" + JAVA_LDFLAGS="$JAVA_LDFLAGS -lbz2" fi # Test whether lz4 library is installed @@ -271,6 +277,7 @@ EOF if [ "$?" = 0 ]; then COMMON_FLAGS="$COMMON_FLAGS -DLZ4" PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -llz4" + JAVA_LDFLAGS="$JAVA_LDFLAGS -llz4" fi # Test whether numa is available @@ -282,6 +289,7 @@ EOF if [ "$?" = 0 ]; then COMMON_FLAGS="$COMMON_FLAGS -DNUMA" PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lnuma" + JAVA_LDFLAGS="$JAVA_LDFLAGS -lnuma" fi # Test whether tcmalloc is available @@ -290,6 +298,7 @@ EOF EOF if [ "$?" = 0 ]; then PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -ltcmalloc" + JAVA_LDFLAGS="$JAVA_LDFLAGS -ltcmalloc" fi fi @@ -306,6 +315,7 @@ if test "$USE_HDFS"; then HDFS_LDFLAGS="$HDFS_LDFLAGS -ldl -lverify -ljava -ljvm" COMMON_FLAGS="$COMMON_FLAGS $HDFS_CCFLAGS" PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS $HDFS_LDFLAGS" + JAVA_LDFLAGS="$JAVA_LDFLAGS $HDFS_LDFLAGS" fi # if Intel SSE instruction set is supported, set USE_SSE=" -msse -msse4.2 " @@ -320,6 +330,7 @@ echo "CC=$CC" >> "$OUTPUT" echo "CXX=$CXX" >> "$OUTPUT" echo "PLATFORM=$PLATFORM" >> "$OUTPUT" echo "PLATFORM_LDFLAGS=$PLATFORM_LDFLAGS" >> "$OUTPUT" +echo "JAVA_LDFLAGS=$JAVA_LDFLAGS" >> "$OUTPUT" echo "VALGRIND_VER=$VALGRIND_VER" >> "$OUTPUT" echo "PLATFORM_CCFLAGS=$PLATFORM_CCFLAGS" >> "$OUTPUT" echo "PLATFORM_CXXFLAGS=$PLATFORM_CXXFLAGS" >> "$OUTPUT" diff --git a/java/Makefile b/java/Makefile index 287fe1021..238ddd93e 100644 --- a/java/Makefile +++ b/java/Makefile @@ -3,11 +3,6 @@ NATIVE_JAVA_CLASSES = org.rocksdb.RocksDB org.rocksdb.Options org.rocksdb.WriteB NATIVE_INCLUDE = ./include ROCKSDB_JAR = rocksdbjni.jar -ROCKSDBJNILIB = ./librocksdbjni.so -ifeq ($(PLATFORM), OS_MACOSX) - ROCKSDBJNILIB = ./librocksdbjni.jnilib -endif - clean: -find . -name "*.class" -exec rm {} \; -find . -name "hs*.log" -exec rm {} \; @@ -16,7 +11,6 @@ clean: java: javac org/rocksdb/util/*.java org/rocksdb/*.java @cp ../HISTORY.md ./HISTORY-CPP.md - jar -cf $(ROCKSDB_JAR) org/rocksdb/*.class org/rocksdb/util/*.class HISTORY*.md $(ROCKSDBJNILIB) @rm -f ./HISTORY-CPP.md javah -d $(NATIVE_INCLUDE) -jni $(NATIVE_JAVA_CLASSES)