📄 m4sh.m4
字号:
# This file is part of Autoconf. -*- Autoconf -*-# M4 sugar for common shell constructs.# Requires GNU M4 and M4sugar.## Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software# Foundation, Inc.## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2, or (at your option)# any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA# 02110-1301, USA.## As a special exception, the Free Software Foundation gives unlimited# permission to copy, distribute and modify the configure scripts that# are the output of Autoconf. You need not follow the terms of the GNU# General Public License when using or distributing such scripts, even# though portions of the text of Autoconf appear in them. The GNU# General Public License (GPL) does govern all other use of the material# that constitutes the Autoconf program.## Certain portions of the Autoconf source text are designed to be copied# (in certain cases, depending on the input) into the output of# Autoconf. We call these the "data" portions. The rest of the Autoconf# source text consists of comments plus executable code that decides which# of the data portions to output in any given case. We call these# comments and executable code the "non-data" portions. Autoconf never# copies any of the non-data portions into its output.## This special exception to the GPL applies to versions of Autoconf# released by the Free Software Foundation. When you make and# distribute a modified version of Autoconf, you may extend this special# exception to the GPL to apply to your modified version as well, *unless*# your modified version has the potential to copy into its output some# of the text that was the non-data portion of the version that you started# with. (In other words, unless your change moves or copies text from# the non-data portions to the data portions.) If your modification has# such potential, you must delete any notice of this special exception# to the GPL from your modified version.## Written by Akim Demaille, Pavel Roskin, Alexandre Oliva, Lars J. Aas# and many other people.# We heavily use m4's diversions both for the initializations and for# required macros, because in both cases we have to issue soon in# output something which is discovered late.### KILL is only used to suppress output.## - BINSH# AC_REQUIRE'd #! /bin/sh line# - HEADER-REVISION# RCS keywords etc.# - HEADER-COMMENT# Purpose of the script etc.# - HEADER-COPYRIGHT# Copyright notice(s)# - M4SH-SANITIZE# M4sh's shell setup# - M4SH-INIT# M4sh initialization# - BODY# The body of the script.# _m4_divert(DIVERSION-NAME)# --------------------------# Convert a diversion name into its number. Otherwise, return# DIVERSION-NAME which is supposed to be an actual diversion number.# Of course it would be nicer to use m4_case here, instead of zillions# of little macros, but it then takes twice longer to run `autoconf'!m4_define([_m4_divert(BINSH)], 0)m4_define([_m4_divert(HEADER-REVISION)], 1)m4_define([_m4_divert(HEADER-COMMENT)], 2)m4_define([_m4_divert(HEADER-COPYRIGHT)], 3)m4_define([_m4_divert(M4SH-SANITIZE)], 4)m4_define([_m4_divert(M4SH-INIT)], 5)m4_define([_m4_divert(BODY)], 1000)# Aaarg. Yet it starts with compatibility issues... Libtool wants to# use NOTICE to insert its own LIBTOOL-INIT stuff. People should ask# before diving into our internals :(m4_copy([_m4_divert(M4SH-INIT)], [_m4_divert(NOTICE)])## ------------------------- #### 1. Sanitizing the shell. #### ------------------------- ### AS_REQUIRE(NAME-TO-CHECK, [BODY-TO-EXPAND = NAME-TO-CHECK])# -----------------------------------------------------------# BODY-TO-EXPAND is some initialization which must be expanded in the# M4SH-INIT section when expanded (required or not). This is very# different from m4_require. For instance:## m4_defun([_FOO_PREPARE], [foo=foo])# m4_defun([FOO],# [m4_require([_FOO_PREPARE])dnl# echo $foo])## m4_defun([_BAR_PREPARE], [bar=bar])# m4_defun([BAR],# [AS_REQUIRE([_BAR_PREPARE])dnl# echo $bar])## AS_INIT# foo1=`FOO`# foo2=`FOO`# bar1=`BAR`# bar2=`BAR`## gives## #! /bin/sh# bar=bar## foo1=`foo=foo# echo $foo`# foo2=`echo $foo`# bar1=`echo $bar`# bar2=`echo $bar`## Due to the simple implementation, all the AS_REQUIRE calls have to be at# the very beginning of the macro body, or the AS_REQUIREs may not be nested.# More exactly, if a macro doesn't have all AS_REQUIREs at its beginning,# it may not be AS_REQUIREd.#m4_define([AS_REQUIRE],[m4_provide_if([$1], [], [m4_divert_text([M4SH-INIT], [m4_default([$2], [$1])])])])# AS_REQUIRE_SHELL_FN(NAME-TO-CHECK, BODY-TO-EXPAND)# --------------------------------------------------# BODY-TO-EXPAND is the body of a shell function to be emitted in the# M4SH-INIT section when expanded (required or not). Unlike other# xx_REQUIRE macros, BODY-TO-EXPAND is mandatory.#m4_define([AS_REQUIRE_SHELL_FN],[_AS_DETECT_REQUIRED([_AS_SHELL_FN_WORK])dnlm4_provide_if([AS_SHELL_FN_$1], [], [m4_provide([AS_SHELL_FN_$1])m4_divert_text([M4SH-INIT], [$1() {$2}])])])# AS_BOURNE_COMPATIBLE# --------------------# Try to be as Bourne and/or POSIX as possible.## FIXME: The assignment to BIN_SH is dubious; see# <http://lists.gnu.org/archive/html/autoconf-patches/2006-03/msg00081.html>.# It might be better to remove it, but first please see# <http://lists.gnu.org/archive/html/bug-autoconf/2006-06/msg00025.html>.m4_define([AS_BOURNE_COMPATIBLE],[# Be Bourne compatibleif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then emulate sh NULLCMD=: [#] Zsh 3.x and 4.x performs word splitting on ${1+"$[@]"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$[@]"}'='"$[@]"' setopt NO_GLOB_SUBSTelse case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esacfiBIN_SH=xpg4; export BIN_SH # for Tru64DUALCASE=1; export DUALCASE # for MKS sh])# _AS_RUN(TEST, [SHELL])# ----------------------# Run TEST under the current shell (if one parameter is used)# or under the given SHELL, protecting it from syntax errors.m4_define([_AS_RUN],[m4_ifval([$2],[{ $2 <<\_ASEOFAS_BOURNE_COMPATIBLE$1_ASEOF}],[(eval "AS_ESCAPE(m4_quote($1))")])])# _AS_DETECT_REQUIRED(TEST)# -------------------------# Refuse to execute under a shell that does not pass the given TEST.m4_define([_AS_DETECT_REQUIRED_BODY], [:])m4_defun([_AS_DETECT_REQUIRED],[m4_require([_AS_DETECT_BETTER_SHELL])dnlm4_expand_once([m4_append([_AS_DETECT_REQUIRED_BODY], [($1) || AS_EXIT(1)])], [_AS_DETECT_REQUIRED_provide($1)])])# _AS_DETECT_SUGGESTED(TEST)# --------------------------# Prefer to execute under a shell that passes the given TEST.m4_define([_AS_DETECT_SUGGESTED_BODY], [:])m4_defun([_AS_DETECT_SUGGESTED],[m4_require([_AS_DETECT_BETTER_SHELL])dnlm4_expand_once([m4_append([_AS_DETECT_SUGGESTED_BODY], [($1) || AS_EXIT(1)])], [_AS_DETECT_SUGGESTED_provide($1)])])# _AS_DETECT_BETTER_SHELL# -----------------------# The real workhorse for detecting a shell with the correct# features.## FIXME: The '/usr/bin/posix' below works around a shell bug in OSF# <http://lists.gnu.org/archive/html/autoconf-patches/2006-03/msg00081.html># but this causes a regression on OpenServer 6.0.0# <http://lists.gnu.org/archive/html/bug-autoconf/2006-06/msg00017.html># The code should test for the OSF bug directly rather than look at# /usr/bin/posix here.## FIXME: The 'test -f "$as_shell.exe"' works around a problem in OS/2# <http://lists.gnu.org/archive/html/autoconf/2006-06/msg00038.html># but we should replace the two test -f calls with a single AS_EXECUTABLE_P.#m4_defun_once([_AS_DETECT_BETTER_SHELL],[m4_wrap([m4_divert_text([M4SH-SANITIZE], [AS_REQUIRE([_AS_UNSET_PREPARE])dnlif test "x$CONFIG_SHELL" = x; then AS_IF([_AS_RUN([_AS_DETECT_REQUIRED_BODY]) 2>/dev/null], [as_have_required=yes], [as_have_required=no]) AS_IF([test $as_have_required = yes && dnl _AS_RUN([_AS_DETECT_SUGGESTED_BODY]) 2> /dev/null], [], [as_candidate_shells= _AS_PATH_WALK([/usr/bin/posix$PATH_SEPARATOR/bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH], [case $as_dir in /*) for as_base in sh bash ksh sh5; do as_candidate_shells="$as_candidate_shells $as_dir/$as_base" done;; esac]) for as_shell in $as_candidate_shells $SHELL; do # Try only shells that exist, to save several forks. AS_IF([{ test -f "$as_shell" || test -f "$as_shell.exe"; } && _AS_RUN([_AS_DETECT_REQUIRED_BODY], [("$as_shell") 2> /dev/null])], [CONFIG_SHELL=$as_shell as_have_required=yes AS_IF([_AS_RUN([_AS_DETECT_SUGGESTED_BODY], ["$as_shell" 2> /dev/null])], [break])]) done AS_IF([test "x$CONFIG_SHELL" != x], [for as_var in BASH_ENV ENV do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var done export CONFIG_SHELL exec "$CONFIG_SHELL" "$as_myself" ${1+"$[@]"}]) AS_IF([test $as_have_required = no], [echo This script requires a shell more modern than all the echo shells that I found on your system. Please install a echo modern shell, or manually run the script under such a echo shell if you do have one. AS_EXIT(1)]) ])fi])])])# _AS_DETECT_BETTER_SHELL# _AS_SHELL_FN_WORK# -----------------# This is a spy to detect "in the wild" shells that do not support shell# functions correctly. It is based on the m4sh.at Autotest testcases.m4_define([_AS_SHELL_FN_WORK],[as_func_return () { (exit [$]1)}as_func_success () { as_func_return 0}as_func_failure () { as_func_return 1}as_func_ret_success () { return 0}as_func_ret_failure () { return 1}exitcode=0AS_IF([as_func_success], [], [exitcode=1 echo as_func_success failed.])AS_IF([as_func_failure], [exitcode=1 echo as_func_failure succeeded.])AS_IF([as_func_ret_success], [], [exitcode=1 echo as_func_ret_success failed.])AS_IF([as_func_ret_failure], [exitcode=1 echo as_func_ret_failure succeeded.])AS_IF([( set x; as_func_ret_success y && test x = "[$]1" )], [], [exitcode=1 echo positional parameters were not saved.])test $exitcode = 0[]dnl])# _AS_SHELL_FN_WORK# AS_COPYRIGHT(TEXT)# ------------------# Emit TEXT, a copyright notice, as a shell comment near the top of the# script. TEXT is evaluated once; to accomplish that, we do not prepend# `# ' but `@%:@ '.m4_define([AS_COPYRIGHT],[m4_divert_text([HEADER-COPYRIGHT],[m4_bpatsubst([$1], [^], [@%:@ ])])])# AS_SHELL_SANITIZE# -----------------m4_defun([AS_SHELL_SANITIZE],[## --------------------- #### M4sh Initialization. #### --------------------- ##AS_BOURNE_COMPATIBLE# PATH needs CR_AS_CR_PREPARE_AS_PATH_SEPARATOR_PREPARE_AS_UNSET_PREPARE# IFS# We need space, tab and new line, in precisely that order. Quoting is# there to prevent editors from complaining about space-tab.# (If _AS_PATH_WALK were called with IFS unset, it would disable word# splitting by setting IFS to empty value.)as_nl=''IFS=" "" $as_nl"# Find who we are. Look in the path if we contain no directory separator.case $[0] in *[[\\/]]* ) as_myself=$[0] ;; *) _AS_PATH_WALK([], [test -r "$as_dir/$[0]" && as_myself=$as_dir/$[0] && break]) ;;esac# We did not find ourselves, most probably we were run as `sh COMMAND'# in which case we are not to be found in the path.if test "x$as_myself" = x; then as_myself=$[0]fiif test ! -f "$as_myself"; then echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 AS_EXITfi# Work around bugs in pre-3.0 UWIN ksh.for as_var in ENV MAIL MAILPATHdo ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_vardonePS1='$ 'PS2='> 'PS4='+ '# NLS nuisances.for as_var in \ LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ LC_TELEPHONE LC_TIMEdo if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then eval $as_var=C; export $as_var else ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var fidone# Required to use basename._AS_EXPR_PREPARE_AS_BASENAME_PREPARE# Name of the executable.as_me=`AS_BASENAME("$[0]")`# CDPATH.$as_unset CDPATH])# AS_SHELL_SANITIZE# _AS_PREPARE# -----------# This macro has a very special status. Normal use of M4sh relies# heavily on AS_REQUIRE, so that needed initializations (such as# _AS_TEST_PREPARE) are performed on need, not on demand. But# Autoconf is the first client of M4sh, and for two reasons: configure# and config.status. Relying on AS_REQUIRE is of course fine for# configure, but fails for config.status (which is created by# configure). So we need a means to force the inclusion of the# various _AS_PREPARE_* on top of config.status. That's basically why# there are so many _AS_PREPARE_* below, and that's also why it is# important not to forget some: config.status needs them.m4_defun([_AS_PREPARE],[_AS_LINENO_PREPARE_AS_DIRNAME_PREPARE_AS_ECHO_N_PREPARE_AS_EXPR_PREPARE_AS_LN_S_PREPARE_AS_MKDIR_P_PREPARE_AS_TEST_PREPARE_AS_TR_CPP_PREPARE_AS_TR_SH_PREPARE])# AS_PREPARE# ----------# Output all the M4sh possible initialization into the initialization# diversion.m4_defun([AS_PREPARE],[m4_divert_text([M4SH-INIT], [_AS_PREPARE])])## ----------------------------- #### 2. Wrappers around builtins. #### ----------------------------- ### This section is lexicographically sorted.# AS_CASE(WORD, [PATTERN1], [IF-MATCHED1]...[DEFAULT])# ----------------------------------------------------# Expand into# | case WORD in# | PATTERN1) IF-MATCHED1 ;;# | ...# | *) DEFAULT ;;# | esacm4_define([_AS_CASE],[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])], [$#], 1, [ *) $1 ;;], [$#], 2, [ $1) m4_default([$2], [:]) ;;], [ $1) m4_default([$2], [:]) ;;$0(m4_shiftn(2, $@))])dnl])m4_defun([AS_CASE],[m4_ifval([$2$3],[case $1 in_AS_CASE(m4_shift($@))esac])dnl])# AS_CASE# AS_EXIT([EXIT-CODE = 1])# ------------------------# Exit and set exit code to EXIT-CODE in the way that it's seen# within "trap 0".## We cannot simply use "exit N" because some shells (zsh and Solaris sh)# will not set $? to N while running the code set by "trap 0"# So we set $? by executing "exit N" in the subshell and then exit.# Other shells don't use `$?' as default for `exit', hence just repeating# the exit value can only help improving portability.m4_define([AS_EXIT],[{ (exit m4_default([$1], 1)); exit m4_default([$1], 1); }])# AS_IF(TEST1, [IF-TRUE1]...[IF-FALSE])# -------------------------------------# Expand into# | if TEST1; then# | IF-TRUE1# | elif TEST2; then# | IF-TRUE2# [...]# | else# | IF-FALSE# | fi# with simplifications if IF-TRUE1 and/or IF-FALSE is empty.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -