1set stdio
2# In FreeBSD, definitions like _POSIX_SOURCE and such are used to *limit*
3# functionality to known API; they don't enable anything. The general intent in
4# BSD is to enable everything by default (effectively, providing the
5# _KITCHEN_SINK_SOURCE mentioned below). So we look for that here, but stay
6# careful that we don't get fooled by presence of FreeBSD that underpins some
7# subsystems in Mac OS X; there are other Apple-specific portability hacks
8# elsewhere we should not interfere with.
9if tst note{ FreeBSD }end compile{
10		#include <sys/param.h>
11		#if !defined(__FreeBSD__) || defined(APPLE)
12		#error not a FreeBSD system
13		#endif
14	}end {
15	}
16elif tst note{ _GNU_SOURCE works }end compile{
17		#define _GNU_SOURCE 1
18		#include <sys/types.h>
19		#include <sys/stat.h>
20		#include <stdlib.h>
21		#include <unistd.h>
22		#include <fcntl.h>
23		#if !defined(__linux__) || !defined( __USE_GNU)
24		(
25		#endif
26	}end {
27		#ifndef _GNU_SOURCE
28		#define _GNU_SOURCE 1
29		#endif
30	}
31elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & _GNU_SOURCE & __EXTENSIONS__ works }end compile{
32		#define _ALL_SOURCE	1
33		#define _POSIX_SOURCE	1
34		#define _POSIX_C_SOURCE	21000101L
35		#define _XOPEN_SOURCE	9900
36		#define _GNU_SOURCE	1
37		#define __EXTENSIONS__	1
38		#include <sys/types.h>
39		#include <sys/stat.h>
40		#include <stdlib.h>
41		#include <unistd.h>
42		#include <fcntl.h>
43	}end {
44		#ifndef _ALL_SOURCE
45		#define _ALL_SOURCE	1
46		#endif
47		#ifndef _POSIX_SOURCE
48		#define _POSIX_SOURCE	1
49		#endif
50		#ifndef _POSIX_C_SOURCE
51		#define _POSIX_C_SOURCE	21000101L
52		#endif
53		#ifndef _XOPEN_SOURCE
54		#define _XOPEN_SOURCE	9900
55		#endif
56		#ifndef _GNU_SOURCE
57		#define _GNU_SOURCE	1
58		#endif
59		#ifndef __EXTENSIONS__
60		#define __EXTENSIONS__	1
61		#endif
62	}
63elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _XOPEN_SOURCE & _GNU_SOURCE & __EXTENSIONS__ works }end compile{
64		#define _ALL_SOURCE	1
65		#define _POSIX_SOURCE	1
66		#define _XOPEN_SOURCE	9900
67		#define _GNU_SOURCE	1
68		#define __EXTENSIONS__	1
69		#include <sys/types.h>
70		#include <sys/stat.h>
71		#include <stdlib.h>
72		#include <unistd.h>
73		#include <fcntl.h>
74	}end {
75		#ifndef _ALL_SOURCE
76		#define _ALL_SOURCE	1
77		#endif
78		#ifndef _POSIX_SOURCE
79		#define _POSIX_SOURCE	1
80		#endif
81		#ifndef _XOPEN_SOURCE
82		#define _XOPEN_SOURCE	9900
83		#endif
84		#ifndef _GNU_SOURCE
85		#define _GNU_SOURCE	1
86		#endif
87		#ifndef __EXTENSIONS__
88		#define __EXTENSIONS__	1
89		#endif
90	}
91elif tst note{ _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & _GNU_SOURCE & __EXTENSIONS__ works }end compile{
92		#define _POSIX_SOURCE	1
93		#define _POSIX_C_SOURCE	21000101L
94		#define _XOPEN_SOURCE	9900
95		#define _GNU_SOURCE	1
96		#define __EXTENSIONS__	1
97		#include <sys/types.h>
98		#include <sys/stat.h>
99		#include <stdlib.h>
100		#include <fcntl.h>
101		#include <unistd.h>
102	}end {
103		#ifndef _POSIX_SOURCE
104		#define _POSIX_SOURCE	1
105		#endif
106		#ifndef _POSIX_C_SOURCE
107		#define _POSIX_C_SOURCE	21000101L
108		#endif
109		#ifndef _XOPEN_SOURCE
110		#define _XOPEN_SOURCE	9900
111		#endif
112		#ifndef _GNU_SOURCE
113		#define _GNU_SOURCE	1
114		#endif
115		#ifndef __EXTENSIONS__
116		#define __EXTENSIONS__	1
117		#endif
118	}
119elif tst note{ _POSIX_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
120		#define _POSIX_SOURCE	1
121		#define _XOPEN_SOURCE	1
122		#define __EXTENSIONS__	1
123		#include <sys/types.h>
124		#include <sys/stat.h>
125		#include <stdlib.h>
126		#include <unistd.h>
127	}end {
128		#ifndef _POSIX_SOURCE
129		#define _POSIX_SOURCE	1
130		#endif
131		#ifndef _XOPEN_SOURCE
132		#define _XOPEN_SOURCE	1
133		#endif
134		#ifndef __EXTENSIONS__
135		#define __EXTENSIONS__	1
136		#endif
137	}
138elif tst note{ _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
139		#define _XOPEN_SOURCE	1
140		#define __EXTENSIONS__	1
141		#include <sys/types.h>
142		#include <sys/stat.h>
143		#include <stdlib.h>
144		#include <unistd.h>
145	}end {
146		#ifndef _XOPEN_SOURCE
147		#define _XOPEN_SOURCE	1
148		#endif
149		#ifndef __EXTENSIONS__
150		#define __EXTENSIONS__	1
151		#endif
152	}
153elif tst note{ _XOPEN_SOURCE works }end compile{
154		#define _XOPEN_SOURCE	1
155		#include <sys/types.h>
156		#include <sys/stat.h>
157		#include <stdlib.h>
158		#include <unistd.h>
159	}end {
160		#ifndef _XOPEN_SOURCE
161		#define _XOPEN_SOURCE	1
162		#endif
163	}
164else tst note{ __EXTENSIONS__ works }end compile{
165		#define __EXTENSIONS__	1
166		#include <sys/types.h>
167		#include <sys/stat.h>
168	}end {
169		#ifndef __EXTENSIONS__
170		#define __EXTENSIONS__	1
171		#endif
172	}
173endif
174
175if tst -D_ISOC99_SOURCE -lm note{ _ISOC99_SOURCE plays nice }end link{
176		#include <sys/types.h>
177		#include <sys/stat.h>
178		#include <stdlib.h>
179		#include <unistd.h>
180		#include <math.h>
181		int main() { return signbit(-0.0); }
182	}end {
183		#ifndef _ISOC99_SOURCE
184		#define _ISOC99_SOURCE	1
185		#endif
186	}
187endif
188
189cat{
190
191/*
192 * this is a nasty game we all play to honor standards symbol visibility
193 * it would help if all implementations had
194 *	_KITCHEN_SINK_SOURCE
195 * that enabled all symbols from the latest implemented standards
196 * that's probably the most useful but least portable request
197 */
198
199#if __MACH__
200#undef  _POSIX_SOURCE
201#undef  _POSIX_C_SOURCE
202#undef  _XOPEN_SOURCE
203#endif
204
205}end
206