+projects (0.6-%BUILD%) unstable; urgency=medium
+  * calls PAKET.prepare (if present) in config step
+  * RSYNC_OPTS in rules.pre
+  * cpp build support
+ -- Michael Wagner <michael@wagnertech.de>  Thu, 11 Apr 2019 22:54:48 +0100
+
 projects (0.5-%BUILD%) unstable; urgency=medium
   * mconfigure -o for Debian 7 downward compatibility
   * works with multiple git tags on the same commit
 
 cp tools/make/rules $base/usr/share/mbuild/
 cp tools/make/insert_build.sh $base/usr/share/mbuild/
 cp tools/make/mMakefile $base/usr/share/mbuild/makefile
+cp tools/make/c_configure.sh $base/usr/share/mbuild/
+cp tools/make/cpp.make $base/usr/share/mbuild/
 
 mkdir -p $base/usr/share/man/man8
 gzip -c doc/mbuild.8 >$base/usr/share/man/man8/mbuild.8.gz
 
 file is needed. Per 
 default this script also performs compile and pack step.
 
+If a
+.B PAKET.prepare
+file is present in the debian directory, it is called.
+
 If a
 .B PAKET.build
-file is present in the debian directory, it is called with a -prepare parameter.
+file is present in the debian directory, it is called with a -prepare parameter (deprecated).
+The current tree is rsync_ed to ~/build.
+
+If a
+.B PAKET.prebuild
+file is present in the debian directory, it is called in the ~/build directory.
+
 .TP
 compile
 To perform the compile step a
   * Build in svn-Umgebung
  -- Michael Wagner <michael@wagnertech.de>  Fr 10. Aug 22:54:48 CEST 2018
 .TP
+PAKET.prepare
+Any executable script file executed in configure step
+.TP
+PAKET.prebuild
+Any executable script file executed in configure step in the ../build directory
+.TP
 PAKET.build
 Any executable script file executing the build in the ../build directory
 .TP
 
        # has to be called in the projects base directory
        # result: "M" in stdout or nothing
        
+       set -e
        project=$(pwd)
        project=${project##*/}
        pushd .. >/dev/null
 }
 
 function set_build {
+       set -e
        if [ -e .svn ]
        then
                version="0.0"
 }
 
 function check_version {
+       set -e
        
        vline=$(head -1 debian/$paket.changelog)
        vline=${vline%-*}
                exit 1
        fi
 }
-# to build a package you need ...
-# <package>.cp (optional): copy step for package production
-# <package>.cpp.sh (optional): commands to setup the C++ compile environment
 
 if [ ! -d debian ]
 then
        
        echo "paket=$paket" >> debian/setenv.sh
        echo "oldpack=\"$oldpack\"" >> debian/setenv.sh
-       cpp_build=0
 
        set_build
        check_version
                    echo "add_inst_tgt += debian/tmp/DEBIAN/postrm" >> rules.pre
        fi
        
-       #cat setenv.sh >> rules.pre
-
        mkdir -p tmp/DEBIAN
 
-       # load util functions for C/C++ - build
-       if [ -f $paket.cpp.sh ]
-       then
-               cpp_build=1
-               . projects/tools/make/c_configure.sh
-               . $paket.cpp.sh
-       fi
-       
        # add export to setenv.sh
        sed -i "s/^/export /" setenv.sh
 
                # proceed
                echo
        else
-               # try old fashoned way
-               control=$(find etc -name $paket.control) || true
-               if [ -z "$control" ]
-               then
-                       echo "warning: control file not found"
-                       echo "  this file is necessary for any package production."
-               else    
-                       echo "Source: $paket
-Section: main
-Priority: optional
-Maintainer: WagnerTech UG <mail@wagnertech.de>
-" > debian/$paket.control
-                       grep -v "Version:" $control |grep -v "Maintainer:" >> debian/$paket.control 
-               fi
+               echo "warning: control file not found"
+               echo "  this file is necessary for any package production."
        fi
        
        # build prepare
+       if [ -x debian/$paket.prepare ]
+       then
+               debian/$paket.prepare
+       fi
        if [ -e debian/$paket.build ]
        then
                if [ -e ../build ]
                        debian/rules sync
                        debian/$paket.build -prepare
                fi
+               # sync build dir
+               . debian/setenv.sh
+               debian/rules sync
+               
+               # executing prebuild
+               if [ -x debian/$paket.prebuild ]
+               then
+                       pushd ~/build >/dev/null
+                       debian/$paket.prebuild
+                       popd >/dev/null
+               fi
        fi
        
        # pack prepare
 
 if [ $compile -eq 1 -a ! -e debian/$paket.build ]
 then
-       echo "no debian/build.sh: skipping build step"
+       echo "no debian/$paket.build: skipping build step"
        compile=0
 fi
 if [ $compile -eq 1 ]
 
 NOP = @echo "No operation for target $@"
 DEB = fakeroot dpkg-deb --build $(oldpack) debian/tmp
 INSERT_BUILD = /usr/share/mbuild/insert_build.sh
+RSYNC_OPT = -av --exclude="build" --exclude="debian/tmp" --exclude="Packages" --exclude=".*"
 
 include debian/rules.pre
 
 
 # Bauen der kompilierten Programme und formatierten Dokumente aus den Quellen im Bauverzeichnis
 build: debian/$(paket).build sync
-       debian/$(paket).build
+       cd ../build ; debian/$(paket).build
        # Build succeeded
 
 pack: $(PACK)
 ../build:
        mkdir ../build
 
-sync:
-       #bash -c 'for dirs in $$(ls); do rsync -av $$dirs ../build; done'
-       rsync -av --exclude="build" --exclude="debian/tmp" --exclude="Packages" --exclude=".*" ./ ../build/
+sync: ../build
+       rsync $(RSYNC_OPT) ./ ../build/
 
 copy: debian/$(paket).cp
        debian/$(paket).cp debian/tmp