+ # add auto created files to .cm.ignore
+ if ! grep Makefile .cm.ignore >/dev/null ; then echo "Makefile" >>.cm.ignore; fi
+ if ! grep configure .cm.ignore >/dev/null ; then echo "configure" >>.cm.ignore; fi
+ if ! grep debian/rules .cm.ignore >/dev/null ; then echo "debian/rules" >>.cm.ignore; fi
+ if ! grep debian/rules.pre .cm.ignore >/dev/null ; then echo "debian/rules.pre" >>.cm.ignore; fi
+ if ! grep debian/setenv.sh .cm.ignore >/dev/null ; then echo "debian/setenv.sh" >>.cm.ignore; fi
+ if ! grep debian/tmp .cm.ignore >/dev/null ; then echo "debian/tmp" >>.cm.ignore; fi
+
+ project=$(pwd)
+ project=${project##*/}
+ pushd .. >/dev/null
+ mCM $project -b -an > /dev/null
+ wc=$(wc $project.batch)
+ rm $project.batch
+ if [ "${wc:0:1}" != "1" ]
+ then
+ echo "M"
+ fi
+ popd >/dev/null
+}
+
+function set_build {
+ set -e
+ if [ -e .svn ]
+ then
+ version="0.0"
+ build=$(svnversion)
+ build=${build/:/-}
+ build="$build$(check_unversioned)"
+ elif [ -e .git ]
+ then
+ tag=$(git describe --tags --match "${paket}_*" 2>/dev/null) || true
+ if test -z "$tag"
+ then
+ # try generic "v_" tag
+ tag=$(git describe --tags --match "v_*" 2>/dev/null) || true
+ fi
+ if test -z "$tag"
+ then
+ tag="0.0-0TOP"
+ fi
+ changes=$(check_unversioned)
+ tag="$tag$changes"
+ version=${tag##*_}
+ version=${version%%-*}
+ build=${tag##*-}
+ else
+ echo "No configuration system found. Cannot determine version."
+ exit 3
+ fi
+}
+
+function check_version {
+ set -e
+
+ vline=$(head -1 debian/$paket.changelog)
+ vline=${vline%-*}
+ clversion=${vline#*(}
+ if [ $version = "0.0" ]
+ then
+ version=$clversion
+ return
+ fi
+
+ # do no check on a modified git repos
+ if [ "${build: -1}" == "M" ]
+ then
+ return
+ fi
+
+ if [ "$clversion" != $version ]
+ then
+ echo "version mismatch: git: $version, changelog: $clversion"
+ exit 4
+ fi
+}
+
+function add_sources {
+ echo "Anz: $#"
+ for suf in $*
+ do
+ find . -name "*.$suf" -exec echo " "{}" \\" >> make.pre \;
+ done
+ if [ $# -eq 2 ]
+ then
+ rm make.tmp || true
+ find . -name "*.$2" -exec echo {} >> make.tmp \;
+ while read line
+ do
+ echo " ${line/\.$2/\.$1} \\" >> make.pre
+ done < make.tmp
+ fi
+}
+
+##############################################################################
+# Main program
+##############################################################################
+
+install_dir="/"
+compile_type=NONE
+extern_build=0
+
+while [ $OPTIND -le "$#" ]
+do
+ if getopts "ha:bc:C:d:e:i:n:t:v:V" opt
+ then
+ case $opt in
+ h) echo_usage
+ exit 0
+ ;;
+ a) ARCH=$OPTARG
+ ;;
+ b) extern_build=1
+ ;;
+ c) compile_type=$OPTARG
+ ;;
+ C) cross=$OPTARG
+ ;;
+ d) compile_dir=$OPTARG
+ ;;
+ d) compile_target=$OPTARG
+ ;;
+ i) install_dir=$OPTARG
+ ;;
+ n) target_name=$OPTARG
+ ;;
+ t) target_type=$OPTARG
+ ;;
+ v) optversion=$OPTARG
+ ;;
+ V) optversion="0.0"
+ ;;
+ \?) echo "Invalid option: -$OPTARG"
+ echo_usage
+ exit 5
+ ;;
+ :) echo "Option -$OPTARG requires an argument."
+ echo_usage
+ exit 6
+ ;;
+ esac
+ else
+ paket="${!OPTIND}"
+ eval OPTIND=OPTIND+1
+ fi
+done
+
+if [ -z "$paket" ]