set stdio
# In FreeBSD, definitions like _POSIX_SOURCE and such are used to *limit*
# functionality to known API; they don't enable anything. The general intent in
# BSD is to enable everything by default (effectively, providing the
# _KITCHEN_SINK_SOURCE mentioned below). So we look for that here, but stay
# careful that we don't get fooled by presence of FreeBSD that underpins some
# subsystems in Mac OS X; there are other Apple-specific portability hacks
# elsewhere we should not interfere with.
if tst note{ FreeBSD, DragonFly BSD, or UnixWare }end compile{
		#include <sys/param.h>
		#if (!defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__USLC__)) || defined(APPLE)
		#error not a FreeBSD or DragonFly BSD system
		#endif
	}end {
	}
elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
		#define _ALL_SOURCE	1
		#define _POSIX_SOURCE	1
		#define _POSIX_C_SOURCE	21000101L
		#define _XOPEN_SOURCE	9900
		#define _GNU_SOURCE	1
		#define __EXTENSIONS__	1
		#include <sys/types.h>
		#include <sys/stat.h>
		#include <stdlib.h>
		#include <unistd.h>
	}end {
		#ifndef _ALL_SOURCE
		#define _ALL_SOURCE	1
		#endif
		#ifndef _POSIX_SOURCE
		#define _POSIX_SOURCE	1
		#endif
		#ifndef _POSIX_C_SOURCE
		#define _POSIX_C_SOURCE	21000101L
		#endif
		#ifndef _XOPEN_SOURCE
		#define _XOPEN_SOURCE	9900
		#endif
		#ifndef _GNU_SOURCE
		#define _GNU_SOURCE	1
		#endif
		#ifndef __EXTENSIONS__
		#define __EXTENSIONS__	1
		#endif
	}
elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
		#define _ALL_SOURCE	1
		#define _POSIX_SOURCE	1
		#define _XOPEN_SOURCE	9900
		#define _GNU_SOURCE	1
		#define __EXTENSIONS__	1
		#include <sys/types.h>
		#include <sys/stat.h>
		#include <stdlib.h>
		#include <unistd.h>
	}end {
		#ifndef _ALL_SOURCE
		#define _ALL_SOURCE	1
		#endif
		#ifndef _POSIX_SOURCE
		#define _POSIX_SOURCE	1
		#endif
		#ifndef _XOPEN_SOURCE
		#define _XOPEN_SOURCE	9900
		#endif
		#ifndef _GNU_SOURCE
		#define _GNU_SOURCE	1
		#endif
		#ifndef __EXTENSIONS__
		#define __EXTENSIONS__	1
		#endif
	}
elif tst note{ _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
		#define _POSIX_SOURCE	1
		#define _POSIX_C_SOURCE	21000101L
		#define _XOPEN_SOURCE	9900
		#define _GNU_SOURCE	1
		#define __EXTENSIONS__	1
		#include <sys/types.h>
		#include <sys/stat.h>
		#include <stdlib.h>
		#include <unistd.h>
	}end {
		#ifndef _POSIX_SOURCE
		#define _POSIX_SOURCE	1
		#endif
		#ifndef _POSIX_C_SOURCE
		#define _POSIX_C_SOURCE	21000101L
		#endif
		#ifndef _XOPEN_SOURCE
		#define _XOPEN_SOURCE	9900
		#endif
		#ifndef _GNU_SOURCE
		#define _GNU_SOURCE	1
		#endif
		#ifndef __EXTENSIONS__
		#define __EXTENSIONS__	1
		#endif
	}
elif tst note{ _POSIX_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
		#define _POSIX_SOURCE	1
		#define _XOPEN_SOURCE	1
		#define __EXTENSIONS__	1
		#include <sys/types.h>
		#include <sys/stat.h>
		#include <stdlib.h>
		#include <unistd.h>
	}end {
		#ifndef _POSIX_SOURCE
		#define _POSIX_SOURCE	1
		#endif
		#ifndef _XOPEN_SOURCE
		#define _XOPEN_SOURCE	1
		#endif
		#ifndef __EXTENSIONS__
		#define __EXTENSIONS__	1
		#endif
	}
elif tst note{ _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
		#define _XOPEN_SOURCE	1
		#define __EXTENSIONS__	1
		#include <sys/types.h>
		#include <sys/stat.h>
		#include <stdlib.h>
		#include <unistd.h>
	}end {
		#ifndef _XOPEN_SOURCE
		#define _XOPEN_SOURCE	1
		#endif
		#ifndef __EXTENSIONS__
		#define __EXTENSIONS__	1
		#endif
	}
elif tst note{ _XOPEN_SOURCE works }end compile{
		#define _XOPEN_SOURCE	1
		#include <sys/types.h>
		#include <sys/stat.h>
		#include <stdlib.h>
		#include <unistd.h>
	}end {
		#ifndef _XOPEN_SOURCE
		#define _XOPEN_SOURCE	1
		#endif
	}
else tst note{ __EXTENSIONS__ works }end compile{
		#define __EXTENSIONS__	1
		#include <sys/types.h>
		#include <sys/stat.h>
	}end {
		#ifndef __EXTENSIONS__
		#define __EXTENSIONS__	1
		#endif
	}
endif

if tst -D_ISOC99_SOURCE -lm note{ _ISOC99_SOURCE plays nice }end link{
		#include <sys/types.h>
		#include <sys/stat.h>
		#include <stdlib.h>
		#include <unistd.h>
		#include <math.h>
		int main() { return signbit(-0.0); }
	}end {
		#ifndef _ISOC99_SOURCE
		#define _ISOC99_SOURCE	1
		#endif
	}
endif

cat{

/*
 * this is a nasty game we all play to honor standards symbol visibility
 * it would help if all implementations had
 *	_KITCHEN_SINK_SOURCE
 * that enabled all symbols from the latest implemented standards
 * that's probably the most useful but least portable request
 */

#if __MACH__
#undef  _POSIX_SOURCE
#endif

}end
