Skip to content

Commit

Permalink
Refactoring of the build configuration script for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
stewid committed Oct 19, 2024
1 parent 055bcfb commit 34aa0c7
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 36 deletions.
1 change: 1 addition & 0 deletions cleanup
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ rm -f src/Makevars
rm -rf autom4te.cache
rm -f src/*.o
rm -f src/*.so
rm -rf .deps
64 changes: 46 additions & 18 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -2098,7 +2098,6 @@ RBIN="${R_HOME}/bin/R"


PKG_CONFIG_NAME="libgit2"
PKG_BREW_NAME="libgit2"
PKG_LIBS="-lgit2"
PKG_CFLAGS=""

Expand Down Expand Up @@ -2165,9 +2164,48 @@ fi

if test "x${BREW}" = xyes; then
BREWDIR=`brew --prefix`
else
curl -sfL "https://autobrew.github.io/scripts/libgit2" > autobrew
. ./autobrew
PKG_CFLAGS="-I${BREWDIR}/opt/libgit2/include"
PKG_LIBS="-L${BREWDIR}/opt/libgit2/lib ${PKG_LIBS}"
elif test -z "${DISABLE_AUTOBREW}"; then
# Try to download a static build of libgit2 and use that.
bottle_ver="1.8.1"
bottle_sha256="9419deece3c3b7bec2ed8ed1caa5f4a3f3f1b049a6d17b0a75b2e05128c10fdf"
bottle_url="https://github.com/autobrew/bundler/releases/download"
bottle="${bottle_url}/libgit2-${bottle_ver}/libgit2-${bottle_ver}-universal.tar.xz"

# Download the bottle
echo "Download autobrew bundle $(basename ${bottle})"
curl -sSL $bottle -o libs.tar.xz

# Verify the checksum of the downloaded bottle
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking SHA256 checksum of downloaded $(basename ${bottle})" >&5
printf %s "checking SHA256 checksum of downloaded $(basename ${bottle})... " >&6; }
: ${bottle_download_sha256=`openssl sha256 libs.tar.xz | sed -e 's:.*= ::'`}
if test "x$bottle_download_sha256" != "x$bottle_sha256"; then
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
as_fn_error $? "The SHA256 checksum of $(basename ${bottle}) didn't match
See 'config.log' for more details" "$LINENO" 5; }
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }

# General setup
BREWDIR="$PWD/.deps"
mkdir -p $BREWDIR
tar -xf libs.tar.xz --strip 1 -C $BREWDIR
rm -f libs.tar.xz

PKG_CFLAGS="-I${BREWDIR}/include"
PKG_LIBS="-L${BREWDIR}/lib ${PKG_LIBS} -lssh2 -lcrypto -lcurl -lz -liconv -framework Security"

# Prevent linking against other libs in /usr/local/lib
for FILE in $BREWDIR/lib/*.a; do
BASENAME=$(basename $FILE)
LIBNAME=$(echo "${BASENAME%.*}" | cut -c4-)
cp -f $FILE $BREWDIR/lib/libbrew$LIBNAME.a
PKG_LIBS=$(echo $PKG_LIBS | sed "s/-l$LIBNAME /-lbrew$LIBNAME /g")
done
fi
;;
esac
Expand Down Expand Up @@ -2199,10 +2237,10 @@ if test "x${libgit2_ver_ok}" = xno; then
echo "
-----------------------------------------------------------------------
Unable to find 'libgit2 >= ${LIBGIT2_MIN_VERSION}' on this system, please install:
libgit2-dev (package on e.g. Debian and Ubuntu)
libgit2-devel (package on e.g. Fedora, CentOS and RHEL)
libgit2 (Homebrew package on OS X)
Configuration failed to find libgit2 library. Try installing:
* brew: libgit2 (MacOS)
* deb: libgit2-dev (Debian, Ubuntu, etc)
* rpm: libgit2-devel (Fedora, CentOS, RHEL)
and try again.
If the libgit2 library is installed on your system but the git2r
Expand All @@ -2218,16 +2256,6 @@ if test "x${libgit2_ver_ok}" = xno; then
or download and install git2r in R using
install.packages('git2r', type='source', configure.vars='LIB_DIR=-L/path/to/libs INCLUDE_DIR=-I/path/to/headers')
On macOS, another possibility is to let the configuration
automatically download the libgit2 library from the Homebrew
package manager with:
R CMD INSTALL git2r-.tar.gz --configure-vars='autobrew=yes'
or
R CMD INSTALL git2r/ --configure-vars='autobrew=yes'
or
install.packages('git2r', type='source', configure.vars='autobrew=yes')
-----------------------------------------------------------------------
"
Expand Down
59 changes: 41 additions & 18 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ RBIN="${R_HOME}/bin/R"
m4_pattern_allow([PKG_CONFIG_NAME])
m4_pattern_allow([PKG_BREW_NAME])
PKG_CONFIG_NAME="libgit2"
PKG_BREW_NAME="libgit2"
PKG_LIBS="-lgit2"
PKG_CFLAGS=""

Expand All @@ -64,9 +63,43 @@ if test "x${INCLUDE_DIR}${LIB_DIR}" = x; then
AC_PROG_BREW
if test "x${BREW}" = xyes; then
BREWDIR=`brew --prefix`
else
curl -sfL "https://autobrew.github.io/scripts/libgit2" > autobrew
. ./autobrew
PKG_CFLAGS="-I${BREWDIR}/opt/libgit2/include"
PKG_LIBS="-L${BREWDIR}/opt/libgit2/lib ${PKG_LIBS}"
elif test -z "${DISABLE_AUTOBREW}"; then
# Try to download a static build of libgit2 and use that.
bottle_ver="1.8.1"
bottle_sha256="9419deece3c3b7bec2ed8ed1caa5f4a3f3f1b049a6d17b0a75b2e05128c10fdf"
bottle_url="https://github.com/autobrew/bundler/releases/download"
bottle="${bottle_url}/libgit2-${bottle_ver}/libgit2-${bottle_ver}-universal.tar.xz"

# Download the bottle
echo "Download autobrew bundle $(basename ${bottle})"
curl -sSL $bottle -o libs.tar.xz

# Verify the checksum of the downloaded bottle
AC_MSG_CHECKING([SHA256 checksum of downloaded $(basename ${bottle})])
: ${bottle_download_sha256=`openssl sha256 libs.tar.xz | sed -e 's:.*= ::'`}
if test "x$bottle_download_sha256" != "x$bottle_sha256"; then
AC_MSG_FAILURE([The SHA256 checksum of $(basename ${bottle}) didn't match])
fi
AC_MSG_RESULT([yes])

# General setup
BREWDIR="$PWD/.deps"
mkdir -p $BREWDIR
tar -xf libs.tar.xz --strip 1 -C $BREWDIR
rm -f libs.tar.xz

PKG_CFLAGS="-I${BREWDIR}/include"
PKG_LIBS="-L${BREWDIR}/lib ${PKG_LIBS} -lssh2 -lcrypto -lcurl -lz -liconv -framework Security"

# Prevent linking against other libs in /usr/local/lib
for FILE in $BREWDIR/lib/*.a; do
BASENAME=$(basename $FILE)
LIBNAME=$(echo "${BASENAME%.*}" | cut -c4-)
cp -f $FILE $BREWDIR/lib/libbrew$LIBNAME.a
PKG_LIBS=$(echo $PKG_LIBS | sed "s/-l$LIBNAME /-lbrew$LIBNAME /g")
done
fi
;;
esac
Expand Down Expand Up @@ -96,10 +129,10 @@ if test "x${libgit2_ver_ok}" = xno; then
echo "
-----------------------------------------------------------------------

Unable to find 'libgit2 >= ${LIBGIT2_MIN_VERSION}' on this system, please install:
libgit2-dev (package on e.g. Debian and Ubuntu)
libgit2-devel (package on e.g. Fedora, CentOS and RHEL)
libgit2 (Homebrew package on OS X)
Configuration failed to find libgit2 library. Try installing:
* brew: libgit2 (MacOS)
* deb: libgit2-dev (Debian, Ubuntu, etc)
* rpm: libgit2-devel (Fedora, CentOS, RHEL)
and try again.

If the libgit2 library is installed on your system but the git2r
Expand All @@ -115,16 +148,6 @@ if test "x${libgit2_ver_ok}" = xno; then
or download and install git2r in R using
install.packages('git2r', type='source', configure.vars='LIB_DIR=-L/path/to/libs INCLUDE_DIR=-I/path/to/headers')

On macOS, another possibility is to let the configuration
automatically download the libgit2 library from the Homebrew
package manager with:

R CMD INSTALL git2r-.tar.gz --configure-vars='autobrew=yes'
or
R CMD INSTALL git2r/ --configure-vars='autobrew=yes'
or
install.packages('git2r', type='source', configure.vars='autobrew=yes')

-----------------------------------------------------------------------

"
Expand Down

0 comments on commit 34aa0c7

Please sign in to comment.