Index: quilt-compat/aclocal.m4
===================================================================
--- /dev/null
+++ quilt-compat/aclocal.m4
@@ -0,0 +1,39 @@
+
+dnl Allow configure to specify a specific binary
+dnl 1: Environment variable
+dnl 2: binary name
+dnl 3: optional list of alternatives
+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]))
+  ])
+  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-compat/configure.ac
===================================================================
--- quilt-compat.orig/configure.ac
+++ quilt-compat/configure.ac
@@ -36,18 +36,8 @@
 
 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,62 +54,38 @@
/

 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'])
+QUILT_COMPAT_PROG_PATH(POD2MAN, pod2man)
+QUILT_COMPAT_PROG_PATH(COLUMN, column)
+QUILT_COMPAT_PROG_PATH(GETOPT, getopt)
+
+if test -n "$GETOPT"; then
+  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
+    getopt_long_syntax=yes
+    AC_MSG_RESULT(yes)
+  else
+    getopt_long_syntax=no
+    AC_MSG_WARN(no)
+    GETOPT=''
+  fi
 fi
 
 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
+QUILT_COMPAT_PROG_PATH(MKTEMP, mktemp)
+
+if test -n "$MKTEMP" ; then
     AC_MSG_CHECKING(whether $MKTEMP -d works)
     if tempdir=`$MKTEMP -d /tmp/$PACKAGE_NAME.XXXXXX 2>/dev/null` && \
        rmdir "$tempdir" ; then
@@ -136,32 +102,9 @@
 fi
 
 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 +226,10 @@
 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-compat/Makefile.in
===================================================================
--- quilt-compat.orig/Makefile.in
+++ quilt-compat/Makefile.in
@@ -15,11 +15,16 @@
 
 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 +35,27 @@
 RPMBUILD :=	@RPMBUILD@
 MTA :=		@MTA@
 
+COMPAT_SYMLINKS  := @COMPAT_SYMLINKS@
+COMPAT_FUNCTIONS := @COMPAT_FUNCTIONS@
+COMPAT_PROGRAMS  := @COMPAT_PROGRAMS@
+
+default: all
+
+define COMPAT_SYMLINK_install
+install-compat-symlink-$(strip $(1)):
+	ln -sf $($(shell echo $(1)| $(AWK) '{print toupper($$1)}')) $(COMPAT_DIR)/$(strip $(1))
+endef
+
+$(foreach symlink, $(COMPAT_SYMLINKS), $(eval $(call COMPAT_SYMLINK_install, $(symlink))))
+
+install-compat-symlinks: $(COMPAT_SYMLINKS:%=install-compat-symlink-%)
+
+define COMPAT_SYMLINK_redefine
+$(shell echo $(1) | $(AWK) '{print toupper($$0)}') := $(1)
+endef
+
+$(foreach symlink, $(COMPAT_SYMLINKS), $(eval $(call COMPAT_SYMLINK_redefine, $(symlink))))
+
 ifeq "$(MSGFMT)" ""
 MAKE_NLS :=	@true
 else
@@ -69,10 +95,12 @@
 
 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 +140,12 @@
 $(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,7 +168,7 @@
 		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                             \
@@ -178,7 +211,7 @@
 
 bin/guards.1 : bin/guards
 	mkdir -p `dirname $@`
-	pod2man $< > $@
+	$(POD2MAN) $< > $@
 
 $(PACKAGE)-$(VERSION).tar.gz : $(SRC) configure $(PACKAGE).spec
 	rm -f $(PACKAGE)-$(VERSION) $@
@@ -232,7 +265,7 @@
 	@echo "Please run ./configure by hand"
 	@false
 
-install : scripts
+install-main: scripts
 	@INSTALL@ -d $(BUILD_ROOT)$(bindir)
 	@INSTALL@ -m 755 $(BIN:%=bin/%) $(BUILD_ROOT)$(bindir)/
 
@@ -265,6 +298,20 @@
 	@INSTALL@ -m 644 bash_completion $(BUILD_ROOT)$(etcdir)/bash_completion.d/quilt
 	@INSTALL@ -m 644 quilt.quiltrc $(BUILD_ROOT)$(etcdir)/
 
+install-compat:
+ifneq ($(COMPAT_PROGRAMS)$(COMPAT_FUNCTIONS)$(COMPAT_SYMLINKS),)
+	@INSTALL@ -d $(BUILD_ROOT)$(COMPAT_DIR)
+	@rm -f $(BUILD_ROOT)$(COMPAT_DIR)/*
+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 $(COMPAT_SYMLINKS:%=install-compat-symlink-%)
+
 uninstall:
 	rm -rf $(BIN:%=$(BUILD_ROOT)$(bindir)/%) \
 	       $(BUILD_ROOT)$(LIB_DIR) \
Index: quilt-compat/bin/quilt.in
===================================================================
--- quilt-compat.orig/bin/quilt.in
+++ quilt-compat/bin/quilt.in
@@ -17,6 +17,15 @@
 	export QUILTRC
 fi
 
+# Support compatibility layer
+if [ -r @QUILT@/compat/compatfns ]
+then
+	source @QUILT@/compat/compatfns
+fi
+
+
+export PATH="@QUILT@/compat:$PATH"
+
 usage()
 {
 
Index: quilt-compat/scripts/patchfns.in
===================================================================
--- quilt-compat.orig/scripts/patchfns.in
+++ quilt-compat/scripts/patchfns.in
@@ -23,6 +23,13 @@
 : ${QUILT_PATCHES:=patches}
 : ${QUILT_PC:=.pc}
 
+# Support compatibility layer
+if [ -r @QUILT@/compat/compatfns ]
+then
+	source @QUILT@/compat/compatfns
+fi
+
+export PATH="@QUILT@/compat:$PATH"
 unset CDPATH
 shopt -s dotglob
 
@@ -644,39 +651,6 @@
 
 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-compat/compat/getopt.in
===================================================================
--- /dev/null
+++ quilt-compat/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-compat/compat/mktemp.sh
===================================================================
--- /dev/null
+++ quilt-compat/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-compat/compat/column.sh
===================================================================
--- /dev/null
+++ quilt-compat/compat/column.sh
@@ -0,0 +1,6 @@
+
+column()
+{
+	cat
+}
+
