Skip to content

Commit

Permalink
Polishing the building options. Done testing with -a and compiling th…
Browse files Browse the repository at this point in the history
…e MPTRAC with make check
  • Loading branch information
hydrogencl committed Aug 4, 2023
1 parent 448b46e commit 0b95b34
Showing 1 changed file with 97 additions and 66 deletions.
163 changes: 97 additions & 66 deletions libs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
###### Presets ######

ifBuildAll=false
ifClean=false
ifBuildGSL=false
ifBuildTS=false
ifBuildZLIB=false
Expand All @@ -24,8 +25,20 @@ ifBuildZSTD=false
ifBuildHDF5=false
ifBuildNETCDF=false
ifSkip=false

numProcs=4

strBuildDir=${PWD}/build
strLibsDir=${PWD}

strFileGSL="gsl-2.7"
strFileHDF5="hdf5-1.12.1"
strFileNETCDF="netcdf-c-4.8.1"
strFileTS="thrustsort-1.2"
strFileZFP="zfp-0.5.5"
strFileZLIB="zlib-1.2.12"
strFileZSTD="zstd-1.5.2"

###### Reminder ######

if [[ $# -lt 1 ]]; then
Expand All @@ -35,17 +48,18 @@ fi

###### Checking the flags ######

while getopts agtzfshnp: flag
while getopts acgtzfshnp: flag
do
case "${flag}" in
a) ifBuildAll=true ; echo "All the libs will be built" ;;
g) ifBuildGSL=true ; echo "GSL" ;;
t) ifBuildTS=true ; echo "TS " ;;
z) ifBuildZLIB=true ; echo "ZLIB" ;;
f) ifBuildZFP=true ; echo "ZFP" ;;
s) ifBuildZSTD=true ; echo "ZSTD" ;;
d) ifBuildHDF5=true ; echo "HDF5" ;;
n) ifBuildNETCDF=true ; echo "NETCDF" ;;
c) ifClean=true ; echo "the build directory will be clean" ;;
g) ifBuildGSL=true ; echo "GSL is selected " ;;
t) ifBuildTS=true ; echo "TS is selected " ;;
z) ifBuildZLIB=true ; echo "ZLIB is selected " ;;
f) ifBuildZFP=true ; echo "ZFP is selected " ;;
s) ifBuildZSTD=true ; echo "ZSTD is selected " ;;
d) ifBuildHDF5=true ; echo "HDF5 is selected " ;;
n) ifBuildNETCDF=true ; echo "NETCDF is selected " ;;
p) numProcs=${OPTARG}
numTotalProcs=`nproc --all`
if [ $numProcs -lt $numTotalProcs ]; then
Expand All @@ -58,17 +72,26 @@ do
printf -- " Please specify which libs ( or all, -a ) you want to build\n"
printf -- " you can specify within a dash, e.g.: -gtzfs to build \n"
printf -- " without NETCDF and HDF5 \n"
printf -- "---------------------------------------------------------------"
printf -- "-a : build all the libs \n"
printf -- "--------------------------------------------------------------\n"
printf -- "-a : build all the libs, \$mptrac/libs/build will be \n"
printf -- " cleaned \n"
printf -- "-c : clean the \$mptrac/libs/build \n"
printf -- "-g : build GSL \n"
printf -- "-t : build TS \n"
printf -- "-z : build ZLIB \n"
printf -- "-f : build ZFP \n"
printf -- "-s : build ZSTD \n"
printf -- "-d : build HDF5 (prerequisite: ZLIB) \n"
printf -- "-n : build NETCDF (prerequisite: HDF5) \n"
printf -- "-p [cores] : how many [cores] to be used by make -j [cores] \n"
printf -- " : default is 4 \n"
printf -- "-p [cores] : how many [cores] to be used by make -j [cores] \n"
printf -- " : default is 4 \n"
printf -- "--------------------------------------------------------------\n"
printf -- " Example: -\n"
printf -- " ./build.sh -c clean the build directory -\n"
printf -- " ./build.sh -a build all the libs -\n"
printf -- " ./build.sh -gtzfs build without HDF5 and NetCDF -\n"
printf -- " ./build.sh -g -p 8 build the GSL with 8 processors -\n"
printf -- "--------------------------------------------------------------\n"
ifSkip=true
;;
esac
Expand All @@ -81,94 +104,109 @@ done

