-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.m4
166 lines (147 loc) · 5.75 KB
/
config.m4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# vim: tabstop=4:softtabstop=4:shiftwidth=4:noexpandtab
m4_include(m4/ax_cflags_warn_all.m4)
m4_include(m4/ax_add_fortify_source.m4)
m4_include(m4/ax_require_defined.m4)
m4_include(m4/ax_append_flag.m4)
m4_include(m4/ax_append_compile_flags.m4)
m4_include(m4/ax_append_link_flags.m4)
m4_include(m4/ax_check_compile_flag.m4)
m4_include(m4/ax_check_link_flag.m4)
m4_include(m4/ax_compiler_flags_cflags.m4)
m4_include(m4/ax_compiler_flags_ldflags.m4)
m4_include(m4/ax_compiler_flags_gir.m4)
m4_include(m4/ax_compiler_flags.m4)
m4_define(AM_LDFLAGS, [LDFLAGS])
# args
PHP_ARG_ENABLE(handlebars, whether to enable handlebars support,
[ --enable-handlebars Enable handlebars support])
PHP_ARG_ENABLE(handlebars-ast, whether to enable handlebars AST support,
[ --enable-handlebars-ast Enable handlebars AST support], [no], [no])
PHP_ARG_ENABLE(handlebars-psr, whether to enable handlebars PSR support,
[ --enable-handlebars-psr Enable handlebars PSR support], [no], [no])
PHP_ARG_ENABLE(handlebars-hardening, whether to enable handlebars hardening support,
[ --enable-handlebars-hardening Enable handlebars hardening support], [yes], [no])
PHP_ARG_ENABLE(handlebars-coverage, whether to enable handlebars coverage support,
[AS_HELP_STRING([--enable-handlebars-coverage], [Enable handlebars coverage support])], [no], [no])
AC_DEFUN([PHP_HANDLEBARS_ADD_SOURCES], [
PHP_HANDLEBARS_SOURCES="$PHP_HANDLEBARS_SOURCES $1"
])
# main
if test "$PHP_HANDLEBARS" != "no"; then
# compilers
AC_PROG_CC_STDC
AC_PROG_CC_C99
AC_MSG_CHECKING([if compiling with gcc])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([], [[
#ifndef __GNUC__
not gcc
#endif
]])],
[GCC=yes], [GCC=no])
AC_MSG_RESULT([$GCC])
AC_MSG_CHECKING([if compiling with clang])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([], [[
#ifndef __clang__
not clang
#endif
]])],
[CLANG=yes], [CLANG=no])
AC_MSG_RESULT([$CLANG])
# programs
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
# warnings
AX_CFLAGS_WARN_ALL([WARN_CFLAGS])
AX_COMPILER_FLAGS([WARN_CFLAGS],[WARN_LDFLAGS],,,[ \
-Wdeprecated-declarations \
-Wmaybe-uninitialized \
-Wno-declaration-after-statement -Wno-error=declaration-after-statement \
-Wno-missing-include-dirs -Wno-error=missing-include-dirs \
-Wno-undef -Wno-error=undef \
-Wno-strict-prototypes -Wno-error=strict-prototypes \
-Wno-old-style-definition -Wno-error=old-style-definition \
-Wno-missing-prototypes -Wno-error=missing-prototypes \
-Wno-missing-declarations -Wno-error=missing-declarations \
-Wno-redundant-decls -Wno-error=redundant-decls \
-Wno-jump-misses-init -Wno-error=jump-misses-init \
-Wno-clobbered -Wno-error=clobbered \
-Wno-shadow -Wno-error=shadow \
-Wno-double-promotion -Wno-error=double-promotion \
-Wno-cast-align -Wno-error=cast-align \
-Wno-missing-braces -Wno-error=missing-braces \
])
CFLAGS="$WARN_CFLAGS $CFLAGS"
LDFLAGS="$WARN_LDFLAGS $LDFLAGS"
# hardening
if test "$PHP_HANDLEBARS_HARDENING" != "no"; then
AX_ADD_FORTIFY_SOURCE()
AX_APPEND_COMPILE_FLAGS([-fstack-protector-strong -fstack-clash-protection], [HARDENING_CFLAGS])
AX_APPEND_LINK_FLAGS([-fstack-protector-strong -fstack-clash-protection], [HARDENING_LDFLAGS])
# See: https://github.com/gdnsd/gdnsd/blob/f23273c688ae267d2b6049f0608f7b42193211fe/configure.ac#L84
AS_IF([test "x$CLANG" != "xyes"], [
AX_APPEND_COMPILE_FLAGS([-fcf-protection], [HARDENING_CFLAGS])
AX_APPEND_LINK_FLAGS([-fcf-protection], [HARDENING_LDFLAGS])
])
# fpic
AX_APPEND_COMPILE_FLAGS([-fpic], [HARDENING_CFLAGS])
AX_APPEND_LINK_FLAGS([-fpic], [HARDENING_LDFLAGS])
fi
CFLAGS="$HARDENING_CFLAGS $CFLAGS"
LDFLAGS="$HARDENING_CFLAGS $LDFLAGS"
# libhandlebars
AC_MSG_CHECKING([for libhandlebars])
if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists handlebars; then
LIBHANDLEBARS_CFLAGS=`$PKG_CONFIG handlebars --cflags`
LIBHANDLEBARS_LIBS=`$PKG_CONFIG handlebars --libs`
LIBHANDLEBARS_VERSION=`$PKG_CONFIG handlebars --modversion`
LIBHANDLEBARS_PATH=`$PKG_CONFIG handlebars --libs-only-L | tail -c+3`
AC_MSG_RESULT([version $LIBHANDLEBARS_VERSION found using pkg-config ($LIBHANDLEBARS_PATH)])
PHP_EVAL_LIBLINE($LIBHANDLEBARS_LIBS, HANDLEBARS_SHARED_LIBADD)
PHP_EVAL_INCLINE($LIBHANDLEBARS_CFLAGS)
else
AC_MSG_ERROR([libhandlebars not found])
fi
# extension
AS_IF([test "$CLANG" = "yes"], [
AH_BOTTOM([
#ifdef __clang__
#include "main/php_config.h"
#/**/undef/**/ HAVE_ASM_GOTO
#endif
])
])
PHP_HANDLEBARS_ADD_SOURCES([
src/php_handlebars.c
src/impl.c
src/exceptions.c
src/options.c
src/registry.c
src/safe_string.c
src/utils.c
src/vm.c
src/value.c
])
if test "$PHP_HANDLEBARS_AST" == "yes"; then
AC_DEFINE([PHP_HANDLEBARS_ENABLE_AST], [1], [Whether to enable AST support])
PHP_HANDLEBARS_ADD_SOURCES([
src/compiler.c
src/opcode.c
src/parser.c
src/program.c
src/token.c
src/tokenizer.c
])
fi
if test "$PHP_HANDLEBARS_COVERAGE" == "yes"; then
CFLAGS="-fprofile-arcs -ftest-coverage $CFLAGS"
LDFLAGS="--coverage $LDFLAGS"
fi
PHP_ADD_BUILD_DIR(src)
PHP_INSTALL_HEADERS([ext/handlebars], [php_handlebars.h])
PHP_NEW_EXTENSION(handlebars, $PHP_HANDLEBARS_SOURCES, $ext_shared, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
if test "$PHP_HANDLEBARS_PSR" != "no"; then
PHP_ADD_EXTENSION_DEP(handlebars, psr, true)
fi
PHP_SUBST(HANDLEBARS_SHARED_LIBADD)
fi