Skip to content
Snippets Groups Projects
dunecontrol 39.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • Christian Engwer's avatar
    Christian Engwer committed
    #!/bin/bash
    
    Christian Engwer's avatar
    Christian Engwer committed
    ###############################################
    ###
    ### check for environment variables
    ###
    
    if test -z "$GREP"; then
      GREP=grep
    fi
    if test -z "$SED"; then
      SED=sed
    fi
    
    Christian Engwer's avatar
    Christian Engwer committed
    
    
    if test -z "$MAKE"; then
    
    Christian Engwer's avatar
    Christian Engwer committed
      MAKE=make
    fi
    
    
    if test -z "$CMAKE"; then
      CMAKE=cmake
    
    Christian Engwer's avatar
    Christian Engwer committed
    ###############################################
    ###
    ### read lib
    ###
    
    
        if test $# -ne 1; then
            echo Usage: canonicalname path >&2
            return 1
        fi
        file="`eval echo $1`" # expand ~
        if test ! -e "$file"; then
            echo $file: file not found >&2
            return 1
        fi
    
        # if this is a symlink, then follow the symlink
    
        if test -L "$file"; then
            fdir="`dirname \"$file\"`"
            flink="`readlink \"$file\"`"
            if test -e "$flink"; then
                # these are absolute links, or links in the CWD
                canonicalname "$flink"
            else
                canonicalname "$fdir/$flink"
            fi
        else
    
            # if this is a file, then remember the filename and
            # canonicalize the directory name
    
            if test -f "$file"; then
                fdir="`dirname \"$file\"`"
                fname="`basename \"$file\"`"
                fdir="`canonicalname \"$fdir\"`"
                echo "$fdir/$fname"
            fi
    
            # if this is a directory, then create an absolute
    
            # directory name and we are done
    
            if test -d "$file"; then
                (cd "$file"; pwd)
            fi
        fi
    
         echo Usage: canonicalpath path >&2
    
    Christian Engwer's avatar
    Christian Engwer committed
    checkdebug () {
      while test $# -gt 0; do
        if test x$1 = x--debug; then
          echo yes
          return
        fi
        shift
      done
      echo no
    }
    
    Christian Engwer's avatar
    Christian Engwer committed
    DEBUG=`checkdebug $@`
    
    if test "x$DEBUG" = "xyes"; then
    
      echo "Terminating $(basename "$0") due to previous errors!" >&2
    
    #
    # for each module load the $CONTROL script part and run $command
    #
    # parameters:
    
    # $1 list of modules
    # $2-$* commands + parameters to execute
    
    Christian Engwer's avatar
    Christian Engwer committed
    build_module() {
      local module=$1
    
      while test $# -gt 0; do
        # get command
        command=$1
        shift
    
        # only load other parameters
        load_opts NONE
        # get command options
        CMD_FLAGS=
        while test $# -gt 0 && test "$1" != ":"; do
          COMMAND=$(echo $command | tr '[:lower:]' '[:upper:]')
          # setup paramter list
          CMD_FLAGS="$CMD_FLAGS \"$1\""
          shift
        done
        if test -z "$CMD_FLAGS"; then
          load_opts $command
        else
          # disable usage of opts file
          if test "x$DUNE_OPTS_FILE" != "x"; then
            echo "WARNING: commandline parameters will overwrite setting in opts file \"$DUNE_OPTS_FILE\""
    
        fi
    
        # skip command delimiter
        if test "$1" = ":"; then shift; fi
    
        # actually run the commands (we already know that these are valid commands)
        local runcommand=run_$command
    
    
    Christian Engwer's avatar
    Christian Engwer committed
        # build the modules
    
        local path="$(eval "echo \$PATH_${module}")"
    
    Christian Engwer's avatar
    Christian Engwer committed
        eval echo "--- calling $command for \$NAME_${module} ---"
    	trap onbuildfailure EXIT
        if ! (
          set -e
          cd "$path"
          export module
    
    	  export ABS_BUILDDIR=$(abs_builddir $module $BUILDDIR)
    
          eval_control $runcommand "$path/$CONTROL"
    
    Christian Engwer's avatar
    Christian Engwer committed
        ); then eval echo "--- Failed to build \$NAME_${module} ---"; exit 1; fi
    	trap onfailure EXIT
    
    Christian Engwer's avatar
    Christian Engwer committed
        eval echo "--- \$NAME_${module} done ---"
    
    #
    # load command options from an opts file
    
    Christian Engwer's avatar
    Christian Engwer committed
    # the name of the opts file is stored in the global variable $DUNE_OPTS_FILE
    
    #
    # parameters:
    # $1 command
    #
    
      local command=$1
      local COMMAND=$(echo $command | tr '[:lower:]' '[:upper:]')
    
      CMD_FLAGS=$(eval echo \$${COMMAND}_FLAGS)
    
      local CMD_FLAGS_FROM_FILE=""
    
      if test "$command" = "NONE"; then
        BUILDDIR=$DUNE_BUILDDIR
    
        if test "x$DUNE_OPTS_FILE" != "x"; then
    
          if test -z "$BUILDDIR"; then
            # no builddir set yet, use build dir from opts file if set
            # Note: if --use-buiddir is used BUILDDIR will be set already
            OPTS_FILE_BUILDDIR="$(eval BUILDDIR=""; . $DUNE_OPTS_FILE; eval echo \$BUILDDIR)"
            if test -n "$OPTS_FILE_BUILDDIR"; then
              BUILDDIR="$OPTS_FILE_BUILDDIR"
            fi
    
          if test -z "$USE_CMAKE"; then
    
            # no USE_CMAKE set yet, use USE_CMAKE from opts file if set
    
            # Note: if --use-cmake is used USE_CMAKE will be set already
            OPTS_FILE_USE_CMAKE="$(eval USE_CMAKE=""; . $DUNE_OPTS_FILE; eval echo \$USE_CMAKE)"
            if test -n "$OPTS_FILE_USE_CMAKE"; then
              USE_CMAKE="$OPTS_FILE_USE_CMAKE"
            fi
    
            # if still no USE_CMAKE is set, default to true
            if test -z "$USE_CMAKE"; then
              USE_CMAKE="yes"
            fi
    
          if test -n "$USE_CMAKE" && test "$system_default_cmake" = "yes"; then
            # We use cmake for building, but CMAKE is not yet set.
            # Check the opts file for it
            OPTS_FILE_CMAKE="$(eval CMAKE=""; . $DUNE_OPTS_FILE; eval echo \$CMAKE)"
            if test -n "$OPTS_FILE_CMAKE"; then
              CMAKE="$OPTS_FILE_CMAKE"
            fi
          fi
    
    Christoph Grüninger's avatar
    Christoph Grüninger committed
        fi
    
      fi
      if test "x$DUNE_OPTS_FILE" != "x"; then
    
        if test "$command" = "configure"; then
          CMAKE_FLAGS="$(. $DUNE_OPTS_FILE; eval echo \$CMAKE_FLAGS)"
        fi
    
        CMD_FLAGS_FROM_FILE="$(eval ${COMMAND}_FLAGS=""; . $DUNE_OPTS_FILE; eval echo \$${COMMAND}_FLAGS)"
    
    Christian Engwer's avatar
    Christian Engwer committed
      fi
    
      if test -n "$CMD_FLAGS_FROM_FILE"; then
    
    Christian Engwer's avatar
    Christian Engwer committed
        echo "----- using default flags \$${COMMAND}_FLAGS from $DUNE_OPTS_FILE -----"
    
        CMD_FLAGS=$CMD_FLAGS_FROM_FILE
    
    Christian Engwer's avatar
    Christian Engwer committed
      elif test -n "$CMD_FLAGS"; then
        echo "----- using default flags \$${COMMAND}_FLAGS from environment -----"
    
      if test "x$USE_CMAKE" != "xno"; then
    
    Markus Blatt's avatar
    Markus Blatt committed
        if test -z "$BUILDDIR"; then
          export BUILDDIR=build-cmake
        fi
    
    abs_builddir()
    {
      local m=$1
      local builddir=$2
      local name="$(eval echo \$NAME_$m)"
      local path="$(eval echo \$PATH_$m)"
      case $BUILDDIR in
    	  /*)
    		  echo $builddir/$name
    		  ;;
    	  *)
    		  echo $path/$builddir
    		  ;;
      esac
    }
    
    
    # Uses the current compiler to extract information about the
    # multiarch triplets and sets the export variable MULTIARCH_LIBDIR
    # according to it.
    # If not compiler is specified then cc or gcc is used.
    extract_multiarch(){
    
      set +e #error in the multiarch detection should not be fatal.
    
      local my_cxx_compiler
      if test "x$MULTIARCH_LIBDIR" != "x"; then
        return
      fi
      if test "x$USE_CMAKE" = "xyes"; then
        load_opts "cmake"
      fi
      if test "x$my_cxx_compiler" == "x"; then
        load_opts "configure"
      fi
    
      my_cxx_compiler=`echo $CMD_FLAGS | $GREP CXX | $SED "s/.*CXX=[\"']\{0,1\}\([^$BLANK'\"]*\)[\"']\{0,1\}.*/\1/"`
    
      if test "x$my_cxx_compiler" == "x"; then
        $(which cc &>/dev/null)
        if test $? -eq "0"; then
          my_cxx_compiler=cc
        else
          my_cxx_compiler=gcc
        fi
      fi
    
      multiarch=$($my_cxx_compiler --print-multiarch 2>/dev/null)
      if test $? -gt 0; then
    
        for i in "target=" "Target:"; do
          multiarch=$($my_cxx_compiler -v 2>&1| $GREP "$i" | $SED "s/.*$i[$BLANK]*\([a-z0-9_-]*\)/\1/" | $SED "s/-[a-z]*-linux-gnu/-linux-gnu/")
         if test -n "$multiarch"; then break; fi
       done
    
      export MULTIARCH_LIBDIR="lib/$multiarch"
    
    }
    
    export PREFIX_DIR="`canonicalpath "$0"`/.."
    
    # Read the modules find part
    . "$PREFIX_DIR/lib/dunemodules.lib"
    
    ###############################################
    
    
    
    ###############################################
    
    # check all parameter
    check_commands() {
      while test $# -gt 0; do
        # get command
        command=$1
        shift
        # skip command options
        while test $# -gt 0 && test "$1" != ":"; do
          shift
        done
        # skip command delimiter
        if test "$1" = ":"; then shift; fi
        # test the commands
        if ! is_command $command; then
          usage
          echo "ERROR: unknown command \"$command\""  >&2
          exit 1
        fi
      done
    }
    
    
    # check wheteher the parameter is valid command or not
    is_command() {
    
    Christian Engwer's avatar
    Christian Engwer committed
    eval '
    case "$1" in
    
      '`echo $COMMANDS | $SED -e 's/ / | /g'`')
    
    Christian Engwer's avatar
    Christian Engwer committed
        return 0
        ;;
      *)
        return 1
        ;;
    esac'
    
    # list of all dunecontrol commands
    
    COMMANDS="printdeps vcsetup update autogen configure make all exec bexec status svn git"
    
    
    # help string for the commands
    
    printdeps_HELP="print recursive dependencies of a module"
    
    vcsetup_HELP="setup version control repository (Git etc.) or working copy (SVN)"
    
    update_HELP="updated all modules from the repository"
    
    autogen_HELP="run the autogen.sh script for each module. Does nothing, if CMake is activated"
    configure_HELP="run configure or cmake for each module"
    
    make_HELP="run make for each module"
    
    all_HELP="\trun 'vcsetup', 'autogen', 'configure' and 'make' command for each module"
    
    Christoph Grüninger's avatar
    Christoph Grüninger committed
    exec_HELP="execute an arbitrary command in each module source directory"
    bexec_HELP="execute an arbitrary command in each module build directory"
    
    status_HELP="show vc status for all modules"
    
    svn_HELP="\trun svn command for each svn managed module"
    
    git_HELP="\trun git command for each git managed module"
    
    # setup command proxies
    # call will be forwarded to run_default_$command
    
    for command in $COMMANDS; do
      eval "run_$command () { run_default_$command; }"
    done
    
    #
    # Check whether we should use cmake for this particular value
    # and set LOCAL_USE_CMAKE accordingly.
    # We use cmake if USE_CMAKE is not set to no and the module has
    # CMake build infrastructure, i.e. a toplevel CMakeLists.txt
    #
    create_local_use_cmake() {
      if test "x$USE_CMAKE" != "xno" && test -e "$(eval "echo \$PATH_$module")/CMakeLists.txt"; then
        LOCAL_USE_CMAKE=yes
      else
        LOCAL_USE_CMAKE=no
      fi
    }
    
    
    
    # default implementations for commands...
    
    # these can be overwritten in the $CONTROL files
    #
    
    Christian Engwer's avatar
    Christian Engwer committed
    run_default_exec () { bash -c "eval $CMD_FLAGS"; }
    
      if test -d "$ABS_BUILDDIR"; then
        bash -c "cd \"$ABS_BUILDDIR\" && eval $CMD_FLAGS";
    
        eval echo "Build directory \\\"$ABS_BUILDDIR\\\" not found, skipping bexec for \$NAME_${module}"
    
      local verbose=0
      local update=""
    
      local is_git=""
      local is_svn=""
      name="$(eval echo \$NAME_$module)"
    
      if test -d .git; then is_git=1; fi
      if test -d .svn; then is_svn=1; fi
      if test ! "$is_svn" -a ! "$is_git" ; then
        echo "module $name not under known version control"
        return
      fi
    
    
    Christian Engwer's avatar
    Christian Engwer committed
      for i in $CMD_FLAGS; do
    
        if eval test "x$i" = "x-v"; then verbose=1; fi
        if eval test "x$i" = "x-vv"; then verbose=2; fi
        if eval test "x$i" = "x-u"; then update="-u"; fi
      done
    
      # is out output connected to a tty?
      if test -t 1; then
        blue="\e[1m\e[34m"
        green="\e[1m\e[32m"
    
        red="\e[1m\e[31m"
    
      if test $verbose -eq 1; then
    
        test "$is_svn" && svn status $update | $GREP -E "^M|^A|^D|^C|^U"
    
        test "$is_git" && git status -uno
    
      elif test $verbose -eq 2; then
    
        test "$is_svn" && svn status $update
        test "$is_git" && git status
    
      if test "$is_svn" ; then
    
        changed=$(svn status | $GREP -E "^M|^A|^D" | wc -l)
        collisions=$(svn status | $GREP -E "^C"| wc -l)
        pending=$(svn status $update | $GREP -E "^...... \* " | wc -l)
    
      fi
      if test "$is_git" ; then
    
        changed=$(git status --porcelain | $GREP -E "^ *M|^ *A|^ *D|^ *R|^ *C" | wc -l)
        collisions=$(git status --porcelain | $GREP -E "^ *U"| wc -l)
        pending=$(git status | $GREP -E "^\# Your branch is ahead |^\# Your branch is behind " | wc -l)
    
      color=$green
      text="no changes"
      if [ $changed -eq 0 ]; then
    
      elif [ $changed -eq 1 ]; then
    
        text="1 change"
      else
    
        text="$changed changes"
      fi
      if [ $pending -eq 0 ]; then
    
      elif [ $pending -eq 1 ]; then
    
        text="$text, 1 update pending"
      else
    
        text="$text, $pending updates pending"
      fi
      if [ $collisions -eq 0 ]; then
    
      elif [ $collisions -eq 1 ]; then
    
        text="$text, 1 collision"
    
        text="$text, $count collisions"
    
      echo -e "$color[$text]$reset $name"
    
    run_default_vcsetup() {
    
      # load user options
      if [ -n "$CMD_FLAGS" ]; then
        eval "$CMD_FLAGS"
      fi
    
    
      # Check for both a file and a directory to cope with Git submodules
      if [ -d .git -o -f .git ] ; then
    
        # Read Whitespace-Hook setting from dune.module file
    
        local SETUPGITHOOK="$($GREP -i "^[$BLANK]*Whitespace-Hook:" dune.module | cut -d ':' -f2 | eval $PARSER_TRIM | tr '[:upper:]' '[:lower:]')"
    
    
        if [ "x$SETUPGITHOOK" = "xyes" ]; then
          # we have to install the Git whitespace hook
    
          # The current Git repository might be a submodule, so we have to start by
          # determining the location of the commit hook
    
          if [ -f .git ] ; then
            # submodule -> .git contains a pointer to the repository
    
            GITHOOKPATH="$($SED 's/gitdir: //' < .git)/hooks/pre-commit"
    
          else
            # standard case, .git is the repository
            GITHOOKPATH=.git/hooks/pre-commit
          fi
    
    
          if [ -n "$DISABLEWHITESPACEHOOK" ] ; then
            # the user doesn't want the Git whitespace hook - deinstall it if necessary and warn the user
            echo "WARNING: The current module wants to install the DUNE whitespace hook, but you have disabled the hook in your options!"
            echo "WARNING: You will have to make sure that your commits don't introduce any trailing whitespace or indentation with tabs!"
            echo "WARNING: Otherwise, your commits might be rejected when trying to push them to an official repository!"
    
    
            if [ -e "$GITHOOKPATH" ]; then
    
              # there is a pre-commit hook, check whether it is our whitespace hook
    
              local HOOKTAG="$(eval head -n 2 \"$GITHOOKPATH\" | tail -n 1)"
    
              if [ "x$HOOKTAG" = "x# dune-git-whitespace-hook" ]; then
                echo "--> Removing DUNE whitespace hook as requested by the user"
    
            fi
          else
            # standard handling of Git whitespace hook
    
            if [ ! -e "$GITHOOKPATH" ]; then
    
              # there is no hook yet, we can safely install ours
              echo "--> Installing Git pre-commit hook to enforce whitespace policy"
    
              cp -p "$PREFIX_DIR/bin/git-whitespace-hook" "$GITHOOKPATH"
    
              # there is already a hook, check whether it is our whitespace hook
    
              local HOOKTAG="$(eval head -n 2 \"$GITHOOKPATH\" | tail -n 1)"
    
              if [ "x$HOOKTAG" = "x# dune-git-whitespace-hook" ]; then
    
                if [ "$PREFIX_DIR/bin/git-whitespace-hook" -nt "$GITHOOKPATH" ]; then
    
                  echo "--> Updating Git pre-commit hook with newer version"
    
                  cp -p "$PREFIX_DIR/bin/git-whitespace-hook" "$GITHOOKPATH"
    
                fi
              else
                echo "WARNING: Existing pre-commit hook found!"
                echo "WARNING: Skipping installation of DUNE whitespace hook!"
                echo "WARNING: If you want to contribute patches to DUNE, you should make sure to call the whitespace hook"
                echo "WARNING: (dune-common/bin/git-whitespace-hook) from you custom pre-commit hook, otherwise your commits"
                echo "WARNING: might contain trailing whitespace and will not apply cleanly to the official repositories!"
              fi
    
            fi
          fi
        fi
    
        # Apply git configuration settings
        if [ -f .vcsetup/config ]; then
          echo -n "--> Setting Git configuration entries... "
          cat .vcsetup/config | while read; do
            # Filter out comments
    
            local COMMENT="$(echo $REPLY | $GREP '^#')"
    
            if [ ! "x$COMMENT" = "x$REPLY" ]; then
    
              # parse line into an array first to catch obvious syntax errors
              # like 'option value; rm -rf /'
    
    
        # Apply user supplied configuration settings
        if [ -n "$GIT_CONFIG_FILE" ]; then
          if [ -f "$GIT_CONFIG_FILE" ]; then
            echo -n "--> Setting custom Git configuration entries from '$GIT_CONFIG_FILE'... "
            cat "$GIT_CONFIG_FILE" | while read; do
              # Filter out comments
    
              local COMMENT="$(echo $REPLY | $GREP '^#')"
    
              if [ ! "x$COMMENT" = "x$REPLY" ]; then
    
                # parse line into an array first to catch obvious syntax errors
                # like 'option value; rm -rf /'
    
              fi
            done
            echo "done"
          else
            echo "WARNING: custom Git config file '$GIT_CONFIG_FILE' not found!"
          fi
        fi
    
    
      fi
    
      # Run custom setup scripts
    
      if [ -d .git -o -f .git -o -d .svn -o -d CVS -o -f stamp-vc ]; then
    
        if [ -d .vcsetup/run.d ]; then
          for SCRIPT in .vcsetup/run.d/* ; do
            if [ -x "$SCRIPT" ]; then
              echo "--> Running $SCRIPT"
              "$SCRIPT"
            fi
          done
        fi
      fi
    }
    
    
    run_default_update () {
      if test -d .svn; then
        svn update
    
        cvs update -dP
    
      elif test -d .git; then
          if test -d ".git/svn" && test -n "`git svn find-rev HEAD`"; then
              # If the current HEAD points to a SVN commit, update via git-svn
              git svn rebase
          else
              # Update all remotes (if any)
              git remote update
    
              # merge all changes fast-forward style if possible
              if ! git merge --ff-only FETCH_HEAD 2> /dev/null; then
                  echo "$module seems to be using git, and could not be"
                  echo "updated automatically. Please update it manually."
                  echo "(Usually, this is done via 'git svn rebase' for modules using"
                  echo "subversion or 'git merge' for modules which use git natively."
                  echo "Conflicts can be resolved using 'git mergetool'.)"
              fi
          fi
    
      else
        echo "WARNING: $module is not under a known version control system."
    
        echo "         We support svn, git and cvs."
    
    run_default_autogen () {
    
      create_local_use_cmake
      if test "x$LOCAL_USE_CMAKE" = "xno"; then
    
        PARAMS="$CMD_FLAGS"
        local M4_PATH=""
        if test -f configure.ac && \
           ( test -d .svn || test -d .git || test -d CVS || test -f stamp-vc ); then
    
          sort_modules $MODULES
          for m in $MODULES; do
    
            path="$(eval "echo \$PATH_$m")"
            MODULE_PATHS="$MODULE_PATHS\"$path\" "
    
          done
          if test -f autogen.sh; then
            eval echo "WARNING: \$NAME_$module contains obsolete autogen.sh," \
                >&2
            echo "         dune-autogen is used instead." >&2
          fi
    
          eval "\"$PREFIX_DIR/bin/dune-autogen\"" "$MODULE_PATHS" "$PARAMS" || exit 1
    
        echo Skipping dune-autogen because of CMake
    
    run_default_configure () {
    
    Christian Engwer's avatar
    Christian Engwer committed
      PARAMS="$CMD_FLAGS"
    
      if test -x configure || test "x$LOCAL_USE_CMAKE" = "xyes" ; then
    
        if test -d "m4"; then
          ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I m4"
        fi
    
        MY_MODULES=
        # get dependencies & suggestions
        sort_modules $module
    
          path="$(eval "echo \$PATH_$m")"
    
          if test "x$LOCAL_USE_CMAKE" = "xyes"; then
              #
              # Translate the configure PARMS to cmake
              export PARAMS
              export CMAKE_PARAMS
              module_translate_options_am2cmake $m $path/lib
          fi
          if test x$module = x$m; then continue; fi # skip myself
    
    Christian Engwer's avatar
    Christian Engwer committed
          name=$(eval "echo \$NAME_$m")
    
          for dir in $path/m4 $path/share/dune/aclocal $path/share/aclocal; do
            if test -d "$dir"; then
                ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I $dir"
            fi
          done
    
    	  local m_ABS_BUILDDIR=$(abs_builddir $m $BUILDDIR)
          if test -d "$m_ABS_BUILDDIR"; then
            PARAMS="$PARAMS \"--with-$name=$m_ABS_BUILDDIR\""
    
            if test x$(eval echo \$INST_$m) != xyes; then
    
          if test "x$LOCAL_USE_CMAKE" = "xyes"; then
    
              if test -d "$m_ABS_BUILDDIR"; then
    	      CMAKE_PARAMS="$CMAKE_PARAMS \"-D""$name""_DIR=$m_ABS_BUILDDIR\""
    
    	      TMP_PARAMS="\"-D""$name""_DIR=$path\""
    	      for i in $MULTIARCH_LIBDIR lib lib64 lib32; do
    		  if test -d "$path/$i/cmake/$name"; then
                          TMP_PARAMS="\"-D""$name""_DIR=$path/$i/cmake/$name\""
    		      break;
    		  fi
    	      done
    	      CMAKE_PARAMS="$CMAKE_PARAMS $TMP_PARAMS"
    
        if test "x$HAVE_duneweb" == "xyes"; then
          PARAMS="$PARAMS \"--with-duneweb=$PATH_duneweb\""
        fi
    
    
        if test "x$LOCAL_USE_CMAKE" = "xyes"; then
    
          # we have to export the compiler and compiler flags
          # such that they are honored by cmake.
          flags="CXX CC CXXFLAGS CFLAGS CPPFLAGS LDFLAGS F77 FFLAGS FLIBS FC FCFLAGS FCLIBS LIBS"
          for i in  $flags; do
    
            cflags=`echo "$PARAMS" | $GREP $i= | $SED -e "s/^\($i=\"[^\"]*\"\).*/\1/" -e "s/.*[$BLANK]\($i=\"[^\"]*\"\).*/\1/" -e "s/^\($i='[^']*'\).*/\1/" -e "s/.*[$BLANK]\($i='[^']*'\).*/\1/"`
    
            if test -n "$cflags" && test "$PARAMS" != "$cflags" ; then
                PREPARAMS="$PREPARAMS $cflags"
              else
    
               cflags=`echo "$PARAMS" | $GREP $i= | $SED -e "s/^\($i=[^$BLANK]*\).*/\1/" -e "s/.*[$BLANK]\($i=[^$BLANK]*\).*/\1/"`
    
               if test -n "$cflags" && test "$PARAMS" != "$cflags" ; then
    
          # MPI flags are special. find_package(MPI) does not honor MPICC, MPICXX
          # Therefore we translate them to CMake variables and add them to CMAKE_FLAGS. Fortran is omitted.
          for i in CC CXX; do
    
            comp=`echo "$PARAMS" | $GREP MPI$i= | $SED -e "s/^\($i=\"[^\"]*\"\).*/\1/" -e "s/.*[$BLANK]\($i=\"[^\"]*\"\).*/\1/" -e "s/^\($i='[^']*'\).*/\1/" -e "s/.*[$BLANK]\($i='[^']*'\).*/\1/"`
    
            if test -n "$comp" && test "$PARAMS" != "$comp" ; then
              CMAKE_FLAGS="-DMPI_$(echo $i| $SED 's/^CC$/C/')""_COMPILER:FILEPATH=`which $comp` $CMAKE_FLAGS"
              else
    
                comp=`echo "$PARAMS" | $GREP MPI$i= | $SED -e "s/^MPI$i=\([^$BLANK]*\).*/\1/" -e "s/.*[$BLANK]MPI$i=\([^$BLANK]*\).*/\1/"`
    
                if test -n "$comp" && test "$PARAMS" != "$comp" ; then
                  CMAKE_FLAGS="-DMPI_$(echo $i| $SED 's/^CC$/C/')""_COMPILER:FILEPATH=`which $comp` $CMAKE_FLAGS"
                fi
            fi
          done
    
          # create build directory if requested
    
          test -d "$ABS_BUILDDIR" || mkdir -p "$ABS_BUILDDIR"
    
          # check for libtool libs, which might break modules depending on this module
    
          test -n "`find . -name \*.la`" && \
    
              echo "Warning: your build directory $ABS_BUILDDIR contains libtool built libraries, please cleanup"
    
          echo "$PREPARAMS $CMAKE -DCMAKE_MODULE_PATH=\"$CMAKE_MODULE_PATH\" $CMAKE_PARAMS $CMAKE_FLAGS \"$SRCDIR\""
          eval $PREPARAMS $CMAKE "-DCMAKE_MODULE_PATH=\"$CMAKE_MODULE_PATH\" $CMAKE_PARAMS $CMAKE_FLAGS \"$SRCDIR\"" || exit 1
    
          PARAMS="$PARAMS ACLOCAL_AMFLAGS=\"$ACLOCAL_FLAGS\""
    
          # create build directory if requested
    
          if test -n "$ABS_BUILDDIR"; then
            test -d "$ABS_BUILDDIR" || mkdir -p "$ABS_BUILDDIR"
    
            cd "$ABS_BUILDDIR"
    
            eval "$SRCDIR/configure" "$PARAMS" || exit 1
          else
            eval ./configure "$PARAMS" || exit 1
          fi
    
      else
        if test -f configure.in || test -f configure.ac; then
    
          echo "ERROR: configure.[in|ac] found, but configure missing." >&2
          echo "Did you forget to run autoconf?" >&2
          echo "Perhaps you didn't update your project to" >&2
          echo "the latest buildsystem changes (FS#382)." >&2
          echo "If your project is under version control, please make sure" >&2
          echo "you have a file stamp-vc in you top_srcdir." >&2
    
    run_default_make () {
    
      test ! -d "$ABS_BUILDDIR" || cd "$ABS_BUILDDIR"
    
    Christian Engwer's avatar
    Christian Engwer committed
      PARAMS="$CMD_FLAGS"
    
      echo "build directory: $BUILDDIR"
    
      if test "$LOCAL_USE_CMAKE" = "no"; then
        echo make "$PARAMS"
        eval $MAKE "$PARAMS"
      else
    
    	# prepend '--' to separate cmake and make parameters
    	if ! $(echo "$PARAMS" | grep -q -- '--'); then
    	  PARAMS="-- $PARAMS"
        fi
        echo $CMAKE --build . "$PARAMS"
        eval $CMAKE --build . "$PARAMS"
    
    run_default_all () {
    
      for cmd in vcsetup autogen configure make; do
    
    Christian Engwer's avatar
    Christian Engwer committed
        eval echo "--- calling $cmd for \$NAME_${module} ---"
        load_opts $cmd
        run_$cmd
      done
    
    Christian Engwer's avatar
    Christian Engwer committed
    run_default_svn () {
      if test -d .svn; then
    
    run_default_git () {
      if test -d .git; then
        PARAMS="$CMD_FLAGS"
        eval git "$PARAMS"
      fi
    }
    
    
    ###############################################
    
      echo "Execution of $(basename "$0") terminated due to errors!" >&2
    
        echo "Usage: $(basename "$0") [OPTIONS] COMMANDS [COMMAND-OPTIONS]"
    
        echo "  Execute COMMANDS for all Dune modules found. All entries in the"
        echo "  DUNE_CONTROL_PATH variable are scanned recursively for Dune modules."
    
        echo "  If DUNE_CONTROL_PATH is empty, the current directory is scanned."
    
        echo "  Dependencies are controlled by the $CONTROL files."
    
        echo "  -h, --help          show this help"
        echo "      --debug         enable debug output of this script"
    
        echo "      --use-cmake     use CMake instead of autotools for building"
        echo "      --no-cmake      use autotools instead of CMake for building"
    
        echo "      --module=mod    apply the actions on module mod"
    
        echo "                      and all modules it depends on"
        echo "      --only=mod      only apply the actions on module mod"
        echo "                      and not the modules it depends on"
        echo "      --current       only apply the actions on the current module,"
    
        echo "                      i.e. the one whose source tree we are standing in,"
        echo "                      and not the modules it depends on"
        echo "      --current-dep   apply the actions on the current module,"
        echo "                      and all modules it depends on"
    
        echo "      --resume        resume a previous run (only consider the modules"
        echo "                      not built successfully on the previous run)"
        echo "      --skipfirst     skip the first module (use with --resume)"
        echo "      --opts=FILE     load default options from FILE"
        echo "                      (see dune-common/doc/example.opts)"
    
        echo "      --builddir=NAME make out-of-source builds in a subdir NAME."
    
        echo "                      This directory is created inside each module."
    
        echo "                      If NAME is an absolute path, the build directory "
        echo "                      is set to NAME/module-name for each module."
    
        echo "      --[COMMAND]-opts=opts   set options for COMMAND"
    
        echo "                     (this is mainly useful for the 'all' COMMAND)"
    
        echo "  Colon-separated list of commands. Available commands are:"
    
        printf "  \`help'\tguess what :-)\n"
        printf "  \`print'\tprint the list of modules sorted after their dependencies\n"
    
        printf "  \`info'\tsame as \`print\', but including whether it is a dependency or suggestion\n"
    
        for i in $COMMANDS; do
    
          printf "  \`$i'\t$(eval echo \$${i}_HELP)\n"
    
        printf "  \`export'\trun eval \`dunecontrol export\` to save the list of\n"
        printf "  \t\tdune.module files to the DUNE_CONTROL_PATH variable\n"
    
    Christian Engwer's avatar
    Christian Engwer committed
    # create the module list
    create_module_list() {
    
      # try to get the resume file name from the options
      if test -z "$RESUME_FILE" && test -n "$DUNE_OPTS_FILE"; then
    
        export RESUME_FILE="$(eval . $DUNE_OPTS_FILE; eval echo \$RESUME_FILE)"
      fi
    
    
      if test "$RESUME_FLAG" = "yes" ; then
        if ! test -s "$RESUME_FILE" ; then
          echo "Error: No previous run to resume. Please make sure that the RESUME_FILE"
          echo "       is the name of a writeable file (currently it is '$RESUME_FILE')"
          exit 1
        fi
    
        export MODULES=
    
            export NAME_`fix_variable_name $a`="$a"
            fix_and_assign MODULE "$a"
            export SEARCH_MODULES="$SEARCH_MODULES $MODULE"
            export ONLY="$ONLY $MODULE"
    
    Christian Engwer's avatar
    Christian Engwer committed
      find_modules_in_path
    
      if test "x$ONLY" != x; then
        export MODULES="$ONLY"
      elif test "x$SEARCH_MODULES" != "x"; then
    
      if test "x$REVERSE_FLAG" = "xyes"; then
        export MODULES="$REVERSEMODULES"
      fi
    
    
      if test "x$SKIPFIRST" = "xyes" ; then
    
        export MODULES=`echo $MODULES " " | cut '--delimiter= ' --fields=2-`
    
      if test -n "$superseded_modules"; then
    
        # sort moules list and make it unique.
    
        superseded_modules=$(echo $superseded_modules | tr ' ' '\n'| sort -u)
    
        echo "The following local modules do supersede the corresponding installed ones:"  >&2
        echo "$superseded_modules"  >&2
    
    # print the module list
    print_module_list() {
      DELIM=$1
      shift
      while test -n "$2"; do
        echo -n "$(eval echo \$NAME_$1)$DELIM"
        shift
      done
      echo -n "$(eval echo \$NAME_$1)"
    }
    
    
    # clear variables
    export SEARCH_MODULES=""
    export MODULES=""
    export ONLY=""
    
    export RESUME_FLAG=no
    
    # read environment variable USE_CMAKE
    export DUNE_USE_CMAKE="$(echo $USE_CMAKE)"
    
    
    # parse commandline parameters
    
    while test $# -gt 0; do
    
    Christian Engwer's avatar
    Christian Engwer committed
        command=$1
    
        set +e
        # stolen from configure...
        # when no option is set, this returns an error code
        arg=`expr "x$option" : 'x[^=]*=\(.*\)'`
        set -e
    
    
        case "$option" in
    
    Christian Engwer's avatar
    Christian Engwer committed
          if test "x$arg" = "x"; then
    
            echo "ERROR: Parameter for --opts is missing"  >&2
            echo  >&2
    
          DUNE_OPTS_FILE=`canonicalname $arg`
    
    Christian Engwer's avatar
    Christian Engwer committed
          if ! test -r "$DUNE_OPTS_FILE"; then
    
            echo "ERROR: could not read opts file \"$DUNE_OPTS_FILE\""  >&2
            echo  >&2
    
          optcmd=`expr "x$option=" : 'x--\([^-]*\)-opts=.*'`
          if is_command $optcmd; then
    
            COMMAND=`echo $optcmd | tr '[:lower:]' '[:upper:]'`
    
            export ${COMMAND}_FLAGS="$arg"
          else
            usage
    
            echo "ERROR: unknown option \"$option\""  >&2
    
    Christian Engwer's avatar
    Christian Engwer committed
          if test "x$arg" = "x"; then
    
            echo "ERROR: Parameter for --module is missing"  >&2
            echo  >&2
    
          for a in `echo $arg | tr ',' ' '`; do
    
    Christian Engwer's avatar
    Christian Engwer committed
            export NAME_`fix_variable_name $a`="$a"
    
            fix_and_assign MODULE "$a"
            export SEARCH_MODULES="$SEARCH_MODULES $MODULE"
          done
    
    Christian Engwer's avatar
    Christian Engwer committed
        --only=*)
    
    Christian Engwer's avatar
    Christian Engwer committed
          if test "x$arg" = "x"; then
    
    Christian Engwer's avatar
    Christian Engwer committed
            usage
    
            echo "ERROR: Parameter for --only is missing"  >&2
            echo  >&2
    
    Christian Engwer's avatar
    Christian Engwer committed
            exit 1;
          fi
    
          for a in `echo $arg | tr ',' ' '`; do
    
    Christian Engwer's avatar
    Christian Engwer committed
            export NAME_`fix_variable_name $a`="$a"
    
            fix_and_assign MODULE "$a"
            export SEARCH_MODULES="$SEARCH_MODULES $MODULE"
            export ONLY="$ONLY $MODULE"
          done