######


if [ $ifSkip = false ]; then
printf "preparing the files \n"
if [ $ifBuildAll = true ] || [ $ifClean = true ]; then
printf "Clean the folder \n"
# Setup...
rm -rf build
target=$(mkdir -p build && cd build && pwd)

printf "Using %d CPUs for make ... \n" $numProcs

# Prepare directories...
mkdir -p $target/src $target/bin $target/include $target/lib $target/man/man1 \
&& cp *tar.bz2 $target/src \
&& cd $target/src \
&& for f in $(ls *tar.bz2) ; do tar xvjf $f ; done \
|| exit
printf "Making the folder with subfolders (src, bin, include, lib, man) \n"
mkdir -p $target/src $target/bin $target/include $target/lib $target/man/man1
else
if ! [ -d build ]; then
printf "Making the folder with subfolders \n"
target=$(mkdir -p build && cd build && pwd)
mkdir -p $target/src $target/bin $target/include $target/lib $target/man/man1
fi
fi
if [ $ifBuildAll = true ] || [ $ifBuildGSL = true ] ; then
printf "\n"
if [ $ifBuildAll = true ] || [ $ifBuildGSL = true ] ; then
cd $strLibsDir
printf "Starting to compile GSL\n"
# GSL...
dir=gsl-2.7
cd $target/src/$dir \
&& ./configure --prefix=$target \
strTarget=$strFileGSL
cp $strTarget.tar.bz2 $strBuildDir/src && cd $strBuildDir/src && tar xvjf $strTarget.tar.bz2
cd $strBuildDir/src/$strTarget \
&& ./configure --prefix=$strBuildDir \
&& make -j $numProcs && make check && make install && make clean \
|| exit
echo -e "\n***** gsl-config *****\n"
$strBuildDir/bin/gsl-config --libs --cflags --version
fi

if [ $ifBuildAll = true ] || [ $ifBuildTS = true ] ; then
printf "\n"
cd $strLibsDir
printf "Starting to compile thrustsort\n"
# Thrust sort...
dir=thrustsort-1.2
cd $target/src/$dir \
&& cp -a libthrustsort_gpu.a libthrustsort_cpu.a $target/lib/ \
strTarget=$strFileTS
cp $strTarget.tar.bz2 $strBuildDir/src && cd $strBuildDir/src && tar xvjf $strTarget.tar.bz2
cd $strBuildDir/src/$strTarget \
&& cp -a libthrustsort_gpu.a libthrustsort_cpu.a $strBuildDir/lib/ \
|| exit
fi

if [ $ifBuildAll = true ] || [ $ifBuildZLIB = true ] ; then
printf "\n"
cd $strLibsDir
printf "Starting to compile ZLIB\n"
# zlib...
dir=zlib-1.2.12
cd $target/src/$dir \
&& ./configure --prefix=$target \
strTarget=$strFileZLIB
cp $strTarget.tar.bz2 $strBuildDir/src && cd $strBuildDir/src && tar xvjf $strTarget.tar.bz2
cd $strBuildDir/src/$strTarget \
&& ./configure --prefix=$strBuildDir \
&& make -j $numProcs && make check && make install && make clean \
|| exit
fi

