Skip to content
Snippets Groups Projects
dunecontrol 9.3 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 $MAKE; then
      MAKE=make
    fi
    
    ###############################################
    ###
    ### read lib
    ###
    
    
         echo Usage: canonicalname path > /dev/stderr
    
      readlink $1 || echo "$(dirname $1)/$(basename $1)"
    }
    
    canonicalpath(){
      if test $# -ne 1; then
         echo Usage: canonicalpath path > /dev/stderr
         return 1
      fi
      (cd $(dirname $(canonicalname $1)) && pwd)
    
    if test "x$1" = "x--debug"; then
      DEBUG=yes
    fi
    
    if test "x$DEBUG" = "xyes"; then
    
    . $(canonicalpath $0)/dunemodules.inc
    
    Christian Engwer's avatar
    Christian Engwer committed
    ###############################################
    
    #
    # for each module load the $CONTROL script part and run $command
    #
    # parameters:
    # $1 command to execute
    #
    
    Christian Engwer's avatar
    Christian Engwer committed
      command="$1"
    
      load_opts $command
      local runcommand=run_$command
    
    Christian Engwer's avatar
    Christian Engwer committed
      modules="$MODULES"
    
    Markus Blatt's avatar
    Markus Blatt committed
      if test x"$ONLY" != x; then
    
    Christian Engwer's avatar
    Christian Engwer committed
    	modules="$ONLY"
    
    Christian Engwer's avatar
    Christian Engwer committed
      fi  
      for module in $modules; do
    
        local path=$(eval "echo \$PATH_${module}")
    
    Christian Engwer's avatar
    Christian Engwer committed
        eval echo "--- calling $command for \$NAME_${module} ---"
    
        if ! (
    
          eval_control $runcommand $path/$CONTROL
    
        ); then echo "--- Failed to build $module ---"; exit 1; fi
        echo "--- $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:]')
    
    Christian Engwer's avatar
    Christian Engwer committed
      if test "x$DUNE_OPTS_FILE" != "x"; then
        echo "----- loading default flags \$${COMMAND}_FLAGS from $DUNE_OPTS_FILE -----"
        CMD_PARAMS="$(. $DUNE_OPTS_FILE; eval echo \$${COMMAND}_FLAGS)"
    
    }
    
    ###############################################
    
    ###
    ### Commands
    ###
    
    # list of all dunecontrol commands
    
    Christian Engwer's avatar
    Christian Engwer committed
    COMMANDS="update autogen configure make all exec svn"
    
    
    # help string for the commands
    update_HELP="updated all modules from the repository"
    autogen_HELP="run the autogen.sh script for each module"
    configure_HELP="run configure for each module"
           # "NOTE: the --with-dune* parameters will be generated by dunecontrol"
    make_HELP="run make for each module"
    
    all_HELP="\trun 'autogen', 'configure' and 'make' command for each module"
    
           # "NOTE: run all for an initial setup"
    exec_HELP="execute an arbitrary command in each module directory"
    
    svn_HELP="\trun svn command for each svn 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
    
    #
    # default implementations for commands... 
    # these can be overwritten in the $CONTROL files
    #
    
    run_default_exec () { bash -c "eval $CMD_PARAMS"; }
    
    run_default_update () {
      if test -d .svn; then
        svn update
        return
      fi
      if test -d CVS; then
        cvs update -dP
        return
      fi
      echo "WARNING: $module is not under a known version control system."
      echo "         We support svn and cvs."
    }
    
    run_default_autogen () {
    
      PARAMS="$CMD_PARAMS"
    
      local M4_PATH=""
    
      if test -x autogen.sh; then
    
        for m in $MODULES; do
          path=$(eval "echo \$PATH_$m")
          if test -d $path/m4; then
    
            M4_PATH="$path $M4_PATH"
    
        eval ./autogen.sh "$M4_PATH" "$PARAMS" || exit 1
    
    run_default_configure () {
    
      PARAMS="$CMD_PARAMS"
    
      if test -x configure; then
    
    Christian Engwer's avatar
    Christian Engwer committed
        if test "x$HAVE_dune_common" = "xyes"; then
    
          PARAMS="$PARAMS \"--with-dune-common=$PATH_dune_common\""
    
    Christian Engwer's avatar
    Christian Engwer committed
        if test "x$HAVE_dune_grid" = "xyes"; then
    
          PARAMS="$PARAMS \"--with-dune-grid=$PATH_dune_grid\""
    
    Christian Engwer's avatar
    Christian Engwer committed
        if test "x$HAVE_dune_istl" = "xyes"; then
    
          PARAMS="$PARAMS \"--with-dune-istl=$PATH_dune_istl\""
    
    Christian Engwer's avatar
    Christian Engwer committed
        if test "x$HAVE_dune_disc" = "xyes"; then
    
          PARAMS="$PARAMS \"--with-dune-disc=$PATH_dune_disc\""
    
        if test "x$HAVE_dune_fem" = "xyes"; then
          PARAMS="$PARAMS \"--with-dune-fem=$PATH_dune_fem\""
        fi
    
    Christian Engwer's avatar
    Christian Engwer committed
        if test "x$HAVE_duneweb" = "xyes"; then
          PARAMS="$PARAMS \"--with-duneweb=$PATH_duneweb\""
        fi
    
        echo ./configure "$PARAMS"
        eval ./configure "$PARAMS" || exit 1
    
      else
        if test -f configure.in || test -f configure.ac; then
    
          echo "ERROR: configure.[in|ac] found, but configure missing" > /dev/stderr
          echo "did you forget to run autoconf?" > /dev/stderr
    
    run_default_make () {
    
      PARAMS="$CMD_PARAMS"
    
      echo make "$PARAMS"
    
    Christian Engwer's avatar
    Christian Engwer committed
      eval $MAKE "$PARAMS"
    
    run_default_all () {
    
      load_opts autogen
    
      load_opts configure
    
    Christian Engwer's avatar
    Christian Engwer committed
    run_default_svn () {
      if test -d .svn; then
    	PARAMS="$CMD_PARAMS"
    	eval svn "$PARAMS"
      fi
    }
    
    
    ###############################################
    
      echo Execution terminated due to errors! > /dev/stderr
    
        echo "Usage: $(basename $0) [OPTIONS] COMMAND [COMMAND-OPTIONS]"
    
        echo "Execute COMMAND for all Dune modules found. All entries in the"
        echo "DUNE_CONTROL_PATH variable are scanned recusively Dune modules."
    	echo "If DUNE_CONTROL_PATH is empty, the current directory is scanned."
    
        echo "Dependencies are controlled by the $CONTROL files."
    
        echo "Options:"
        echo "  -h, --help         show this help"
        echo "      --debug        enable debug output of this script"
    
    Markus Blatt's avatar
    Markus Blatt committed
        echo "      --module=mod   only 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 "      --opts=FILE    load default options from FILE"
    
        echo "                     (see dune-common/doc/example.opts)"
    
        printf "  \`help'\tguess what :-)\n"
        printf "  \`print'\tprint the list of modules sorted after their dependencies\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
    if test "x$1" = "x"; then
    
    while test $# -gt 0; do
    
        set +e
        # stolen from configure...
        # when no option is set, this returns an error code
        arg=`expr "x$option" : 'x[^=]*=\(.*\)'`
    
        arg=$(eval "echo $arg")
    
        case "$option" in
    
    Christian Engwer's avatar
    Christian Engwer committed
          if test "x$arg" = "x"; then
    
            echo "ERROR: Parameter for --opts is missing"  > /dev/stderr
            echo  > /dev/stderr
    
    Christian Engwer's avatar
    Christian Engwer committed
          DUNE_OPTS_FILE=$(canonicalpath $arg)/$(basename $arg)
          if ! test -r "$DUNE_OPTS_FILE"; then
    
            echo "ERROR: could not read opts file \"$DUNE_OPTS_FILE\""  > /dev/stderr
            echo  > /dev/stderr
    
    Christian Engwer's avatar
    Christian Engwer committed
          if test "x$arg" = "x"; then
    
            echo "ERROR: Parameter for --module is missing"  > /dev/stderr
            echo  > /dev/stderr
    
          export NAME_`fix_variable_name $arg`="$arg"
    
          fix_and_assign MODULE "$arg"
    
    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"  > /dev/stderr
            echo  > /dev/stderr
    
    Christian Engwer's avatar
    Christian Engwer committed
            exit 1;
          fi
    
          export NAME_`fix_variable_name $arg`="$arg"
    
          fix_and_assign ONLY "$arg"
          fix_and_assign MODULE "$arg"
    
    Christian Engwer's avatar
    Christian Engwer committed
        ;;
    
    while test $# -gt 0; do
    
      # setup paramter list
      CMD_PARAMS="$CMD_PARAMS \"$1\""
      shift
      # disable usage of opts file
    
    Christian Engwer's avatar
    Christian Engwer committed
      if test "x$DUNE_OPTS_FILE" != "x"; then
        echo "WARNING: commandline parameters will overwrite setting in opts file \"$DUNE_OPTS_FILE\""
    
    Christian Engwer's avatar
    Christian Engwer committed
      DUNE_OPTS_FILE=""
    
    # We need to run this via eval in order construct the case for the commands
    eval '
    
    case "$command" in
    
      '$(echo $COMMANDS | sed -e 's/ / | /g')')
    
        if test "x$MODULE" = "x"; then
    
        for mod in $MODULES; do
          NAMES="$NAMES$(eval echo \$NAME_$mod) "
        done
        echo "--- going to build $NAMES ---"
    
          build_modules $command
    
        if test "x$MODULE" = "x"; then
    
          sort_modules $MODULES
        else
          sort_modules $MODULE
    
        for mod in $MODULES; do
          echo -n "$(eval echo \$NAME_$mod) "
        done
        echo
    
      export)
        find_modules_in_path
        if test "x$MODULE" = "x"; then
          sort_modules $MODULES
        else
          sort_modules $MODULE
        fi
        if test x. = x$DUNE_CONTROL_PATH; then
          DUNE_CONTROL_PATH=""
        fi
        for mod in $MODULES; do
          if test x != x$DUNE_CONTROL_PATH; then
            export DUNE_CONTROL_PATH="$DUNE_CONTROL_PATH:$(eval echo \$PATH_$mod/dune.module)"
          else
            export DUNE_CONTROL_PATH="$(eval echo \$PATH_$mod/dune.module)"
          fi
        done
        echo export DUNE_CONTROL_PATH=$DUNE_CONTROL_PATH
        ;;    
    
        echo "ERROR: unknown command \"$command\""  > /dev/stderr