1717# (Thus reducing code duplication)
1818
1919SCRIPTPATH=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
20+ SPECIFIC_OSES_SUPPORTED=" ubuntu-18.04, ubuntu-20.04, ubuntu-22.04, centos-7, osx"
2021
2122# include echo.sh
2223. $SCRIPTPATH /echo.sh
@@ -58,6 +59,29 @@ function DetectOs {
5859 fi
5960}
6061
62+ function DetectOs2 {
63+ # detect operating system
64+ if [ ` uname` = " Linux" ]; then
65+ # linux
66+ PROCVERSION=$( cat /proc/version)
67+ if echo " $PROCVERSION " | grep -Eiq ' Red Hat' ; then
68+ echo rhel;
69+ elif echo " $PROCVERSION " | grep -Eiq ' debian|buntu|mint|eepin' ; then
70+ echo debian;
71+ elif echo " $PROCVERSION " | grep -Eiq ' SUSE|suse' ; then
72+ echo suse;
73+ else
74+ echo other_distro;
75+ fi
76+ elif [ ` uname` = " Darwin" ]; then
77+ # macOS
78+ echo osx
79+ else
80+ echo " ERROR: Operating system ` uname` is not supported."
81+ exit 1
82+ fi
83+ }
84+
6185# This function checks if the given operating system is supported. If not, it
6286# prints an error message, a list of supported systems; and exits the script.
6387# Arguments:
@@ -71,10 +95,18 @@ function CheckOsSupported {
7195
7296 local BDM_INSTALL_SRC=$1
7397 local BDM_OS=$2
74-
75- local BDM_INSTALL_OS_SRC=$BDM_INSTALL_SRC /$BDM_OS
76-
77- if [ ! -d " $BDM_INSTALL_OS_SRC " ]; then
98+ local BDM_INSTALL_OS_SRC=" "
99+ local SPECIFIC_BDM_OS=$( DetectOs)
100+
101+ if echo " $SPECIFIC_OSES_SUPPORTED " | grep -Eiq " $SPECIFIC_BDM_OS " ; then
102+ if [ " $BDM_OS " == " osx" ]; then
103+ BDM_INSTALL_OS_SRC=$BDM_INSTALL_SRC /$BDM_OS /common
104+ else
105+ BDM_INSTALL_OS_SRC=$BDM_INSTALL_SRC /$BDM_OS /$SPECIFIC_BDM_OS
106+ fi
107+ elif [ " $BDM_OS " == " osx" ] || [ " $BDM_OS " == " rhel" ] || [ " $BDM_OS " == " debian" ] || [ " $BDM_OS " == " suse" ] ; then
108+ BDM_INSTALL_OS_SRC=$BDM_INSTALL_SRC /$BDM_OS /common
109+ else
78110 echo " ERROR: This operating system (${BDM_OS} ) is not supported"
79111 echo " Supported operating systems are: "
80112 pushd $BDM_INSTALL_SRC > /dev/null
@@ -108,12 +140,27 @@ function CompileListOfPackages {
108140 local BDM_INSTALL_SRC=" $2 "
109141 local LOCAL_OS=$3
110142
143+ local SPECIFIC_BDM_OS=$( DetectOs)
144+ local BDM_OS=$( DetectOs2)
111145 # The list of packages on Ubuntu 20.04 is identical to Ubuntu 18.04
112- if [ $LOCAL_OS == " ubuntu-20.04" ]; then
113- LOCAL_OS =" ubuntu-18.04"
146+ if [ $SPECIFIC_BDM_OS == " ubuntu-20.04" ]; then
147+ SPECIFIC_BDM_OS =" ubuntu-18.04"
114148 fi
115149
116- local BDM_INSTALL_OS_SRC=$BDM_INSTALL_SRC /$LOCAL_OS
150+ local BDM_INSTALL_OS_SRC=" "
151+
152+ if echo " $SPECIFIC_OSES_SUPPORTED " | grep -Eiq " $SPECIFIC_BDM_OS " ; then
153+ if [ " $BDM_OS " == " osx" ]; then
154+ BDM_INSTALL_OS_SRC=$BDM_INSTALL_SRC /$BDM_OS /common
155+ else
156+ BDM_INSTALL_OS_SRC=$BDM_INSTALL_SRC /$BDM_OS /$SPECIFIC_BDM_OS
157+ fi
158+ elif [ " $BDM_OS " == " osx" ] || [ " $BDM_OS " == " rhel" ] || [ " $BDM_OS " == " debian" ] || [ " $BDM_OS " == " suse" ]; then
159+ BDM_INSTALL_OS_SRC=$BDM_INSTALL_SRC /$BDM_OS /common
160+ else
161+ echo " ERROR: This operating system (${BDM_OS} ) is not supported"
162+ exit 1;
163+ fi
117164
118165 BDM_PKG_LIST=" "
119166 if [ $1 == " all" ]; then
@@ -179,7 +226,65 @@ function CleanBuild {
179226 else
180227 mkdir -p $BUILD_DIR
181228 fi
229+ cd $BDM_PROJECT_DIR
230+ BDM_PROJECT_DIR_2=$( pwd)
182231 cd $BUILD_DIR
232+
233+ CLEAN_BUILD_OS=$( DetectOs2)
234+
235+ GCC_VER=$( gcc --version | grep gcc) || true
236+ # GCC_VER=$(gcc --version | grep gcc | grep -oE ' |\S+' | awk '{print $NF}' | cut -d '.' -f 1-2)
237+ if [ -n " ${GCC_VER} " ]; then
238+ read -ra tokens <<< $GCC_VER
239+ result=()
240+ current_token=" "
241+ for token in " ${tokens[@]} " ; do
242+ if [[ -n $current_token ]]; then
243+ current_token+=" $token "
244+ if [[ $current_token == * ' )' ]]; then
245+ result+=(" $current_token " )
246+ current_token=" "
247+ fi
248+ else
249+ if [[ $token == ' (' * && $token != * ' )' ]]; then
250+ current_token=" $token "
251+ else
252+ result+=(" $token " )
253+ fi
254+ fi
255+ done
256+ if [[ -n $current_token ]]; then
257+ result+=(" $current_token " )
258+ fi
259+ GCC_VER=${result[2]}
260+ GCC_VER=$( echo $GCC_VER | cut -d ' .' -f 1-2)
261+ fi
262+ if [ " $CLEAN_BUILD_OS " != " osx" ]; then
263+ if [ -z " ${GCC_VER} " ] || [ ` echo " $GCC_VER >= 12" | bc -q` -ne 0 ] || [ ` echo " $GCC_VER < 9" | bc -q` -ne 0 ]; then
264+
265+
266+ if $( command -v gcc-11 > /dev/null) && $( command -v g++-11 > /dev/null) && $( command -v gfortran-11 > /dev/null) ; then
267+
268+ echo " ******************************************************************"
269+ echo " Found suitable gcc version installed (gcc-11) via your
270+ distribution's package manager.
271+ Using that."
272+ echo " ******************************************************************" ;
273+
274+ export CC=gcc-11
275+ export CXX=g++-11
276+ export FC=gfortran-11
277+ export OMPI_CC=gcc-11
278+ export OMPI_CXX=g++-11
279+ export OMPI_FC=gfortran-11
280+ export QMAKE_CC=gcc-11
281+ export QMAKE_CXX=g++-11
282+ export LINK=g++-11
283+
284+ fi
285+ fi
286+ fi
287+
183288 echo " CMAKEFLAGS $BDM_CMAKE_FLAGS "
184289 cmake $BDM_CMAKE_FLAGS ..
185290 make -j$( CPUCount) && make install
@@ -217,15 +322,28 @@ function CallOSSpecificScript {
217322 shift
218323 local BDM_SCRIPT_FILE=" $1 "
219324 shift
220- local BDM_LOCAL_OS=$( DetectOs)
325+ local SPECIFIC_BDM_OS=$( DetectOs)
326+ local BDM_OS=$( DetectOs2)
221327 local BDM_SCRIPT_ARGUMENTS=$@
222328 local BDM_INSTALL_SRC=$BDM_PROJECT_DIR /util/installation
223329
224330 # detect os
225- local BDM_INSTALL_OS_SRC=$BDM_INSTALL_SRC /$BDM_LOCAL_OS
331+ local BDM_INSTALL_OS_SRC=" "
332+
333+ if echo " $SPECIFIC_OSES_SUPPORTED " | grep -Eiq " $SPECIFIC_BDM_OS " ; then
334+ if [ " $BDM_OS " == " osx" ]; then
335+ BDM_INSTALL_OS_SRC=$BDM_INSTALL_SRC /$BDM_OS /common
336+ else
337+ BDM_INSTALL_OS_SRC=$BDM_INSTALL_SRC /$BDM_OS /$SPECIFIC_BDM_OS
338+ fi
339+ elif [ " $BDM_OS " == " osx" ] || [ " $BDM_OS " == " rhel" ] || [ " $BDM_OS " == " debian" ] || [ " $BDM_OS " == " suse" ]; then
340+ BDM_INSTALL_OS_SRC=$BDM_INSTALL_SRC /$BDM_OS /common
341+ else
342+ echo " ERROR: This operating system (${BDM_OS} ) is not supported"
343+ exit 1;
344+ fi
226345
227346 # check if this system is supported
228- CheckOsSupported $BDM_INSTALL_SRC $BDM_LOCAL_OS
229347
230348 # check if script exists for the detected OS
231349 local BDM_SCRIPTPATH=$BDM_INSTALL_OS_SRC /$BDM_SCRIPT_FILE
@@ -390,7 +508,7 @@ function EchoFinishInstallation {
390508 EchoNewStep " For other shells, or for more information, see:"
391509 EchoNewStep " ${BDM_ECHO_UNDERLINE} https://biodynamo.org/docs/userguide/first_steps/"
392510 echo
393- # any warnings about users' post-install shell
511+ # any warnings about users' post-install shell
394512 # configuration may be added to the function called below
395513 WarnPossibleBadShellConfigs || true
396514}
0 commit comments