aboutsummaryrefslogtreecommitdiff
path: root/m4/mhd_sys_extentions.m4
blob: 0fff57edc1667ecfa2a419af5fb6068c6d49a94f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
# SYNOPSIS
#
#   MHD_SYS_EXT([VAR-ADD-CPPFLAGS])
#
# DESCRIPTION
#
#   This macro checks system headers and add defines that enable maximum
#   number of exposed system interfaces. Macro verifies that added defines
#   will not break basic headers, some defines are also checked against
#   real recognition by headers.
#   If VAR-ADD-CPPFLAGS is specified, defines will be added to this variable
#   in form suitable for CPPFLAGS. Otherwise defines will be added to
#   configuration header (usually 'config.h').
#
#   Example usage:
#
#     MHD_SYS_EXT
#
#   or
#
#     MHD_SYS_EXT([CPPFLAGS])
#
#   Macro is not enforced to be called before AC_COMPILE_IFELSE, but it
#   advisable to call macro before any compile and header tests since
#   additional defines can change results of those tests.
#
#   Defined in command line macros are always honored and cache variables
#   used in all checks so if any test will not work correctly on some
#   platform, user may simply fix it by giving correct defines in CPPFLAGS
#   or by giving cache variable in configure parameters, for example:
#
#     ./configure CPPFLAGS='-D_XOPEN_SOURCE=1 -D_XOPEN_SOURCE_EXTENDED'
#
#   or
#
#     ./configure mhd_cv_define__xopen_source_sevenh_works=no
#
#   This simplify building from source on exotic platforms as patching
#   of configure.ac is not required to change results of tests.
#
# LICENSE
#
#   Copyright (c) 2016 Karlson2k (Evgeny Grin) <k2k@narod.ru>
#
#   Copying and distribution of this file, with or without modification, are
#   permitted in any medium without royalty provided the copyright notice
#   and this notice are preserved. This file is offered as-is, without any
#   warranty.

#serial 1

