build-dunepdsprce.sh
Go to the documentation of this file.
1 #!/bin/bash
2 
3 # build dunepdsprce
4 
5 PRODUCT_NAME=dunepdsprce
6 
7 # designed to work on Jenkins
8 
9 # for checking out from JJ's github repo
10 
11 echo "dunepdsprce JJ github: $JJVERSION"
12 
13 # -- the base qualifier is only the compiler version qualifier: e.g. "e15"
14 
15 echo "base qualifiers: $QUAL"
16 
17 # note -- this script knows about the correspondence between compiler qualifiers and compiler versions.
18 # there is another if-block later on with the same information (apologies for the duplication). If a new compiler
19 # version is added here, it must also be added where CV is set.
20 
21 COMPILERVERS=unknown
22 COMPILERCOMMAND=unknown
23 if [ $QUAL = e14 ]; then
24  COMPILERVERS="gcc v6_3_0"
25  COMPILERCOMMAND=g++
26 elif [ $QUAL = e15 ]; then
27  COMPILERVERS="gcc v6_4_0"
28  COMPILERCOMMAND=g++
29 elif [ $QUAL = e17 ]; then
30  COMPILERVERS="gcc v7_3_0"
31  COMPILERCOMMAND=g++
32 elif [ $QUAL = c2 ]; then
33  COMPILERVERS="clang v5_0_1"
34  COMPILERCOMMAND=clang++
35 elif [ $QUAL = e19 ]; then
36  COMPILERVERS="gcc v8_2_0"
37  COMPILERCOMMAND=g++
38 elif [ $QUAL = e20 ]; then
39  COMPILERVERS="gcc v9_3_0"
40  COMPILERCOMMAND=g++
41 elif [ $QUAL = c7 ]; then
42  COMPILERVERS="clang v7_0_0"
43  COMPILERCOMMAND=clang++
44 fi
45 
46 echo "Compiler and version string: " $COMPILERVERS
47 echo "Compiler command: " $COMPILERCOMMAND
48 
49 echo "COMPILERQUAL_LIST: " $COMPILERQUAL_LIST
50 
51 if [ "$COMPILERVERS" = unknown ]; then
52  echo "unknown compiler flag: $QUAL"
53  exit 1
54 fi
55 
56 # -- prof or debug
57 
58 echo "build type: $BUILDTYPE"
59 
60 # -- gen, avx, or avx2
61 
62 echo "simd qualifier: $SIMDQUALIFIER"
63 
64 echo "workspace: $WORKSPACE"
65 
66 
67 # Environment setup; look in CVMFS first
68 
69 if [ -f /cvmfs/dune.opensciencegrid.org/products/dune/setup_dune.sh ]; then
70  source /cvmfs/dune.opensciencegrid.org/products/dune/setup_dune.sh || exit 1
71 elif [ -f /grid/fermiapp/products/dune/setup_dune_fermiapp.sh ]; then
72  source /grid/fermiapp/products/dune/setup_dune_fermiapp.sh || exit 1
73 else
74  echo "No setup file found."
75  exit 1
76 fi
77 
78 setup ${COMPILERVERS}
79 
80 # Use system git on macos, and the one in ups for linux
81 
82 if ! uname | grep -q Darwin; then
83  setup git || exit 1
84 fi
85 setup gitflow || exit 1
86 
87 rm -rf $WORKSPACE/temp || exit 1
88 mkdir -p $WORKSPACE/temp || exit 1
89 mkdir -p $WORKSPACE/copyBack || exit 1
90 rm -f $WORKSPACE/copyBack/* || exit 1
91 cd $WORKSPACE/temp || exit 1
92 CURDIR=`pwd`
93 
94 # change all dots to underscores, and capital V's to little v's in the version string
95 # add our own suffix as the compiler version moves more rapidly than the product version
96 
97 VERSION=`echo ${JJVERSION} | sed -e "s/V/v/g" | sed -e "s/\./_/g"`${VERSIONSUFFIX}
98 
99 LINDAR=linux
100 FLAVOR=`ups flavor -4`
101 if [ `uname` = Darwin ]; then
102  FLAVOR=`ups flavor -2`
103  LINDAR=darwin
104 fi
105 
106 touch ${PRODUCT_NAME} || exit 1
107 rm -rf ${PRODUCT_NAME} || exit 1
108 touch inputdir || exit 1
109 rm -rf inputdir || exit 1
110 mkdir -p ${PRODUCT_NAME}/${VERSION}/source || exit 1
111 mkdir ${PRODUCT_NAME}/${VERSION}/include || exit 1
112 mkdir ${PRODUCT_NAME}/${VERSION}/data || exit 1
113 mkdir ${PRODUCT_NAME}/${VERSION}/ups || exit 1
114 
115 
116 TABLEFILENAME=${PRODUCT_NAME}/${VERSION}/ups/${PRODUCT_NAME}.table
117 touch ${TABLEFILENAME} || exit 1
118 rm -rf ${TABLEFILENAME} || exit 1
119 cat > ${TABLEFILENAME} <<EOF
120 File=Table
121 Product=dunepdsprce
122 
123 #*************************************************
124 # Starting Group definition
125 Group:
126 
127 EOF
128 
129 for CQ in $COMPILERQUAL_LIST; do
130  touch tablefrag.txt || exit 1
131  rm -rf tablefrag.txt || exit 1
132  cat > tablefrag.txt <<'EOF'
133 
134 Flavor=ANY
135 Qualifiers=QUALIFIER_REPLACE_STRING:gen:debug
136 
137  Action=DefineFQ
138  envSet (DUNEPDSPRCE_FQ_DIR, ${UPS_PROD_DIR}/${UPS_PROD_FLAVOR}-QUALIFIER_REPLACE_STRING-gen-debug)
139 
140  Action = ExtraSetup
141  setupRequired( COMPILERVERS_REPLACE_STRING )
142 
143 Flavor=ANY
144 Qualifiers=QUALIFIER_REPLACE_STRING:avx:debug
145 
146  Action=DefineFQ
147  envSet (DUNEPDSPRCE_FQ_DIR, ${UPS_PROD_DIR}/${UPS_PROD_FLAVOR}-QUALIFIER_REPLACE_STRING-avx-debug)
148 
149  Action = ExtraSetup
150  setupRequired( COMPILERVERS_REPLACE_STRING )
151 
152 Flavor=ANY
153 Qualifiers=QUALIFIER_REPLACE_STRING:avx2:debug
154 
155  Action=DefineFQ
156  envSet (DUNEPDSPRCE_FQ_DIR, ${UPS_PROD_DIR}/${UPS_PROD_FLAVOR}-QUALIFIER_REPLACE_STRING-avx2-debug)
157 
158  Action = ExtraSetup
159  setupRequired( COMPILERVERS_REPLACE_STRING )
160 
161 Flavor=ANY
162 Qualifiers=QUALIFIER_REPLACE_STRING:gen:prof
163 
164  Action=DefineFQ
165  envSet (DUNEPDSPRCE_FQ_DIR, ${UPS_PROD_DIR}/${UPS_PROD_FLAVOR}-QUALIFIER_REPLACE_STRING-gen-prof)
166 
167  Action = ExtraSetup
168  setupRequired( COMPILERVERS_REPLACE_STRING )
169 
170 Flavor=ANY
171 Qualifiers=QUALIFIER_REPLACE_STRING:avx:prof
172 
173  Action=DefineFQ
174  envSet (DUNEPDSPRCE_FQ_DIR, ${UPS_PROD_DIR}/${UPS_PROD_FLAVOR}-QUALIFIER_REPLACE_STRING-avx-prof)
175 
176  Action = ExtraSetup
177  setupRequired( COMPILERVERS_REPLACE_STRING )
178 
179 Flavor=ANY
180 Qualifiers=QUALIFIER_REPLACE_STRING:avx2:prof
181 
182  Action=DefineFQ
183  envSet (DUNEPDSPRCE_FQ_DIR, ${UPS_PROD_DIR}/${UPS_PROD_FLAVOR}-QUALIFIER_REPLACE_STRING-avx2-prof)
184 
185  Action = ExtraSetup
186  setupRequired( COMPILERVERS_REPLACE_STRING )
187 
188 EOF
189 
190 CV=unknown
191 if [ $CQ = e14 ]; then
192  CV="gcc v6_3_0"
193 elif [ $CQ = e15 ]; then
194  CV="gcc v6_4_0"
195 elif [ $CQ = e17 ]; then
196  CV="gcc v7_3_0"
197 elif [ $CQ = c2 ]; then
198  CV="clang v5_0_1"
199 elif [ $CQ = e19 ]; then
200  CV="gcc v8_2_0"
201 elif [ $CQ = e20 ]; then
202  CV="gcc v9_3_0"
203 elif [ $CQ = c7 ]; then
204  CV="clang v7_0_0"
205 fi
206 if [ "$CV" = unknown ]; then
207  echo "unknown compiler flag in COMPILERQUAL_LIST : $CQ"
208  exit 1
209 fi
210 
211 sed -e "s/QUALIFIER_REPLACE_STRING/${CQ}/g" < tablefrag.txt | sed -e "s/COMPILERVERS_REPLACE_STRING/${CV}/g" >> ${TABLEFILENAME} || exit 1
212 rm -f tablefrag.txt || exit 1
213 
214 done
215 
216 cat >> ${TABLEFILENAME} <<'EOF'
217 Common:
218  Action=setup
219  setupenv()
220  proddir()
221  ExeActionRequired(DefineFQ)
222  envSet(DUNEPDSPRCE_DIR, ${UPS_PROD_DIR})
223  envSet(DUNEPDSPRCE_VERSION, ${UPS_PROD_VERSION})
224  envSet(DUNEPDSPRCE_INC, ${DUNEPDSPRCE_DIR}/include)
225  envSet(DUNEPDSPRCE_LIB, ${DUNEPDSPRCE_FQ_DIR}/lib)
226  # add the lib directory to LD_LIBRARY_PATH
227  if ( test `uname` = "Darwin" )
228  envPrepend(DYLD_LIBRARY_PATH, ${DUNEPDSPRCE_FQ_DIR}/lib)
229  else()
230  envPrepend(LD_LIBRARY_PATH, ${DUNEPDSPRCE_FQ_DIR}/lib)
231  endif ( test `uname` = "Darwin" )
232  # add the bin directory to the path if it exists
233  if ( sh -c 'for dd in bin;do [ -d ${DUNEPDSPRCE_FQ_DIR}/$dd ] && exit;done;exit 1' )
234  pathPrepend(PATH, ${DUNEPDSPRCE_FQ_DIR}/bin )
235  else ()
236  execute( true, NO_UPS_ENV )
237  endif ( sh -c 'for dd in bin;do [ -d ${DUNEPDSPRCE_FQ_DIR}/$dd ] && exit;done;exit 1' )
238  # useful variables
239 # envPrepend(CMAKE_PREFIX_PATH, ${DUNEPDSPRCE_DIR} ) this package doesn't use cmake
240 # envPrepend(PKG_CONFIG_PATH, ${DUNEPDSPRCE_DIR} )
241  # requirements
242  exeActionRequired(ExtraSetup)
243 End:
244 # End Group definition
245 #*************************************************
246 
247 EOF
248 
249 mkdir inputdir || exit 1
250 cd inputdir
251 git clone https://github.com/dune/dunepdsprce.git || exit 1
252 cd dunepdsprce || exit 1
253 git checkout tags/${JJVERSION} || exit 1
254 
255 # copy all the files that do not need building. Copy the headers later when we're done as they are in the install directory
256 
257 cp -R -L dam/source/* ${CURDIR}/${PRODUCT_NAME}/${VERSION}/source || exit 1
258 
259 # skip the example data files
260 
261 # cp -R -L data/* ${CURDIR}/${PRODUCT_NAME}/${VERSION}/data || exit 1
262 
263 DIRNAME=${CURDIR}/${PRODUCT_NAME}/${VERSION}/${FLAVOR}-${QUAL}-${SIMDQUALIFIER}-${BUILDTYPE}
264 mkdir -p ${DIRNAME} || exit 1
265 rm -rf ${DIRNAME}/* || exit 1
266 mkdir ${DIRNAME}/bin || exit 1
267 mkdir ${DIRNAME}/lib || exit 1
268 
269 cd ${CURDIR}/inputdir/dunepdsprce/dam/source/cc/make || exit 1
270 make clean || exit 1
271 
272 if [ $BUILDTYPE = prof ]; then
273  echo "Making optimized version"
274  make CC=${COMPILERCOMMAND} CXX=${COMPILERCOMMAND} LD=${COMPILERCOMMAND} PROD=1 target=x86_64-${SIMDQUALIFIER}-${LINDAR} || exit 1
275 else
276  echo "Making debug version"
277  make CC=${COMPILERCOMMAND} CXX=${COMPILERCOMMAND} LD=${COMPILERCOMMAND} target=x86_64-${SIMDQUALIFIER}-${LINDAR} || exit 1
278 fi
279 
280 cp -R -L ${CURDIR}/inputdir/dunepdsprce/install/x86_64-${SIMDQUALIFIER}-${LINDAR}/bin/* ${CURDIR}/${PRODUCT_NAME}/${VERSION}/${FLAVOR}-${QUAL}-${SIMDQUALIFIER}-${BUILDTYPE}/bin
281 
282 # JJ builds a program called "reader" which probably shouldn't be in the user's PATH. Rename it if it exists
283 
284 if [ -e ${CURDIR}/${PRODUCT_NAME}/${VERSION}/${FLAVOR}-${QUAL}-${SIMDQUALIFIER}-${BUILDTYPE}/bin/reader ]; then
285  mv ${CURDIR}/${PRODUCT_NAME}/${VERSION}/${FLAVOR}-${QUAL}-${SIMDQUALIFIER}-${BUILDTYPE}/bin/reader ${CURDIR}/${PRODUCT_NAME}/${VERSION}/${FLAVOR}-${QUAL}-${SIMDQUALIFIER}-${BUILDTYPE}/bin/${PRODUCT_NAME}_testreader
286 fi
287 
288 # in the case of the shared libraries, we want to only copy the libraries once, and make new symlinks with relative paths
289 
290 cd ${CURDIR}/inputdir/dunepdsprce/dam/export/x86_64-${SIMDQUALIFIER}-${LINDAR}/lib
291 for LIBFILE in $( ls ); do
292  if [ -h ${LIBFILE} ]; then
293  TMPVAR=`readlink ${LIBFILE}`
294  ln -s `basename ${TMPVAR}` ${CURDIR}/${PRODUCT_NAME}/${VERSION}/${FLAVOR}-${QUAL}-${SIMDQUALIFIER}-${BUILDTYPE}/lib/${LIBFILE} || exit 1
295  else
296  cp ${LIBFILE} ${CURDIR}/${PRODUCT_NAME}/${VERSION}/${FLAVOR}-${QUAL}-${SIMDQUALIFIER}-${BUILDTYPE}/lib || exit 1
297  fi
298 done
299 
300 cp -R -L ${CURDIR}/inputdir/dunepdsprce/install/x86_64-${SIMDQUALIFIER}-${LINDAR}/include/* ${CURDIR}/${PRODUCT_NAME}/${VERSION}/include || exit 1
301 
302 # assemble the UPS product and declare it
303 
304 cd ${CURDIR} || exit 1
305 
306 # for testing the tarball, remove so we keep .upsfiles as is when
307 # unwinding into a real products area
308 
309 mkdir .upsfiles || exit 1
310 cat <<EOF > .upsfiles/dbconfig
311 FILE = DBCONFIG
312 AUTHORIZED_NODES = *
313 VERSION_SUBDIR = 1
314 PROD_DIR_PREFIX = \${UPS_THIS_DB}
315 UPD_USERCODE_DIR = \${UPS_THIS_DB}/.updfiles
316 EOF
317 
318 ups declare ${PRODUCT_NAME} ${VERSION} -f ${FLAVOR} -m ${PRODUCT_NAME}.table -z `pwd` -r ./${PRODUCT_NAME}/${VERSION} -q ${BUILDTYPE}:${QUAL}:${SIMDQUALIFIER}
319 
320 rm -rf .upsfiles || exit 1
321 
322 # clean up
323 rm -rf ${CURDIR}/inputdir || exit 1
324 
325 cd ${CURDIR} || exit 1
326 
327 ls -la
328 
329 VERSIONDOTS=`echo ${VERSION} | sed -e "s/_/./g"`
330 SUBDIR=`get-directory-name subdir | sed -e "s/\./-/g"`
331 
332 # use SUBDIR instead of FLAVOR
333 
334 FULLNAME=${PRODUCT_NAME}-${VERSIONDOTS}-${SUBDIR}-${QUAL}-${SIMDQUALIFIER}-${BUILDTYPE}
335 
336 # strip off the first "v" in the version number
337 
338 FULLNAMESTRIPPED=`echo $FULLNAME | sed -e "s/${PRODUCT_NAME}-v/${PRODUCT_NAME}-/"`
339 
340 tar -cjf $WORKSPACE/copyBack/${FULLNAMESTRIPPED}.tar.bz2 .
341 
342 ls -l $WORKSPACE/copyBack/
343 cd $WORKSPACE || exit 1
344 rm -rf $WORKSPACE/temp || exit 1
345 
346 exit 0