1 | #!/bin/bash |
---|
2 | set -e -u # exit on most (not all!) error codes, and error on unset variables |
---|
3 | |
---|
4 | # Installs xios |
---|
5 | # Rewritten 02/2024 A. Barral |
---|
6 | |
---|
7 | function read_args { |
---|
8 | ## Defaults |
---|
9 | install_dir=$(pwd) |
---|
10 | |
---|
11 | xios_branch="2.6" |
---|
12 | xios_rev="2568" |
---|
13 | arch="local" |
---|
14 | make_j="8" |
---|
15 | # Not inputs |
---|
16 | hdf5_home=$(dirname "$(dirname "$(readlink -f "$(which h5pcc)")")") |
---|
17 | mpi_home=$(dirname "$(dirname "$(readlink -f "$(which mpif90)")")") |
---|
18 | |
---|
19 | while (($# > 0)); do |
---|
20 | case $1 in |
---|
21 | "-h") cat <<eof |
---|
22 | $0 [ -prefix path ] where (path) to install (default: $install_dir) |
---|
23 | [ -branch branch] XIOS branch trunk|2.5|2.6 (default: $xios_branch) |
---|
24 | [ -rev number ] XIOS revision (default: $xios_rev) |
---|
25 | [ -arch ARCH ] Use ARCH file (provided by XIOS) (default: make/use a local arch file) |
---|
26 | [ -make_j N ] Number of procs for compilation |
---|
27 | eof |
---|
28 | exit;; |
---|
29 | "-prefix") install_dir=$2; shift; shift;; |
---|
30 | "-branch") xios_branch=$2; shift; shift;; |
---|
31 | "-rev") xios_rev=$2; shift; shift;; |
---|
32 | "-arch") arch=$2; shift; shift;; |
---|
33 | "-make_j") make_j=$2; shift; shift;; |
---|
34 | *) echo "Error, bad argument $1"; $0 -h; exit |
---|
35 | esac |
---|
36 | done |
---|
37 | } |
---|
38 | |
---|
39 | function download_xios { |
---|
40 | # Install directory (get full path) |
---|
41 | mkdir -p "$install_dir" |
---|
42 | install_dir=$(cd "$install_dir" || exit 1; pwd -P) |
---|
43 | |
---|
44 | local xios_http |
---|
45 | case $xios_branch in |
---|
46 | "trunk") xios_http="http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS/trunk";; |
---|
47 | "2.5") xios_http="http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS/branchs/xios-2.5";; |
---|
48 | "2.6") xios_http="http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS2/branches/xios-2.6";; |
---|
49 | *) echo "Error, bad argument for -branch ! Did not expect $xios_branch"; exit 1;; |
---|
50 | esac |
---|
51 | |
---|
52 | cd "$install_dir" || exit 1 |
---|
53 | svn co --revision "$xios_rev" "$xios_http" XIOS |
---|
54 | } |
---|
55 | |
---|
56 | function create_local_arch { |
---|
57 | cd "$install_dir/XIOS/arch" || exit 1 |
---|
58 | |
---|
59 | cat <<eof > arch-local.env |
---|
60 | export MPI_LIB="-L${mpi_home}/lib -lmpi" |
---|
61 | |
---|
62 | export NETCDFC_INC="\$(nc-config --includedir)" |
---|
63 | export NETCDFC_LIB="\$(nc-config --libdir)" |
---|
64 | |
---|
65 | export NETCDFF_INC="\$(nf-config --includedir)" |
---|
66 | export NETCDFF_LIB="\$(nf-config --prefix)/lib" |
---|
67 | |
---|
68 | export NETCDFCXX_INC="\$(ncxx4-config --includedir)" |
---|
69 | export NETCDFCXX_LIB="\$(ncxx4-config --libdir)" |
---|
70 | eof |
---|
71 | |
---|
72 | cat <<eof > arch-local.fcm |
---|
73 | %CCOMPILER "$(which mpicc)" |
---|
74 | %FCOMPILER "$(which mpif90)" |
---|
75 | %LINKER "$(which mpif90)" |
---|
76 | |
---|
77 | %BASE_CFLAGS -w -std=c++11 -D__XIOS_EXCEPTION |
---|
78 | %PROD_CFLAGS -O3 -D BOOST_DISABLE_ASSERTS |
---|
79 | %DEV_CFLAGS -g -O2 |
---|
80 | %DEBUG_CFLAGS -g -DBZ_DEBUG |
---|
81 | |
---|
82 | %BASE_FFLAGS -D__NONE__ -ffree-line-length-none |
---|
83 | %PROD_FFLAGS -O3 |
---|
84 | %DEV_FFLAGS -g -O2 |
---|
85 | %DEBUG_FFLAGS -g |
---|
86 | |
---|
87 | %BASE_INC -D__NONE__ |
---|
88 | %BASE_LD -lstdc++ -Wl,-rpath=${mpi_home}/lib |
---|
89 | |
---|
90 | %CPP $(which mpicc) -EP |
---|
91 | %FPP cpp -P |
---|
92 | %MAKE make |
---|
93 | eof |
---|
94 | cat <<eof > arch-local.path |
---|
95 | NETCDF_INCDIR="-I\${NETCDFC_INC} -I\${NETCDFF_INC} -I\${NETCDFCXX_INC}" |
---|
96 | NETCDF_LIBDIR="-L\${NETCDFC_LIB} -L\${NETCDFF_LIB} -L\${NETCDFCXX_LIB}" |
---|
97 | NETCDF_LIB="-lnetcdf -lnetcdff -lnetcdf_c++4" |
---|
98 | |
---|
99 | HDF5_INCDIR="-I${hdf5_home}/include" |
---|
100 | HDF5_LIBDIR="-L${hdf5_home}/lib" |
---|
101 | HDF5_LIB="-lhdf5_hl -lhdf5 -lz -lcurl" |
---|
102 | eof |
---|
103 | } |
---|
104 | |
---|
105 | function make_xios { |
---|
106 | cd "$install_dir/XIOS" |
---|
107 | echo "Compiling xios, see $(pwd)/make_xios.out" |
---|
108 | ./make_xios --arch "$arch" --job "$make_j" >make_xios.out 2>&1 |
---|
109 | } |
---|
110 | |
---|
111 | read_args "$@" |
---|
112 | download_xios |
---|
113 | if [[ $arch = "local" ]]; then create_local_arch; fi |
---|
114 | make_xios |
---|
115 | |
---|