Newer
Older
#!/bin/bash
#
# TODO:
#
# * anpasen, dass bei installiertem Dune das DUNEDIR nicht an
# autogen.sh uebergeben weden muss.
Markus Blatt
committed
# * Check whether the module and module directory does not exists already,
set -e
Christian Engwer
committed
canonicalname(){
if test $# -ne 1; then
Christian Engwer
committed
echo Usage: canonicalname path > /dev/stderr
return 1
fi
Christian Engwer
committed
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)
Sreejith Pulloor Kuttanikkad
committed
echo Dune project/module generator
echo -----------------------------
################## READ OPTIONS ##################
while [ "$DATACORRECT" != "y" -a "$DATACORRECT" != "Y" ]; do
PROJECT=""
while [ -z $PROJECT ]; do
read -p "New Project name? (A directory with this name will be created, e.g.: dune-grid): " PROJECT
Markus Blatt
committed
MODULE="$PROJECT"
Markus Blatt
committed
# Read the modules find part
Christian Engwer
committed
. $(canonicalpath $0)/dunemodules.inc
if [ "$MODULES" = "" ]; then
# get the real module names
SRC_MODULES=""
for i in $MODULES; do
mod=$(eval echo \$NAME_$i)
SRC_MODULES="$SRC_MODULES $mod"
# get installed modules
PKG_MODULES="`pkg-config --list-all | grep dune | cut -d' ' -f1`"
# merge lists
ALL_MODULES="`echo $SRC_MODULES $PKG_MODULES | tr ' ' '\n' | sort | uniq`"
Markus Blatt
committed
DEPENDENCIES=""
echo "Which modules should this module depend on? Following modules are found:"
for i in $ALL_MODULES; do echo " $i"; done
while [ -z "$DEPENDENCIES" ]; do
read -p "Enter space separated list: " DEPENDENCIES
Markus Blatt
committed
done
VERSION=""
while [ -z $VERSION ]; do
Sreejith Pulloor Kuttanikkad
committed
read -p "Project/Module version? " VERSION
done
MAINTAINER=""
while [ -z $MAINTAINER ]; do
read -p "Maintainers email address? " MAINTAINER
done
echo
echo -n "creating Project \"$PROJECT\", version $VERSION "
echo "with maintainer \"$MAINTAINER\""
Markus Blatt
committed
echo "which depends on \"$DEPENDENCIES\""
read -p "Are these informations correct? [y/N] " DATACORRECT
done
echo
echo "A sample code $MODULE.cc is generated in the \"$PROJECT\" directory."
echo "Look at the README and dune.module files there."
echo "Now you can run dunecontrol script which will setup the new module."
echo "Sometimes you may have to tweak configure.ac a bit."
Sreejith Pulloor Kuttanikkad
committed
mkdir "$PROJECT"
Sreejith Pulloor Kuttanikkad
committed
################## dune.module ##################
cat > "$PROJECT/dune.module" <<C_DELIM
#dune module information file#
##############################
#Name of the module
Sreejith Pulloor Kuttanikkad
committed
#depending on
Markus Blatt
committed
Depends:$DEPENDENCIES
Sreejith Pulloor Kuttanikkad
committed
C_DELIM
################## CONFIGURE.AC ##################
## Create the parameters passed to DUNE_CHECK_ALL
j=0
for i in $DEPENDENCIES; do
if [ "$j" = "0" ]; then
CHECK="[$i]"
j=1
else
CHECK="$CHECK,[$i]"
fi
done
# we need the module with _ instead of - to not confuse automake
fix_and_assign CMODULE $MODULE
cat > "$PROJECT/configure.ac" <<C_DELIM
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.50)
AC_INIT($PROJECT, $VERSION, $MAINTAINER)
AM_INIT_AUTOMAKE($PROJECT, $VERSION, $MAINTAINER)
AC_CONFIG_SRCDIR([$CMODULE.cc])
AM_CONFIG_HEADER([config.h])
Sreejith Pulloor Kuttanikkad
committed
# we need no more than the standard DUNE-stuff
# implicitly set the Dune-flags everywhere
AC_SUBST(AM_CPPFLAGS, \$DUNE_CPPFLAGS)
AC_SUBST(AM_LDFLAGS, \$DUNE_LDFLAGS)
LIBS="\$DUNE_LIBS"
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
# finally print the summary information
DUNE_SUMMARY_ALL
C_DELIM
################## AUTOGEN.SH ##################
cat > "$PROJECT/autogen.sh" <<A_DELIM
#!/bin/sh
Sreejith Pulloor Kuttanikkad
committed
# $Id$
Sreejith Pulloor Kuttanikkad
committed
# barf on errors
set -e
usage () {
echo "Usage: ./autogen.sh [options]"
Sreejith Pulloor Kuttanikkad
committed
echo " --ac=, --acversion=VERSION use a specific VERSION of autoconf"
echo " --am=, --amversion=VERSION use a specific VERSION of automake"
echo " -h, --help you already found this :-)"
}
Sreejith Pulloor Kuttanikkad
committed
for OPT in "\$@"; do
set +e
# stolen from configure...
# when no option is set, this returns an error code
arg=\`expr "x\$OPT" : 'x[^=]*=\(.*\)'\`
set -e
case "\$OPT" in
Sreejith Pulloor Kuttanikkad
committed
--ac=*|--acversion=*)
Sreejith Pulloor Kuttanikkad
committed
usage;
exit 1;
fi
ACVERSION=\$arg
;;
--am=*|--amversion=*)
Sreejith Pulloor Kuttanikkad
committed
usage;
exit 1;
fi
AMVERSION=\$arg
;;
-h|--help) usage ; exit 0 ;;
Sreejith Pulloor Kuttanikkad
committed
*)
if test -d "\$OPT/m4"; then
ACLOCAL_FLAGS="\$ACLOCAL_FLAGS -I \$OPT/m4"
fi
if test -d "$OPT/share/aclocal"; then
ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I $OPT/share/aclocal"
fi
Sreejith Pulloor Kuttanikkad
committed
if test -d "\$OPT/am"; then
am_dir="\$OPT/am"
fi
;;
esac
done
Sreejith Pulloor Kuttanikkad
committed
## report parameters
if test "x\$ACVERSION" != "x"; then
echo "Forcing autoconf version \$ACVERSION"
if ! which autoconf\$ACVERSION > /dev/null; then
echo
echo "Error: Could not find autoconf\$ACVERSION"
echo " Did you specify a wrong version?"
exit 1
fi
fi
Sreejith Pulloor Kuttanikkad
committed
if test "x\$AMVERSION" != "x"; then
echo "Forcing automake version \$AMVERSION"
if ! which automake\$AMVERSION > /dev/null; then
echo
echo "Error: Could not find automake\$AMVERSION"
echo " Did you specify a wrong version?"
exit 1
fi
fi
Sreejith Pulloor Kuttanikkad
committed
## run autotools
echo "--> libtoolize..."
Sreejith Pulloor Kuttanikkad
committed
# this script won't rewrite the files if they already exist. This is a
# PITA when you want to upgrade libtool, thus I'm setting --force
libtoolize --force
Sreejith Pulloor Kuttanikkad
committed
# prepare everything
echo "--> aclocal..."
Sreejith Pulloor Kuttanikkad
committed
aclocal\$AMVERSION \$ACLOCAL_FLAGS
Sreejith Pulloor Kuttanikkad
committed
# applications should provide a config.h for now
echo "--> autoheader..."
Sreejith Pulloor Kuttanikkad
committed
autoheader\$ACVERSION
# create a link to the dune-common am directory
echo "--> linking dune-common/am..."
rm -f am
ln -s \$am_dir am
Sreejith Pulloor Kuttanikkad
committed
# call automake/conf
echo "--> automake..."
Sreejith Pulloor Kuttanikkad
committed
automake\$AMVERSION --add-missing
echo "--> autoconf..."
Sreejith Pulloor Kuttanikkad
committed
autoconf\$ACVERSION
Sreejith Pulloor Kuttanikkad
committed
## tell the user what to do next
echo "Now run ./configure "
A_DELIM
chmod +x "$PROJECT/autogen.sh"
################## README ##################
cat > "$PROJECT/README" <<R_DELIM
Preparing the Sources
=========================
Additional to the software mentioned in README you'll need the
following programs installed on your system:
automake >= 1.5
autoconf >= 2.50
libtool
Getting started
---------------
If these preliminaries are met, you should run the script
./autogen.sh
which calls the GNU autoconf/automake to create a ./configure-script
and the Makefiles. Most probably you'll have to provide where to find
the DUNE-files by
./autogen.sh --with-dune=PATH
where PATH is a directory with a dune/-subdirectory inside (this
convention is needed to keep the #include-syntax consistent even when
the headers are installed into /usr/include/dune later).
Passing options to ./configure
------------------------------
autogen.sh also calls the newly created configure-script to
conveniently pass on options about the used compiler. Thus you'll have
to provide autogen.sh any options you want configure to get, e.g.
./autogen.sh --with-dune=... --with-albert=... --without-x
Choosing the compiler and the options
-------------------------------------
The selection of the compiler works as follows: if --gnu or --intel is
passed to autogen it reads the content of gcc.opts or icc.opts to get
the default compiler flags. With the option --optim you can switch the
compiler-specific optimization parameters on.
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
If you want to change the compiler options to your favourites you can
either
- adapt the appropriate .opts-file and rerun autogen.sh. Please don't
commit this changed file to CVS if you're not sure if the options
work for everybody.
- copy an existing .opts-file to a new name, change the options and
use
./autogen.sh --opts=my.opts
More info
---------
See
./autogen.sh --help
and (if it exists)
./configure --help
for further options.
The full build-system is described in the dune/doc/Buildsystem (not in
duneapps/doc!)
\$Id$
R_DELIM
################## MAKEFILE.AM ##################
cat> "$PROJECT/Makefile.am" << M_DELIM
# \$Id$
# we need the module file to be able to build via dunecontrol
EXTRA_DIST=dune.module
# possible options
#LDADD = \$(UG_LDFLAGS) \$(AMIRAMESH_LDFLAGS) \$(UG_LIBS) \$(AMIRAMESH_LIBS)
#AM_CPPFLAGS = \$(UG_CPPFLAGS) \$(AMIRAMESH_CPPFLAGS)
noinst_PROGRAMS = ${CMODULE}
${CMODULE}_SOURCES = $CMODULE.cc
${CMODULE}_CXXFLAGS = \$(MPI_CPPFLAGS) \$(UG_CPPFLAGS) \$(AMIRAMESH_CPPFLAGS) \$(ALBERTA_CPPFLAGS)
${CMODULE}_LDADD = \$(MPI_LDFLAGS) \$(ALBERTA_LDFLAGS) \$(ALBERTA_LIBS) \$(AMIRAMESH_LDFLAGS) \$(AMIRAMESH_LIBS) \$(UG_LDFLAGS) \$(UG_LIBS) \$(MPI_LDFLAGS) \$(DUNE_LDFLAGS) \$(DUNE_LIBS)
Sreejith Pulloor Kuttanikkad
committed
# don't follow the full GNU-standard
# we need automake 1.5
AUTOMAKE_OPTIONS = foreign 1.5
Sreejith Pulloor Kuttanikkad
committed
# pass most important options when "make distcheck" is used
DISTCHECK_CONFIGURE_FLAGS = --with-dune=\$(DUNEROOT) CXX="\$(CXX)" CC="\$(CC)"
M_DELIM
################## PROJECT.CC ##################
cat> "$PROJECT/$CMODULE.cc" << CC_DELIM
Sreejith Pulloor Kuttanikkad
committed
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <iostream>
#include"dune/common/mpihelper.hh" // An initializer of MPI
#include"dune/common/exceptions.hh" // We use exceptions
int main(int argc, char** argv)
{
try{
//Maybe initialize Mpi
Dune::MPIHelper& helper = Dune::MPIHelper::instance(argc, argv);
std::cout << "Hello World! This is ${PROJECT}." << std::endl;
if(Dune::MPIHelper::isFake)
std::cout<< "This is a sequential program." << std::endl;
else
std::cout<<"I am rank "<<helper.rank()<<" of "<<helper.size()
<<" processes!"<<std::endl;
return 0;
}
catch (Dune::Exception &e){
std::cerr << "Dune reported error: " << e << std::endl;
}
catch (...){
std::cerr << "Unknown exception thrown!" << std::endl;
}
}
CC_DELIM