Ralf Wildenhues <[EMAIL PROTECTED]> writes: > Hi Ed, > > * Ed Hartnett wrote on Sat, Nov 05, 2005 at 07:52:01PM CET: >> >> My current problem is that I have some reference netCDF files, which >> ship with the distribution. I also have a test program, which produces >> data files that need to be identical to the reference files shipped >> with the dist. >> >> But the problem is the reference files are in the source directory, >> and the test files are in the build directory. >> >> At the moment, I am doing this with a one-line shell script, which >> does something like this: >> >> cmp nctest_classic.nc ref_nctest_classic.nc >> >> What I need to do, apparently, is somehow construct this shell script >> from the Makefile, using $(srcdir) somehow. > > This would be one possibility. You could have a shell_script.in with > srcdir="@srcdir@" > cmp "$srcdir/ref_nctest_classic.nc" nctest_classic.nc > > and list shell_script in configure.ac as > AC_CONFIG_FILES([shell_script], [chmod a+x shell_script]) > > But this is probably even overkill. You could just export a shell > variable containing srcdir from Makefile to the script -- no need to > construct that at all, then: If, for example, you use the Automake test > feature, as in > TESTS = shell_script ... > check_SCRIPTS = ... > check_PROGRAMS = ... > > then you could just add > TESTS_ENVIRONMENT = srcdir="$(srcdir)" ...
AH-HA!!! Yes, this worked beautifully. I never knew about this. Looking at the automake manual I find: " The variable `TESTS_ENVIRONMENT' can be used to set environment variables for the test run; the environment variable `srcdir' is set in the rule. If all your test programs are scripts, you can also set `TESTS_ENVIRONMENT' to an invocation of the shell (e.g. `$(SHELL) -x'); this can be useful for debugging the tests. " This seems to imply that I don't even need the line that sets TESTS_ENVIRONMENT, because srcdir is already going to be defined in the environment that my test script runs in. And sure enough, it still works after I take it out. So I can use $srcdir without setting it in test scripts. Presumably I can also fetch environmental vars from test programs, or pass them on the command line as parameters. (I have a fortran test program that is opening a reference file shipped with the distribution, and I need it to find srcdir too.) > > and use "$srcdir" within the script. Or, if you have many scripts that > share some initialization, you could just substitute this initialization > part and source that from all shell scripts (by `. ./defs', for example). > >> Or is there a way to use some make target for this? Any suggestions or >> web examples would be helpful. I'm going to take another look at the >> info files and around the web. There must be a better way to run this >> cmp test without a whole extra shell script! > > Yep. Examples for test suites are contained in (sorry for the shameless > plugs): > Automake test suite: Automake, Libtool-1.5.x > Autotest test suite: Autoconf, Libtool-CVS > DejaGNU test suite: GCC > Thanks Ralf! I will first see how many problems I can clear away with the use of environment vars in my test scripts... Thanks again for all the help! You are really making netCDF-4.0 possible. Ed -- Ed Hartnett -- [EMAIL PROTECTED]