[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: AC_CONFIG_LINKS breaks every second time
From: |
Ralf Wildenhues |
Subject: |
Re: AC_CONFIG_LINKS breaks every second time |
Date: |
Tue, 24 Jul 2007 22:15:06 +0200 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
Hello Sebastian,
* Sebastian Freundt wrote on Mon, Jul 23, 2007 at 11:31:07PM CEST:
[...]
> my build directory (distinct from $srcdir):
> /home/src/=build/
>
> There's an AC_CONFIG_LINKS([src/s:src/s]) in my configure.ac.
> configure or config.status, respectively, now do the following:
>
> 1. in a clean build directory: create the src subdirectory, create the
> symlink from $srcdir/src/s to $builddir/src/s
> 2. in a configured build directory: delete $builddir/src/s and create a
> link from $builddir/src/s(!) to $builddir/src/s
> 3. in such a screwed build directory, another invocation of config.status
> yields the correct link again ($builddir/src/s -> $srcdir/src/s)
Interesting setup. For it to work with Autoconf 2.59 required that the
source tree and the build tree be different. (I assume that that is the
version you originally got this to work with.) If both trees coincide,
you would get an error if config.status is executed more than once, and
you already have a broken file after the first configure run.
My first gut reaction to this setup was of the sort "doctor it hurts
when I do this -- so don't do it". And there is a somewhat
non-intuitive reason for this, too: files that exist under identical
names in the source and the build trees are confusing. Confusing to
the developer, and a hassle with the 'make' program. That is due to
all the tiny differences in how different 'make' implementations do
VPATH handling. Finally, on systems where 'ls -s' does not work right,
the file is copied, so you may still have to take care of
synchronization issues if you rely on those, such as having the wrong
header file included or so.
Nonetheless, I see that there may be valid uses of this setup, so here's
a patch against CVS Autoconf to try (once quoted, with 'diff -b', for
readability, as most of the status.m4 changes are due to reindentation).
Note that, as exercised in the test, you can use
test "$srcdir" != '.' && AC_CONFIG_LINKS([src/t:src/t])
to avoid the warning at config.status time; incidentally, writing it
that way will make your code compatible with Autoconf 2.59 as well. ;-)
WDYT? Is the warning too much (and should rather be AC_MSG_NOTICE)?
OK to apply?
Cheers, and thanks for the nice report,
Ralf
2007-07-24 Ralf Wildenhues <address@hidden>
* lib/autoconf/status.m4 (_AC_OUTPUT_LINK): Do not try to link a
file to itself if source and build trees coincide.
* tests/torture.at (AC_CONFIG_LINKS and identical files): New
test.
Report by Sebastian Freundt <address@hidden>.
| --- lib/autoconf/status.m4 20 Jul 2007 23:11:53 -0000 1.136
| +++ lib/autoconf/status.m4 24 Jul 2007 19:58:00 -0000
| @@ -871,7 +871,13 @@
| # CONFIG_LINK
| #
|
| - test -r "$ac_source" || ac_source=$srcdir/$ac_source
| + if test "$ac_source" = "$ac_file" && test "$srcdir" = '.'; then
| + AC_MSG_WARN([not linking $ac_source to itself])
| + else
| + # Prefer the file from the source tree if names are identical.
| + if test "$ac_source" = "$ac_file" || test ! -r "$ac_source"; then
| + ac_source=$srcdir/$ac_source
| + fi
|
| AC_MSG_NOTICE([linking $ac_source to $ac_file])
|
| @@ -889,6 +895,7 @@
| ln "$ac_source" "$ac_file" 2>/dev/null ||
| cp -p "$ac_source" "$ac_file" ||
| AC_MSG_ERROR([cannot link or copy $ac_source to $ac_file])
| + fi
| ])# _AC_OUTPUT_LINK
Index: lib/autoconf/status.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/status.m4,v
retrieving revision 1.136
diff -u -r1.136 status.m4
--- lib/autoconf/status.m4 20 Jul 2007 23:11:53 -0000 1.136
+++ lib/autoconf/status.m4 24 Jul 2007 20:08:59 -0000
@@ -871,24 +871,31 @@
# CONFIG_LINK
#
- test -r "$ac_source" || ac_source=$srcdir/$ac_source
+ if test "$ac_source" = "$ac_file" && test "$srcdir" = '.'; then
+ AC_MSG_WARN([not linking $ac_source to itself])
+ else
+ # Prefer the file from the source tree if names are identical.
+ if test "$ac_source" = "$ac_file" || test ! -r "$ac_source"; then
+ ac_source=$srcdir/$ac_source
+ fi
- AC_MSG_NOTICE([linking $ac_source to $ac_file])
+ AC_MSG_NOTICE([linking $ac_source to $ac_file])
- if test ! -r "$ac_source"; then
- AC_MSG_ERROR([$ac_source: file not found])
- fi
- rm -f "$ac_file"
+ if test ! -r "$ac_source"; then
+ AC_MSG_ERROR([$ac_source: file not found])
+ fi
+ rm -f "$ac_file"
- # Try a relative symlink, then a hard link, then a copy.
- case $srcdir in
- [[\\/$]]* | ?:[[\\/]]* ) ac_rel_source=$ac_source ;;
- *) ac_rel_source=$ac_top_build_prefix$ac_source ;;
- esac
- ln -s "$ac_rel_source" "$ac_file" 2>/dev/null ||
- ln "$ac_source" "$ac_file" 2>/dev/null ||
- cp -p "$ac_source" "$ac_file" ||
- AC_MSG_ERROR([cannot link or copy $ac_source to $ac_file])
+ # Try a relative symlink, then a hard link, then a copy.
+ case $srcdir in
+ [[\\/$]]* | ?:[[\\/]]* ) ac_rel_source=$ac_source ;;
+ *) ac_rel_source=$ac_top_build_prefix$ac_source ;;
+ esac
+ ln -s "$ac_rel_source" "$ac_file" 2>/dev/null ||
+ ln "$ac_source" "$ac_file" 2>/dev/null ||
+ cp -p "$ac_source" "$ac_file" ||
+ AC_MSG_ERROR([cannot link or copy $ac_source to $ac_file])
+ fi
])# _AC_OUTPUT_LINK
Index: tests/torture.at
===================================================================
RCS file: /cvsroot/autoconf/autoconf/tests/torture.at,v
retrieving revision 1.84
diff -u -r1.84 torture.at
--- tests/torture.at 20 Jul 2007 23:11:55 -0000 1.84
+++ tests/torture.at 24 Jul 2007 20:09:00 -0000
@@ -880,6 +880,40 @@
AT_CLEANUP
+## ------------------------------------- ##
+## AC_CONFIG_LINKS and identical files. ##
+## ------------------------------------- ##
+AT_SETUP([AC_CONFIG_LINKS and identical files])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_CONFIG_LINKS([src/s:src/s])
+test "$srcdir" != '.' && AC_CONFIG_LINKS([src/t:src/t])
+AC_OUTPUT
+]])
+
+mkdir src build
+echo file1 > src/s
+echo file2 > src/t
+AT_CHECK_AUTOCONF
+cd build
+AT_CHECK([../configure && ../configure], 0, [ignore])
+AT_CHECK([cat src/s src/t], 0, [file1
+file2
+])
+cd ..
+AT_CHECK([./configure && ./configure], 0, [ignore], [stderr])
+AT_CHECK([grep src/t stderr], 1)
+AT_CHECK([cat src/s src/t], 0, [file1
+file2
+])
+AT_CHECK(["`pwd`"/configure && "`pwd`"/configure], 0, [ignore], [ignore])
+AT_CHECK([cat src/s src/t], 0, [file1
+file2
+])
+
+AT_CLEANUP
+
AT_BANNER([autoreconf.])
- Re: AC_CONFIG_LINKS breaks every second time,
Ralf Wildenhues <=