Index: quilt-compat9/aclocal.m4
===================================================================
--- /dev/null
+++ quilt-compat9/aclocal.m4
@@ -0,0 +1,4 @@
+
+m4_include(m4/compat.m4)dnl
+m4_include(m4/getopt.m4)dnl
+m4_include(m4/mktemp.m4)dnl
Index: quilt-compat9/m4/compat.m4
===================================================================
--- /dev/null
+++ quilt-compat9/m4/compat.m4
@@ -0,0 +1,49 @@
+
+dnl Allow configure to specify a specific binary
+dnl 1: Environment variable
+dnl 2: binary name
+dnl 3: optional list of alternatives
+dnl 4: tests to verify binary works.  tests should set $1='' to signify failure
+AC_DEFUN([QUILT_COMPAT_PROG_PATH],[
+  m4_define([internal_$2_cmd],[esyscmd(ls compat/$2.in compat/$2.sh 2>/dev/null)])
+  m4_if(internal_$2_cmd,[],[],
+    m4_define([internal_$2_shell_func],[esyscmd(ls compat/$2.sh 2>/dev/null)])
+  )
+
+  AC_ARG_WITH($2, AC_HELP_STRING(
+    [--with-$2], [name of the $2 executable to use]
+                 m4_if(internal_$2_cmd,[],[],[ (or 'none'
+                          to use an internal mechanism)])),
+  [
+    if test ! x"$withval" = xnone; then
+      $1="$withval"
+      AC_MSG_NOTICE([Using $2 executable $$2])
+      COMPAT_SYMLINKS="$COMPAT_SYMLINKS $2"
+    fi
+  ],[
+    AC_PATH_PROG($1, m4_if([$3],[],[$2],[$3]))
+  ])
+  m4_if([$4],[],[],[
+  if test -n "$$1"; then
+    $1_RESULT='yes'
+    $4
+    if test ! x"$$1_RESULT" = xyes; then
+      $1=''
+    fi
+  fi
+  ])
+  if test -z "$$1"; then
+    m4_if(internal_$2_cmd,[],[
+      AC_MSG_ERROR([Please specify the location of $2 with the option '--with-$2'])
+    ],[
+      AC_MSG_WARN([Using internal $2 mechanism.  Use option '--with-$2' to override])
+      m4_if(internal_$2_shell_func,[],[
+        COMPAT_PROGRAMS="$COMPAT_PROGRAMS $2"],[
+	COMPAT_FUNCTIONS="$COMPAT_FUNCTIONS $2"]);
+      $1=$2
+    ])
+  fi
+  AC_SUBST($1)
+])
+
+
Index: quilt-compat9/m4/getopt.m4
===================================================================
--- /dev/null
+++ quilt-compat9/m4/getopt.m4
@@ -0,0 +1,16 @@
+
+AC_DEFUN([AX_PROG_GETOPT_LONG],[
+  AC_MSG_CHECKING(for getopt --long syntax)
+  dnl check GNU syntax
+  $GETOPT -o t --long test -- --test | grep -q 'illegal option'
+  getopt_long_errors=$?
+  $GETOPT -o t --long test -- --test | grep -qe '^ *--test *--'
+  getopt_long_works=$?
+  if test $getopt_long_errors -eq 1 -a $getopt_long_works -eq 0; then
+    AC_MSG_RESULT(yes)
+  else
+    AC_MSG_WARN(no)
+    GETOPT_RESULT='no'
+  fi
+])
+
Index: quilt-compat9/m4/mktemp.m4
===================================================================
--- /dev/null
+++ quilt-compat9/m4/mktemp.m4
@@ -0,0 +1,12 @@
+
+AC_DEFUN([AX_PROG_MKTEMP_DIR],[
+  AC_MSG_CHECKING(whether $MKTEMP -d works)
+  if tempdir=`$MKTEMP -d /tmp/$PACKAGE_NAME.XXXXXX 2>/dev/null` && \
+       rmdir "$tempdir" ; then
+    AC_MSG_RESULT(yes)
+  else
+    AC_MSG_WARN(no)
+    MKTEMP_RESULT='no'
+  fi
+])
+
Index: quilt-compat9/configure.ac
===================================================================
--- quilt-compat9.orig/configure.ac
+++ quilt-compat9/configure.ac
@@ -36,18 +36,8 @@ fi
 
 dnl Check for Bourne-Again Shell
 unset BASH  # bash sets this itself!
