netcdf-c/ncdap_test/t_srcdir.h
Dennis Heimbigner 7be9506aac Modified ncdap_test to allow a different method
to get TOPSRCDIR that avoids use of
TEST_ENVIRONMENT and makes automake and cmake
more consistent.

Basic assumption is that abs_top_srcdir (and
cmake equivalent) is known at 'make check' time,
so we can use -D flag to compile a program that
has the value of abs_top_srcdir embedded into it
as a constant.

We define two new files in ncdap_test:
1. t_srcdir.h -- provide a gettopsrcdir() function
   to return the topsrcdir value to the test program.
2. topsrcdir.c -- a program that calls gettopsrcdir()
   and prints its output (minus any newline) on stdout.
   This is used in .sh files to get topsrcdir.
2017-01-18 21:46:47 -07:00

24 lines
503 B
C

#define XSTRINGIFY(s) #s
#define STRINGIFY(s) XSTRINGIFY(s)
static const char*
gettopsrcdir(void)
{
const char* topsrcdir;
#ifdef TOPSRCDIR
topsrcdir = STRINGIFY(TOPSRCDIR);
#else
static char wd[8192];
getwd(wd,sizeof(wd));
strcat(wd,SEP);
strcat(wd,"..");
topsrcdir = wd;
#endif
if(topsrcdir == NULL) {
fprintf(stderr,"*** FAIL: $abs_top_srcdir not defined\n");
exit(1);
}
fprintf(stderr,"topsrcdir=%s\n",topsrcdir);
return topsrcdir;
}