AC_DEFUN([MHD_SYS_EXT],[dnl
  AC_PREREQ([2.64])dnl for AS_VAR_IF, m4_ifnblank
  AC_LANG_PUSH([C])dnl Use C language for simplicity
  mhd_mse_added_exts_flags=""
  mhd_mse_added_prolog=""
  MHD_CHECK_DEFINED([[_XOPEN_SOURCE]], [], [dnl
    AC_CACHE_CHECK([[whether predefined value of _XOPEN_SOURCE is more or equal 500]],
      [[mhd_cv_macro__xopen_source_def_fiveh]], [dnl
      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#if _XOPEN_SOURCE+0 < 500
#error Value of _XOPEN_SOURCE is less than 500
choke me now;
#endif
          ]],[[int i = 0; i++]])],dnl
        [[mhd_cv_macro__xopen_source_def_fiveh="yes"]],
        [[mhd_cv_macro__xopen_source_def_fiveh="no"]]
      )
    ])
    AS_VAR_IF([mhd_cv_macro__xopen_source_def_fiveh], [["no"]], [dnl
      _MHD_XOPEN_ADD([])
    ])
  ],
  [
    dnl Some platforms (namely: Solaris) use '==' checks instead of '>='
    dnl for _XOPEN_SOURCE, resulting that unknown for platform values are
    dnl interpreted as oldest and platform expose reduced number of
    dnl interfaces. Next checks will ensure that platform recognise
    dnl requested mode instead of blindly define high number that can
    dnl be simply ignored by platform.
    MHD_CHECK_ACCEPT_DEFINE([[_XOPEN_SOURCE]], [[700]], [], [dnl
      AC_CACHE_CHECK([[whether _XOPEN_SOURCE with value 700 really enable POSIX.1-2008/SUSv4 features]],
        [[mhd_cv_define__xopen_source_sevenh_works]], [dnl
        _MHD_CHECK_XOPEN_ENABLE([[700]], [
_MHD_BASIC_INCLUDES
[
/* Check will be passed if ALL features are avalable 
 * and failed if ANY feature is not avalable. */
int main()
{

#ifndef stpncpy
  (void) stpncpy;
#endif
#ifndef strnlen
  (void) strnlen;
#endif

#if !defined(__NetBSD__) && !defined(__OpenBSD__)
/* NetBSD and OpenBSD didn't implement wcsnlen() for some reason. */
#ifndef wcsnlen
  (void) wcsnlen;
#endif
#endif

#ifdef __CYGWIN__
/* The only depend function on Cygwin, but missing on some other platforms */
#ifndef strndup
  (void) strndup;
#endif
#endif

#ifndef __sun
/* illumos forget to uncomment some _XPG7 macros. */
#ifndef renameat
  (void) renameat;
#endif

#ifndef getline
  (void) getline;
#endif
#endif /* ! __sun */

/* gmtime_r() becomes mandatory only in POSIX.1-2008. */
#ifndef gmtime_r
  (void) gmtime_r;
#endif

/* unsetenv() actually defined in POSIX.1-2001 so it
 * must be present with _XOPEN_SOURCE == 700 too. */
#ifndef unsetenv
  (void) unsetenv;
#endif

  return 0;
}
          ]],
          [[mhd_cv_define__xopen_source_sevenh_works="yes"]],
          [[mhd_cv_define__xopen_source_sevenh_works="no"]]
        )dnl
      ])dnl
    ])
    AS_IF([[test "x$mhd_cv_define__xopen_source_accepted_700" = "xyes" &&
      test "x$mhd_cv_define__xopen_source_sevenh_works" = "xyes"]], [dnl
      _MHD_SYS_EXT_ADD_FLAG([[_XOPEN_SOURCE]], [[700]])
    ], [dnl
      MHD_CHECK_ACCEPT_DEFINE([[_XOPEN_SOURCE]], [[600]], [], [dnl
        AC_CACHE_CHECK([[whether _XOPEN_SOURCE with value 600 really enable POSIX.1-2001/SUSv3 features]],
          [[mhd_cv_define__xopen_source_sixh_works]], [dnl
          _MHD_CHECK_XOPEN_ENABLE([[600]], [
_MHD_BASIC_INCLUDES
[
/* Check will be passed if ALL features are available
 * and failed if ANY feature is not available. */
int main()
{

#ifndef setenv
  (void) setenv;
#endif

#ifndef __NetBSD__
#ifndef vsscanf
  (void) vsscanf;
#endif
#endif

/* Availability of next features varies, but they all must be present
 * on platform with support for _XOPEN_SOURCE = 600. */

/* vsnprintf() should be available with _XOPEN_SOURCE >= 500, but some platforms
 * provide it only with _POSIX_C_SOURCE >= 200112 (autodefined when
 * _XOPEN_SOURCE >= 600) where specification of vsnprintf() is aligned with
 * ISO C99 while others platforms defined it with even earlier standards. */
#ifndef vsnprintf
  (void) vsnprintf;
#endif

/* On platforms that prefer POSIX over X/Open, fseeko() is available
 * with _POSIX_C_SOURCE >= 200112 (autodefined when _XOPEN_SOURCE >= 600).
 * On other platforms it should be available with _XOPEN_SOURCE >= 500. */
#ifndef fseeko
  (void) fseeko;
#endif

/* F_GETOWN must be defined with _XOPEN_SOURCE >= 600, but some platforms
 * define it with _XOPEN_SOURCE >= 500. */
#ifndef F_GETOWN
#error F_GETOWN is not defined
choke me now;
#endif
  return 0;
}
            ]],
            [[mhd_cv_define__xopen_source_sixh_works="yes"]],
            [[mhd_cv_define__xopen_source_sixh_works="no"]]
          )dnl
        ])dnl
      ])
      AS_IF([[test "x$mhd_cv_define__xopen_source_accepted_600" = "xyes" &&
        test "x$mhd_cv_define__xopen_source_sixh_works" = "xyes"]], [dnl
        _MHD_SYS_EXT_ADD_FLAG([[_XOPEN_SOURCE]], [[600]])
      ], [dnl
        MHD_CHECK_ACCEPT_DEFINE([[_XOPEN_SOURCE]], [[500]], [], [dnl
          AC_CACHE_CHECK([[whether _XOPEN_SOURCE with value 500 really enable SUSv2/XPG5 features]],
            [mhd_cv_define__xopen_source_fiveh_works], [dnl
            _MHD_CHECK_XOPEN_ENABLE([[500]], [
_MHD_BASIC_INCLUDES
[
/* Check will be passed if ALL features are available
 * and failed if ANY feature is not available. */
int main()
{
/* It's not easy to write reliable test for _XOPEN_SOURCE = 500 as
 * platforms not always precisely follow this standard and some
 * functions are already deprecated in later standards. */

/* Availability of next features varies, but they all must be present
 * on platform with correct support for _XOPEN_SOURCE = 500. */

/* Mandatory with _XOPEN_SOURCE >= 500 but as XSI extension available
 * with much older standards. */
#ifndef ftruncate
  (void) ftruncate;
#endif

/* Added with _XOPEN_SOURCE >= 500 but was available in some standards
 * before. XSI extension. */
#ifndef pread
  (void) pread;
#endif

#ifndef __APPLE__
/* Actually comes from XPG4v2 and must be available
 * with _XOPEN_SOURCE >= 500 as well. */
#ifndef symlink
  (void) symlink;
#endif

/* Actually comes from XPG4v2 and must be available
 * with _XOPEN_SOURCE >= 500 as well. XSI extension. */
#ifndef strdup
  (void) strdup;
#endif
#endif /* ! __APPLE__ */
  return 0;
}
              ]],
              [[mhd_cv_define__xopen_source_fiveh_works="yes"]],
              [[mhd_cv_define__xopen_source_fiveh_works="no"]]
            )dnl
          ])dnl
        ])
        AS_IF([[test "x$mhd_cv_define__xopen_source_accepted_500" = "xyes" && ]dnl
          [test "x$mhd_cv_define__xopen_source_fiveh_works" = "xyes"]], [dnl
          _MHD_SYS_EXT_ADD_FLAG([[_XOPEN_SOURCE]], [[500]])
        ],
        [
          [#] Earlier standards are widely supported, so just define macros to maximum value
          [#] which do not break headers.
          _MHD_XOPEN_ADD([[#define _XOPEN_SOURCE 1]])
          AC_CACHE_CHECK([[whether headers accept _XOPEN_SOURCE with value 1]],
            [mhd_cv_define__xopen_source_accepted_1], [dnl
            AS_IF([[test "x$mhd_cv_define__xopen_source_extended_accepted" = "xyes" || ]dnl
                   [test "x$mhd_cv_define__xopen_version_accepted" = "xyes"]],
              [[mhd_cv_define__xopen_source_accepted_1="yes"]],
            [
              MHD_CHECK_BASIC_HEADERS([[#define _XOPEN_SOURCE 1]],
                [[mhd_cv_define__xopen_source_accepted_1="yes"]],
                [[mhd_cv_define__xopen_source_accepted_1="no"]])
            ])
          ])
          AS_VAR_IF([[mhd_cv_define__xopen_source_accepted_1]], [["yes"]], [dnl
            _MHD_SYS_EXT_ADD_FLAG([[_XOPEN_SOURCE]], [[1]])
          ])
        ])
      ])
    ])
  ])
  dnl Add other extensions.
  dnl Use compiler-based test for determinig target.

  dnl Always add _GNU_SOURCE if headers allow.
  MHD_CHECK_DEF_AND_ACCEPT([[_GNU_SOURCE]], [],
    [[${mhd_mse_added_prolog}]], [],
    [_MHD_SYS_EXT_ADD_FLAG([[_GNU_SOURCE]])])

  dnl __BSD_VISIBLE is actually a small hack for FreeBSD.
  dnl Funny that it's used in Android headers too.
  AC_CACHE_CHECK([[whether to try __BSD_VISIBLE macro]],
    [[mhd_cv_macro_try___bsd_visible]], [dnl
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#if !defined(__FreeBSD__) && !defined (__ANDROID__)
#error Target is not FreeBSD or Android
choke me now;
#endif
        ]],[])],
      [[mhd_cv_macro_try___bsd_visible="yes"]],
      [[mhd_cv_macro_try___bsd_visible="no"]]
    )
  ])
  AS_VAR_IF([[mhd_cv_macro_try___bsd_visible]], [["yes"]],
  [dnl
    AC_CACHE_CHECK([[whether __BSD_VISIBLE is already defined]],
      [[mhd_cv_macro___bsd_visible_defined]], [dnl
      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
${mhd_mse_added_prolog}
/* Warning: test with inverted logic! */
#ifdef __BSD_VISIBLE
#error __BSD_VISIBLE is defined
choke me now;
#endif
#ifdef __ANDROID__
/* if __BSD_VISIBLE is not defined, Android usually defines it to 1 */
#include <stdio.h>
#if defined(__BSD_VISIBLE) && __BSD_VISIBLE == 1
#error __BSD_VISIBLE is autodefined by headers to value 1
choke me now;
#endif
#endif
          ]],[])
      ],
        [[mhd_cv_macro___bsd_visible_defined="no"]],
        [[mhd_cv_macro___bsd_visible_defined="yes"]]
      )
    ])
    AS_VAR_IF([[mhd_cv_macro___bsd_visible_defined]], [["yes"]], [[:]],
    [dnl
      MHD_CHECK_ACCEPT_DEFINE(
        [[__BSD_VISIBLE]], [], [[${mhd_mse_added_prolog}]],
        [_MHD_SYS_EXT_ADD_FLAG([[__BSD_VISIBLE]])]
      )dnl
    ])
  ])


  dnl _DARWIN_C_SOURCE enables additional functionality on Darwin.
  MHD_CHECK_DEFINED_MSG([[__APPLE__]], [[${mhd_mse_added_prolog}]],
    [[whether to try _DARWIN_C_SOURCE macro]],
  [dnl
    MHD_CHECK_DEF_AND_ACCEPT(
      [[_DARWIN_C_SOURCE]], [], [[${mhd_mse_added_prolog}]], [],
      [_MHD_SYS_EXT_ADD_FLAG([[_DARWIN_C_SOURCE]])]
    )dnl
  ])

  dnl __EXTENSIONS__ unlocks almost all interfaces on Solaris.
  MHD_CHECK_DEFINED_MSG([[__sun]], [[${mhd_mse_added_prolog}]],
    [[whether to try __EXTENSIONS__ macro]],
  [dnl
    MHD_CHECK_DEF_AND_ACCEPT(
      [[__EXTENSIONS__]], [], [[${mhd_mse_added_prolog}]], [],
      [_MHD_SYS_EXT_ADD_FLAG([[__EXTENSIONS__]])]
    )dnl
  ])

  dnl _NETBSD_SOURCE switch on almost all headers definitions on NetBSD.
  MHD_CHECK_DEFINED_MSG([[__NetBSD__]], [[${mhd_mse_added_prolog}]],
    [[whether to try _NETBSD_SOURCE macro]],
  [dnl
    MHD_CHECK_DEF_AND_ACCEPT(
      [[_NETBSD_SOURCE]], [], [[${mhd_mse_added_prolog}]], [],
      [_MHD_SYS_EXT_ADD_FLAG([[_NETBSD_SOURCE]])]
    )dnl
  ])

  dnl _BSD_SOURCE currently used only on OpenBSD to unhide functions.
  MHD_CHECK_DEFINED_MSG([[__OpenBSD__]], [[${mhd_mse_added_prolog}]],
    [[whether to try _BSD_SOURCE macro]],
  [dnl
    MHD_CHECK_DEF_AND_ACCEPT(
      [[_BSD_SOURCE]], [], [[${mhd_mse_added_prolog}]], [],
      [_MHD_SYS_EXT_ADD_FLAG([[_BSD_SOURCE]])]
    )dnl
  ])

  dnl _TANDEM_SOURCE unhides most functions on NonStop OS
  dnl (which comes from Tandem Computers decades ago).
  MHD_CHECK_DEFINED_MSG([[__TANDEM]], [[${mhd_mse_added_prolog}]],
    [[whether to try _TANDEM_SOURCE macro]],
  [dnl
    MHD_CHECK_DEF_AND_ACCEPT(
      [[_TANDEM_SOURCE]], [], [[${mhd_mse_added_prolog}]], [],
      [_MHD_SYS_EXT_ADD_FLAG([[_TANDEM_SOURCE]])]
    )dnl
  ])

  dnl _ALL_SOURCE makes visible POSIX and non-POSIX symbols
  dnl on z/OS, AIX and Interix.
  AC_CACHE_CHECK([[whether to try _ALL_SOURCE macro]],
    [[mhd_cv_macro_try__all_source]], [dnl
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#if !defined(__TOS_MVS__) && !defined (__INTERIX)
#error Target is not z/OS, AIX or Interix
choke me now;
#endif
        ]],[])],
      [[mhd_cv_macro_try__all_source="yes"]],
      [[mhd_cv_macro_try__all_source="no"]]
    )
  ])
  AS_VAR_IF([[mhd_cv_macro_try__all_source]], [["yes"]],
  [dnl
    MHD_CHECK_DEF_AND_ACCEPT(
      [[_ALL_SOURCE]], [], [[${mhd_mse_added_prolog}]], [],
      [_MHD_SYS_EXT_ADD_FLAG([[_TANDEM_SOURCE]])]
    )dnl
  ])

  dnl Discard temporal prolog with set of defines.
  AS_UNSET([[mhd_mse_added_prolog]])
  dnl Determined all required defines.
  AC_MSG_CHECKING([[for final set of defined symbols]])
  m4_ifblank([$1], [dnl
    AH_TEMPLATE([[_XOPEN_SOURCE]], [Define to maximum value supported by system headers])dnl
    AH_TEMPLATE([[_XOPEN_SOURCE_EXTENDED]], [Define to 1 if _XOPEN_SOURCE is defined to value less than 500 ]dnl
      [and system headers requre this symbol])dnl
    AH_TEMPLATE([[_XOPEN_VERSION]], [Define to maximum value supported by system headers if _XOPEN_SOURCE ]dnl
      [is defined to value less than 500 and headers do not support _XOPEN_SOURCE_EXTENDED])dnl
    AH_TEMPLATE([[_GNU_SOURCE]], [Define to 1 to enable GNU-related header features])dnl
    AH_TEMPLATE([[__BSD_VISIBLE]], [Define to 1 if it is required by headers to expose additional symbols])dnl
    AH_TEMPLATE([[_DARWIN_C_SOURCE]], [Define to 1 if it is required by headers to expose additional symbols])dnl
    AH_TEMPLATE([[__EXTENSIONS__]], [Define to 1 if it is required by headers to expose additional symbols])dnl
    AH_TEMPLATE([[_NETBSD_SOURCE]], [Define to 1 if it is required by headers to expose additional symbols])dnl
    AH_TEMPLATE([[_BSD_SOURCE]], [Define to 1 if it is required by headers to expose additional symbols])dnl
    AH_TEMPLATE([[_TANDEM_SOURCE]], [Define to 1 if it is required by headers to expose additional symbols])dnl
    AH_TEMPLATE([[_ALL_SOURCE]], [Define to 1 if it is required by headers to expose additional symbols])dnl
  ])
  for mhd_mse_Flag in $mhd_mse_added_exts_flags
  do
    m4_ifnblank([$1], [dnl
      AS_VAR_APPEND([$1],[[" -D$mhd_mse_Flag"]])
    ], [dnl
      AS_CASE([[$mhd_mse_Flag]], [[*=*]],
      [dnl
        AC_DEFINE_UNQUOTED([[`echo $mhd_mse_Flag | cut -f 1 -d =`]],
          [[`echo $mhd_mse_Flag | cut -f 2 -d = -s`]])
      ], [dnl
        AC_DEFINE_UNQUOTED([[$mhd_mse_Flag]])
      ])
    ])
  done
  dnl Trim whitespaces
  mhd_mse_result=`echo $mhd_mse_added_exts_flags`
  AC_MSG_RESULT([[$mhd_mse_result]])
  AS_UNSET([[mhd_mse_result]])

  AS_UNSET([[mhd_mse_added_exts_flags]])
  AC_LANG_POP([C])
])


