Blame | Last modification | View Log | RSS feed
#!/bin/bash
function colorecho
{
echo -e$2 "\033[33m$1\033[39m"
}
function errorecho
{
echo -e "\031[33m$1\033[39m"
}
function helptext()
{
colorecho "#------------------------------"
colorecho "# Configure instructions: -----"
colorecho "#------------------------------"
colorecho ""
colorecho "./configure [option] [type] [install directories] [ostype]"
colorecho ""
colorecho "[option] = Option for configure:"
colorecho " help Display configure instructions."
colorecho " nomake Only prepare system dependent files (base directory and online/offline mode)."
colorecho " all Prepare system dependent files and make used libraries."
colorecho " clean Clean the installation directory. Does not clean the results directory."
colorecho " compress Compress the source code in a tar-ball."
colorecho ""
colorecho "[type] = Configure for use in online or offline mode (only needed in nomake and all):"
colorecho " I Online mode."
colorecho " O Offline mode (no connection to CAMAC, motor, voltage supply and scope)."
colorecho " S Offline mode with scope connection (no connection to CAMAC, motor and voltage supply)."
colorecho ""
colorecho "[install directories] = Directories where ROOT and NET-SNMP are installed (when running with superuser, this is important, otherwise optional):"
colorecho " --root-install=/root/install/directory"
colorecho " --snmp-install=/snmp/install/directory"
colorecho ""
colorecho "[ostype] = Specific setting for 64bit or 32bit version of OS (optional):"
colorecho " --ostype=i686 32bit OS type"
colorecho " --ostype=x86_64 64bit OS type"
colorecho ""
colorecho "Example:"
colorecho " ./configure all I --root-install=/home/user/root --snmp-install=/home/user/snmp"
colorecho ""
colorecho "#------------------------------"
}
# Check for arguments
if [ "$1" == "" ]; then
errorecho "Error! No arguments supplied."
echo ""
helptext
exit 1
else
# When using help, only display help and then exit
if [ "$1" == "help" ]; then
helptext
exit 0
fi
# Print help and exit if we give a wrong first argument
if [ "$1" != "nomake" ] && [ "$1" != "all" ] && [ "$1" != "clean" ] && [ "$1" != "compress" ]; then
errorecho "Error! Wrong configuration option selected (first argument)."
echo ""
helptext
exit 1
fi
startdir=$PWD
# Check for ROOT and NET-SNMP install directories and for OS type
snmpsearch="--snmp-install="
rootsearch="--root-install="
ossearch="--ostype="
snmpdirectory=-1
rootdirectory=-1
osmanual=-1
for var in $@
do
case $var in
"$snmpsearch"*)
snmpdirectory=${var#$snmpsearch}
echo "NET-SNMP directory: $snmpdirectory";;
"$rootsearch"*)
rootdirectory=${var#$rootsearch}
echo "ROOT directory: $rootdirectory";;
"$ossearch"*)
osmanual=${var#$ossearch};;
*) ;;
esac
done
# If n ot supplied, check automatically for OS type
if [ $osmanual == -1 ]; then
ostype=`uname -p`
if [ "$ostype" != "x86_64" ] && [ "$ostype" != "i686" ]; then
ostype=`uname -i`
if [ "$ostype" != "x86_64" ] && [ "$ostype" != "i686" ]; then
ostype=`uname -m`
fi
fi
else
ostype=$osmanual
fi
# Check for installation directory of ROOT - if variables not currently set, remind user to set them before running make
if [ "$1" != "clean" ] && [ "$1" != "compress" ]; then
if [ $rootdirectory != -1 ]; then
printenv ROOTSYS > /dev/null
if [ $? != 0 ]; then
colorecho "ROOT environment variables not set. Please run \"source $rootdirectory/bin/thisroot.sh\", before using make."
fi
else
colorecho "Before running make, please make sure ROOT environment variables are set."
fi
fi
# Compiles the table microcontroller program
if [ "$1" == "all" ]; then
if [ -d $startdir/MIKRO ]; then
cd $startdir/MIKRO
rm -f $startdir/MIKRO/mikro_ctrl
make
cd $startdir
fi
fi
# When using compress, only create a tar-ball and then exit
if [ "$1" == "compress" ]; then
cd $startdir
if [ ! -d $startdir/camac_gui_windowed ]; then
mkdir $startdir/camac_gui_windowed
mkdir $startdir/camac_gui_windowed/results
echo "Copying source files to temporary directory $startdir/camac_gui_windowed..."
cp -r configure daq.h daqscope.h GuiLinkDef.h libxxusb.cpp root_include.h README start.cxx windowed_test.C windowed_test.h wusbcc.h wusbxx_dll.c wusbxx_dll.h mpod/ MIKRO/ vxi11_x86_64/ vxi11_i686/ input/ fieldpoint/ ./camac_gui_windowed/
cd $startdir/camac_gui_windowed
echo "Cleaning the base directory in $startdir/camac_gui_windowed..."
rm -f *.bakc
cd $startdir/camac_gui_windowed/input
echo "Cleaning the input directory in $startdir/camac_gui_windowed/input..."
rm -f *.bak
cd $startdir/camac_gui_windowed/vxi11_x86_64
echo "Cleaning the 64 bit VXI11 directory in $startdir/camac_gui_windowed/vxi11_x86_64..."
rm -f *.bak
make clean
cd $startdir/camac_gui_windowed/vxi11_i686
echo "Cleaning the 32 bit VXI11 directory in $startdir/camac_gui_windowed/vxi11_i686..."
rm -f *.bak
make clean
cd $startdir
echo "Creating a tar-ball camac_gui_windowed.tar.gz..."
tar czf $startdir/camac_gui_windowed.tar.gz ./camac_gui_windowed
echo "Removing the temporary directory $startdir/camac_gui_windowed..."
rm -r $startdir/camac_gui_windowed
exit 0
else
errorecho "Error! Directory ./camac_gui_windowed already exists."
exit 1
fi
fi
# Configure the workstation information and directory of program (0 if we find something and 1 otherwise)
basedir=$(echo $startdir | sed 's/\//\\\//g')
if [ "$1" == "nomake" ] || [ "$1" == "all" ]; then
if [ "$2" == "O" ] || [ "$2" == "I" ] || [ "$2" == "S" ]; then
# Setting up the current working computer
grep -q "#define WORKSTAT 'N'" $startdir/input/workstation.h.in
if [ $? == 0 ]; then
sed "s/define WORKSTAT 'N'/define WORKSTAT '$2'/" $startdir/input/workstation.h.in > $startdir/input/workstation.h.mid
fi
grep -q "#define rootdir \"path-to-installation\"" $startdir/input/workstation.h.in
if [ $? == 0 ]; then
sed "s/path-to-installation/$basedir/g" $startdir/input/workstation.h.mid > $startdir/input/workstation.h.mid2
rm $startdir/input/workstation.h.mid
fi
# Check if we are connected to IJS network
etnet=$(ifconfig | grep "178.172.43.")
if [ "$etnet" == "" ]; then
sed "s/define IJSNET 1/define IJSNET 0/" $startdir/input/workstation.h.mid2 > $startdir/workstation.h
rm $startdir/input/workstation.h.mid2
else
cp $startdir/input/workstation.h.mid2 $startdir/workstation.h
rm $startdir/input/workstation.h.mid2
fi
# Setting up the OS type specific files
grep -q "#include \"vxi11_user.h\"" $startdir/input/daqscope.C.in
if [ $? == 0 ]; then
sed "s/vxi11_user.h/.\/vxi11_$ostype\/vxi11_user.h/g" $startdir/input/daqscope.C.in > $startdir/daqscope.C
fi
grep -q "SHLIB = \$(LIBFILE) libvxi11.a" $startdir/input/Makefile.in
if [ $? == 0 ]; then
if [ "$2" == "I" ]; then
sed "s/SHLIB = \$(LIBFILE) libvxi11.a/SHLIB = \$(LIBFILE) libvxi11.a -lusb/g" $startdir/input/Makefile.in > $startdir/Makefile.mid
fi
fi
grep -q "CAMLIB = \$(LIBFILE)" $startdir/input/Makefile.in
if [ $? == 0 ]; then
if [ "$2" == "I" ]; then
sed "s/CAMLIB = \$(LIBFILE)/CAMLIB = \$(LIBFILE) -lusb/g" $startdir/Makefile.mid > $startdir/Makefile.mid2
rm $startdir/Makefile.mid
elif [ "$2" == "O" ] || [ "$2" == "S" ]; then
cp $startdir/input/Makefile.in $startdir/Makefile.mid2
fi
fi
sed "s/OSTYPE=none/OSTYPE=$ostype/g" $startdir/Makefile.mid2 > $startdir/Makefile
rm $startdir/Makefile.mid2
if [ "$2" == "O" ] || [ "$2" == "S" ]; then
cp $startdir/input/daqusb.C.offline $startdir/daqusb.C
cp $startdir/input/libxxusb.h.offline $startdir/libxxusb.h
cp $startdir/input/usb.h.offline $startdir/usb.h
elif [ "$2" == "I" ]; then
cp $startdir/input/daqusb.C.online $startdir/daqusb.C
cp $startdir/input/libxxusb.h.online $startdir/libxxusb.h
fi
echo "#!/bin/bash" > $startdir/start.sh
echo "dir=\`dirname \$0\`" >> $startdir/start.sh
echo "" >> $startdir/start.sh
echo "snmpdirectory=$snmpdirectory" >> $startdir/start.sh
echo "rootdirectory=$rootdirectory" >> $startdir/start.sh
echo "" >> $startdir/start.sh
cat $startdir/input/start.sh.in >> $startdir/start.sh
chmod a+x $startdir/start.sh
fi
fi
# In case we just want to set the workstation information, exit here
if [ "$1" == "nomake" ]; then
exit 0
fi
# 64 bit configuration rules
if [ $ostype == "x86_64" ]; then
vxidir=$startdir/vxi11_$ostype
if [ -d $vxidir ]; then
cd $vxidir
if [ "$1" == "clean" ]; then
make clean
cd $startdir
make clean
rm -f Makefile
else
if [ "$2" == "O" ] || [ "$2" == "I" ] || [ "$2" == "S" ]; then
make
else
errorecho "Error! No configuration type selected (second argument)."
echo ""
helptext
exit 1
fi
fi
cd $startdir
else
errorecho "No 64 bit VXI11 source folder."
exit 1
fi
# 32 bit configuration rules
elif [ $ostype == "i686" ]; then
vxidir=$startdir/vxi11_$ostype
if [ -d $vxidir ]; then
cd $vxidir
if [ "$1" == "clean" ]; then
make clean
cd $startdir
make clean
rm -f Makefile
else
if [ "$2" == "O" ] || [ "$2" == "I" ] || [ "$2" == "S" ]; then
make
else
errorecho "Error! No installation type selected (second argument)."
echo ""
helptext
exit 1
fi
fi
cd $startdir
else
errorecho "No 32 bit VXI11 source folder."
exit 1
fi
else
errorecho "No OS type information found."
exit 1
fi
fi
exit 0