xref: /netbsd-src/external/bsd/am-utils/dist/m4/macros/check_gnu_getopt.m4 (revision a53f50b9b44dc9467ccc9c464999b1d1c509cb0c)
1*a53f50b9Schristosdnl ######################################################################
2*a53f50b9Schristosdnl Do we have a GNUish getopt
3*a53f50b9SchristosAC_DEFUN([AMU_CHECK_GNU_GETOPT],
4*a53f50b9Schristos[
5*a53f50b9SchristosAC_CACHE_CHECK([for GNU getopt], ac_cv_sys_gnu_getopt, [
6*a53f50b9SchristosAC_TRY_RUN([
7*a53f50b9Schristos#include <stdio.h>
8*a53f50b9Schristos#include <unistd.h>
9*a53f50b9Schristosint main()
10*a53f50b9Schristos{
11*a53f50b9Schristos   int argc = 3;
12*a53f50b9Schristos   char *argv[] = { "actest", "arg", "-x", NULL };
13*a53f50b9Schristos   int c;
14*a53f50b9Schristos   FILE* rf;
15*a53f50b9Schristos   int isGNU = 0;
16*a53f50b9Schristos
17*a53f50b9Schristos   rf = fopen("conftestresult", "w");
18*a53f50b9Schristos   if (rf == NULL) exit(1);
19*a53f50b9Schristos
20*a53f50b9Schristos   while ( (c = getopt(argc, argv, "x")) != -1 ) {
21*a53f50b9Schristos       switch ( c ) {
22*a53f50b9Schristos          case 'x':
23*a53f50b9Schristos	     isGNU=1;
24*a53f50b9Schristos             break;
25*a53f50b9Schristos          default:
26*a53f50b9Schristos             exit(1);
27*a53f50b9Schristos       }
28*a53f50b9Schristos   }
29*a53f50b9Schristos   fprintf(rf, isGNU ? "yes" : "no");
30*a53f50b9Schristos   exit(0);
31*a53f50b9Schristos}
32*a53f50b9Schristos],[
33*a53f50b9Schristosac_cv_sys_gnu_getopt="`cat conftestresult`"
34*a53f50b9Schristos],[
35*a53f50b9Schristosac_cv_sys_gnu_getopt="fail"
36*a53f50b9Schristos])
37*a53f50b9Schristos])
38*a53f50b9Schristosif test "$ac_cv_sys_gnu_getopt" = "yes"
39*a53f50b9Schristosthen
40*a53f50b9Schristos    AC_DEFINE(HAVE_GNU_GETOPT)
41*a53f50b9Schristosfi
42*a53f50b9Schristos])
43