forked from NCAR/NCEPlibs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_ncep_libs.sh
executable file
·150 lines (132 loc) · 5.14 KB
/
make_ncep_libs.sh
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
#!/bin/bash
#==========================================================================
#
# Description: This script builds the NCEP libraries used by NEMSfv3gfs v1
#
# Usage: see function usage below
#
# Examples:
# > ./make_ncep_libs.sh -h
# > ./make_ncep_libs.sh -s theia -c intel -d /scratch4/home/USERNAME/NCEPlibs-20180401 -o 1
# > ./make_ncep_libs.sh -s cheyenne -c pgi -d /glade/p/work/USERNAME/NCEPlibs-20180401 -o 0
# > ./make_ncep_libs.sh -s macosx -c gnu -d /usr/local/NCEPlibs-20180401 -o 1
#
#==========================================================================
# Define functions.
function fail { [ -n "$1" ] && printf "\n%s\n" "$1"; exit 1; }
function usage {
echo "Usage: "
echo "$THIS_FILE -s system -c compiler -d installdir -o openmp -a compileall | -h"
echo " Where: system [required] can be : ${validsystems[@]}"
echo " compiler [required] can be : ${validcompilers[@]}"
echo " installdir [required] is the installation destination (must exist)"
echo " openmp [required] is an OpenMP build flag and can be ${validopenmpflags[@]}"
echo " compileall [optional] is a flag to build the full set of libraries (only valid on cheyenne and macosx) and can be ${validopenmpflags[@]}"
exit 1
}
NCEPLIBS_SRC_DIR=`pwd`
THIS_FILE=$(basename "$0" )
#--------------------------------------------------------------
# Define available options
#--------------------------------------------------------------
validsystems=( theia jet cheyenne macosx linux )
validcompilers=( intel pgi gnu )
validopenmpflags=( 0 1 )
validcompileallflags=( 0 1 )
#--------------------------------------------------------------
# Parse command line arguments
#--------------------------------------------------------------
while getopts :s:c:d:o:a:help opt; do
case $opt in
s) SYSTEM=$OPTARG ;;
c) COMPILER=$OPTARG ;;
d) NCEPLIBS_DST_DIR=$OPTARG ;;
o) OPENMP=$OPTARG ;;
a) COMPILEALL=$OPTARG ;;
h) usage ;;
*) usage ;;
esac
done
# Check if all mandatory arguments are provided
if [ -z $SYSTEM ] ; then usage; fi
if [ -z $COMPILER ] ; then usage; fi
if [ -z $NCEPLIBS_DST_DIR ] ; then usage; fi
if [ -z $OPENMP ] ; then usage; fi
if [ -z $COMPILEALL ] ; then COMPILEALL=0; fi #COMPILEALL is an optional argument
# Ensure value ($2) of variable ($1) is contained in list of validvalues ($3)
function checkvalid {
if [ $# -lt 3 ]; then
echo $FUNCNAME requires at least 3 arguments: stopping
exit 1
fi
var_name=$1 && shift
input_val=$1 && shift
valid_vars=($@)
for x in ${valid_vars[@]}; do
if [ "$input_val" == "$x" ]; then
echo "${var_name}=${input_val} is valid."
return
fi
done
echo "ERROR: ${var_name}=${input_val} is invalid. Valid values are: ${valid_vars[@]}"
exit 1
}
checkvalid SYSTEM ${SYSTEM} ${validsystems[@]}
checkvalid COMPILER ${COMPILER} ${validcompilers[@]}
checkvalid OPENMP ${OPENMP} ${validopenmpflags[@]}
checkvalid COMPILEALL ${COMPILEALL} ${validcompileallflags[@]}
if [ -d ${NCEPLIBS_DST_DIR} ]; then
echo "Destination directory ${NCEPLIBS_DST_DIR} exists."
else
echo "ERROR: Destination directory ${NCEPLIBS_DST_DIR} does not exist."
exit 1
fi
#--------------------------------------------------------------
# Check that all libraries are available on this platform
#--------------------------------------------------------------
if [ "$COMPILEALL" == "1" ]; then
if [ "${SYSTEM}" != "cheyenne" -a "${SYSTEM}" != "macosx" -a "${SYSTEM}" != "theia" ]; then
echo "ERROR: Compile all option (-a 1) only supported for 'cheyenne', 'macosx', and 'theia' at this time"
exit 1
fi
fi
#--------------------------------------------------------------
# Get the build root directory
#--------------------------------------------------------------
export BUILD_DIR="${NCEPLIBS_SRC_DIR}/exec_${SYSTEM}.${COMPILER}"
echo
echo "Building NCEP libraries in ${BUILD_DIR} ..."
echo
#--------------------------------------------------------------
# Copy appropriate macros.make file
#--------------------------------------------------------------
MACROS_FILE=${NCEPLIBS_SRC_DIR}/macros.make
if [ -f ${MACROS_FILE} ]; then
rm -rf ${MACROS_FILE}
fi
cp -v ${MACROS_FILE}.${SYSTEM}.${COMPILER} ${MACROS_FILE}
#--------------------------------------------------------------
# Copy library source to BUILD_DIR and build
#--------------------------------------------------------------
rsync -a macros.make Makefile src ${BUILD_DIR}
cd ${BUILD_DIR}
if [ "$COMPILEALL" == "1" ]; then
make all || fail "An error occurred building the NCEP libraries"
else
make some || fail "An error occurred building the NCEP libraries"
fi
#--------------------------------------------------------------
# Install to NCEPLIBS_DST_DIR
#--------------------------------------------------------------
echo
echo "Installing to ${NCEPLIBS_DST_DIR} ..."
echo
rm -fr ${NCEPLIBS_DST_DIR}/lib
rm -fr ${NCEPLIBS_DST_DIR}/include
mkdir ${NCEPLIBS_DST_DIR}/lib
mkdir ${NCEPLIBS_DST_DIR}/include
cp -av ${BUILD_DIR}/include/* ${NCEPLIBS_DST_DIR}/include/
cp -av ${BUILD_DIR}/lib*.a ${NCEPLIBS_DST_DIR}/lib/
echo
echo "To build FV3, set environment variable NCEPLIBS_DIR to ${NCEPLIBS_DST_DIR}"
echo