Skip to content
Snippets Groups Projects
dunecontrol 6.74 KiB
Newer Older
  • Learn to ignore specific revisions
  • 
    if test "x$1" = "x--debug"; then
      DEBUG=yes
    fi
    
    if test "x$DEBUG" = "xyes"; then
    
    
    ###############################################
    
    #
    # Configuration
    #
    
    # name of the "control" files
    CONTROL="dune.module"
    
    ###############################################
    
    #
    # LIB
    #
    
    parse_control() {
      if test -f "$1"; then
    	export module=$(echo $(grep Module: "$1" | cut -d ':' -f2))
        deps=$(echo $(grep Depends: "$1" | cut -d ':' -f2))
        sugs=$(echo $(grep Suggests: "$1" | cut -d ':' -f2))
    	path=$(dirname "$1")
        if test "x$module" != "x"; then
          export HAVE_${module}=yes
    	  export PATH_${module}="$path"
    	  export DEPS_${module}="$deps"
    	  export SUGS_${module}="$sugs"
        fi
      else
    	echo "ERROR: could not read file $1"
    	false
      fi
    }
    
    find_modules() {
      if test -d "$1"; then
        dir=$(cd "$1" && pwd)
    	while read m; do
    	  if test "x$m" != "x"; then
    		export module=""
    		parse_control "$m"
            export MODULES="$MODULES $module"
          fi
    	done <<EOF
     $(find "$dir" -name $CONTROL )
    EOF
      else
    	echo "ERROR: could not find directory $1"
    	false
      fi
    }
    
    #
    # load the $CONTROL file, skip all control variables
    # and run a command
    #
    # parameters:
    # $1 command to execute
    # $2 full path of the $CONTROL file
    #
    eval_control() {
      command=$1
      file=$2
      shift 2
      if test -f "$file"; then
    	# open subshell
    	(
    
          # load functions defined in $file
    	  # if $command is not defined in $file,
    	  # then the default implementation will be executed
    	  eval "$(grep -v -e '^[[:alnum:]]\+:' $file)"
    	  # execute $command
    
      fi
    }
    
    _build_module() {
      command=$1
      module=$2
      shift 2
    
      if test "x$(eval echo \$BUILD_DONE_${command}_${module})" != "xyes"; then
    
        echo "--- building $module ---"
    	# resolve dependencies
    	for dep in $(eval "echo \$DEPS_$module"); do
          echo "--- $module depends on $dep ... calling ---"
    
          (set -e; _build_module $command $dep "$@") || false
    
        done
    	# resolve suggestions
    	for dep in $(eval "echo \$SUGS_$module"); do
          echo -n "--- $module suggests $dep ... "
          if test "x$(eval echo \$HAVE_$dep)" != "x"; then
    		echo "calling ---"
    
            (set -e; _build_module $command $dep "$@") || false
    
    	  else
    		echo "skipping ---"
    	  fi
        done
    	# really build this module
    	echo "--- calling $command for $module ---"
    
        export BUILD_DONE_${command}_${module}=yes
    
    	path=$(eval "echo \$PATH_${module}")
    	(
    
          cd "$path"
    	  eval_control $command $path/$CONTROL "$@"
    
      else
        echo "--- skipping $module ---"
      fi
    }
    
    build_modules() {
    
      command=$1
      runcommand=run_$command
    
      load_opts $command
    
      for m in $MODULES; do
    
        _build_module $runcommand $m "$@"
    
    load_opts() {
      command=$1
      COMMAND=$(echo $command | tr '[:lower:]' '[:upper:]')
      if test "x$OPTS_FILE" != "x"; then
        echo "----- loading default flags \$${COMMAND}_FLAGS from $OPTS_FILE -----"
        CMD_PARAMS="$(. $OPTS_FILE; eval echo \$${COMMAND}_FLAGS)"
      fi
    
    }
    
    ###############################################
    
    #
    # default implementations for commands... 
    # these can be overwritten in the $CONTROL files
    #
    
    
    COMMANDS="autogen configure make all exec"
    
    run_default_nothing () { echo -n; }
    
    run_default_exec () { bash -c "eval $CMD_PARAMS"; }
    
    run_default_update () { echo "WARNING: Doing nothing"; }
    
    run_default_autogen () {
    
      PARAMS="$CMD_PARAMS"
    
      if test -x autogen.sh; then
    	for m in $MODULES; do
    	  path=$(eval "echo \$PATH_$m")
    	  if test -d $path/m4; then
    
    		ACLOCAL_FLAGS="$path $ACLOCAL_FLAGS"
    
    	eval ./autogen.sh "$ACLOCAL_FLAGS" "$PARAMS" || exit 1
    
    run_default_configure () {
    
      PARAMS="$CMD_PARAMS"
    
      if test -x configure; then
    
        if test "x$HAVE_dune_common" == "xyes"; then
          PARAMS="$PARAMS \"--with-dunecommon=$PATH_dune_common\""
        fi
        if test "x$HAVE_dune_grid" == "xyes"; then
          PARAMS="$PARAMS \"--with-dunegrid=$PATH_dune_grid\""
        fi
        if test "x$HAVE_dune_istl" == "xyes"; then
          PARAMS="$PARAMS \"--with-duneistl=$PATH_dune_istl\""
        fi
        if test "x$HAVE_dune_disc" == "xyes"; then
    
          PARAMS="$PARAMS \"--with-dunedisc=$PATH_dune_disc\""
    
    	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"
    	  echo "did you forget to run autoconf?"
    
    run_default_make () {
    
      PARAMS="$CMD_PARAMS"
    
      echo make "$PARAMS"
      eval make "$PARAMS"
    
    run_default_all () {
    
      load_opts autogen
    
      load_opts configure
    
    run_nothing () {
      run_default_nothing "$@"
    }
    run_exec () {
      run_default_exec "$@"
    
    }
    run_update () {
      run_default_update "$@"
    }
    run_autogen () {
      run_default_autogen "$@"
    }
    run_configure () {
      run_default_configure "$@"
    }
    run_make () {
      run_default_make "$@"
    }
    run_all () {
      run_default_all "$@"
    }
    
    
    ###############################################
    
    #
    # main
    #
    
    
    onfailure() {
      echo Execution terminated due to errors!
      exit 1
    }
    
    
    usage () {
        echo "Usage: $0 [OPTIONS] COMMAND [COMMAND-OPTIONS]"
        echo ""
        echo "Execute COMMAND for all Dune modules."
        echo "Dependencies are controlled by the dune.module files."
        echo ""
    	echo "Options:"
    	echo "  -h, --help         show this help"
    	echo "      --debug        enable debug output of this script"
    	echo "      --opts=FILE    load default options from FILE (see dune-common/bin/example.opts)"
    	echo "Commands:"
    	echo "  \`help'"
    	for i in $COMMANDS; do
          echo "  \`$i'"
        done
        echo
    }
    
    
    if test "x$1" == "x"; then
      usage
      exit 1
    fi
    
    
    while test "x$1" != "x"; do
    	# get option
    	option=$1
    	shift
    
    	# get args
        set +e
        # stolen from configure...
        # when no option is set, this returns an error code
        arg=`expr "x$option" : 'x[^=]*=\(.*\)'`
        set -e
    
    	# switch
        case "$option" in
    	--opts=*)
    	  if test "x$arg" == "x"; then
    		usage
    		echo "ERROR: Parameter for --opts is missing"
    		echo
    		exit 1;
    	  fi
    	  OPTS_FILE=$(cd $(dirname $arg); pwd)/$(basename $arg)
    	  if ! test -r "$OPTS_FILE"; then
    		usage
    		echo "ERROR: could not read opts file \"$OPTS_FILE\""
    		echo
    		exit 1;
    	  fi
    	;;
    	-h|--help) 
          command=help
    	  break
        ;;
    	--debug) true ;;
    	*)
          command=$option
    	  break
        ;;
        esac
    done
    
    while test "x$1" != "x"; do
      # setup paramter list
      CMD_PARAMS="$CMD_PARAMS \"$1\""
      shift
      # disable usage of opts file
      if test "x$OPTS_FILE" != "x"; then
    	echo "WARNING: commandline parameters will overwrite setting in opts file \"$OPTS_FILE\""
      fi 
      OPTS_FILE=""
    done
    
    case "$command" in
    
      update | autogen | configure | make | all | exec | nothing)
    
        find_modules .
    
        build_modules $command "$@"
    
    	usage
    	;;
      *)
        echo "ERROR: unknown command \"$command\""
    	usage