Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

#!/bin/bash

function helptext()
{
  echo "#------------------------------"
  echo "# Configure instructions: -----"
  echo "#------------------------------"
  echo ""
  echo "./configure [option] [type]"
  echo ""
  echo "[option] = Option for configure:"
  echo "  - help = Display configure instructions."
  echo "  - nomake = Only prepare workstation.h file (base directory and online/offline mode)."
  echo "  - all = Prepare workstation.h file and set used libraries."
  echo "  - clean = Clean the installation directory."
  echo "  - compress = Compress the source code in a tar-ball."
  echo ""
  echo "[type] = Configure for use in online or offline mode (only needed in nomake and all):"
  echo "  - I = Online mode."
  echo "  - O = Offline mode (no connection to CAMAC, motor, voltage supply and scope)."
  echo ""
  echo "#------------------------------"
}

# Check for arguments
if [ "$1" == "" ]; then
  echo "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
    echo "Error! Wrong configuration option selected (first argument)."
    echo ""
    helptext
    exit 1
  fi

  startdir=$PWD

  ostype=`uname -p`

  # 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 libxxusb.h libxxusb.o root_include.h start.cxx usb.h windowed_test.C windowed_test.h wusbcc.h wusbxx_dll.c wusbxx_dll.h wusbxx_dll.o mpod/ MIKRO/ vxi11_x86_64/ vxi11_i686/ input/ ./camac_gui_windowed/
      cd $startdir/camac_gui_windowed
      echo "Cleaning the base directory in $startdir/camac_gui_windowed..."
      rm -f *.bak
      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
      echo "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" ]; then
      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/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/workstation.h.mid > $startdir/workstation.h
        rm $startdir/workstation.h.mid
      fi
      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
          rm $startdir/Makefile.mid
        elif [ "$2" == "O" ]; then
          cp $startdir/input/Makefile.in $startdir/Makefile
        fi
      fi

      if [ "$2" == "O" ]; then
        cp $startdir/input/daqusb.C.offline $startdir/daqusb.C
        cp $startdir/input/start.sh.offline $startdir/start.sh
      elif [ "$2" == "I" ]; then
        cp $startdir/input/daqusb.C.online $startdir/daqusb.C
        cp $startdir/input/start.sh.online $startdir/start.sh
      fi
    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" ]; then
          make
        else
          echo "Error! No configuration type selected (second argument)."
          echo ""
          helptext
          exit 1
        fi
      fi
      cd $startdir
    else
      echo "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" ]; then
          make
        else
          echo "Error! No installation type selected (second argument)."
          echo ""
          helptext
          exit 1
        fi
      fi
      cd $startdir
    else
      echo "No 32 bit VXI11 source folder."
      exit 1
    fi
  else
    echo "No OS type information found."
    exit 1
  fi
fi

exit 0