-AC_ARG_WITH(bash, AC_HELP_STRING(
-    [--with-bash], [name of the bash executable to use]),
-    [
-	BASH="$withval"
-	AC_SUBST(BASH)
-	AC_MSG_NOTICE([Using bash executable $BASH])
-    ],[
-	AC_PATH_PROG(BASH, bash)
-    ])
-if test -z "$BASH" ; then
-    AC_MSG_ERROR([Please specify the location of bash with the option '--with-bash'])
-fi
+
+QUILT_COMPAT_PROG_PATH(BASH, bash)
 
 # It would be nice not to have to use backticks, but too many retarded sh
 # implementations still don't support $( )
@@ -64,104 +54,24 @@ version of bash from ftp.gnu.org
 fi
 
 dnl Check for Perl
-AC_ARG_WITH(perl, AC_HELP_STRING(
-    [--with-perl], [name of the Perl executable to use]),
-    [
-	PERL="$withval"
-	AC_SUBST(PERL)
-	AC_MSG_NOTICE([Using Perl executable $PERL])
-    ],[
-	AC_PATH_PROGS(PERL, [perl perl5])
-    ])
-if test -z "$PERL" ; then
-    AC_MSG_ERROR([Please specify the location of Perl with the option '--with-perl'])
-fi
-
+QUILT_COMPAT_PROG_PATH(PERL, perl, [perl perl5])
+QUILT_COMPAT_PROG_PATH(GREP, grep)
 dnl Check for sed
-AC_ARG_WITH(sed, AC_HELP_STRING(
-    [--with-sed], [name of the sed executable to use]),
-    [
-	SED="$withval"
-	AC_SUBST(SED)
-	AC_MSG_NOTICE([Using sed executable $SED])
-    ],[
-	SED="sed"
-	AC_SUBST(SED)
-    ])
-
+QUILT_COMPAT_PROG_PATH(SED, sed)
 dnl Check for awk
-AC_ARG_WITH(awk, AC_HELP_STRING(
-    [--with-awk], [name of the awk executable to use]),
-    [
-	AWK="$withval"
-	AC_SUBST(AWK)
-	AC_MSG_NOTICE([Using awk executable $AWK])
-    ],[
-	AC_PATH_PROGS(AWK, [gawk awk])
-    ])
+QUILT_COMPAT_PROG_PATH(AWK, awk, [gawk awk])
 
-dnl Test for awk features that may be mising?
-
-if test -z "$AWK" ; then
-    AC_MSG_ERROR([Please specify the location of awk with the option '--with-awk'])
-fi
+QUILT_COMPAT_PROG_PATH(POD2MAN, pod2man)
+QUILT_COMPAT_PROG_PATH(COLUMN, column)
+QUILT_COMPAT_PROG_PATH(GETOPT, getopt, [], [AX_PROG_GETOPT_LONG])
 
 dnl Checks for mktemp (for creating temporary files and directories)
-AC_ARG_WITH(mktemp, AC_HELP_STRING(
-    [--with-mktemp], [name of the mktemp executable to use (or 'none'
-		      to use a quilt internal mechanism)]),
-    [
-	MKTEMP="$withval"
-	AC_SUBST(MKTEMP)
-	AC_MSG_NOTICE([Using mktemp executable $MKTEMP])
-    ],[
-	AC_PATH_PROG(MKTEMP, mktemp)
-    ])
-if test -z "$MKTEMP" -o "$MKTEMP" = "none" ; then
-    MKTEMP=internal_mktemp
-else
-    AC_MSG_CHECKING(whether $MKTEMP -d works)
-    if tempdir=`$MKTEMP -d /tmp/$PACKAGE_NAME.XXXXXX 2>/dev/null` && \
-       rmdir "$tempdir" ; then
-	AC_MSG_RESULT(yes)
-    else
-	AC_MSG_RESULT(no)
-	AC_MSG_ERROR([
-'$MKTEMP -d' does not create temporary directories.
-If you don't have a version of mktemp that can create directories, you
-can specify '--with-mktemp=none' and $PACKAGE_NAME will use its own
-internal tempfile generation mechanism.
-])
-    fi
-fi
+QUILT_COMPAT_PROG_PATH(MKTEMP, mktemp, [], [AX_PROG_MKTEMP_DIR])
 
 dnl Check for diff
