1# SPDX-License-Identifier: FSFAP
2#
3# AX_POSIX_SHELL
4# -------------
5# Check for a POSIX-compatible shell.
6#
7# LICENSE
8#
9#   Copyright (c) 2021 Internet Systems Consortium
10#
11#   Copying and distribution of this file, with or without modification, are
12#   permitted in any medium without royalty provided the copyright notice
13#   and this notice are preserved. This file is offered as-is, without any
14#   warranty.
15
16AC_DEFUN([AX_POSIX_SHELL],
17	 [AC_CACHE_CHECK([for a POSIX-compatible shell], [ac_cv_prog_shell],
18			 [ac_test_shell_script='
19			  test "$(expr 1 + 1)" = "2" &&
20			  test "$(( 1 + 1 ))" = "2"
21			  '
22
23			  for ac_cv_prog_shell in \
24			    "$CONFIG_SHELL" "$SHELL" /bin/sh /bin/bash /bin/ksh /bin/sh5 no; do
25			    AS_CASE([$ac_cv_prog_shell],
26				    [/*],[
27				      AS_IF(["$ac_cv_prog_shell" -c "$ac_test_shell_script" 2>/dev/null],
28					    [break])
29				    ])
30			  done
31			 ])
32	  AS_IF([test "$ac_cv_prog_shell" = "no"],
33		[SHELL=/bin/sh
34		 AC_MSG_WARN([using $SHELL, even though it does not conform to POSIX])
35		],
36		[SHELL="$ac_cv_prog_shell"
37		])
38	  AC_SUBST([SHELL])
39	 ])
40