Newer
Older
###############################################
###
### check for environment variables
###
if test -z $MAKE; then
MAKE=make
fi
###############################################
###
### read lib
###
Christian Engwer
committed
canonicalname(){
if test $# -ne 1; then
echo Usage: canonicalname path >&2
return 1
fi
name="$1"
while test -L "$name"; do
if ! test -e "$name"; then
echo $name: file not found >&2
return 1
fi
if newname="`readlink $name`"; then
name="$newname"
else
echo "$(dirname $name)/$(basename $name)"
fi
done
echo $name
Christian Engwer
committed
}
canonicalpath(){
if test $# -ne 1; then
echo Usage: canonicalpath path >&2
Christian Engwer
committed
return 1
fi
(cd $(dirname $(canonicalname $1)) && pwd)
if test "x$1" = "x--debug"; then
DEBUG=yes
fi
if test "x$DEBUG" = "xyes"; then
set -x
set -v
fi
export COMMAND_DIR="`canonicalpath $0`"
Markus Blatt
committed
# Read the modules find part
. "$COMMAND_DIR/dunemodules.inc"
Markus Blatt
committed
# create PKG_CONFIG_PATH for installed dune modules
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:`canonicalpath $0`/../lib/pkgconfig"
#
# for each module load the $CONTROL script part and run $command
#
# parameters:
# $1 command to execute
#
build_modules() {
load_opts $command
local runcommand=run_$command
local path=$(eval "echo \$PATH_${module}")
eval echo "--- calling $command for \$NAME_${module} ---"
eval_control $runcommand $path/$CONTROL
); then eval echo "--- Failed to build \$NAME_${module} ---"; exit 1; fi
Christian Engwer
committed
eval echo "--- \$NAME_${module} done ---"
#
# load command options from an opts file
# 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:]')
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)"
else
CMD_PARAMS="$(eval echo \$${COMMAND}_FLAGS)"
}
###############################################
# check wheteher the parameter is valid command or not
is_command() {
eval '
case "$1" in
'$(echo $COMMANDS | sed -e 's/ / | /g')')
return 0
;;
*)
return 1
;;
esac'
}
# list of all dunecontrol commands
COMMANDS="update autogen configure make all exec status 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"
status_HELP="show vc status for all modules"
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_status () {
local verbose=0
local update=""
for i in $CMD_PARAMS; 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"
reset="\e[0m\e[37m"
fi
if test $verbose -eq 1; then
svn status $update | grep -E "^M|^A|^D|^C|^U"
elif test $verbose -eq 2; then
svn status $update
fi
name="$(eval echo \$NAME_$module)"
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)
color=$green
text="no changes"
if [ $changed -eq 0 ]; then
true
elif [ $changed -eq 1 ]; then
color=$blue;
text="1 change"
else
color=$blue;
text="$changed changes"
fi
if [ $pending -eq 0 ]; then
true
elif [ $pending -eq 1 ]; then
color=$blue;
text="$text, 1 update pending"
else
color=$blue;
text="$text, $pending updates pending"
fi
if [ $collisions -eq 0 ]; then
true
elif [ $collisions -eq 1 ]; then
color=$red
text="$text, 1 collision"
color=$red
text="$text, $count collisions"
echo -e "$color[$text]$reset $name"
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."
}
Christian Engwer
committed
if test -x autogen.sh; then
for m in $FOUND_MODULES; do
path=$(eval "echo \$PATH_$m")
if test -d $path/m4; then
M4_PATH="$path $M4_PATH"
fi
done
if test -f autogen.sh; then
eval echo "WARNING: \$NAME_$module contains obsolete autogen.sh," >&2
echo " dune-autogen is used instead." >&2
# eval ./autogen.sh "$M4_PATH" "$PARAMS" || exit 1
Christian Engwer
committed
eval "$COMMAND_DIR/dune-autogen" "$M4_PATH" "$PARAMS" || exit 1
fi
run_default_configure () {
PARAMS="$PARAMS \"--with-dune-common=$PATH_dune_common\""
PARAMS="$PARAMS \"--with-dune-grid=$PATH_dune_grid\""
PARAMS="$PARAMS \"--with-dune-istl=$PATH_dune_istl\""
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
if test "x$HAVE_dune_subgrid" = "xyes"; then
PARAMS="$PARAMS \"--with-dune-subgrid=$PATH_dune_subgrid\""
fi
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" >&2
echo "did you forget to run autoconf?" >&2
run_default_svn () {
if test -d .svn; then
PARAMS="$CMD_PARAMS"
eval svn "$PARAMS"
fi
}
###############################################
echo "Execution of $(basename $0) terminated due to errors!" >&2
(
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 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 "Options:"
echo " -h, --help show this help"
echo " --debug enable debug output of this script"
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)"
echo " --[COMMAND]-opts=opts set options for COMMAND"
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"
# create the module list
create_module_list() {
find_modules_in_path
Christian Engwer
committed
if test "x$SEARCH_MODULES" != "x"; then
Christian Engwer
committed
else
sort_modules $MODULES
fi
if test "x$ONLY" != x; then
export MODULES="$ONLY"
fi
}
# 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 command opts
for i in $COMMANDS; do
COMMAND=$(echo $i | tr '[:lower:]' '[:upper:]')
export ${COMMAND}_FLAGS=""
done
Christian Engwer
committed
# clear variables
export SEARCH_MODULES=""
export MODULES=""
export ONLY=""
# parse commandline parameters
# get option
option=$1
shift
set +e
# stolen from configure...
# when no option is set, this returns an error code
arg=`expr "x$option" : 'x[^=]*=\(.*\)'`
set -e
echo "ERROR: Parameter for --opts is missing" >&2
echo >&2
DUNE_OPTS_FILE=$(canonicalpath $arg)/$(basename $arg)
if ! test -r "$DUNE_OPTS_FILE"; then
echo "ERROR: could not read opts file \"$DUNE_OPTS_FILE\"" >&2
echo >&2
;;
--*-opts=*)
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
exit 1
fi
-p|--print)
command=print
break
;;
echo "ERROR: Parameter for --module is missing" >&2
echo >&2
for a in `echo $arg | tr ',' ' '`; do
export NAME_`fix_variable_name $arg`="$a"
fix_and_assign MODULE "$a"
export SEARCH_MODULES="$SEARCH_MODULES $MODULE"
done
echo "ERROR: Parameter for --only is missing" >&2
echo >&2
for a in `echo $arg | tr ',' ' '`; do
export NAME_`fix_variable_name $arg`="$a"
fix_and_assign MODULE "$a"
export SEARCH_MODULES="$SEARCH_MODULES $MODULE"
export ONLY="$ONLY $MODULE"
done
echo "ERROR: Unknown option \`$option'" >&2
echo >&2
COMMAND=$(echo $command | tr '[:lower:]' '[:upper:]')
# setup paramter list
CMD_PARAMS="$CMD_PARAMS \"$1\""
shift
# 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\""
# We need to run this via eval in order construct the case for the commands
print)
eval "print_module_list ' ' $MODULES"
m4depends)
find_modules_in_path
if test "x$SEARCH_MODULES" != "x"; then
MODULES=$SEARCH_MODULES
fi
sort_dependencies $MODULES
eval "print_module_list ',' $MODULES"
;;
m4suggests)
find_modules_in_path
if test "x$SEARCH_MODULES" != "x"; then
MODULES=$SEARCH_MODULES
eval "print_module_list ',' $MODULES"
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
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
m4create)
find_modules_in_path
mainmod=`echo $SEARCH_MODULES`
fname="dependencies.m4"
name=`eval echo \\${NAME_$mainmod}`
version=`eval echo \\${VERS_$mainmod}`
maintainer=`eval echo \\${MAIN_$mainmod}`
echo "writing $fname"
echo " for $name $version $maintainer"
cat > $fname <<EOF
m4_define([DUNE_AC_INIT],[
AC_INIT([$name], [$version], [$maintainer])
AC_SUBST([DUNE_MOD_VERSION], [$version])
AC_SUBST([DUNE_MOD_NAME], [$name])
AC_SUBST([DUNE_MAINTAINER_NAME], [$maintainer])
# don't build shared libs per default, this is way better for debugging...
m4_ifdef([LT_INIT],
[LT_INIT],
[AC_DEFUN([LT_OUTPUT])])
AC_DISABLE_SHARED
])
AC_DEFUN([DUNE_CHECK_MOD_DEPENDENCIES], [
AC_REQUIRE([PKG_PROG_PKG_CONFIG])
AC_PROG_LIBTOOL
AC_PROG_CXX
LT_OUTPUT
EOF
### DEPENDENCIES
if test "x$SEARCH_MODULES" != "x"; then
MODULES=$SEARCH_MODULES
fi
sort_dependencies $MODULES
for mod in $MODULES; do
name=`eval echo \\$NAME_$mod`
MOD=`echo $mod | tr [:lower:] [:upper:]`
cat >> $fname <<EOF
### check dependency $name
# invoke checks required by this module
AC_REQUIRE([${MOD}_CHECKS])
# invoke check for this module
AC_REQUIRE([${MOD}_CHECK_MODULE])
if test x\$with_$mod = xno; then
AC_MSG_ERROR([could not find required module _dune_name])
fi
EOF
done
###
sort_suggestions $mainmod
for mod in $MODULES; do
name=`eval echo \\$NAME_$mod`
MOD=`echo $mod | tr [:lower:] [:upper:]`
cat >> $fname <<EOF
### check suggestion $name
# invoke checks required by this module
AC_REQUIRE([${MOD}_CHECKS])
# invoke check for this module
AC_REQUIRE([${MOD}_CHECK_MODULE])
if test x\$with_$mod = xno; then
AC_MSG_WARN([could not find suggested module _dune_name])
fi
EOF
done
###
mod=$mainmod
name=`eval echo \\$NAME_$mod`
MOD=`echo $mod | tr [:lower:] [:upper:]`
cat >> $fname <<EOF
### invoke checks for $name
AC_REQUIRE([${MOD}_CHECKS])
])
EOF
;;
if is_command $command; then
for mod in $MODULES; do
NAMES="$NAMES$(eval echo \$NAME_$mod) "
done
echo "--- going to build $NAMES ---"
build_modules $command
echo "--- done ---"
else
usage
echo "ERROR: unknown command \"$command\"" >&2
exit 1
fi