-AC_ARG_WITH(diff, AC_HELP_STRING(
-    [--with-diff], [name of the diff executable to use]),
-    [
-	DIFF="$withval"
-	AC_SUBST(DIFF)
-	AC_MSG_NOTICE([Using diff executable $DIFF])
-    ],[
-	AC_PATH_PROG(DIFF, diff)
-    ])
-if test -z "$DIFF"; then
-    AC_MSG_ERROR([Please specify the location of diff with the option '--with-diff'])
-fi
-
+QUILT_COMPAT_PROG_PATH(DIFF, diff)
 dnl Check for patch
-AC_ARG_WITH(patch, AC_HELP_STRING(
-    [--with-patch], [name of the patch executable to use]),
-    [
-	PATCH="$withval"
-	AC_SUBST(PATCH)
-	AC_MSG_NOTICE([Using patch executable $PATCH])
-    ],[
-	AC_PATH_PROG(PATCH, patch)
-    ])
-if test -z "$PATCH"; then
-    AC_MSG_ERROR([Please specify the location of patch with the option '--with-patch'])
-fi
+QUILT_COMPAT_PROG_PATH(PATCH, patch)
 
 # Sun's patch is a mess, issue a warning.  But we are going to continue with
 # the build because you might just be lucky.
@@ -283,6 +193,10 @@ dnl Check for rpmbuild (v4) vs. rpm (v3)
 AC_PATH_PROGS(RPMBUILD, [rpmbuild rpm])
 AC_SUBST(RPMBUILD)
 
+AC_SUBST(COMPAT_SYMLINKS)
+AC_SUBST(COMPAT_PROGRAMS)
+AC_SUBST(COMPAT_FUNCTIONS)
+
 AC_CONFIG_FILES(Makefile)
 AC_OUTPUT
 
Index: quilt-compat9/Makefile.in
===================================================================
--- quilt-compat9.orig/Makefile.in
+++ quilt-compat9/Makefile.in
@@ -1,3 +1,5 @@
+SHELL := @BASH@
+
 PACKAGE :=	@PACKAGE_NAME@
 VERSION :=	@PACKAGE_VERSION@
 RELEASE :=	@PACKAGE_RELEASE@
