GNU M4 is an implementation of the traditional Unix macro processor. It is mostly SVR4 compatible although it has some extensions (for example, handling more than 9 positional parameters to macros). GNU M4 also has built-in functions for including files, running shell commands, doing arithmetic, etc.
GNU M4 is a macro processor in the sense that it copies its input to the output expanding macros as it goes. Macros are either builtin or user-defined and can take any number of arguments. Besides just doing macro expansion, m4 has builtin functions for including named files, running UNIX commands, doing integer arithmetic, manipulating text in various ways, recursion etc... m4 can be used either as a front-end to a compiler or as a macro processor in its own right.
One of the biggest users of GNU M4 is the GNU Autoconf project.
简单而通俗易懂的翻译下:GNU M4是传统UNIX宏处理器的一种实现方式,它还具有一些内置功能,包括文件,shell,运算等。
作为一个宏处理器,将输入复制到扩展的输出,它要么内置,要么用户定义,且可以接受参数。另外这个还有内置函数,包括命名文件、运行UNIX命令、执行整数运算、以各种方式操作文本、递归等。M4既可以作为编译器的前端使用,也可以作为自己的宏处理器使用。
GNU M4的最大用户之一是GNU AutoCOF项目。
到这里大致了解到,它是作为一个宏处理器,然后再想想PHP扩展里面用到它做了什么,先看看 php源码扩展目录ext中 bcmath 中的代码:
dnl
dnl $Id$
dnl
PHP_ARG_ENABLE(bcmath, whether to enable bc style precision math functions,
[ --enable-bcmath Enable bc style precision math functions])
if test "$PHP_BCMATH" != "no"; then
PHP_NEW_EXTENSION(bcmath, bcmath.c \
libbcmath/src/add.c libbcmath/src/div.c libbcmath/src/init.c libbcmath/src/neg.c libbcmath/src/outofmem.c libbcmath/src/raisemod.c libbcmath/src/rt.c libbcmath/src/sub.c \
libbcmath/src/compare.c libbcmath/src/divmod.c libbcmath/src/int2num.c libbcmath/src/num2long.c libbcmath/src/output.c libbcmath/src/recmul.c \
libbcmath/src/sqrt.c libbcmath/src/zero.c libbcmath/src/debug.c libbcmath/src/doaddsub.c libbcmath/src/nearzero.c libbcmath/src/num2str.c libbcmath/src/raise.c \
libbcmath/src/rmzero.c libbcmath/src/str2num.c,
$ext_shared,,-I@ext_srcdir@/libbcmath/src)
PHP_ADD_BUILD_DIR($ext_builddir/libbcmath/src)
AC_DEFINE(HAVE_BCMATH, 1, [Whether you have bcmath])
fi