automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] `compile' with spaces in arguments


From: Alexandre Duret-Lutz
Subject: Re: [PATCH] `compile' with spaces in arguments
Date: Fri, 10 Sep 2004 20:37:50 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

>>> "Ralf" == Ralf Wildenhues <address@hidden> writes:

 Ralf> Currently, the `compile' script does not allow spaces in arguments.

Thanks.  I'm installing the following variation of this patch on
HEAD and branch-1-9.

One thing I learnt about the cycling "$@" idiom is to `shift'
only after you have re-`set' the arguments.  This way you ensure
"$@" is never empty and do not need the ${1-"$@"} cruft. 
(Release 1.8.2 was essentially a fix for this...)


2004-09-10  Ralf Wildenhues  <address@hidden>
            Alexandre Duret-Lutz  <address@hidden>

        * lib/compile: Preserve spaces in arguments (for example
        -DPACKAGE_STRING="foo 0.1").
        * tests/compile.test: New file.
        * tests/Makefile.am (TESTS): Add compile.test.

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 18:21:06 -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.20
 
-# 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,37 +55,41 @@
     ;;
 esac
 
-
-prog=$1
-shift
-
 ofile=
 cfile=
-args=
-while test $# -gt 0; do
-  case "$1" in
-    -o)
-      # configure might choose to run compile as `compile cc -o foo foo.c'.
-      # So we do something ugly here.
-      ofile=$2
-      shift
-      case "$ofile" in
-       *.o | *.obj)
-         ;;
-       *)
-         args="$args -o $ofile"
-         ofile=
-         ;;
-      esac
-       ;;
-    *.c)
-      cfile=$1
-      args="$args $1"
-      ;;
-    *)
-      args="$args $1"
-      ;;
-  esac
+eat=
+
+for arg
+do
+  if test -n "$eat"; then
+    eat=
+  else
+    case $1 in
+      -o)
+       # configure might choose to run compile as `compile cc -o foo foo.c'.
+       # So we strip `-o arg' only if arg is an object.
+       eat=1
+       case $2 in
+         *.o | *.obj)
+           ofile=$2
+           ;;
+         *)
+           set x "$@" -o "$2"
+           shift
+           ;;
+       esac
+       ;;
+      *.c)
+       cfile=$1
+       set x "$@" "$1"
+       shift
+       ;;
+      *)
+       set x "$@" "$1"
+       shift
+       ;;
+    esac
+  fi
   shift
 done
 
@@ -95,35 +99,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 "$@"
 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
+"$@"
 status=$?
 
 if test -f "$cofile"; then
   mv "$cofile" "$ofile"
 fi
 
-rmdir $lockdir
+rmdir "$lockdir"
 exit $status
 
 # Local Variables:
Index: tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.am,v
retrieving revision 1.565.2.2
diff -u -r1.565.2.2 Makefile.am
--- tests/Makefile.am   7 Sep 2004 06:26:21 -0000       1.565.2.2
+++ tests/Makefile.am   10 Sep 2004 18:21:06 -0000
@@ -93,6 +93,7 @@
 comment5.test \
 comment6.test \
 comment7.test \
+compile.test \
 compile_f90_c_cxx.test \
 compile_f_c_cxx.test \
 cond.test \
Index: tests/compile.test
===================================================================
RCS file: tests/compile.test
diff -N tests/compile.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/compile.test  10 Sep 2004 18:21:06 -0000
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Copyright (C) 2004  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# Make sure `compile' preserves spaces in its arguments.
+
+. ./defs || exit 1
+
+set -e
+
+cp $testsrcdir/../lib/compile .
+
+# -o 'a c' should not be stripped because 'a c' is not an object
+# (it does not matter whether touch creates ./-- or not)
+./compile touch a.o -- -o 'a c' a.c
+test -f 'a c'
+test -f ./-o
+test -f a.o
+test -f a.c
+
+rm 'a c' ./-o a.o a.c
+
+./compile touch a.o -- -o 'a c.o' a.c
+test -f 'a c.o'
+test ! -f ./-o
+test ! -f a.o
+test -f a.c

-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]