-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgalacticusInstallMacOS.sh
More file actions
executable file
·240 lines (214 loc) · 11.1 KB
/
Copy pathgalacticusInstallMacOS.sh
File metadata and controls
executable file
·240 lines (214 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/usr/bin/env bash
# Script to install all tools and libraries needed for Galacticus, and then build Galacticus itself on MacOS.
# Andrew Benson (09-April-2024)
# NOTE: You will require `sudo` priveleges to use this script, and will be prompted to enter your password (possibly multiple
# times) during installation.
# NOTE: If you receive any prompt asking for a choice, go with the default (i.e. just press "enter").
# NOTE: If you see a pop-up saying ““Terminal” would like to administer your computer. Administration can include modifying
# passwords, networking, and system settings.”, click to approve it.
# WARNING: This script should be considered to be a beta-release. If you experience problems using it, please report these at the
# Galacticus discussion forum:
#
# https://github.com/galacticusorg/galacticus/discussions
# Abort immediately if any command fails (including a failed download or a failure in a pipeline), so that problems such as
# a failed HDF5 download cause the script to exit with an error status right away, rather than surfacing much later as a
# confusing build failure.
set -eo pipefail
# Ensure that XCode developer tools are installed.
if [[ ! $(xcode-select -p) ]]; then
xcode-select --install
fi
export PATH=$PATH:/opt/local/bin:/usr/local/bin
# Point GCC 16's Darwin driver at the active SDK. Without SDKROOT, GCC 16 fails to locate the system headers
# (e.g. <stdlib.h>, <limits.h>) and libraries, so even a trivial compile fails ("C compiler cannot create
# executables"). We resolve the SDK dynamically from the runner's own toolchain, so this tracks whatever SDK is
# current rather than pinning to a fixed version.
export SDKROOT="$(xcrun --show-sdk-path)"
# Determine number of CPUs available.
countCPUs=`sysctl -n hw.ncpu`
# Determine OS version.
os_ver=$(sw_vers -productVersion)
IFS='.' read -r -a ver <<< "$os_ver"
# Select appropriate MacPorts version based on the OS version.
if [[ "${ver}" -eq 11 ]]; then
macportsversion=2.7.1
macportsbase=2.7.1-11-BigSur
elif [[ "${ver}" -eq 12 ]]; then
macportsversion=2.9.1
macportsbase=2.9.1-12-Monterey
elif [[ "${ver}" -eq 13 ]]; then
macportsversion=2.9.1
macportsbase=2.9.1-13-Ventura
elif [[ "${ver}" -eq 14 ]]; then
macportsversion=2.9.1
macportsbase=2.9.1-14-Sonoma
elif [[ "${ver}" -eq 15 ]]; then
macportsversion=2.11.6
macportsbase=2.11.6-15-Sequoia
else
echo Unknown MacOS version: ${os_ver}
exit 1
fi
# Download and install MacPorts.
curl -fL --retry 3 https://github.com/macports/macports-base/releases/download/v${macportsversion}/MacPorts-${macportsbase}.pkg --output MacPorts-${macportsbase}.pkg
sudo installer -pkg ./MacPorts-${macportsbase}.pkg -target /
rm ./MacPorts-${macportsbase}.pkg
# Install GCC 16 via HomeBrew. As of GCC 16.1 the `gcc` formula provides GCC 16, installing version-suffixed
# binaries (`gcc-16`, `g++-16`, `gfortran-16`) into the HomeBrew prefix, which is already on PATH.
#
# The runner images (and many user machines) ship a pre-installed, older `gcc`, so `brew update` is required
# first to refresh the formula index; without it `brew install gcc` reports the stale version as "already
# installed and up-to-date" and GCC 16 is never fetched. We then upgrade an existing `gcc` to 16, or install it
# if it is absent. We branch explicitly on whether the formula is already installed rather than relying on
# `brew upgrade gcc` failing when it is absent, since that emits a noisy "Warning: gcc not installed".
# Remove the untrusted `aws/tap` tap that ships on the GitHub runner images; otherwise `brew update` emits a noisy
# "taps are not trusted" warning. Ignore failure in case the tap is not present (e.g. on a user's machine).
brew untap aws/tap 2>/dev/null || true
brew update
if brew list --formula gcc &>/dev/null; then
brew upgrade gcc
else
brew install gcc
fi
# Install guile v3.0 via MacPorts.
sudo port install guile-3.0
sudo port select --set guile guile-3.0
# Install GSL via MacPorts.
sudo port install gsl
# Install CMake via MacPorts. This is required to build HDF5: the Autotools build system was removed in HDF5 2.0,
# so HDF5 is now built with CMake.
sudo port install cmake
# Install libmatheval v1.1.13 from source.
curl -fL --retry 3 https://github.com/galacticusorg/libmatheval/releases/download/latest/libmatheval-1.1.13.tar.gz --output libmatheval-1.1.13.tar.gz
tar xvfz libmatheval-1.1.13.tar.gz
cd libmatheval-1.1.13
# Patch following the approach used in MacPorts (https://github.com/macports/macports-ports/tree/master/math/libmatheval).
sed -E -i~ s/"#undef HAVE_SCM_T_BITS"/"#define HAVE_SCM_T_BITS 1"/ config.h.in
# Set guile paths following the approach used in MacPorts (https://github.com/macports/macports-ports/tree/master/math/libmatheval).
CC=gcc-16 PKG_CONFIG=/opt/local/bin/pkg-config GUILE=/opt/local/bin/guile-3.0 GUILE_CONFIG=/opt/local/bin/guile-config-3.0 GUILE_TOOLS=/opt/local/bin/guile-tools-3.0 ./configure --prefix=/usr/local
make -j${countCPUs}
sudo make install
cd ..
rm -rf libmatheval-1.1.13.tar.gz libmatheval-1.1.13
# Install qhull from source.
curl -fL --retry 3 http://www.qhull.org/download/qhull-2020-src-8.0.2.tgz --output qhull-2020-src-8.0.2.tgz
tar xvfz qhull-2020-src-8.0.2.tgz
cd qhull-2020.2
make -j${countCPUs} CC=gcc-16 CXX=g++-16
sudo make install
cd ..
rm -rf qhull-2020-src-8.0.2.tgz qhull-2020.2
# Install hdf5 from source. HDF5 2.x uses CMake (the Autotools build system was removed in HDF5 2.0). Deprecated symbols
# are disabled to build against the strict HDF5 2.x API surface; Galacticus caps its own output format at the HDF5 1.14
# version so that output remains readable by HDF5 1.14 readers.
curl -fL --retry 3 https://github.com/HDFGroup/hdf5/releases/download/2.1.0/hdf5-2.1.0.tar.gz --output hdf5-2.1.0.tar.gz
tar -vxzf hdf5-2.1.0.tar.gz
cd hdf5-2.1.0
# Patch files to ensure we include sys/syslimits.h which defines PATH_MAX
sed -E -i~ 's/^(# *include +<limits\.h>.*)$/\1\n#include <sys\/syslimits.h>\n/' src/H5private.h src/H5public.h
# Work around an upstream typo in HDF5 2.1.0: config/lt_vers.am declares the high-level Fortran shared-library interface
# version as `LT_HL_F_VERS_INTERFACE1` (stray trailing `1`), so the CMake build emits an empty dylib compatibility version
# (`.0.0`) for libhdf5_hl_f90cstub, which the newer macOS linker (ld-prime on Apple Silicon / macOS 14+) rejects. Correct
# the variable name so the compatibility version becomes `320.0.0`.
sed -i~ 's/LT_HL_F_VERS_INTERFACE1/LT_HL_F_VERS_INTERFACE/' config/lt_vers.am
cmakeExtraFlags=()
if [[ "${ver}" -eq 13 ]]; then
# On MacOS 13 there is an issue with the linker no longer supporting the '-commons' flag, so force use of the classic linker
# (https://www.scivision.dev/xcode-ld_classic/).
cmakeExtraFlags=(-DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS -Wl,-ld_classic" -DCMAKE_SHARED_LINKER_FLAGS="$LDFLAGS -Wl,-ld_classic" -DCMAKE_MODULE_LINKER_FLAGS="$LDFLAGS -Wl,-ld_classic")
elif [[ "${ver}" -eq 14 ]]; then
HDF5CFLAGS=-I/Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk/usr/include
# On MacOS 14 the 'sys/cdefs.h' header file contains pre-processor code which is not parseable by GCC. As it is
# Clang-specific, we just make a copy of this file and destroy the problematic code.
mkdir sys
cp /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/sys/cdefs.h sys/
sed -E -i~ s/"clang::"/"clang"/ sys/cdefs.h
HDF5CFLAGS="-I`pwd` ${HDF5CFLAGS}"
cmakeExtraFlags=(-DCMAKE_C_FLAGS="${HDF5CFLAGS}")
fi
# HDF5_BUILD_WITH_INSTALL_NAME=ON gives the installed dylibs absolute install_names (/usr/local/lib/...) rather than CMake's
# default @rpath, so an executable linked against them records absolute paths and dyld can load libhdf5*.dylib at run time
# without needing an rpath entry (matching the Autotools HDF5 1.14 behaviour).
cmake -S . -B build -G "Unix Makefiles" \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=gcc-16 \
-DCMAKE_CXX_COMPILER=g++-16 \
-DCMAKE_Fortran_COMPILER=gfortran-16 \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_STATIC_LIBS=ON \
-DBUILD_TESTING=OFF \
-DHDF5_BUILD_FORTRAN=ON \
-DHDF5_BUILD_HL_LIB=ON \
-DHDF5_BUILD_CPP_LIB=OFF \
-DHDF5_BUILD_TOOLS=ON \
-DHDF5_BUILD_EXAMPLES=OFF \
-DHDF5_ENABLE_PARALLEL=OFF \
-DHDF5_ENABLE_ZLIB_SUPPORT=ON \
-DHDF5_ENABLE_SZIP_SUPPORT=OFF \
-DHDF5_ENABLE_DEPRECATED_SYMBOLS=OFF \
-DHDF5_ENABLE_NONSTANDARD_FEATURE_FLOAT16=OFF \
-DHDF5_BUILD_WITH_INSTALL_NAME=ON \
-DHDF5_DEFAULT_API_VERSION=v200 \
"${cmakeExtraFlags[@]}"
cmake --build build -j${countCPUs}
sudo cmake --install build
cd ..
rm -rf hdf5-2.1.0 hdf5-2.1.0.tar.gz
# Install FoX v4.1.4 from source.
curl -fL --retry 3 https://github.com/galacticusorg/fox/archive/refs/tags/v4.1.4.tar.gz --output FoX-4.1.4.tar.gz
tar xvfz FoX-4.1.4.tar.gz
cd fox-4.1.4
FC=gfortran-16 ./configure --prefix=/usr/local
make -j${countCPUs}
sudo make install
cd ..
rm -rf fox-4.1.4 FoX-4.1.4.tar.gz
# Install FFTW v3.3.4 from source.
curl -fL --retry 3 ftp://ftp.fftw.org/pub/fftw/fftw-3.3.4.tar.gz --output fftw-3.3.4.tar.gz
tar xvfz fftw-3.3.4.tar.gz
cd fftw-3.3.4
F77=gfortran-16 CC=gcc-16 ./configure --prefix=/usr/local
make -j${countCPUs}
sudo make install
cd ..
rm -rf fftw-3.3.4 fftw-3.3.4.tar.gz
# Install ANN from source.
curl -fL --retry 3 http://www.cs.umd.edu/~mount/ANN/Files/1.1.2/ann_1.1.2.tar.gz --output ann_1.1.2.tar.gz
tar xvfz ann_1.1.2.tar.gz
cd ann_1.1.2
sed -E -i~ s/"C\+\+ = g\+\+"/"C\+\+ = g\+\+\-16"/ Make-config
# ANN's ann_test.cpp uses an `istream >> char*` idiom that newer C++ standards no longer match against any operator>>
# overload — force -std=gnu++17 to keep it accepted. We pick gnu++17 over c++17 because the strict-ISO mode triggered
# by c++17 sets __STRICT_ANSI__, which causes the macOS SDK headers to hide non-strict declarations.
sed -E -i~ s,"CFLAGS = -O3","CFLAGS = -O3 -std=gnu++17", Make-config
make macosx-g++
if [ $? -ne 0 ]; then
exit 1
fi
sudo cp bin/* /usr/local/bin/.
sudo cp lib/* /usr/local/lib/.
sudo cp -R include/* /usr/local/include/.
# Install Python 3 (with pip) via MacPorts. This is needed to install Galacticus' Python build dependencies.
sudo port install python312 py312-pip
sudo port select --set python3 python312
sudo port select --set pip3 pip312
# Clone the Galacticus repository.
git clone https://github.com/galacticusorg/galacticus.git
# Create a Python virtual environment and install Galacticus' Python build dependencies (declared in pyproject.toml).
/opt/local/bin/python3.12 -m venv galacticus/python-venv
source galacticus/python-venv/bin/activate
pip install -e galacticus
# Build Galacticus.
cd galacticus
export GALACTICUS_EXEC_PATH=`pwd`
export FCCOMPILER=gfortran-16
export CCOMPILER=gcc-16
export CPPCOMPILER=g++-16
export GALACTICUS_FCFLAGS="-fintrinsic-modules-path /usr/local/include -fintrinsic-modules-path /usr/local/finclude -L/usr/local/lib -L/opt/local/lib"
if [[ "${ver}" -eq 13 ]]; then
export GALACTICUS_FCFLAGS="$GALACTICUS_FCFLAGS -Wl,-ld_classic"
fi
export GALACTICUS_CFLAGS="-I/usr/local/include -I/opt/local/include"
export GALACTICUS_CPPFLAGS="-I/usr/local/include -I/opt/local/include"
make -j${countCPUs} Galacticus.exe