tags:

views:

33

answers:

2

I need to use a file for one of my tests written using Check. I initially hardcoded the path, which worked fine. However, this didn't work when the code is built outside of the source directory. I came up with the following solution which somewhat works. (I then prefix pathnames with TESTS_DIR)

# Set correct directory for test files
AS_IF([test "x$srcdir" = x.],
      [TESTS_DIR=""],
      [TESTS_DIR="$srcdir/tests/"])
AC_DEFINE_UNQUOTED([TESTS_DIR], ["$TESTS_DIR"], [directory for test files])

Unfortunately, this fails again for make distcheck. I could post specific path layouts and structures, but I'm wondering if there's an "easy" way to refer to files in the source directory in all these cases. Thanks!

UPDATE: I've tried to use absolute paths, but it seems $abs_top_srcdir isn't set when I tried to update the define in configure.ac. Any thoughts as to why that is would be appreciated.

A: 

I don't see the problem. Why can't you pass the location of your file as an argument to your check program... ?

Paul Praet
How do I get the location of the files? Obviously my method of passing the path (which I am doing) does not work.
Michael Mior
Sorry, but I still don't get it.. Why does passing the path not work ?
Paul Praet
Good question. That's what I'd like to understand. The file can't be found by my test program when moved into the distribution directory.
Michael Mior
see my update above
Michael Mior
A: 

I discovered that the problem was that $top_srcdir is not set at configure time. Instead, I added -DTESTS_DIR="\"$(top_srcdir)/tests/\"" to AM_CFLAGS in my tests Makefile.am and also added all directories containing test files to EXTRA_DIST.

Michael Mior