[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] `compile' with spaces in arguments
From: |
Ralf Wildenhues |
Subject: |
[PATCH] `compile' with spaces in arguments |
Date: |
Fri, 10 Sep 2004 17:21:53 +0200 |
User-agent: |
Mutt/1.4.1i |
Currently, the `compile' script does not allow spaces in arguments.
If, for all relevant shells,
- the `set' builtin allows to set enough positional parameters,
and
- echo "foo \"bar\""
is portable,
and
- no other constructs except `while arg\n do' and `set' and `shift'
modify the positional parameters in any way,
and
- `while arg\n do' does not update its loop list from changed
positional parameters,
then the patch below allows spaces as much as possible in a portable
way. The last point can be amended by using $# and counting, but that
might require non-builtins. [This is all that I wasn't sure about w.r.t
portable shell.]
I'm not sure if the pattern for lockdir should be modified to make
spaces to underscores?
Please consider inclusion after testing this on as many shells as
possible. I know it is very slow, but it allows almost any characters
within the options, and the possibly quadratic algorithm is completely
contained within shell builtins (`shift', that is).
Regards,
Ralf
2004-09-10 Ralf Wildenhues <address@hidden>
* lib/compile: allow options with spaces (for example
-DPACKAGE_STRING="foo 0.1") as generally as possible, with
possibly $#^2 complexity, but hopefully portable.
Index: lib/compile
===================================================================
RCS file: /cvs/automake/automake/lib/compile,v
retrieving revision 1.7
diff -u -r1.7 compile
--- lib/compile 9 Nov 2003 00:10:50 -0000 1.7
+++ lib/compile 10 Sep 2004 14:12:00 -0000
@@ -1,9 +1,9 @@
#! /bin/sh
# Wrapper for compilers which do not understand `-c -o'.
-scriptversion=2003-11-09.00
+scriptversion=2004-09-10.00
-# Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
+# Copyright (C) 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
# Written by Tom Tromey <address@hidden>.
#
# This program is free software; you can redistribute it and/or modify
@@ -55,38 +55,51 @@
;;
esac
+test "${ZSH_VERSION+set}" = set && alias -g '${1+"$@"}'='"$@"'
prog=$1
shift
ofile=
cfile=
-args=
-while test $# -gt 0; do
- case "$1" in
+eat=no
+for arg
+do
+ shift
+ case $eat in
+ yes)
+ eat=no
+ continue
+ ;;
+ no)
+ ;;
+ esac
+ case "$arg" in
-o)
# configure might choose to run compile as `compile cc -o foo foo.c'.
# So we do something ugly here.
- ofile=$2
- shift
+ eat=yes
+ ofile=$1
case "$ofile" in
*.o | *.obj)
;;
*)
- args="$args -o $ofile"
+ set x ${1+"$@"} -o "$ofile"
+ shift
ofile=
;;
esac
- ;;
+ ;;
*.c)
- cfile=$1
- args="$args $1"
+ cfile=$arg
+ set x ${1+"$@"} "$arg"
+ shift
;;
*)
- args="$args $1"
+ set x ${1+"$@"} "$arg"
+ shift
;;
esac
- shift
done
if test -z "$ofile" || test -z "$cfile"; then
@@ -95,35 +108,35 @@
# normal compilation that the losing compiler can handle. If no
# `.c' file was seen then we are probably linking. That is also
# ok.
- exec "$prog" $args
+ exec "$prog" ${1+"$@"}
fi
# Name of file we expect compiler to create.
-cofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
+cofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
# Create the lock directory.
# Note: use `[/.-]' here to ensure that we don't use the same name
# that we are using for the .o file. Also, base the name on the expected
# object file name, since that is what matters with a parallel build.
-lockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d
+lockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d
while true; do
- if mkdir $lockdir > /dev/null 2>&1; then
+ if mkdir "$lockdir" > /dev/null 2>&1; then
break
fi
sleep 1
done
# FIXME: race condition here if user kills between mkdir and trap.
-trap "rmdir $lockdir; exit 1" 1 2 15
+trap "rmdir \"$lockdir\"; exit 1" 1 2 15
# Run the compile.
-"$prog" $args
+"$prog" ${1+"$@"}
status=$?
if test -f "$cofile"; then
mv "$cofile" "$ofile"
fi
-rmdir $lockdir
+rmdir "$lockdir"
exit $status
# Local Variables:
- [PATCH] `compile' with spaces in arguments,
Ralf Wildenhues <=