if [ $ifBuildAll = true ] || [ $ifBuildZFP = true ] ; then
printf "\n"
cd $strLibsDir
printf "Starting to compile ZFP\n"
# zfp...
dir=zfp-0.5.5
cd $target/src/$dir \
strTarget=$strFileZFP
cp $strTarget.tar.bz2 $strBuildDir/src && cd $strBuildDir/src && tar xvjf $strTarget.tar.bz2
cd $strBuildDir/src/$strTarget \
&& make && make test \
&& cp -a bin/* $target/bin/ \
&& cp -a include/* $target/include/ \
&& cp -a lib/* $target/lib/ \
&& cp -a bin/* $strBuildDir/bin/ \
&& cp -a include/* $strBuildDir/include/ \
&& cp -a lib/* $strBuildDir/lib/ \
|| exit
fi

if [ $ifBuildAll = true ] || [ $ifBuildZSTD = true ] ; then
printf "\n"
cd $strLibsDir
printf "starting to compile ZSTD \n"
# zstd...
dir=zstd-1.5.2
cd $target/src/$dir \
strTarget=$strFileZSTD
cp $strTarget.tar.bz2 $strBuildDir/src && cd $strBuildDir/src && tar xvjf $strTarget.tar.bz2
cd $strBuildDir/src/$strTarget \
&& make -j $numProcs && make check \
&& cp -a lib/libzstd* $target/lib/ \
&& cp -a lib/*.h $target/include/ \
&& ln -sf $target/lib/libzstd.so.1.5.2 $target/lib/libzstd.so \
&& cp -a lib/libzstd* $strBuildDir/lib/ \
&& cp -a lib/*.h $strBuildDir/include/ \
&& ln -sf $strBuildDir/$strTarget/lib/libzstd.so.1.5.2 $strBuildDir/lib/libzstd.so \
&& make clean \
|| exit
fi

if [ $ifBuildAll = true ] || [ $ifBuildHDF5 = true ] ; then
printf "\n"
cd $strLibsDir
printf "starting to compile HDF5 with zlib\n"
# HDF5...
dir=hdf5-1.12.1
cd $target/src/$dir \
&& ./configure --prefix=$target --with-zlib=$target --enable-hl \
strTarget=$strFileHDF5
cp $strTarget.tar.bz2 $strBuildDir/src && cd $strBuildDir/src && tar xvjf $strTarget.tar.bz2
cd $strBuildDir/src/$strTarget \
&& ./configure --prefix=$strBuildDir --with-zlib=$strBuildDir --enable-hl \
&& make -j $numProcs && make check && make install && make clean \
|| exit
fi

if [ $ifBuildAll = true ] || [ $ifBuildNETCDF = true ] ; then
cd $strLibsDir
printf "starting to compile netCDF \n"
# netCDF...
dir=netcdf-c-4.8.1
cd $target/src/$dir \
&& CPPFLAGS=-I$target/include LDFLAGS=-L$target/lib ./configure --prefix=$target --disable-dap --disable-nczarr \
strTarget=$strFileNETCDF
cp $strTarget.tar.bz2 $strBuildDir/src && cd $strBuildDir/src && tar xvjf $strTarget.tar.bz2
cd $strBuildDir/src/$strTarget \
&& CPPFLAGS=-I$strBuildDir/include LDFLAGS=-L$strBuildDir/lib ./configure --prefix=$strBuildDir --disable-dap --disable-nczarr \
&& make -j $numProcs && make check && make install && make clean \
|| exit
echo -e "\n***** nc-config *****"
$strBuildDir/bin/nc-config --all
fi

# # Chemistry using KPP...
Expand All @@ -177,14 +215,7 @@ fi
# export KPP_FLEX_LIB_DIR=$target/src/$dir
# cd $target/src/$dir/mptrac-chem \
# && ../bin/kpp chem.kpp && make lib && cp libkpp.a $target/lib && cp *.h $target/include


if [ $ifSkip = false ] ; then
printf "Summary of the compilation \n"
# Summary...
echo -e "\n***** gsl-config *****\n"
$target/bin/gsl-config --libs --cflags --version
echo -e "\n***** nc-config *****"
$target/bin/nc-config --all
printf "All selected compilations are done"
if [ $ifSkip = false ] || [$ifBuildAll = true ] ; then
printf "All selected compilations are done.\n"
fi

0 comments on commit 0b95b34

Please sign in to comment.