On 31/10/2010 10:20, Ralf Wildenhues wrote:
* Paul J. Davis wrote on Sun, Oct 31, 2010 at 12:10:01AM CEST:
On Oct 30, 2010, at 5:17 PM, Jason Curl<jcurln...@arcor.de>  wrote:
When building my package with "./configure" everything works well as
some datafiles that are required for tests are in the correct place
(my tests don't need to be installed with "make install"). However,
when I use VPATH builds with "../configure", I don't know how to get
my data files copied from the source to the current build path.

I've just read up on VPATH, and I think gmake is assuming, that
while the datafiles are in the source, the dependencies are
satisfied, even though they aren't in the build directory.

The following rules don't work:
Right.  If @srcdir@ is '.', then GNU make will error out here
(non-GNU make would destroy your data, except that it will barf over the
use of $<  outside of inference rules first).

test.ini: @srcdir@/test.ini
  cp $<  $@

./test.ini: @srcdir@/test.ini
  cp $<  $@

An alternative can be to use AC_CONFIG_LINKS with identical source and
target name for files: the link-or-copy will the only be made if in a
VPATH build.  You need Autoconf>= 2.62 and Automake>= 1.11 for this to
work correctly (please set AC_PREREQ and Automake Option to this end,
because the older versions had bugs that could cause source file
removal.)  Please report any remaining bugs.

It's unfortunate that I can't use this functionality, one of my build machines is still ubuntu 8.04 and this still has autoconf 2.61 and automake 1.10.1.

I've implemented a shell script to do the copies for me based on a phony rule (moving the check out of make and into a script). Tested for VPATH and non-VPATH. It allows me to keep all changes local to the directory where the tests are made. The phony rules are a dependency to "all-local" so they get copied at the end of the process. I didn't use myprog_DEPENDENCIES as this would cause a link

e.g.
Makefile.am

all-local: cpreadini cpoptionini

cpreadini:
    @srcdir@/cpfiles.sh @srcdir@/read.ini ./read.ini

cpoptionini:
    @srcdir@/cpfiles.sh @srcdir@/option1.ini ./option1.ini
    @srcdir@/cpfiles.sh @srcdir@/option2.ini ./option2.ini

.PHONY: cpreadini cpoptionini

Feedback welcome.

Thanks for your help Ralf & Paul.
Jason.

#!/bin/sh

SRC="$1"
DST="$2"

# Check input parameters
if [ $# -lt 2 ]; then
  echo "$0 <src> <dest>"
  exit 2
fi

# Check that the source file exists
if [ ! -e $SRC ]; then
  echo "$SRC not found"
  exit 2
fi
 
if [ ! -e $DST ]; then
  echo "cp $SRC $DST"
  cp $SRC $DST
else
  # Check that we have the 'stat' binary. If not, we don't do the copy.
  which stat > /dev/null

  if [ $? -eq 1 ]; then
    echo "warning: stat not found, no comparison can be made"
    exit 0
  fi

  SRCT=$(stat -c %Y $SRC)
  DSTT=$(stat -c %Y $DST)
  if [ $DSTT -lt $SRCT ]; then
    echo "cp $SRC (time=$SRCT) $DST (time=$DSTT)"
    cp -f $SRC $DST
  fi
fi

Reply via email to