#
# _MHD_SYS_EXT_ADD_FLAG(FLAG, [FLAG-VALUE = 1])
#
# Internal macro, only to be used from MHD_SYS_EXT, _MHD_XOPEN_ADD

m4_define([_MHD_SYS_EXT_ADD_FLAG], [dnl
  m4_ifnblank([$2],[dnl
    mhd_mse_added_exts_flags="$mhd_mse_added_exts_flags m4_normalize($1)=m4_normalize($2)"
    mhd_mse_added_prolog="${mhd_mse_added_prolog}[#define ]m4_normalize($1) m4_normalize($2)
"
  ], [dnl
    mhd_mse_added_exts_flags="$mhd_mse_added_exts_flags m4_normalize($1)"
    mhd_mse_added_prolog="${mhd_mse_added_prolog}[#define ]m4_normalize($1) 1
"
  ])dnl
])

#
# _MHD_VAR_IF(VAR, VALUE, [IF-EQ], [IF-NOT-EQ])
#
# Same as AS_VAR_IF, except that it expands to nothing if
# both IF-EQ and IF-NOT-EQ are empty.

m4_define([_MHD_VAR_IF],[dnl
m4_ifnblank([$3][$4],[dnl
m4_ifblank([$4],[AS_VAR_IF([$1],[$2],[$3])],[dnl
AS_VAR_IF([$1],[$2],[$3],[$4])])])])

