Skip to content

Commit 34aa0c7

Browse files
committed
Refactoring of the build configuration script for macOS
1 parent 055bcfb commit 34aa0c7

File tree

3 files changed

+88
-36
lines changed

3 files changed

+88
-36
lines changed

cleanup

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ rm -f src/Makevars
55
rm -rf autom4te.cache
66
rm -f src/*.o
77
rm -f src/*.so
8+
rm -rf .deps

configure

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,7 +2098,6 @@ RBIN="${R_HOME}/bin/R"
20982098

20992099

21002100
PKG_CONFIG_NAME="libgit2"
2101-
PKG_BREW_NAME="libgit2"
21022101
PKG_LIBS="-lgit2"
21032102
PKG_CFLAGS=""
21042103

@@ -2165,9 +2164,48 @@ fi
21652164

21662165
if test "x${BREW}" = xyes; then
21672166
BREWDIR=`brew --prefix`
2168-
else
2169-
curl -sfL "https://autobrew.github.io/scripts/libgit2" > autobrew
2170-
. ./autobrew
2167+
PKG_CFLAGS="-I${BREWDIR}/opt/libgit2/include"
2168+
PKG_LIBS="-L${BREWDIR}/opt/libgit2/lib ${PKG_LIBS}"
2169+
elif test -z "${DISABLE_AUTOBREW}"; then
2170+
# Try to download a static build of libgit2 and use that.
2171+
bottle_ver="1.8.1"
2172+
bottle_sha256="9419deece3c3b7bec2ed8ed1caa5f4a3f3f1b049a6d17b0a75b2e05128c10fdf"
2173+
bottle_url="https://github.com/autobrew/bundler/releases/download"
2174+
bottle="${bottle_url}/libgit2-${bottle_ver}/libgit2-${bottle_ver}-universal.tar.xz"
2175+
2176+
# Download the bottle
2177+
echo "Download autobrew bundle $(basename ${bottle})"
2178+
curl -sSL $bottle -o libs.tar.xz
2179+
2180+
# Verify the checksum of the downloaded bottle
2181+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking SHA256 checksum of downloaded $(basename ${bottle})" >&5
2182+
printf %s "checking SHA256 checksum of downloaded $(basename ${bottle})... " >&6; }
2183+
: ${bottle_download_sha256=`openssl sha256 libs.tar.xz | sed -e 's:.*= ::'`}
2184+
if test "x$bottle_download_sha256" != "x$bottle_sha256"; then
2185+
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
2186+
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
2187+
as_fn_error $? "The SHA256 checksum of $(basename ${bottle}) didn't match
2188+
See 'config.log' for more details" "$LINENO" 5; }
2189+
fi
2190+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
2191+
printf "%s\n" "yes" >&6; }
2192+
2193+
# General setup
2194+
BREWDIR="$PWD/.deps"
2195+
mkdir -p $BREWDIR
2196+
tar -xf libs.tar.xz --strip 1 -C $BREWDIR
2197+
rm -f libs.tar.xz
2198+
2199+
PKG_CFLAGS="-I${BREWDIR}/include"
2200+
PKG_LIBS="-L${BREWDIR}/lib ${PKG_LIBS} -lssh2 -lcrypto -lcurl -lz -liconv -framework Security"
2201+
2202+
# Prevent linking against other libs in /usr/local/lib
2203+
for FILE in $BREWDIR/lib/*.a; do
2204+
BASENAME=$(basename $FILE)
2205+
LIBNAME=$(echo "${BASENAME%.*}" | cut -c4-)
2206+
cp -f $FILE $BREWDIR/lib/libbrew$LIBNAME.a
2207+
PKG_LIBS=$(echo $PKG_LIBS | sed "s/-l$LIBNAME /-lbrew$LIBNAME /g")
2208+
done
21712209
fi
21722210
;;
21732211
esac
@@ -2199,10 +2237,10 @@ if test "x${libgit2_ver_ok}" = xno; then
21992237
echo "
22002238
-----------------------------------------------------------------------
22012239
2202-
Unable to find 'libgit2 >= ${LIBGIT2_MIN_VERSION}' on this system, please install:
2203-
libgit2-dev (package on e.g. Debian and Ubuntu)
2204-
libgit2-devel (package on e.g. Fedora, CentOS and RHEL)
2205-
libgit2 (Homebrew package on OS X)
2240+
Configuration failed to find libgit2 library. Try installing:
2241+
* brew: libgit2 (MacOS)
2242+
* deb: libgit2-dev (Debian, Ubuntu, etc)
2243+
* rpm: libgit2-devel (Fedora, CentOS, RHEL)
22062244
and try again.
22072245
22082246
If the libgit2 library is installed on your system but the git2r
@@ -2218,16 +2256,6 @@ if test "x${libgit2_ver_ok}" = xno; then
22182256
or download and install git2r in R using
22192257
install.packages('git2r', type='source', configure.vars='LIB_DIR=-L/path/to/libs INCLUDE_DIR=-I/path/to/headers')
22202258
2221-
On macOS, another possibility is to let the configuration
2222-
automatically download the libgit2 library from the Homebrew
2223-
package manager with:
2224-
2225-
R CMD INSTALL git2r-.tar.gz --configure-vars='autobrew=yes'
2226-
or
2227-
R CMD INSTALL git2r/ --configure-vars='autobrew=yes'
2228-
or
2229-
install.packages('git2r', type='source', configure.vars='autobrew=yes')
2230-
22312259
-----------------------------------------------------------------------
22322260
22332261
"

configure.ac

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ RBIN="${R_HOME}/bin/R"
3939
m4_pattern_allow([PKG_CONFIG_NAME])
4040
m4_pattern_allow([PKG_BREW_NAME])
4141
PKG_CONFIG_NAME="libgit2"
42-
PKG_BREW_NAME="libgit2"
4342
PKG_LIBS="-lgit2"
4443
PKG_CFLAGS=""
4544

@@ -64,9 +63,43 @@ if test "x${INCLUDE_DIR}${LIB_DIR}" = x; then
6463
AC_PROG_BREW
6564
if test "x${BREW}" = xyes; then
6665
BREWDIR=`brew --prefix`
67-
else
68-
curl -sfL "https://autobrew.github.io/scripts/libgit2" > autobrew
69-
. ./autobrew
66+
PKG_CFLAGS="-I${BREWDIR}/opt/libgit2/include"
67+
PKG_LIBS="-L${BREWDIR}/opt/libgit2/lib ${PKG_LIBS}"
68+
elif test -z "${DISABLE_AUTOBREW}"; then
69+
# Try to download a static build of libgit2 and use that.
70+
bottle_ver="1.8.1"
71+
bottle_sha256="9419deece3c3b7bec2ed8ed1caa5f4a3f3f1b049a6d17b0a75b2e05128c10fdf"
72+
bottle_url="https://github.com/autobrew/bundler/releases/download"
73+
bottle="${bottle_url}/libgit2-${bottle_ver}/libgit2-${bottle_ver}-universal.tar.xz"
74+
75+
# Download the bottle
76+
echo "Download autobrew bundle $(basename ${bottle})"
77+
curl -sSL $bottle -o libs.tar.xz
78+
79+
# Verify the checksum of the downloaded bottle
80+
AC_MSG_CHECKING([SHA256 checksum of downloaded $(basename ${bottle})])
81+
: ${bottle_download_sha256=`openssl sha256 libs.tar.xz | sed -e 's:.*= ::'`}
82+
if test "x$bottle_download_sha256" != "x$bottle_sha256"; then
83+
AC_MSG_FAILURE([The SHA256 checksum of $(basename ${bottle}) didn't match])
84+
fi
85+
AC_MSG_RESULT([yes])
86+
87+
# General setup
88+
BREWDIR="$PWD/.deps"
89+
mkdir -p $BREWDIR
90+
tar -xf libs.tar.xz --strip 1 -C $BREWDIR
91+
rm -f libs.tar.xz
92+
93+
PKG_CFLAGS="-I${BREWDIR}/include"
94+
PKG_LIBS="-L${BREWDIR}/lib ${PKG_LIBS} -lssh2 -lcrypto -lcurl -lz -liconv -framework Security"
95+
96+
# Prevent linking against other libs in /usr/local/lib
97+
for FILE in $BREWDIR/lib/*.a; do
98+
BASENAME=$(basename $FILE)
99+
LIBNAME=$(echo "${BASENAME%.*}" | cut -c4-)
100+
cp -f $FILE $BREWDIR/lib/libbrew$LIBNAME.a
101+
PKG_LIBS=$(echo $PKG_LIBS | sed "s/-l$LIBNAME /-lbrew$LIBNAME /g")
102+
done
70103
fi
71104
;;
72105
esac
@@ -96,10 +129,10 @@ if test "x${libgit2_ver_ok}" = xno; then
96129
echo "
97130
-----------------------------------------------------------------------
98131

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

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

118-
On macOS, another possibility is to let the configuration
119-
automatically download the libgit2 library from the Homebrew
120-
package manager with:
121-
122-
R CMD INSTALL git2r-.tar.gz --configure-vars='autobrew=yes'
123-
or
124-
R CMD INSTALL git2r/ --configure-vars='autobrew=yes'
125-
or
126-
install.packages('git2r', type='source', configure.vars='autobrew=yes')
127-
128151
-----------------------------------------------------------------------
129152

130153
"

0 commit comments

Comments
 (0)