mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-27 07:30:33 +08:00
7be9506aac
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.
24 lines
503 B
C
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;
|
|
}
|