# SYNOPSIS
#
# _MHD_CHECK_XOPEN_ENABLE(_XOPEN_SOURCE-VALUE, FEATURES_TEST,
#                         [ACTION-IF-ENABLED-BY-XOPEN_SOURCE],
#                         [ACTION-IF-NOT],
#                         [ACTION-IF-FEATURES-AVALABLE],
#                         [ACTION-IF-FEATURES-NOT-AVALABLE],
#                         [ACTION-IF-ONLY-WITH-EXTENSIONS]
#                         [ACTION-IF-WITHOUT-ALL])
#
# DESCRIPTION
#
#   This macro determines whether the _XOPEN_SOURCE with
#   _XOPEN_SOURCE-VALUE really enable some header features. FEATURES_TEST
#   must contains required includes and main function.
#   One of ACTION-IF-ENABLED-BY-XOPEN_SOURCE and ACTION-IF-NOT
#   is always executed depending on test results.
#   One of ACTION-IF-FEATURES-AVALABLE and is ACTION-IF-FEATURES-NOT-AVALABLE
#   is executed if features can be enabled by _XOPEN_SOURCE, by currently
#   defined (by compiler flags or by predefined macros) extensions or
#   all checked combinations are failed to enable features.
#   ACTION-IF-ONLY-WITH-EXTENSIONS is executed if features can be
#   enabled with not undefined extension.
#   ACTION-IF-WITHOUT-ALL is executed if features work with all
#   disabled extensions (including _XOPEN_SOURCE).

