# mbuild configuration file
 
-# type of compile. Possible values: NONE, CPP, CMAKE, PDF
+# type of compile. Possible values: NONE, CPP, CMAKE, PDF, OLD (for downward compatibility)
 compile_type=NONE
 # compile target
 compile_target=
 
        echo "  -V : version set by project"
 }
 
+function create_build {
+       pushd $BUILD_DIR >/dev/null
+               if [ "$compile_type" == "PDF" ]
+               then
+                       echo "make $compile_target" > debian/$paket.build
+                       chmod 755 debian/$paket.build
+               else
+                       echo "build for compile_type not implemented."
+                       exit 10
+               fi
+       popd >/dev/null
+}
 function cmake_check {
        pushd ../build >/dev/null
                # do checks
        fi
 
        # .build
-       if [ "$compile_type" != "CMAKE" ]
+       if [ "$compile_type" != "CMAKE" -a "$compile_type" != "OLD" ]
        then
                cp debian/rules.pre $BUILD_DIR/$compile_dir/make.pre
                pushd $BUILD_DIR/$compile_dir >/dev/null
                popd >/dev/null
        fi
                
-       if [ -x debian/$paket.build ]
+       if [ -x debian/$paket.prebuild ]
        then
-               if [ -x debian/$paket.prebuild ]
-               then
-                       pushd $BUILD_DIR >/dev/null
-                               . debian/setenv.sh
-                               debian/$paket.prebuild
-                       popd >/dev/null
-               fi
+               pushd $BUILD_DIR >/dev/null
+                       . debian/setenv.sh
+                       debian/$paket.prebuild
+               popd >/dev/null
+       fi
+       if ! [ -x debian/$paket.build -o -f debian/$paket.cmake ]
+       then
+               create_build
        fi
 
        # .cmake
 
        ./configure -I
 }
 
+function create_conf {
+       if [ -f "debian/$paket.cmake" ]
+       then
+               echo "compile_type=CMAKE" > debian/$paket.conf
+       elif [ -f "debian/$paket.build" ]
+       then
+               if [ -f "debian/$paket.cpp" ]
+               then
+                       echo "compile_type=CPP" > debian/$paket.conf
+               else
+                       echo "compile_type=OLD" > debian/$paket.conf
+               fi
+       else
+               echo "compile_type=NONE" > debian/$paket.conf
+       fi
+       
+       if [ -f "$paket.control" -a -f "$paket.cp" ]
+       then
+               echo "target_type=DEB" >> debian/$paket.conf
+       else
+               echo "target_type=FILE" >> debian/$paket.conf
+       fi
+       echo "$paket.conf created."
+}
+
 ##############################################################################
 # Main program
 ##############################################################################
 
 if [ ! -f debian/$paket.conf ]
 then
+       # check if any files for $paket are present
+       if ! ls debian/$paket.* 2>/dev/null
+       then
+               echo "$paket is no build target in this repository."
+               exit 5
+       fi
+       
+       # build conf file
        echo "$paket.conf missing. We create it ..."
-       echo "to be implemented ..."
-       exit 5
+       create_conf
 fi
 
 if [ ! -e configure ]
                rm -rf ~/build
                mkdir ~/build
        fi
+       configure_args="$configure_args -b"
 fi
 
 # perform configure
 elif [ "$target_type" == "FILE" ]
 then
        echo "PACK=version" >> debian/rules.pre
-       if [ -z "$compile_target" ]
+       if [ "$compile_type" != "OLD" ]
        then
-               echo "compile_target is needed for target_type FILE"
-               exit 12
+               if [ -z "$compile_target" ]
+               then
+                       echo "compile_target is needed for target_type FILE"
+                       exit 12
+               fi
+               echo "TARGET = $compile_target" >> debian/rules.pre
        fi
-       echo "TARGET = $compile_target" >> debian/rules.pre
-       
 else
        echo "Unknown target type: $target_type"
        exit 13