@@ -15,11 +17,16 @@ etcdir :=	$(subst /usr/etc,/etc,$(prefix
 
 QUILT_DIR =	$(datadir)/$(PACKAGE)
 SCRIPTS_DIR =	$(QUILT_DIR)/scripts
+COMPAT_DIR =	$(QUILT_DIR)/compat
 LIB_DIR =	$(libdir)/$(PACKAGE)
 
 INSTALL :=	@INSTALL@
+POD2MAN :=	@POD2MAN@
+COLUMN :=	@COLUMN@
+GETOPT :=	@GETOPT@
 PERL :=		@PERL@
 BASH :=		@BASH@
+GREP :=		@GREP@
 SED :=		@SED@
 AWK :=		@AWK@
 DIFF :=		@DIFF@
@@ -30,6 +37,10 @@ DIFFSTAT :=	@DIFFSTAT@
 RPMBUILD :=	@RPMBUILD@
 MTA :=		@MTA@
 
+COMPAT_SYMLINKS  := @COMPAT_SYMLINKS@
+COMPAT_FUNCTIONS := @COMPAT_FUNCTIONS@
+COMPAT_PROGRAMS  := @COMPAT_PROGRAMS@
+
 ifeq "$(MSGFMT)" ""
 MAKE_NLS :=	@true
 else
@@ -69,10 +80,12 @@ DIRT +=		$(QUILT_IN:%=quilt/%)
 
 SCRIPTS_IN :=	patchfns parse-patch inspect dependency-graph edmail \
 		remove-trailing-ws
+
+COMPAT :=       $(COMPAT_PROGRAMS:%=compat/%) $(COMPAT_FUNCTIONS:%=compat/%)
 SCRIPTS_SRC :=	$(SCRIPTS_IN:%=%.in)
 SCRIPTS :=	$(SCRIPTS_IN)
-SRC +=		$(SCRIPTS_SRC:%=scripts/%)
-DIRT +=		$(SCRIPTS_IN:%=scripts/%)
+SRC +=		$(SCRIPTS_SRC:%=scripts/%) $(COMPAT_PROGRAMS:%=compat/%.in)
+DIRT +=		$(SCRIPTS_IN:%=scripts/%) $(COMPAT) compat/compatfns
 
 LIB_SRC :=	backup-files.c
 LIB :=		backup-files$(EXEEXT)
@@ -112,7 +125,12 @@ all : scripts
 $(LIB:%=lib/%) : $(LIB_SRC:%.c=lib/%.o)
 	$(CC) -o $@ $(LDFLAGS) $^ $(LIBS)
 
-scripts : $(BIN:%=bin/%) $(QUILT:%=quilt/%) $(SCRIPTS:%=scripts/%) \
+compat : $(COMPAT)
+ifneq ($(COMPAT_FUNCTIONS),)
+	cat $(COMPAT_FUNCTIONS:%=compat/%) > compat/compatfns
+endif
+
+scripts : $(BIN:%=bin/%) $(QUILT:%=quilt/%) $(SCRIPTS:%=scripts/%) compat \
 	  $(LIB:%=lib/%) $(DOC:%=doc/%) $(MAN1)
 
 dist : clean $(PACKAGE)-$(VERSION).tar.gz
@@ -135,20 +153,20 @@ doc/README : doc/README.in $(QUILT:%=qui
 		esac ; \
 	done 2>&1 < $< > $@
 	
-doc/quilt.1: doc/quilt.1.in $(QUILT:%=quilt/%)
+doc/quilt.1: doc/quilt.1.in $(QUILT:%=quilt/%) $(COMPAT)
 	@echo "quilt.1.in -> quilt.1"
 	@here=`pwd`;                                     \
 	 while read line; do                             \
 	  case "$$line" in                               \
 	    '@REFERENCE''@')                             \
 	       for cmd in $(sort $(QUILT:%=quilt/%)) ; do \
-		(@BASH@ -c ". scripts/patchfns ; LC_ALL=C . $$here/$$cmd -h")| \
+		($(BASH) -c ". scripts/patchfns ; LC_ALL=C . $$here/$$cmd -h")| \
 		   sed -e 's/Usage: quilt //'            \
 	               -e 's/^\([^ ]*\)/\\fB\1\\fP/'     \
 		       -e 's/^/.IP "/' -e 's/$$/ " 4/' | \
 	           head -n 1;                            \
 	         echo ;                                  \
-		(@BASH@ -c ". scripts/patchfns ; LC_ALL=C . $$here/$$cmd -h")| \
+		($(BASH) -c ". scripts/patchfns ; LC_ALL=C . $$here/$$cmd -h")| \
 	         grep -v 'Usage: quilt' |                \
 	           sed -e $$'s/^\t//'                    \
 	               -e $$'s/\t/\\\n/' |               \
@@ -169,7 +187,7 @@ reference : $(QUILT:%=quilt/%) scripts/p
 	for i in $(filter-out scripts/patchfns,$+); \
 	do \
 		echo; \
-		(@BASH@ -c ". scripts/patchfns ; cd $$dir ;LC_ALL=C . $$i -h"); \
+		($(BASH) -c ". scripts/patchfns ; cd $$dir ;LC_ALL=C . $$i -h"); \
 		echo; \
 	done | \
 	sed -e 's/\$$EDITOR ([^)]*)/$$EDITOR/' \
@@ -178,7 +196,7 @@ reference : $(QUILT:%=quilt/%) scripts/p
 
 bin/guards.1 : bin/guards
 	mkdir -p `dirname $@`
-	pod2man $< > $@
+	$(POD2MAN) $< > $@
 
 $(PACKAGE)-$(VERSION).tar.gz : $(SRC) configure $(PACKAGE).spec
 	rm -f $(PACKAGE)-$(VERSION) $@
@@ -232,38 +250,57 @@ Makefile : Makefile.in
 	@echo "Please run ./configure by hand"
 	@false
 
-install : scripts
-	@INSTALL@ -d $(BUILD_ROOT)$(bindir)
-	@INSTALL@ -m 755 $(BIN:%=bin/%) $(BUILD_ROOT)$(bindir)/
+install-main: scripts
+	$(INSTALL) -d $(BUILD_ROOT)$(bindir)
+	$(INSTALL) -m 755 $(BIN:%=bin/%) $(BUILD_ROOT)$(bindir)/
 
-	@INSTALL@ -d $(BUILD_ROOT)$(QUILT_DIR)
-	@INSTALL@ -m 755 $(QUILT:%=quilt/%) $(BUILD_ROOT)$(QUILT_DIR)/
+	$(INSTALL) -d $(BUILD_ROOT)$(QUILT_DIR)
+	$(INSTALL) -m 755 $(QUILT:%=quilt/%) $(BUILD_ROOT)$(QUILT_DIR)/
 	
-	@INSTALL@ -d $(BUILD_ROOT)$(SCRIPTS_DIR)
-	@INSTALL@ -m 755 $(patsubst %,scripts/%, \
+	$(INSTALL) -d $(BUILD_ROOT)$(SCRIPTS_DIR)
+	$(INSTALL) -m 755 $(patsubst %,scripts/%, \
 			     $(filter-out patchfns,$(SCRIPTS))) \
 		  $(BUILD_ROOT)$(SCRIPTS_DIR)
-	@INSTALL@ -m 644 scripts/patchfns $(BUILD_ROOT)$(SCRIPTS_DIR)
+	$(INSTALL) -m 644 scripts/patchfns $(BUILD_ROOT)$(SCRIPTS_DIR)
 
-	@INSTALL@ -d $(BUILD_ROOT)$(LIB_DIR)
-	@INSTALL@ -m 755 -s $(LIB:%=lib/%) $(BUILD_ROOT)$(LIB_DIR)/
+	$(INSTALL) -d $(BUILD_ROOT)$(LIB_DIR)
+	$(INSTALL) -m 755 -s $(LIB:%=lib/%) $(BUILD_ROOT)$(LIB_DIR)/
 
-	@INSTALL@ -d $(BUILD_ROOT)$(docdir)/$(PACKAGE)-$(VERSION)/
-	@INSTALL@ -m 644 doc/README \
+	$(INSTALL) -d $(BUILD_ROOT)$(docdir)/$(PACKAGE)-$(VERSION)/
+	$(INSTALL) -m 644 doc/README \
 		$(BUILD_ROOT)$(docdir)/$(PACKAGE)-$(VERSION)/
-	@INSTALL@ -m 644 doc/quilt.pdf doc/README.MAIL \
+	$(INSTALL) -m 644 doc/quilt.pdf doc/README.MAIL \
 		$(BUILD_ROOT)$(docdir)/$(PACKAGE)-$(VERSION)/
 
-	@INSTALL@ -d $(BUILD_ROOT)$(mandir)/man1
-	@INSTALL@ -m 644 $(MAN1) $(BUILD_ROOT)$(mandir)/man1/
+	$(INSTALL) -d $(BUILD_ROOT)$(mandir)/man1
+	$(INSTALL) -m 644 $(MAN1) $(BUILD_ROOT)$(mandir)/man1/
 	
 	$(MAKE_NLS) -C po install BUILD_ROOT=$(BUILD_ROOT) \
 		LINGUAS="$(LINGUAS)" localedir=$(localedir)
 
-	@INSTALL@ -d $(BUILD_ROOT)$(etcdir)
-	@INSTALL@ -d $(BUILD_ROOT)$(etcdir)/bash_completion.d
-	@INSTALL@ -m 644 bash_completion $(BUILD_ROOT)$(etcdir)/bash_completion.d/quilt
-	@INSTALL@ -m 644 quilt.quiltrc $(BUILD_ROOT)$(etcdir)/
+	$(INSTALL) -d $(BUILD_ROOT)$(etcdir)
+	$(INSTALL) -d $(BUILD_ROOT)$(etcdir)/bash_completion.d
+	$(INSTALL) -m 644 bash_completion $(BUILD_ROOT)$(etcdir)/bash_completion.d/quilt
+	$(INSTALL) -m 644 quilt.quiltrc $(BUILD_ROOT)$(etcdir)/
+
+define COMPAT_SYMLINK_install
+	ln -s $($(shell echo $(1)| $(AWK) '{print toupper($$1)}')) $(COMPAT_DIR)/$(strip $(1))
+endef
+
+install-compat:
+ifneq ($(COMPAT_PROGRAMS)$(COMPAT_FUNCTIONS)$(COMPAT_SYMLINKS),)
+	@rm -rf $(BUILD_ROOT)$(COMPAT_DIR)/
+	$(INSTALL) -d $(BUILD_ROOT)$(COMPAT_DIR)
+	$(foreach symlink, $(COMPAT_SYMLINKS), $(call COMPAT_SYMLINK_install, $(symlink)))
+ifneq ($(COMPAT_PROGRAMS),)
+	$(INSTALL) -m 755 $(COMPAT_PROGRAMS:%=compat/%) $(BUILD_ROOT)$(COMPAT_DIR)
+endif
+ifneq ($(COMPAT_FUNCTIONS),)
+	$(INSTALL) -m 644 compat/compatfns $(BUILD_ROOT)$(COMPAT_DIR)
+endif
+endif
+
+install: scripts install-main install-compat
 
 uninstall:
 	rm -rf $(BIN:%=$(BUILD_ROOT)$(bindir)/%) \
Index: quilt-compat9/bin/quilt.in
===================================================================
--- quilt-compat9.orig/bin/quilt.in
+++ quilt-compat9/bin/quilt.in
@@ -17,6 +17,15 @@ then
 	export QUILTRC
 fi
 
+# Support compatibility layer
+if [ -d @QUILT@/compat ]
+then
+	export PATH="@QUILT@/compat:$PATH"
+        if [ -r @QUILT@/compat/compatfns ]
+		source @QUILT@/compat/compatfns
+	fi
+fi
+
 usage()
 {
 
Index: quilt-compat9/scripts/patchfns.in
===================================================================
--- quilt-compat9.orig/scripts/patchfns.in
+++ quilt-compat9/scripts/patchfns.in
@@ -23,6 +23,15 @@ DB_VERSION=2
 : ${QUILT_PATCHES:=patches}
 : ${QUILT_PC:=.pc}
 
+# Support compatibility layer
+if [ -d @QUILT@/compat ]
+then
+	export PATH="@QUILT@/compat:$PATH"
+	if [ -r @QUILT@/compat/compatfns ]
+		source @QUILT@/compat/compatfns
+	fi
+fi
+
 unset CDPATH
 shopt -s dotglob
 
@@ -644,39 +653,6 @@ in_array()
 
 gen_tempfile()
 {
-	# This is a substitute for the mktemp executable.
-	internal_mktemp()
-	{
-		local try n
-		if [ x"$1" = x"-d" ]
-		then
-			for ((n=0 ; $n<100 ; n++))
-			do
-				try=${2%XXXXXX}$RANDOM
-				mkdir -m 700 $try 2>/dev/null \
-				&& break
-			done
-		else
-			local user_mask=$(umask)
-			umask 077
-			set -o noclobber
-			for ((n=0 ; $n<100 ; n++))
-			do
-				try=${1%XXXXXX}$RANDOM
-				echo -n "" 2> /dev/null > $try \
-				&& break
-			done
-			set +o noclobber
-			umask $user_mask
-		fi
-		if [ $n -lt 100 ]
-		then
-			echo $try
-		else
-			return 1
-		fi
-	}
-
 	local name
 	if [ "$1" = -d ]
 	then
Index: quilt-compat9/compat/getopt.in
===================================================================
--- /dev/null
+++ quilt-compat9/compat/getopt.in
@@ -0,0 +1,98 @@
+#! @PERL@ -w
+
+#  This script is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License version 2 as
+#  published by the Free Software Foundation.
+#
+#  See the COPYING and AUTHORS files for more details.
+
+use strict;
+
+my ($opts,$args) = split(/ -- /, join(' ',@ARGV));
+
+# there is no reason to parse
+# the opts if there are no args.
+if (! $args) {
+	print ' -- ';
+	exit;
+}
+
+my $short_opts = '';
+my @long_opts;
+
+# nothing fancy to see here; this script provides minimal compatibility
+# with the getopt from util-linux until a cross platform binary exists.
+if ($opts =~ /^-o ([a-zA-Z:]*)( --long .*)*/) {
+	$short_opts = $1;
+	if ($2) {
+		my $long_opts = $2;
+		$long_opts =~ s/^\s*--long //g;
+		$long_opts =~ s/ --long /,/g;
+		@long_opts = split(/,/,$long_opts);
+	}
+}
+
+my @words=split(/\s+/,$args);
+
+my @barewords;
+my @options;
+
+# set the the previous option name when a param is required
+my $need_param;
+
+foreach my $word (@words) {
+	# allow '-' to be an option value
+	if (!$need_param && $word !~ /^-./) {
+		push @barewords, $word;
+		next;
+	}
+	if ($need_param) {
+		die "expecting param for $need_param" if $word =~ /^-./;
+		push @options, $word;
+		$need_param = undef;
+		next;
+	}
+	# process short options
+	if ($word =~ s/^-([^-])/$1/) {
+		my @letters = reverse(split(//,$word));
+		while (@letters) {
+			my $letter = pop @letters;
+			my $found = grep(/$letter/, $short_opts);
+			push @options, '-'.$letter;
+			die "illegal option: $letter" if !$found;
+			if (grep(/$letter:/, $short_opts)) {
+				if (scalar(@letters) == 0) {
+					$need_param = $letter;
+				} else {
+					# short options can have numerical args
+					# embedded in the short option list: -UO
+					die "unexpected character after option $letter"
+						if ($letters[$#letters] !~ /[0-9]/);
+					my @digits;
+					while (scalar(@letters) && ($letters[$#letters] =~ /[0-9]/)) {
+						push @digits, pop @letters;
+					}
+					push @options, join('',reverse @digits);
+				}
+			}
+		}
+	}
+	# process long options
+	if ($word =~ s/^--//) {
+		my $param = '';
+		if ($word =~ /(.*)=(.*)/) {
+			$word = $1;
+			$param = $2;
+		}
+		my ($found) = grep(/^$word:?$/,@long_opts);
+		die "illegal option: $word" if !$found;
+		die "$word: unexpected paramater $param" if $found !~ /:$/ && $param ne '';
+
+		$need_param = $word if $found =~ /:$/ && $param eq '';
+		push @options, "--$word";
+		push @options, $param if $param;
+	}
+}
+
+print "@options -- @barewords"
+
Index: quilt-compat9/compat/mktemp.sh
===================================================================
--- /dev/null
+++ quilt-compat9/compat/mktemp.sh
@@ -0,0 +1,31 @@
+
+mktemp()
+{
+	local try n
+	if [ x"$1" = x"-d" ]
+	then
+		for ((n=0 ; $n<100 ; n++))
+		do
+			try=${2%XXXXXX}$RANDOM
+			mkdir -m 700 $try 2>/dev/null && break
+		done
+	else
+		local user_mask=$(umask)
+		umask 077
+		set -o noclobber
+		for ((n=0 ; $n<100 ; n++))
+		do
+			try=${1%XXXXXX}$RANDOM
+			echo -n "" 2> /dev/null > $try && break
+		done
+		set +o noclobber
+		umask $user_mask
+	fi
+	if [ $n -lt 100 ]
+	then
+		echo $try
+	else
+		return 1
+	fi
+}
+
Index: quilt-compat9/compat/column.sh
===================================================================
--- /dev/null
+++ quilt-compat9/compat/column.sh
@@ -0,0 +1,6 @@
+
+column()
+{
+	cat
+}
+
