Skip to content

Commit 0697d55

Browse files
committed
configure_fastr: provide basic support to MacOS users that do not use homebrew
(cherry picked from commit 0f1ae54)
1 parent 52c2b7b commit 0697d55

File tree

1 file changed

+155
-79
lines changed

1 file changed

+155
-79
lines changed

com.oracle.truffle.r.native/run/configure_fastr

Lines changed: 155 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -38,50 +38,52 @@ done
3838

3939
function printHelp {
4040
if [[ "$OSTYPE" == "darwin"* ]]; then
41-
echo "usage: configure_fastr [--help] [--configure-etc [--enable-native-compilers-toolchain]] [--gcc-lib-path <path>]"
41+
echo "usage: configure_fastr [--help] [--configure-etc [--enable-native-compilers-toolchain]] [--gcc-lib-path <path>]"
4242
else
43-
echo "usage: configure_fastr [--help] [--configure-etc [--enable-native-compilers-toolchain]]"
44-
fi
43+
echo "usage: configure_fastr [--help] [--configure-etc [--enable-native-compilers-toolchain]]"
44+
fi
4545

46-
echo ""
47-
echo "optional arguments:"
48-
echo " --configure-etc Configure the files in the 'etc' folder. Unless '--enable-native-compilers-toolchain' is specified, the configuration will not affect the 'etc/Makeconf' file to preserve the original compilers toolchain configuration."
49-
echo " --enable-native-compilers-toolchain Include the 'etc/Makefile' file into the configuration. It will replace the original compiler toolchain configuration in 'etc/Makefile' with the native compilers toolchain."
50-
if [[ "$OSTYPE" == "darwin"* ]]; then
46+
echo ""
47+
echo "optional arguments:"
48+
echo " --configure-etc Configure the files in the 'etc' folder. Unless '--enable-native-compilers-toolchain' is specified, the configuration will not affect the 'etc/Makeconf' file to preserve the original compilers toolchain configuration."
49+
echo " --enable-native-compilers-toolchain Include the 'etc/Makefile' file into the configuration. It will replace the original compiler toolchain configuration in 'etc/Makefile' with the native compilers toolchain."
50+
if [[ "$OSTYPE" == "darwin"* ]]; then
5151
echo " --gcc-lib-path <path> Use the <path> to locate the required gfortran libraries."
52-
fi
52+
echo " --macos-no-homebrew Allows the script to proceed even if the target system does not have homebrew"
53+
fi
5354

54-
echo ""
55-
echo "examples:"
56-
echo " * Basic FastR configuration:"
57-
echo ""
58-
echo " configure_fastr"
59-
echo ""
60-
echo " * An advanced FastR configuration with an additional configuration of the 'etc' folder except 'etc/Makefile':"
61-
echo ""
62-
echo " configure_fastr --configure-etc"
63-
echo ""
55+
echo ""
56+
echo "examples:"
57+
echo " * Basic FastR configuration:"
58+
echo ""
59+
echo " configure_fastr"
60+
echo ""
61+
echo " * An advanced FastR configuration with an additional configuration of the 'etc' folder except 'etc/Makefile':"
62+
echo ""
63+
echo " configure_fastr --configure-etc"
64+
echo ""
6465
if [[ "$OSTYPE" == "darwin"* ]]; then
65-
echo " * The most advanced FastR configuration with the complete configuration of the 'etc' folder. It also specifies the GCC path to locate the required libraries:"
66-
echo ""
67-
echo " configure_fastr --configure-etc --enable-native-compilers-toolchain --gcc-lib-path /usr/local/Cellar/gcc\@4.9/4.9.4_1/lib/gcc/4.9/"
66+
echo " * The most advanced FastR configuration with the complete configuration of the 'etc' folder. It also specifies the GCC path to locate the required libraries:"
67+
echo ""
68+
echo " configure_fastr --configure-etc --enable-native-compilers-toolchain --gcc-lib-path /usr/local/Cellar/gcc\@4.9/4.9.4_1/lib/gcc/4.9/"
6869
else
69-
echo " * The most advanced FastR configuration with the complete configuration of the 'etc' folder:"
70-
echo ""
71-
echo " configure_fastr --configure-etc --enable-native-compilers-toolchain"
72-
fi
73-
echo ""
70+
echo " * The most advanced FastR configuration with the complete configuration of the 'etc' folder:"
71+
echo ""
72+
echo " configure_fastr --configure-etc --enable-native-compilers-toolchain"
73+
fi
74+
echo ""
7475
}
7576

