Skip to content
Snippets Groups Projects
duneproject 11.6 KiB
Newer Older
  • Learn to ignore specific revisions
  • # * In case of an installed Dune, it should not be necessary to pass the
    #   dune-common dir to autogen.sh.
    # * Check module names entered as dependencies.
    
    	if test $# -ne 1; then
    		echo Usage: canonicalname path >&2
    		return 1
    	fi
    	file="$1"
    	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
    
      dirname $(canonicalname "$1")
    
    pkg_config_dependencies(){
        if test $# -ne 1; then
    
    	echo Usage: pkg_config_dependencies name >&2
    
    	return 1
        fi
        name="$1"
        depends="`pkg-config --variable=DEPENDENCIES $name| sed -e 's/,/ /g'`"
        for pkg in $depends; do
    	depends="$depends `pkg_config_dependencies $pkg`"
        done
        echo $depends
    }
    
    
    Markus Blatt's avatar
     
    Markus Blatt committed
    modulesexist(){
      allfound=0
    
      for dep in $1; do
          found=0
          for module in $2; do
    	  if [ "$dep" = "$module" ]; then
    	      found=1
    	      break
    	  fi
          done
          if [ "$found" = "0" ]; then
    
    	  echo "ERROR:">&2
    	  echo "Module with name $dep was not found" >&2
    	  echo "Did you forget to specify it's location" >&2
    	  echo "in the DUNE_CONTROL_PATH variable?">&2
    	  echo >&2
    
    Markus Blatt's avatar
     
    Markus Blatt committed
    	  allfound=1
          fi
      done
      return $allfound
    }
    
    
    Markus Blatt's avatar
     
    Markus Blatt committed
    make_unique(){
      if [ "$#" = "1" ]; then
          # take first word
          for exclude_word in $1; do
    	  break;
          done
          make_unique $exclude_word "$1" 0
      else
          local exclude_word="$1"
          local words="$2"
          local pos="$3"
          local length=0
          local i=0
          local new_words=""
          local cur=0
          for word in $words; do
    	  if [ $i -le $pos ]; then
    	      i=$((i+1))
    	      length=$((length+1))
    	      new_words="$new_words $word"
    	      continue
    	  fi
    	  if [ "$word" != "$exclude_word" ]; then
    	      new_words="$new_words $word"
    	      if [ "$((length-1))" = "$pos" ]; then
    		  next_word="$word"
    	      fi
    	      length=$((length+1))
    	  fi
          done
          if [ "$pos" -lt "$length" ]; then
           # process next word
    	  make_unique "$next_word" "$new_words" $((pos+1))
          else
    	  export UNIQUE_WORDS="$new_words"
          fi
      fi
    }
           
    
    echo
    echo == Dune project/module generator ==
    echo
    echo duneproject will assist you in the creation of a new Dune application.
    echo During this process a new directory with the name of your project will be
    echo created. This directory will hold all configuration and Makefiles and a
    echo simple example application.
    echo
    
    ################## FIND AVAILABLE MODULES ##################
    
    . $(canonicalpath $0)/dunemodules.inc
    
    
    # create PKG_CONFIG_PATH for installed dune modules
    export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$(canonicalpath $0)/../lib/pkgconfig"
    
    
    # search for modules, both installed and src modules
    find_modules_in_path
    
    
    # get the real module names
    
    MODULES=""
    for i in $FOUND_MODULES; do
    
      mod=$(eval echo \$NAME_$i)
    
      MODULES="$MODULES$mod "
    
    if [ "$MODULES" = "" ]; then
      echo "ERROR:">&2
      echo "  No dune modules were found!">&2
      echo "  Did you forget to specify the places where ">&2
      echo "  you installed your modules in the ">&2
      echo "  DUNE_CONTROL_PATH environment variable">&2
      echo "  and adjusted the PKG_CONFIG_PATH environment">&2
      echo "  accordingly?" >&2
    
    ################## READ OPTIONS ##################
    
    while [ "$DATACORRECT" != "y" -a "$DATACORRECT" != "Y" ]; do
      PROJECT=""
      while [ -z $PROJECT ]; do
    
        read -p "1) Name of your new Project? (e.g.: dune-grid): " PROJECT
    
        if echo "$MODULES" | grep -q ^$PROJECT$; then
    
          read -p "   A module named $PROJECT already exists. Continue anyway? [y/N] " CONT
          if test x$DELETE = xy -o x$DELETE = xY; then
            PROJECT=""
          fi
        fi
    
    Markus Blatt's avatar
     
    Markus Blatt committed
      DEP_OK=1
    
      while [ "$DEPOK" != 0 ]; do
    
      echo "2) Which modules should this module depend on?"
      echo "   Following modules are found:"
    
      echo "   $MODULES"
    #  for i in $MODULES; do echo -n " $i"; done
    #  echo ""
    
      while [ -z "$DEPENDENCIES" ]; do
    
          read -p "   Enter space separated list: " DEPENDENCIES
    
    Markus Blatt's avatar
     
    Markus Blatt committed
      set +e
    
      modulesexist "$DEPENDENCIES" "$MODULES"
    
    Markus Blatt's avatar
     
    Markus Blatt committed
      DEPOK=$?
      set -e
      done
    
        read -p "3) Project/Module version? " VERSION
    
      done
      MAINTAINER=""
      while [ -z $MAINTAINER ]; do
    
        read -p "4) Maintainers email address? " MAINTAINER
    
      echo "creating Project \"$PROJECT\", version $VERSION "
    
      echo "which depends on \"$DEPENDENCIES\""
    
      echo "with maintainer \"$MAINTAINER\""
    
      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."
    
    if test -d $PROJECT; then
      echo WARNING:
      echo "A directory with the name $PROJECT already exists."
      echo "Do you want to continue anyway?"
      read -p "Type Y to overwrite the old directory, N to abort. [y/N] " DELETE
      if test x$DELETE != xy -a x$DELETE != xY; then
        echo Abort...
        exit 1
      fi
      rm -rf "$PROJECT"
    fi
    
    
    ################## dune.module ##################
    cat > "$PROJECT/dune.module" <<C_DELIM
    
    #dune module information file#
    ##############################
    
    #Name of the module
    
    Module:$MODULE
    
    Version:$VERSION
    Maintainer:$MAINTAINER
    
    C_DELIM
    
    ################## CONFIGURE.AC ##################
    
    
    ## Create the parameters passed to DUNE_CHECK_ALL
    
    Markus Blatt's avatar
     
    Markus Blatt committed
    
    
    # save module list of dunemodules.inc
    save_MODULES=$MODULES
    for name in $DEPENDENCIES; do
      mod="`fix_variable_name $name`"
      if test "x$(eval echo \$HAVE_$mod)" != "x"; then
        # found via dunemodules.inc
    
        sort_modules "$mod"
        for mod in $MODULES; do
          M_DEPS="$M_DEPS $(eval echo \$NAME_$mod)"
        done
    
        MODULES=$save_MODULES
      else
        # found via pkg-config
    
        M_DEPS="`pkg_config_dependencies $name` $name"
        #M_DEPS="`pkg-config --variable=Requires $name`"
    
      fi
      for dep in $M_DEPS; do
    
    Markus Blatt's avatar
     
    Markus Blatt committed
          CHECK="$CHECK [$dep]"
    
    Markus Blatt's avatar
     
    Markus Blatt committed
    make_unique "$CHECK"
    
    Markus Blatt's avatar
     
    Markus Blatt committed
    
    # insert , between modules
    j=0
    for dep in $UNIQUE_WORDS; do
    if [ "$j" = "0" ]; then
          CHECK="$dep"
          j=1
        else
          CHECK="$CHECK, $dep"
        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)
    
    DUNE_AC_INIT # gets module version from dune.module file
    
    AM_INIT_AUTOMAKE
    
    AC_CONFIG_SRCDIR([$CMODULE.cc])
    
    Markus Blatt's avatar
     
    Markus Blatt committed
    # we need no more than the standard DE-stuff
    
    # this module depends on $DEPENDENCIES
    # this implies checking for $CHECK
    
    DUNE_CHECK_ALL
    
    
    # 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
    
    ################## 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:
    
    If these preliminaries are met, you should run 
    
    which will find all installed dune modules as well as all dune modules 
    (not installed) which sources reside in a subdirectory of the current 
    directory. Note that if dune is not installed properly you will either
    have to add the directory where the dunecontrol script resides (probably 
    ./dune-common/bin) to your path or specify the relative path of the script.
    
    On your project and all uninstalled DUNE source modules found the script 
    will then calls the GNU autoconf/automake to create a ./configure-script 
    and the Makefiles. Afterwards that configure script will be called and the
    modules will be build using make all
    
    Most probably you'll have to provide additional information to dunecontrol 
    (e. g. compilers, configure options) and/or make options. 
    
    The most convenient way is to use options files in this case. The files
    defining three variables:
    
    AUTOGEN_FLAGS    flags passed to autogen
    CONFIGURE_FLAGS  flags passed to configure
    MAKE_FLAGS       flags passed to make
    
    An example options file might look like this:
    
    #use this options to autogen, configure and make if no other options are given
    AUTOGEN_FLAGS="--ac=2.50 --ac=1.8" #Forces automake 2,50 and autoconf 1.8
    CONFIGURE_FLAGS="CXX=g++-3.4 --prefix=/install/path" #force g++-3.4 as compiler
    MAKE_FLAGS=install #Per default run make install instead of simply make
    
    If you save this information into example.opts you can path the opts file to
    dunecontrol via the --opts option, e. g.
    
      dunecontrol --opts=example.opts all
    
    To get a full list of available configure flags just run
    
    after running at least 
      dunecontrol autogen
    
    The full build-system is described in the dune-common/doc/buildsystem (SVN version) or under share/doc/dune-common/buildsystem if you installed DUNE!
    
    
    R_DELIM
    
    ################## MAKEFILE.AM ##################
    cat> "$PROJECT/Makefile.am" << M_DELIM
    # \$Id$
    
    
    Markus Blatt's avatar
    Markus Blatt committed
    # 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)
    
    
    ${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)
    
    # don't follow the full GNU-standard
    # we need automake 1.5
    AUTOMAKE_OPTIONS = foreign 1.5
    
    # pass most important options when "make distcheck" is used
    DISTCHECK_CONFIGURE_FLAGS = --with-dune=\$(DUNEROOT) CXX="\$(CXX)" CC="\$(CC)"
    
    Christian Engwer's avatar
    Christian Engwer committed
    ################## STAMP-VC ##################
    touch $PROJECT/stamp-vc
    
    
    ################## PROJECT.CC ##################
    
    cat> "$PROJECT/$CMODULE.cc" << CC_DELIM
    
    #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;
      }