Debian Codegraph @

configure

raw symbols SCIP
1 #!/bin/sh
2 # Anticonf (tm) script by Jeroen Ooms (2025)
3 # This script will query 'pkg-config' for the required cflags and ldflags.
4 # If pkg-config is unavailable or does not find the library, try setting
5 # INCLUDE_DIR and LIB_DIR manually via e.g:
6 # R CMD INSTALL --configure-vars='INCLUDE_DIR=/.../include LIB_DIR=/.../lib'
7
8 # Library settings
9 PKG_CONFIG_NAME="libcurl"
10 PKG_DEB_NAME="libcurl4-openssl-dev"
11 PKG_RPM_NAME="libcurl-devel"
12 PKG_APK_NAME="curl-dev"
13 PKG_TEST_HEADER="<curl/curl.h>"
14 PKG_LIBS="-lcurl"
15 PKG_CFLAGS=""
16
17 #export PKG_CONFIG_PATH="/opt/homebrew/opt/curl/lib/pkgconfig"
18
19 # (Jan 2025) MacOS ships a very buggy libcurl 8.7.1 so we avoid this until apple updates it
20 # See: https://github.com/jeroen/curl/issues/376
21 if [ `uname` = "Darwin" ]; then
22 MINVERSION="--atleast-version=8.8.0"
23 fi
24
25 # Use pkg-config if available
26 pkg-config ${PKG_CONFIG_NAME} ${MINVERSION} 2>/dev/null
27 if [ $? -eq 0 ]; then
28 PKGCONFIG_CFLAGS=`pkg-config --cflags ${PKG_CONFIG_NAME}`
29 case "$PKGCONFIG_CFLAGS" in
30 *CURL_STATICLIB*) PKGCONFIG_LIBS=`pkg-config --libs --static ${PKG_CONFIG_NAME}`;;
31 *) PKGCONFIG_LIBS=`pkg-config --libs ${PKG_CONFIG_NAME}`;;
32 esac
33 fi
34
35 # Note that cflags may be empty in case of success
36 if [ "$CURL_CFLAGS" ] || [ "$CURL_LIBS" ]; then
37 echo "Found CURL_CFLAGS and/or CURL_LIBS!"
38 PKG_CFLAGS="$CURL_CFLAGS"
39 PKG_LIBS="$CURL_LIBS"
40 elif [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]; then
41 echo "Found INCLUDE_DIR and/or LIB_DIR!"
42 PKG_CFLAGS="-I$INCLUDE_DIR $PKG_CFLAGS"
43 PKG_LIBS="-L$LIB_DIR $PKG_LIBS"
44 elif [ "$PKGCONFIG_CFLAGS" ] || [ "$PKGCONFIG_LIBS" ]; then
45 echo "Found pkg-config cflags and libs!"
46 PKG_CFLAGS=${PKGCONFIG_CFLAGS}
47 PKG_LIBS=${PKGCONFIG_LIBS}
48 elif [ `uname` = "Darwin" ]; then
49 # Temporary fix for: https://github.com/jeroen/curl/issues/376
50 curl -sfL "https://autobrew.github.io/scripts/libcurl-macos" > autobrew
51 . ./autobrew
52 fi
53
54 # Find compiler
55 CC=`${R_HOME}/bin/R CMD config CC`
56 CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS`
57 CPPFLAGS=`${R_HOME}/bin/R CMD config CPPFLAGS`
58
59 # For debugging
60 echo "Using PKG_CFLAGS=$PKG_CFLAGS"
61 echo "Using PKG_LIBS=$PKG_LIBS"
62
63 # Test configuration
64 echo "#include $PKG_TEST_HEADER" | ${CC} ${CPPFLAGS} ${PKG_CFLAGS} ${CFLAGS} -E -xc - >/dev/null 2>configure.log
65
66 # Customize the error
67 if [ $? -ne 0 ]; then
68 echo "--------------------------- [ANTICONF] --------------------------------"
69 echo "Configuration failed because $PKG_CONFIG_NAME was not found. Try installing:"
70 echo " * deb: $PKG_DEB_NAME (Debian, Ubuntu, etc)"
71 echo " * rpm: $PKG_RPM_NAME (Fedora, CentOS, RHEL)"
72 echo " * apk: $PKG_APK_NAME (Alpine)"
73 echo "If $PKG_CONFIG_NAME is already installed, check that 'pkg-config' is in your"
74 echo "PATH and PKG_CONFIG_PATH contains a $PKG_CONFIG_NAME.pc file. If pkg-config"
75 echo "is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:"
76 echo "R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'"
77 echo "-------------------------- [ERROR MESSAGE] ---------------------------"
78 cat configure.log
79 echo "--------------------------------------------------------------------"
80 exit 1
81 fi
82
83 # Test minimum version
84 ${CC} -E ${CPPFLAGS} ${PKG_CFLAGS} ${CFLAGS} tools/version.c >/dev/null 2>&1
85 if [ $? -ne 0 ]; then
86
87 # On curl < 7.73 (RHEL-8 / Ubuntu 20.04) enable the static library
88 if [ `uname` = "Linux" ]; then
89 echo "Local libcurl is too old. Downloading a static libcurl for legacy Linux..."
90 echo "For alternative solutions see: https://github.com/jeroen/curl/issues/416"
91 curl -sOL "https://github.com/jeroen/curl/releases/download/libcurl-8.14.1/get-curl-linux.sh" && . ./get-curl-linux.sh
92 fi
93
94 # MacOS 13 CRAN builder has MacOS 11.3 SDK
95 # Also for people compiling from source on MacOS 11
96 if [ `uname` = "Darwin" ] && [ -z "$BREWDIR" ] && ${R_HOME}/bin/Rscript --vanilla tools/testversion.R "7.80"; then
97 PKG_CFLAGS="$PKG_CFLAGS -DENABLE_MACOS_POLYFILL"
98 fi
99 fi
100
101 # Write to Makevars
102 sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars
103
104 # Success
105 exit 0