From 73641c4e73d8634eebe8fe00b96ba039da883b27 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 16 Jan 2017 15:56:56 -0800 Subject: [PATCH] build.sh: if new enough libgit2 is installed, use it Right now this is only designed for Linux where current distros all should have a new enough libgit2 (and our instructions tell people to install this with system tools, so we should also use it). Signed-off-by: Dirk Hohndel --- CMakeLists.txt | 1 + cmake/Modules/FindLIBGIT2.cmake | 7 ++- scripts/build.sh | 85 ++++++++++++++++++--------------- 3 files changed, 53 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 09936c834..811480149 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ option(LIBMARBLE_FROM_PKGCONFIG "use pkg-config to retrieve marble" OFF) #Library Handling option(FORCE_LIBSSH "force linking with libssh to workaround libgit2 bug" ON) +option(LIBGIT2_DYNAMIC "search for libgit2.so before libgit2.a" OFF) #Options regarding disabling parts of subsurface. option(NO_MARBLE "disable the marble widget" OFF) diff --git a/cmake/Modules/FindLIBGIT2.cmake b/cmake/Modules/FindLIBGIT2.cmake index cedb96d36..da51cc497 100644 --- a/cmake/Modules/FindLIBGIT2.cmake +++ b/cmake/Modules/FindLIBGIT2.cmake @@ -22,8 +22,13 @@ HINTS /usr/include ) +IF ( LIBGIT2_DYNAMIC ) + SET( LIBGIT2_SO libgit2.so ) +ENDIF() + FIND_LIBRARY( LIBGIT2_LIBRARIES NAMES + ${LIBGIT2_SO} libgit2.a git2 HINTS @@ -36,4 +41,4 @@ SET(LIBGIT2_LIBRARIES ${LIBGIT2_LIBRARIES} -lssl -lcrypto) INCLUDE( FindPackageHandleStandardArgs ) FIND_PACKAGE_HANDLE_STANDARD_ARGS( git2 DEFAULT_MSG LIBGIT2_INCLUDE_DIR LIBGIT2_LIBRARIES ) -include_directories(${LIBGIT2_INCLUDE_DIR}}) \ No newline at end of file +include_directories(${LIBGIT2_INCLUDE_DIR}}) diff --git a/scripts/build.sh b/scripts/build.sh index e78b0e051..f60d7045b 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -3,7 +3,6 @@ # this should be run from the src directory, the layout is supposed to # look like this: #.../src/subsurface -# /libgit2 # /marble-source # /libdivecomputer # @@ -73,37 +72,52 @@ export PKG_CONFIG_PATH=$INSTALL_ROOT/lib/pkgconfig:$PKG_CONFIG_PATH echo Building in $SRC, installing in $INSTALL_ROOT -# build libgit2 - -cd $SRC - -if [ ! -d libgit2 ] ; then - if [[ $1 = local ]] ; then - git clone $SRC/../libgit2 libgit2 - else - git clone git://github.com/libgit2/libgit2 - fi -fi -cd libgit2 -# let's build with a recent enough version of master for the latest features -git fetch origin -if ! git checkout v0.24.5 ; then - echo "Can't find the right tag in libgit2 - giving up" - exit 1 -fi -mkdir -p build -cd build -cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_ROOT -DCMAKE_BUILD_TYPE=Release -DBUILD_CLAR=OFF .. -make -j4 -make install - +# set up the right file name extensions if [ $PLATFORM = Darwin ] ; then - # in order for macdeployqt to do its job correctly, we need the full path in the dylib ID - cd $INSTALL_ROOT/lib - NAME=$(otool -L libgit2.dylib | grep -v : | head -1 | cut -f1 -d\ | tr -d '\t') - echo $NAME | grep / > /dev/null 2>&1 - if [ $? -eq 1 ] ; then - install_name_tool -id "$INSTALL_ROOT/lib/$NAME" "$INSTALL_ROOT/lib/$NAME" + SH_LIB_EXT=dylib +else + SH_LIB_EXT=so + + # check if we need to build libgit2 (and do so if necessary) + + LIBGIT_ARGS=" -DLIBGIT2_DYNAMIC=ON " + LIBGIT=$(ldconfig -p | grep libgit2\\.so\\. | awk -F. '{ print $NF }') +fi + +if [[ $PLATFORM = Darwin || "$LIBGIT" < "24" ]] ; then + + LIBGIT_ARGS=" -DLIBGIT2_INCLUDE_DIR=$INSTALL_ROOT/include -DLIBGIT2_LIBRARIES=$INSTALL_ROOT/lib/libgit2.$SH_LIB_EXT " + + cd $SRC + + if [ ! -d libgit2 ] ; then + if [[ $1 = local ]] ; then + git clone $SRC/../libgit2 libgit2 + else + git clone git://github.com/libgit2/libgit2 + fi + fi + cd libgit2 + # let's build with a recent enough version of master for the latest features + git fetch origin + if ! git checkout v0.24.5 ; then + echo "Can't find the right tag in libgit2 - giving up" + exit 1 + fi + mkdir -p build + cd build + cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_ROOT -DCMAKE_BUILD_TYPE=Release -DBUILD_CLAR=OFF .. + make -j4 + make install + + if [ $PLATFORM = Darwin ] ; then + # in order for macdeployqt to do its job correctly, we need the full path in the dylib ID + cd $INSTALL_ROOT/lib + NAME=$(otool -L libgit2.dylib | grep -v : | head -1 | cut -f1 -d\ | tr -d '\t') + echo $NAME | grep / > /dev/null 2>&1 + if [ $? -eq 1 ] ; then + install_name_tool -id "$INSTALL_ROOT/lib/$NAME" "$INSTALL_ROOT/lib/$NAME" + fi fi fi @@ -227,12 +241,6 @@ fi # finally, build Subsurface -if [ $PLATFORM = Darwin ] ; then - SH_LIB_EXT=dylib -else - SH_LIB_EXT=so -fi - cd $SRC/subsurface for (( i=0 ; i < ${#BUILDS[@]} ; i++ )) ; do SUBSURFACE_EXECUTABLE=${BUILDS[$i]} @@ -250,8 +258,7 @@ for (( i=0 ; i < ${#BUILDS[@]} ; i++ )) ; do export CMAKE_PREFIX_PATH="$INSTALL_ROOT/lib/cmake;${CMAKE_PREFIX_PATH}" cmake -DCMAKE_BUILD_TYPE=Debug .. \ -DSUBSURFACE_TARGET_EXECUTABLE=$SUBSURFACE_EXECUTABLE \ - -DLIBGIT2_INCLUDE_DIR=$INSTALL_ROOT/include \ - -DLIBGIT2_LIBRARIES=$INSTALL_ROOT/lib/libgit2.$SH_LIB_EXT \ + ${LIBGIT_ARGS} \ -DLIBDIVECOMPUTER_INCLUDE_DIR=$INSTALL_ROOT/include \ -DLIBDIVECOMPUTER_LIBRARIES=$INSTALL_ROOT/lib/libdivecomputer.a \ -DMARBLE_INCLUDE_DIR=$INSTALL_ROOT/include \