AC_DEFUN([_MHD_CHECK_XOPEN_ENABLE], [dnl
  AS_VAR_PUSHDEF([src_Var], [[mhd_cxoe_tmp_src_variable]])dnl
  AS_VAR_SET([src_Var],["
$2
"])dnl Reduce 'configure' size

  dnl Some platforms enable most features when no
  dnl specific mode is requested by macro.
  dnl Check whether features test works without _XOPEN_SOURCE and
  dnl with disabled extensions (undefined most of
  dnl predefined macros for specific requested mode).
  AC_COMPILE_IFELSE([AC_LANG_SOURCE([
_MHD_UNDEF_ALL_EXT
$src_Var
    ])],
  [dnl
    _AS_ECHO_LOG([[Checked features work with undefined all extensions and without _XOPEN_SOURCE]])
    dnl Checked features is enabled in platform's "default" mode.
    dnl Try to disable features by requesting oldest X/Open mode.
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
_MHD_UNDEF_ALL_EXT
[#define _XOPEN_SOURCE 1]
$src_Var
      ])],
    [dnl
      _AS_ECHO_LOG([[Checked features work with undefined all extensions and with _XOPEN_SOURCE=1]])
      dnl Features still work in oldest X/Open mode.
      dnl Some platforms enable all XSI features for any _XOPEN_SOURCE value.
      dnl Apply some fuzzy logic, try to use _POSIX_C_SOURCE with oldest number.
      AC_COMPILE_IFELSE([AC_LANG_SOURCE([
_MHD_UNDEF_ALL_EXT
[#define _POSIX_C_SOURCE 1]
$src_Var
        ])],
      [dnl
        _AS_ECHO_LOG([[Checked features work with undefined all extensions and with _POSIX_C_SOURCE=1]])
        dnl Features still work in oldest _POSIX_C_SOURCE mode.
        dnl Try to disable features by requesting strict ANSI C mode.
        AC_COMPILE_IFELSE([AC_LANG_SOURCE([
_MHD_UNDEF_ALL_EXT
[#define  _ANSI_SOURCE 1]
$src_Var
          ])],
        [dnl
          _AS_ECHO_LOG([[Checked features work with undefined all extensions and with _ANSI_SOURCE]])
          dnl Features still work in strict _ANSI_SOURCE mode.
          dnl Assume that _XOPEN_SOURCE, _POSIX_C_SOURCE and _ANSI_SOURCE has no influence on
          dnl enabling of features as features are enabled always unconditionally.
          m4_n([$4])dnl ACTION-IF-NOT-ENABLED-BY-XOPEN_SOURCE
        ], [dnl
          _AS_ECHO_LOG([[Checked features do not work with undefined all extensions and with _ANSI_SOURCE]])
          dnl Features do not work in strict _ANSI_SOURCE mode.
          dnl Try to enable features by _XOPEN_SOURCE with specified value.
          AC_COMPILE_IFELSE([AC_LANG_SOURCE([
_MHD_UNDEF_ALL_EXT
[#define  _ANSI_SOURCE 1]
[#define _XOPEN_SOURCE] $1
$src_Var
            ])],
          [dnl
            _AS_ECHO_LOG([[Checked features work with undefined all extensions and with _ANSI_SOURCE and _XOPEN_SOURCE=]$1])
            dnl Finally, features were  disabled by strict ANSI mode and enabled by adding _XOPEN_SOURCE.
            dnl Assume that _XOPEN_SOURCE can enable features.
            m4_n([$3])dnl ACTION-IF-ENABLED-BY-XOPEN_SOURCE
          ], [dnl
            _AS_ECHO_LOG([[Checked features do not work with undefined all extensions and with _ANSI_SOURCE and _XOPEN_SOURCE=]$1])
            dnl Features are not enabled in strict ANSI mode with _XOPEN_SOURCE.
            dnl Actually this is not correct documented situation and _ANSI_SOURCE may have
            dnl priority over _XOPEN_SOURCE or headers are not controlled by _XOPEN_SOURCE at all.
            dnl As features work in all mode except strict ANSI regardless of _XOPEN_SOURCE,
            dnl assume that _XOPEN_SOURCE do not control visibility of features.
            m4_n([$4])dnl ACTION-IF-NOT-ENABLED-BY-XOPEN_SOURCE
          ])
        ])
      ], [dnl
        _AS_ECHO_LOG([[Checked features do not work with undefined all extensions and with _POSIX_C_SOURCE=1]])
        dnl Features do not work in oldest _POSIX_C_SOURCE mode.
        dnl OK, features were disabled by _POSIX_C_SOURCE.
        dnl Check whether headers controlled by _XOPEN_SOURCE too.
        AC_COMPILE_IFELSE([AC_LANG_SOURCE([
_MHD_UNDEF_ALL_EXT
[#define _POSIX_C_SOURCE 1]
[#define _XOPEN_SOURCE] $1
$src_Var
          ])],
        [dnl
          _AS_ECHO_LOG([[Checked features work with undefined all extensions and with _POSIX_C_SOURCE=1 and _XOPEN_SOURCE=]$1])
          dnl Features were enabled again after adding _XOPEN_SOURCE with value.
          dnl Assume that headers can be controlled by _XOPEN_SOURCE with specified value.
          m4_n([$3])dnl ACTION-IF-ENABLED-BY-XOPEN_SOURCE
        ], [dnl
          _AS_ECHO_LOG([[Checked features do not work with undefined all extensions and with _POSIX_C_SOURCE=1 and _XOPEN_SOURCE=]$1])
          dnl Features still work after adding _XOPEN_SOURCE with value.
          dnl It's unclear whether headers know only about _POSIX_C_SOURCE or
          dnl _POSIX_C_SOURCE have priority over _XOPEN_SOURCE (standards are
          dnl silent about priorities).
          dnl Assume that it's unknown whether _XOPEN_SOURCE can turn on features.
          m4_n([$4])dnl ACTION-IF-NOT-ENABLED-BY-XOPEN_SOURCE
        ])
      ])
    ], [dnl
      _AS_ECHO_LOG([[Checked features does not work with undefined all extensions and with _XOPEN_SOURCE=1]])
      dnl Features disabled by oldest X/Open mode.
      dnl Check whether requested _XOPEN_SOURCE value will turn on features.
      AC_COMPILE_IFELSE([AC_LANG_SOURCE([
_MHD_UNDEF_ALL_EXT
[#define _XOPEN_SOURCE] $1
$src_Var
        ])],
      [dnl
        _AS_ECHO_LOG([[Checked features work with undefined all extensions and with _XOPEN_SOURCE=]$1])
        dnl Features work with _XOPEN_SOURCE requested value and do not work
        dnl with value 1.
        dnl Assume that _XOPEN_SOURCE really turn on features.
        m4_n([$3])dnl ACTION-IF-ENABLED-BY-XOPEN_SOURCE
      ], [dnl
        _AS_ECHO_LOG([[Checked features do not work with undefined all extensions and with _XOPEN_SOURCE=]$1])
        dnl Features do not work with _XOPEN_SOURCE, but work in "default" mode.
        dnl Assume that features cannot be enabled by requested _XOPEN_SOURCE value.
        m4_n([$4])dnl ACTION-IF-NOT-ENABLED-BY-XOPEN_SOURCE
      ])
    ])
    m4_n([$5])dnl ACTION-IF-FEATURES-AVALABLE
    m4_n([$8])dnl ACTION-IF-WITHOUT-ALL
  ],
  [dnl
    _AS_ECHO_LOG([[Checked features do not work with undefined all extensions and without _XOPEN_SOURCE]])
    dnl Features do not work with turned off extensions.
    dnl Check whether they can be enabled by _XOPEN_SOURCE.
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
_MHD_UNDEF_ALL_EXT
[#define _XOPEN_SOURCE] $1
$src_Var
      ])],
    [dnl
      _AS_ECHO_LOG([[Checked features work with undefined all extensions and with _XOPEN_SOURCE=]$1])
      dnl Features work with _XOPEN_SOURCE and do not work without _XOPEN_SOURCE.
      dnl Assume that _XOPEN_SOURCE really turn on features.
      m4_n([$3])dnl ACTION-IF-ENABLED-BY-XOPEN_SOURCE
      m4_n([$5])dnl ACTION-IF-FEATURES-AVALABLE
    ],
    [dnl
      _AS_ECHO_LOG([[Checked features do not work with undefined all extensions and with _XOPEN_SOURCE=]$1])
      dnl Features do not work with _XOPEN_SOURCE and turned off extensions.
      dnl Retry without turning off known extensions.
      AC_COMPILE_IFELSE([AC_LANG_SOURCE([
[#define _XOPEN_SOURCE] $1
$src_Var
        ])],
      [dnl
        _AS_ECHO_LOG([[Checked features work with current extensions and with _XOPEN_SOURCE=]$1])
        dnl Features work with _XOPEN_SOURCE and without turning off extensions.
        dnl Check whether features work with oldest _XOPEN_SOURCE or it was enabled only by extensions.
        AC_COMPILE_IFELSE([AC_LANG_SOURCE([
[#define _XOPEN_SOURCE 1]
$src_Var
          ])],
        [dnl
          _AS_ECHO_LOG([[Checked features work with current extensions and with _XOPEN_SOURCE=1]])
          dnl Features still work with oldest _XOPEN_SOURCE.
          dnl Assume that _XOPEN_SOURCE has no influence on enabling of features.
          m4_n([$4])dnl ACTION-IF-NOT-ENABLED-BY-XOPEN_SOURCE
        ], [dnl
          _AS_ECHO_LOG([[Checked features do not work with current extensions and with _XOPEN_SOURCE=1]])
          dnl Features do not work with oldest _XOPEN_SOURCE.
          dnl Assume that _XOPEN_SOURCE really turn on features.
          m4_n([$3])dnl ACTION-IF-ENABLED-BY-XOPEN_SOURCE
        ])
        m4_n([$5])dnl ACTION-IF-FEATURES-AVALABLE
        m4_n([$7])dnl ACTION-IF-ONLY-WITH-EXTENSIONS
      ], [dnl
        _AS_ECHO_LOG([[Checked features do not work with current extensions and with _XOPEN_SOURCE=]$1])
        dnl Features do not work in all checked conditions.
        dnl Assume that _XOPEN_SOURCE cannot enable feature.
        m4_n([$4])dnl ACTION-IF-NOT-ENABLED-BY-XOPEN_SOURCE
        m4_n([$6])dnl ACTION-IF-FEATURE-NOT-AVALABLE
      ])
    ])
  ])
  AS_UNSET([src_Var])
  AS_VAR_POPDEF([src_Var])dnl
])


#
# MHD_CHECK_HEADER_PRESENCE(headername.h)
#
# Check only by preprocessor whether header file is present.

AC_DEFUN([MHD_CHECK_HEADER_PRESENCE], [dnl
  AC_PREREQ([2.64])dnl for AS_VAR_PUSHDEF, AS_VAR_SET
  AS_VAR_PUSHDEF([mhd_cache_Var],[mhd_cv_header_[]$1[]_present])dnl
  AC_CACHE_CHECK([for presence of $1], [mhd_cache_Var], [dnl
    dnl Hack autoconf to get pure result of only single header presence
    cat > conftest.$ac_ext <<_ACEOF
@%:@include <[]$1[]>
_ACEOF
    AC_PREPROC_IFELSE([],
      [AS_VAR_SET([mhd_cache_Var],[["yes"]])],
      [AS_VAR_SET([mhd_cache_Var],[["no"]])]
    )
    rm -f conftest.$ac_ext
  ])
  AS_VAR_POPDEF([mhd_cache_Var])dnl
])


#
# MHD_CHECK_HEADERS_PRESENCE(oneheader.h otherheader.h ...)
#
# Check each specified header in whitespace-separated list for presence.

AC_DEFUN([MHD_CHECK_HEADERS_PRESENCE], [dnl
  AC_PREREQ([2.60])dnl for m4_foreach_w
  m4_foreach_w([mhd_chk_Header], [$1],
    [MHD_CHECK_HEADER_PRESENCE(m4_defn([mhd_chk_Header]))]
  )dnl
])


#
# MHD_CHECK_HEADERS_PRESENCE_COMPACT(oneheader.h otherheader.h ...)
#
# Same as MHD_CHECK_HEADERS_PRESENCE, but a bit slower and produce more compact 'configure'.

AC_DEFUN([MHD_CHECK_HEADERS_PRESENCE_COMPACT], [dnl
  for mhd_chk_Header in $1 ; do
    MHD_CHECK_HEADER_PRESENCE([[${mhd_chk_Header}]])
  done
])


#
# MHD_CHECK_BASIC_HEADERS_PRESENCE
#
# Check basic headers for presence.

AC_DEFUN([MHD_CHECK_BASIC_HEADERS_PRESENCE], [dnl
  MHD_CHECK_HEADERS_PRESENCE([stdio.h wchar.h stdlib.h string.h strings.h stdint.h fcntl.h sys/types.h time.h unistd.h])
])


#
# _MHD_SET_BASIC_INCLUDES
#
# Internal preparatory macro.

AC_DEFUN([_MHD_SET_BASIC_INCLUDES], [dnl
  AC_REQUIRE([MHD_CHECK_BASIC_HEADERS_PRESENCE])dnl
  AS_IF([[test -z "$mhd_basic_headers_includes"]], [dnl
    AS_VAR_IF([mhd_cv_header_stdio_h_present], [["yes"]],
      [[mhd_basic_headers_includes="\
#include <stdio.h>
"     ]],[[mhd_basic_headers_includes=""]]
    )
    AS_VAR_IF([mhd_cv_header_sys_types_h_present], [["yes"]],
      [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
#include <sys/types.h>
"     ]]
    )
    AS_VAR_IF([mhd_cv_header_wchar_h_present], [["yes"]],
      [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
#include <wchar.h>
"     ]]
    )
    AS_VAR_IF([mhd_cv_header_stdlib_h_present], [["yes"]],
      [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
#include <stdlib.h>
"     ]]
    )
    AS_VAR_IF([mhd_cv_header_string_h_present], [["yes"]],
      [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
#include <string.h>
"     ]]
    )
    AS_VAR_IF([mhd_cv_header_strings_h_present], [["yes"]],
      [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
#include <strings.h>
"     ]]
    )
    AS_VAR_IF([mhd_cv_header_stdint_h_present], [["yes"]],
      [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
#include <stdint.h>
"     ]]
    )
    AS_VAR_IF([mhd_cv_header_fcntl_h_present], [["yes"]],
      [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
#include <fcntl.h>
"     ]]
    )
    AS_VAR_IF([mhd_cv_header_time_h_present], [["yes"]],
      [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
#include <time.h>
"     ]]
    )
    AS_VAR_IF([mhd_cv_header_unistd_h_present], [["yes"]],
      [[mhd_basic_headers_includes="${mhd_basic_headers_includes}\
#include <unistd.h>
"     ]]
    )
  ])dnl
])


#
# _MHD_BASIC_INCLUDES
#
# Internal macro. Output set of basic includes.

AC_DEFUN([_MHD_BASIC_INCLUDES], [AC_REQUIRE([_MHD_SET_BASIC_INCLUDES])dnl
[ /* Start of MHD basic test includes */
$mhd_basic_headers_includes /* End of MHD basic test includes */
]])


#
# MHD_CHECK_BASIC_HEADERS([PROLOG], [ACTION-IF-OK], [ACTION-IF-FAIL])
#
# Check whether basic headers can be compiled with specified prolog.

AC_DEFUN([MHD_CHECK_BASIC_HEADERS], [dnl
  AC_COMPILE_IFELSE([dnl
    AC_LANG_PROGRAM([m4_n([$1])dnl
_MHD_BASIC_INCLUDES
    ], [[int i = 1; i++]])
  ], [$2], [$3])
])


#
# _MHD_SET_UNDEF_ALL_EXT
#
# Internal preparatory macro.

AC_DEFUN([_MHD_SET_UNDEF_ALL_EXT], [m4_divert_text([INIT_PREPARE],[dnl
[mhd_undef_all_extensions="
#ifdef _GNU_SOURCE
#undef _GNU_SOURCE
#endif
#ifdef _XOPEN_SOURCE
#undef _XOPEN_SOURCE
#endif
#ifdef _XOPEN_SOURCE_EXTENDED
#undef _XOPEN_SOURCE_EXTENDED
#endif
#ifdef _XOPEN_VERSION
#undef _XOPEN_VERSION
#endif
#ifdef _POSIX_C_SOURCE
#undef _POSIX_C_SOURCE
#endif
#ifdef _POSIX_SOURCE
#undef _POSIX_SOURCE
#endif
#ifdef _DEFAULT_SOURCE
#undef _DEFAULT_SOURCE
#endif
#ifdef _BSD_SOURCE
#undef _BSD_SOURCE
#endif
#ifdef _SVID_SOURCE
#undef _SVID_SOURCE
#endif
#ifdef __EXTENSIONS__
#undef __EXTENSIONS__
#endif
#ifdef _ALL_SOURCE
#undef _ALL_SOURCE
#endif
#ifdef _TANDEM_SOURCE
#undef _TANDEM_SOURCE
#endif
#ifdef _DARWIN_C_SOURCE
#undef _DARWIN_C_SOURCE
#endif
#ifdef __BSD_VISIBLE
#undef __BSD_VISIBLE
#endif
#ifdef _NETBSD_SOURCE
#undef _NETBSD_SOURCE
#endif
"
]])])


#
# _MHD_UNDEF_ALL_EXT
#
# Output prolog that undefine all known extension and visibility macros.

AC_DEFUN([_MHD_UNDEF_ALL_EXT], [dnl
AC_REQUIRE([_MHD_SET_UNDEF_ALL_EXT])dnl
$mhd_undef_all_extensions
])


#
# _MHD_CHECK_DEFINED(SYMBOL, [PROLOG],
#                    [ACTION-IF-DEFINED], [ACTION-IF-NOT-DEFINED])
#
# Silently checks for defined symbols.

AC_DEFUN([_MHD_CHECK_DEFINED], [dnl
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
m4_n([$2])dnl
[#ifndef ]$1[
#error ]$1[ is not defined
choke me now;
#endif
        ]],[])
    ], [$3], [$4]
  )
])


#
# MHD_CHECK_DEFINED(SYMBOL, [PROLOG],
#                   [ACTION-IF-DEFINED], [ACTION-IF-NOT-DEFINED],
#                   [MESSAGE])
#
# Cache-check for defined symbols with printing results.

AC_DEFUN([MHD_CHECK_DEFINED], [dnl
  AS_VAR_PUSHDEF([mhd_cache_Var],
    [mhd_cv_macro_[]m4_tolower($1)_defined])dnl
  AC_CACHE_CHECK([dnl
m4_ifnblank([$5], [$5], [whether $1 is already defined])],
    [mhd_cache_Var],
  [
    _MHD_CHECK_DEFINED([$1], [$2],
      [mhd_cache_Var="yes"],
      [mhd_cache_Var="no"]
    )
  ])
  _MHD_VAR_IF([mhd_cache_Var], [["yes"]], [$3], [$4])
  AS_VAR_POPDEF([mhd_cache_Var])dnl
])


#
# MHD_CHECK_DEFINED_MSG(SYMBOL, [PROLOG], [MESSAGE]
#                       [ACTION-IF-DEFINED], [ACTION-IF-NOT-DEFINED])
#
# Cache-check for defined symbols with printing results.
# Reordered arguments for better readability.

AC_DEFUN([MHD_CHECK_DEFINED_MSG],[dnl
MHD_CHECK_DEFINED([$1],[$2],[$4],[$5],[$3])])

#
# MHD_CHECK_ACCEPT_DEFINE(DEFINE-SYMBOL, [DEFINE-VALUE = 1], [PROLOG],
#                         [ACTION-IF-ACCEPTED], [ACTION-IF-NOT-ACCEPTED],
#                         [MESSAGE])
#
# Cache-check whether specific defined symbol do not break basic headers.

AC_DEFUN([MHD_CHECK_ACCEPT_DEFINE], [dnl
  AC_PREREQ([2.64])dnl for AS_VAR_PUSHDEF, AS_VAR_SET, m4_ifnblank
  AS_VAR_PUSHDEF([mhd_cache_Var],
    [mhd_cv_define_[]m4_tolower($1)_accepted[]m4_ifnblank([$2],[_[]$2])])dnl
  AC_CACHE_CHECK([dnl
m4_ifnblank([$6],[$6],[whether headers accept $1[]m4_ifnblank([$2],[ with value $2])])],
    [mhd_cache_Var], [dnl
    MHD_CHECK_BASIC_HEADERS([
m4_n([$3])[#define ]$1 m4_default_nblank([$2],[[1]])],
      [mhd_cache_Var="yes"], [mhd_cache_Var="no"]
    )
  ])
  _MHD_VAR_IF([mhd_cache_Var], [["yes"]], [$4], [$5])
  AS_VAR_POPDEF([mhd_cache_Var])dnl
])


#
# MHD_CHECK_DEF_AND_ACCEPT(DEFINE-SYMBOL, [DEFINE-VALUE = 1], [PROLOG],
#                         [ACTION-IF-DEFINED],
#                         [ACTION-IF-ACCEPTED], [ACTION-IF-NOT-ACCEPTED])
#
# Combination of MHD_CHECK_DEFINED_ECHO and MHD_CHECK_ACCEPT_DEFINE.
# First check whether symbol is already defined and, if not defined,
# checks whether it can be defined.

AC_DEFUN([MHD_CHECK_DEF_AND_ACCEPT], [dnl
  MHD_CHECK_DEFINED([$1], [$3], [$4], [dnl
    MHD_CHECK_ACCEPT_DEFINE([$1], [$2], [$3], [$5], [$6])dnl
  ])dnl
])


#
# _MHD_XOPEN_ADD([PROLOG])
#
# Internal macro. Only to be used in MHD_SYS_EXT.

AC_DEFUN([_MHD_XOPEN_ADD], [dnl
  MHD_CHECK_DEF_AND_ACCEPT([[_XOPEN_SOURCE_EXTENDED]], [],
    [[${mhd_mse_added_prolog}]m4_n([$1])], [],
  [dnl
    _MHD_SYS_EXT_ADD_FLAG([[_XOPEN_SOURCE_EXTENDED]])dnl
  ], [dnl
    MHD_CHECK_DEFINED([[_XOPEN_VERSION]],
      [[${mhd_mse_added_prolog}]m4_n([$1])], [],
    [dnl
      AC_CACHE_CHECK([[for value of _XOPEN_VERSION accepted by headers]],
        [mhd_cv_define__xopen_version_accepted], [dnl
        MHD_CHECK_BASIC_HEADERS([
[${mhd_mse_added_prolog}]m4_n([$1])
[#define _XOPEN_VERSION 4]],
          [[mhd_cv_define__xopen_version_accepted="4"]],
        [
          MHD_CHECK_BASIC_HEADERS([
[${mhd_mse_added_prolog}]m4_n([$1])
[#define _XOPEN_VERSION 3]],
            [[mhd_cv_define__xopen_version_accepted="3"]],
            [[mhd_cv_define__xopen_version_accepted="no"]]
          )
        ])
      ])
      AS_VAR_IF([mhd_cv_define__xopen_version_accepted], [["no"]],
        [[:]],
      [dnl
        _MHD_SYS_EXT_ADD_FLAG([[_XOPEN_VERSION]],
          [[${mhd_cv_define__xopen_version_accepted}]]dnl
        )
      ])
    ])
  ])
])