Skip to content

Commit 4d46f26

Browse files
authored
Autotools: Update skeleton extension config.m4 template (#15147)
- Comments refactored to a bit more guide way - Basic help text added to the HAVE_<EXTENSION>* preprocessor macro definitions - Raw shell ifs replaced with AS_VAR_IF M4 macros - Code wrapped inside the line length of 80 characters - pkg-config functionality added on top - non-pkg-config functionality added afterwards - The loop refactored a bit with a break and check message done afterwards [skip ci]
1 parent 9083ce4 commit 4d46f26

File tree

1 file changed

+69
-52
lines changed

1 file changed

+69
-52
lines changed

ext/skeleton/config.m4.in

Lines changed: 69 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,109 @@
1-
dnl config.m4 for extension %EXTNAME%
1+
dnl Autotools config.m4 for PHP extension %EXTNAME%
22

3-
dnl Comments in this file start with the string 'dnl'.
3+
dnl Comments in this file start with the string 'dnl' (discard to next line).
44
dnl Remove where necessary.
55

6-
dnl If your extension references something external, use 'with':
7-
6+
dnl If extension references and depends on an external library package, use
7+
dnl the '--with-%EXTNAME%' configure option:
88
dnl PHP_ARG_WITH([%EXTNAME%],
99
dnl [for %EXTNAME% support],
1010
dnl [AS_HELP_STRING([--with-%EXTNAME%],
1111
dnl [Include %EXTNAME% support])])
1212

13-
dnl Otherwise use 'enable':
14-
13+
dnl Otherwise use the '--enable-%EXTNAME%' configure option:
1514
PHP_ARG_ENABLE([%EXTNAME%],
1615
[whether to enable %EXTNAME% support],
1716
[AS_HELP_STRING([--enable-%EXTNAME%],
1817
[Enable %EXTNAME% support])],
1918
[no])
2019

21-
if test "$PHP_%EXTNAMECAPS%" != "no"; then
22-
dnl Write more examples of tests here...
20+
AS_VAR_IF([PHP_%EXTNAMECAPS%], [no],, [
21+
dnl This section is executed when extension is enabled with one of the above
22+
dnl configure options. Adjust and add tests here.
2323

24-
dnl Remove this code block if the library does not support pkg-config.
24+
dnl
25+
dnl Use and adjust this code block if extension depends on external library
26+
dnl package which supports pkg-config.
27+
dnl
28+
dnl Find library package with pkg-config.
2529
dnl PKG_CHECK_MODULES([LIBFOO], [foo])
26-
dnl PHP_EVAL_INCLINE([$LIBFOO_CFLAGS])
27-
dnl PHP_EVAL_LIBLINE([$LIBFOO_LIBS], [%EXTNAMECAPS%_SHARED_LIBADD])
28-
29-
dnl If you need to check for a particular library version using PKG_CHECK_MODULES,
30+
dnl
31+
dnl Or if you need to check for a particular library version with pkg-config,
3032
dnl you can use comparison operators. For example:
3133
dnl PKG_CHECK_MODULES([LIBFOO], [foo >= 1.2.3])
3234
dnl PKG_CHECK_MODULES([LIBFOO], [foo < 3.4])
3335
dnl PKG_CHECK_MODULES([LIBFOO], [foo = 1.2.3])
34-
35-
dnl Remove this code block if the library supports pkg-config.
36-
dnl --with-%EXTNAME% -> check with-path
37-
dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
38-
dnl SEARCH_FOR="/include/%EXTNAME%.h" # you most likely want to change this
39-
dnl if test -r $PHP_%EXTNAMECAPS%/$SEARCH_FOR; then # path given as parameter
40-
dnl %EXTNAMECAPS%_DIR=$PHP_%EXTNAMECAPS%
41-
dnl else # search default path list
42-
dnl AC_MSG_CHECKING([for %EXTNAME% files in default path])
43-
dnl for i in $SEARCH_PATH ; do
44-
dnl if test -r $i/$SEARCH_FOR; then
45-
dnl %EXTNAMECAPS%_DIR=$i
46-
dnl AC_MSG_RESULT([found in $i])
47-
dnl fi
48-
dnl done
49-
dnl fi
5036
dnl
51-
dnl if test -z "$%EXTNAMECAPS%_DIR"; then
52-
dnl AC_MSG_RESULT([not found])
53-
dnl AC_MSG_ERROR([Please reinstall the %EXTNAME% distribution])
54-
dnl fi
55-
56-
dnl Remove this code block if the library supports pkg-config.
57-
dnl --with-%EXTNAME% -> add include path
58-
dnl PHP_ADD_INCLUDE([$%EXTNAMECAPS%_DIR/include])
59-
60-
dnl Remove this code block if the library supports pkg-config.
61-
dnl --with-%EXTNAME% -> check for lib and symbol presence
62-
dnl LIBNAME=%EXTNAMECAPS% # you may want to change this
63-
dnl LIBSYMBOL=%EXTNAMECAPS% # you most likely want to change this
64-
37+
dnl Add library compilation and linker flags to extension.
38+
dnl PHP_EVAL_INCLINE([$LIBFOO_CFLAGS])
39+
dnl PHP_EVAL_LIBLINE([$LIBFOO_LIBS], [%EXTNAMECAPS%_SHARED_LIBADD])
40+
dnl
41+
dnl Check for library and symbol presence.
42+
dnl LIBNAME=%EXTNAME% # you may want to change this
43+
dnl LIBSYMBOL=%EXTNAME% # you most likely want to change this
44+
dnl
6545
dnl If you need to check for a particular library function (e.g. a conditional
6646
dnl or version-dependent feature) and you are using pkg-config:
6747
dnl PHP_CHECK_LIBRARY([$LIBNAME], [$LIBSYMBOL],
68-
dnl [AC_DEFINE([HAVE_%EXTNAMECAPS%_FEATURE], [1], [ ])],
48+
dnl [AC_DEFINE([HAVE_%EXTNAMECAPS%_FEATURE], [1],
49+
dnl [Define to 1 if %EXTNAME% has the 'FEATURE'.])],
6950
dnl [AC_MSG_ERROR([FEATURE not supported by your %EXTNAME% library.])],
7051
dnl [$LIBFOO_LIBS])
52+
dnl
7153

54+
dnl
55+
dnl Or use and adjust this code block if extension depends on external library
56+
dnl package, which does not support pkg-config.
57+
dnl
58+
dnl Path to library package can be given as parameter (--with-%EXTNAME%=<DIR>)
59+
dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
60+
dnl SEARCH_FOR="/include/%EXTNAME%.h" # you most likely want to change this
61+
dnl AS_IF([test -r $PHP_%EXTNAMECAPS%/$SEARCH_FOR],
62+
dnl [%EXTNAMECAPS%_DIR=$PHP_%EXTNAMECAPS%],
63+
dnl [
64+
dnl for i in $SEARCH_PATH; do
65+
dnl AS_IF([test -r $i/$SEARCH_FOR],
66+
dnl [%EXTNAMECAPS%_DIR=$i; break;])
67+
dnl done
68+
dnl ])
69+
dnl
70+
dnl AC_MSG_CHECKING([for %EXTNAME% library package])
71+
dnl AS_VAR_IF([%EXTNAMECAPS%_DIR],, [
72+
dnl AC_MSG_RESULT([not found])
73+
dnl AC_MSG_ERROR([Please reinstall the %EXTNAME% library package])
74+
dnl ], [AC_MSG_RESULT([found in $%EXTNAMECAPS%_DIR])])
75+
dnl
76+
dnl Add include flag where library package headers are located on the system.
77+
dnl PHP_ADD_INCLUDE([$%EXTNAMECAPS%_DIR/include])
78+
dnl
79+
dnl Check for library and symbol presence.
80+
dnl LIBNAME=%EXTNAME% # you may want to change this
81+
dnl LIBSYMBOL=%EXTNAME% # you most likely want to change this
82+
dnl
7283
dnl If you need to check for a particular library function (e.g. a conditional
7384
dnl or version-dependent feature) and you are not using pkg-config:
74-
dnl PHP_CHECK_LIBRARY([$LIBNAME], [$LIBSYMBOL],
75-
dnl [PHP_ADD_LIBRARY_WITH_PATH([$LIBNAME],
76-
dnl [$%EXTNAMECAPS%_DIR/$PHP_LIBDIR],
77-
dnl [%EXTNAMECAPS%_SHARED_LIBADD])
78-
dnl AC_DEFINE([HAVE_%EXTNAMECAPS%_FEATURE], [1], [ ])
85+
dnl PHP_CHECK_LIBRARY([$LIBNAME], [$LIBSYMBOL], [
86+
dnl PHP_ADD_LIBRARY_WITH_PATH([$LIBNAME],
87+
dnl [$%EXTNAMECAPS%_DIR/$PHP_LIBDIR],
88+
dnl [%EXTNAMECAPS%_SHARED_LIBADD])
89+
dnl AC_DEFINE([HAVE_%EXTNAMECAPS%_FEATURE], [1],
90+
dnl [Define to 1 if %EXTNAME% has the 'FEATURE'.])
7991
dnl ],
8092
dnl [AC_MSG_ERROR([FEATURE not supported by your %EXTNAME% library.])],
8193
dnl [-L$%EXTNAMECAPS%_DIR/$PHP_LIBDIR -lm])
8294
dnl
95+
96+
dnl Add linked libraries flags for shared extension to the generated Makefile.
8397
dnl PHP_SUBST([%EXTNAMECAPS%_SHARED_LIBADD])
8498

85-
dnl In case of no dependencies
86-
AC_DEFINE(HAVE_%EXTNAMECAPS%, 1, [ Have %EXTNAME% support ])
99+
dnl Define a preprocessor macro to indicate that this PHP extension can
100+
dnl be dynamically loaded as a shared module or is statically built into PHP.
101+
AC_DEFINE([HAVE_%EXTNAMECAPS%], [1],
102+
[Define to 1 if PHP extension '%EXTNAME%' is available.])
87103

104+
dnl Configure extension sources and compilation flags.
88105
PHP_NEW_EXTENSION([%EXTNAME%],
89106
[%EXTNAME%.c],
90107
[$ext_shared],,
91108
[-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
92-
fi
109+
])

0 commit comments

Comments
 (0)