7677
GCC_LIB_PATH=""
7778
CONFIGURE_ARGS=""
7879
CONFIGURE_ETC=0
7980
CONFIGURE_NATIVE_TOOLCHAIN=0
81+
NO_BREW=0
8082
while [[ $# -gt 0 ]]; do
8183
case $1 in
8284
--help)
83-
printHelp
84-
exit 0
85+
printHelp
86+
exit 0
8587
;;
8688
--gcc-lib-path)
8789
shift
@@ -90,6 +92,9 @@ while [[ $# -gt 0 ]]; do
9092
--configure-etc)
9193
CONFIGURE_ETC=1
9294
;;
95+
--macos-no-homebrew)
96+
NO_BREW=1
97+
;;
9398
--enable-native-compilers-toolchain)
9499
CONFIGURE_NATIVE_TOOLCHAIN=1
95100
CONFIGURE_ARGS="$CONFIGURE_ARGS $1"
@@ -147,52 +152,123 @@ fi
147152
echo "The basic configuration of FastR was successfull."
148153
fi
149154
elif [[ "$OSTYPE" == "darwin"* ]]; then
150-
151-
GCC_DARWIN_HOME=/usr/local/Cellar/gcc@4.9/4.9.4_1/lib/gcc/4.9
152-
153-
if [ -d "$GCC_DARWIN_HOME" ] ; then
154-
echo "gcc 4.9 installation found."
155-
155+
156+
if which brew; then
157+
GCC_DARWIN_HOME=/usr/local/Cellar/gcc@4.9/4.9.4_1/lib/gcc/4.9
158+
159+
if [ -d "$GCC_DARWIN_HOME" ] ; then
160+
echo "gcc 4.9 installation found."
161+
162+
cd -P "$( dirname "$source" )/../lib"
163+
# correct paths on Mac OSX
164+
GFORTRAN_LIBRARIES="libgfortran.3.dylib libquadmath.0.dylib libgomp.1.dylib libgcc_s.1.dylib"
165+
TARGET_LIBRARIES="`find ../library/* | grep "\(\.dylib\|\.so\)$"` `find * | grep "\(\.dylib\|\.so\)$"`"
166+
for GFORTRAN_LIB in $GFORTRAN_LIBRARIES
167+
do
168+
LIB_LOCATION="${GCC_DARWIN_HOME}/${GFORTRAN_LIB}"
169+
for TARGET_LIB in $TARGET_LIBRARIES
170+
do
171+
# don't look at symlinks
172+
if [ ! -L "${TARGET_LIB}" ] ; then
173+
# grep for the current path of this gfortran library in this library's linking info
174+
CURRENT_LIB_NAME=`otool -L ${TARGET_LIB} | grep -o "\t.*${GFORTRAN_LIB}"`
175+
if [ ! -z "$CURRENT_LIB_NAME" ] ; then
176+
if [ "$CURRENT_LIB_NAME" != "$LIB_LOCATION" ] ; then
177+
# change to the new location
178+
echo "changing path to ${GFORTRAN_LIB} in ${TARGET_LIB} to $LIB_LOCATION"
179+
install_name_tool -change $CURRENT_LIB_NAME $LIB_LOCATION ${TARGET_LIB}
180+
fi
181+
fi
182+
fi
183+
done
184+
done
185+
else
186+
echo "No Homebrew gcc 4.9 installation found."
187+
echo "Please ensure that you have gcc installed on your system using the homebrew command:"
188+
echo " brew install gcc@4.9"
189+
190+
HOMEBREW_PREFIX_OUT=`brew config | grep HOMEBREW_PREFIX`
191+
HOMEBREW_PREFIX=${HOMEBREW_PREFIX_OUT##*: }
192+
if [[ "$HOMEBREW_PREFIX" != "/usr/local" ]]; then
193+
echo "Your Homebrew uses other than the default installation directory prefix (i.e. /usr/local)."\
194+
"Since FastR assumes the default prefix, use the following command to create a symbolic link to your Homebrew installations:"
195+
echo " sudo ln -s $HOMEBREW_PREFIX/Cellar /usr/local/Cellar"
196+
fi
197+
198+
exit 1
199+
fi
200+
else # not "which brew"
201+
if [ $NO_BREW = 0 ]; then
202+
echo "FastR depends on GFortran 3 runtime libraries."
203+
echo "It appears that this system does not use the homebrew package manager."
204+
echo "We suggest to use homebrew and install the necessary dependencies with:"
205+
echo " brew install gcc@4.9"
206+
echo "If you want to use another installation of GFortran 3 libraries, re-run this script with '--macos-no-homebrew'."
207+
exit 2
208+
fi
209+
156210
cd -P "$( dirname "$source" )/../lib"
157-
# correct paths on Mac OSX
158-
GFORTRAN_LIBRARIES="libgfortran.3.dylib libquadmath.0.dylib libgomp.1.dylib libgcc_s.1.dylib"
211+
# correct paths on Mac OSX
212+
GFORTRAN_LIBRARIES="libgfortran.3.dylib libquadmath.0.dylib libgomp.1.dylib libgcc_s.1.dylib"
213+
# This allows determining if all libraries were found after the main loop
214+
GFORTRAN_LIBRARIES_CHECK="libgfortran libquadmath libgomp libgcc_s"
215+
GFORTRAN_LOCATIONS="$GCC_LIB_PATH /opt/local/lib /opt/local/lib/libgcc /usr/local/gfortran/lib"
159216
TARGET_LIBRARIES="`find ../library/* | grep "\(\.dylib\|\.so\)$"` `find * | grep "\(\.dylib\|\.so\)$"`"
217+
FOUND=""
218+
FOUND_FULL=""
219+
LAST_FOUND=""
160220
for GFORTRAN_LIB in $GFORTRAN_LIBRARIES
161221
do
162-
LIB_LOCATION="${GCC_DARWIN_HOME}/${GFORTRAN_LIB}"
163-
for TARGET_LIB in $TARGET_LIBRARIES
164-
do
165-
# don't look at symlinks
166-
if [ ! -L "${TARGET_LIB}" ] ; then
167-
# grep for the current path of this gfortran library in this library's linking info
168-
CURRENT_LIB_NAME=`otool -L ${TARGET_LIB} | grep -o "\t.*${GFORTRAN_LIB}"`
169-
if [ ! -z "$CURRENT_LIB_NAME" ] ; then
170-
if [ "$CURRENT_LIB_NAME" != "$LIB_LOCATION" ] ; then
171-
# change to the new location
172-
echo "changing path to ${GFORTRAN_LIB} in ${TARGET_LIB} to $LIB_LOCATION"
173-
install_name_tool -change $CURRENT_LIB_NAME $LIB_LOCATION ${TARGET_LIB}
174-
fi
175-
fi
176-
fi
177-
done
222+
# Remove the 'dylib' extension
223+
GFORTRAN_LIB_BASE=${GFORTRAN_LIB%.*}
224+
# Remove the number extension
225+
GFORTRAN_LIB_BASE=${GFORTRAN_LIB_BASE%.*}
226+
if [ "$LAST_FOUND" = "$GFORTRAN_LIB_BASE" ] ; then
227+
# A previous version of the current library has already been found
228+
echo "skipping $GFORTRAN_LIB"
229+
continue;
230+
fi
231+
for LOCATION in $GFORTRAN_LOCATIONS
232+
do
233+
if test -f "${LOCATION}/${GFORTRAN_LIB}"; then
234+
LIB_LOCATION="${LOCATION}/${GFORTRAN_LIB}"
235+
FOUND="$FOUND $GFORTRAN_LIB_BASE"
236+
LAST_FOUND=$GFORTRAN_LIB_BASE
237+
echo "${GFORTRAN_LIB} found at ${LIB_LOCATION}"
238+
for TARGET_LIB in $TARGET_LIBRARIES
239+
do
240+
# don't look at symlinks
241+
if [ ! -L "${TARGET_LIB}" ] ; then
242+
# grep for the current path of this gfortran library in this library's linking info
243+
CURRENT_LIB_NAME=`otool -L ${TARGET_LIB} | grep -o "\t.*${GFORTRAN_LIB_BASE}[^ ]*"`
244+
if [ ! -z "$CURRENT_LIB_NAME" ] ; then
245+
if [ "$CURRENT_LIB_NAME" != "$LIB_LOCATION" ] ; then
246+
# change to the new location
247+
echo "changing path to ${GFORTRAN_LIB} in ${TARGET_LIB} to $LIB_LOCATION"
248+
FOUND_FULL="${FOUND_FULL}\n ${LIB_LOCATION}"
249+
install_name_tool -change $CURRENT_LIB_NAME $LIB_LOCATION ${TARGET_LIB}
250+
fi
251+
fi
252+
fi
253+
done
254+
break
255+
fi
256+
done
178257
done
179-
180-
else
181-
echo "No Homebrew gcc 4.9 installation found."
182-
echo "Please ensure that you have gcc installed on your system using the homebrew command:"
183-
echo " brew install gcc@4.9"
184-
185-
HOMEBREW_PREFIX_OUT=`brew config | grep HOMEBREW_PREFIX`
186-
HOMEBREW_PREFIX=${HOMEBREW_PREFIX_OUT##*: }
187-
if [[ "$HOMEBREW_PREFIX" != "/usr/local" ]]; then
188-
echo "Your Homebrew uses other than the default installation directory prefix (i.e. /usr/local)."\
189-
"Since FastR assumes the default prefix, use the following command to create a symbolic link to your Homebrew installations:"
190-
echo " sudo ln -s $HOMEBREW_PREFIX/Cellar /usr/local/Cellar"
191-
fi
192-
193-
exit 1
194-
fi
195258

259+
if [ "$FOUND" != " $GFORTRAN_LIBRARIES_CHECK" ] ; then
260+
echo "From expected libraries '$GFORTRAN_LIBRARIES_CHECK' found only '$FOUND'."
261+
echo "Please ensure that you have GFortran 3 installed on your system."
262+
echo "We suggest to use homebrew and install the necessary dependencies with:"
263+
echo " brew install gcc@4.9"
264+
echo "If the GFortran 3 runtime libraries are installed in a non-standard location, you can specify that location using the '--gcc-lib-path' parameter."
265+
exit 1
266+
else
267+
echo "Succesfully updated FastR installation to use the GFortran 3 system libraries."
268+
FASTR_HOME=$(cd ..; pwd -P )
269+
echo "The fortran compiler flags in $FASTR_HOME/etc/Makeconf (variable FLIBS) were not updated and must be adjusted manually!"
270+
fi
271+
fi # which brew
196272
else
197273
echo "Unknown operating system."
198274
echo "FastR may still work."
@@ -207,16 +283,16 @@ fi
207283
res=$?
208284
if [[ $res != 0 ]]; then
209285
echo "The configuration step failed."
210-
echo "The log was saved into ${PWD}/configure.log"
211-
echo "FastR may still work, but compilation of some R packages may fail"
212-
exit 1
213-
fi
214-
ed Makeconf < edMakeconf.etc > /dev/null 2>/dev/null
215-
export R_DEFAULT_PACKAGES=base
216-
R_LIBS_USER=`"../bin/R" --slave -e 'cat(path.expand(Sys.getenv("R_LIBS_USER")))'`
217-
echo "Creating user specific library directory: $R_LIBS_USER"
218-
mkdir -p "$R_LIBS_USER"
219-
echo "DONE"
286+
echo "The log was saved into ${PWD}/configure.log"
287+
echo "FastR may still work, but compilation of some R packages may fail"
288+
exit 1
289+
fi
290+
ed Makeconf < edMakeconf.etc > /dev/null 2>/dev/null
291+
export R_DEFAULT_PACKAGES=base
292+
R_LIBS_USER=`"../bin/R" --slave -e 'cat(path.expand(Sys.getenv("R_LIBS_USER")))'`
293+
echo "Creating user specific library directory: $R_LIBS_USER"
294+
mkdir -p "$R_LIBS_USER"
295+
echo "DONE"
220296
fi
221297

222298
)

0 commit comments

Comments
 (0)