-
Notifications
You must be signed in to change notification settings - Fork 15
/
php_ext_embed.m4
203 lines (170 loc) · 6.47 KB
/
php_ext_embed.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
dnl
dnl $Id$
dnl
dnl This file contains helper autoconf functions for php_ext_embed
dnl
PHP_ARG_WITH(libelf, with libelf path,
[ --with-libelf search libelf at this path], /usr)
ext_embed_files_header=php_ext_embed_libs.h
AC_DEFUN([PHP_EXT_EMBED_CHECK_VALID],[
if test "$PHP_EXT_EMBED_DIR" = ""; then
PHP_EXT_EMBED_DIR=php-ext-embed
fi
])
dnl
dnl PHP_EXT_EMBED_NEW_EXTENSION(extname, sources [, shared [, sapi_class [, extra-cflags [, cxx [, zend_ext]]]]])
dnl
dnl Includes an extension in the build.
dnl
dnl It is a wrapper for PHP_NEW_EXTENSION to inculude php_ext_embed.c
dnl
dnl "extname" is the name of the ext/ subdir where the extension resides.
dnl "sources" is a list of files relative to the subdir which are used
dnl to build the extension.
dnl "shared" can be set to "shared" or "yes" to build the extension as
dnl a dynamically loadable library. Optional parameter "sapi_class" can
dnl be set to "cli" to mark extension build only with CLI or CGI sapi's.
dnl "extra-cflags" are passed to the compiler, with
dnl @ext_srcdir@ and @ext_builddir@ being substituted.
dnl "cxx" can be used to indicate that a C++ shared module is desired.
dnl "zend_ext" indicates a zend extension.
AC_DEFUN([PHP_EXT_EMBED_NEW_EXTENSION],[
PHP_EXT_EMBED_CHECK_VALID()
if test "$3" != "yes" && test "$3" != "shared"; then
AC_MSG_ERROR("static build is not supported yet")
fi
PHP_NEW_EXTENSION($1, [$2 $PHP_EXT_EMBED_DIR/*.c], $3, $4, $5, $6, $7)
case $host_alias in
*linux* | *bsd*[)]
dnl FIXME tricky way to add custom command after build for Linux
echo " objcopy $php_ext_embed_libs .libs/$1.so" >> Makefile.objects
;;
esac
])
dnl
dnl PHP_EXT_EMBED_INIT(extname)
dnl
dnl check dependencies
dnl
dnl "extname" is the name of the ext/ subdir where the extension resides.
AC_DEFUN([PHP_EXT_EMBED_INIT],[
PHP_EXT_EMBED_CHECK_VALID()
AC_MSG_CHECKING([whether php_ext_embed_dir is correct])
if test -f "$PHP_EXT_EMBED_DIR/php_ext_embed.h"; then
AC_MSG_RESULT([yes])
else
AC_MSG_ERROR([php_ext_embed.h is not exist])
fi
PHP_ADD_INCLUDE($PHP_EXT_EMBED_DIR)
which dpkg-architecture 2>&1 > /dev/null
if [[ $? == 0 ]]; then
DEB_HOST_MULTIARCH=`dpkg-architecture -qDEB_HOST_MULTIARCH`
fi
case $host_alias in
*darwin*[)]
;;
*[)]
PHP_EXT_CHECK_LIBELF($1)
;;
esac
])
AC_DEFUN([PHP_EXT_CHECK_LIBELF],[
AC_MSG_CHECKING([whether libelf is found])
EXT_EMBED_SEARCH_PATH="$PHP_LIBELF /usr/local /usr $LIBRARY_PATH $LD_LIBRARY_PATH"
AC_MSG_CHECKING(search libelf in $EXT_EMBED_SEARCH_PATH)
EXT_EMBED_SEARCH_FOR="include/libelf.h"
SEARCH_LIB="libelf"
for i in $EXT_EMBED_SEARCH_PATH; do
if test "$EXT_EMBED_LIBELF_INCLUDE_DIR" != "" && test "$EXT_EMBED_LIBELF_LIB_DIR" != ""; then
break
fi
if test -r $i/$EXT_EMBED_SEARCH_FOR; then
EXT_EMBED_LIBELF_INCLUDE_DIR=$i
AC_MSG_RESULT(libelf header found header in $i)
fi
BASELIB=$i/$PHP_LIBDIR
if test "$EXT_EMBED_LIBELF_LIB_DIR" != ""; then
continue
fi
if test -r $BASELIB/$DEB_HOST_MULTIARCH/$SEARCH_LIB.a || test -r $BASELIB/$DEB_HOST_MULTIARCH/$SEARCH_LIB.$SHLIB_SUFFIX_NAME; then
EXT_EMBED_LIBELF_LIB_DIR=$BASELIB/$DEB_HOST_MULTIARCH
AC_MSG_RESULT(libelf lib found in $EXT_EMBED_LIBELF_LIB_DIR)
continue
fi
if test -r $BASELIB/$SEARCH_LIB.a || test -r $BASELIB/$SEARCH_LIB.$SHLIB_SUFFIX_NAME; then
EXT_EMBED_LIBELF_LIB_DIR=$BASELIB
AC_MSG_RESULT(libelf lib found in $EXT_EMBED_LIBELF_LIB_DIR)
fi
done
if test "$EXT_EMBED_LIBELF_INCLUDE_DIR" == "" || test "$EXT_EMBED_LIBELF_LIB_DIR" == ""; then
AC_MSG_ERROR([libelf not found])
fi
PHP_ADD_INCLUDE($EXT_EMBED_LIBELF_INCLUDE_DIR/include)
PHP_ADD_LIBRARY_WITH_PATH(elf, $EXT_EMBED_LIBELF_LIB_DIR, translit($1,a-z_-,A-Z__)_SHARED_LIBADD)
])
dnl
dnl PHP_EXT_EMBED_ADD_INCLUDE_LIB(extname, sources)
dnl
dnl Includes php lib to extension
dnl
dnl "extname" is the name of the ext/ subdir where the extension resides.
dnl "sources" is a list of files relative to the subdir which need to be
dnl embeded to extension
AC_DEFUN([PHP_EXT_EMBED_ADD_INCLUDE_LIB],[
php_ext_upper_name=translit($1,a-z-,A-Z_)
AC_MSG_RESULT(Generate embed files header)
sources="$2"
if test "${sources#*\/*}" != "$sources" && test ! -d ${sources%/*}; then
AC_MSG_ERROR([php lib path points to a directory that does not exist])
fi
if test `ls -1 $sources | wc -l` = 0; then
AC_MSG_ERROR([php lib files empty, please add your libs])
fi
echo "" > $ext_embed_files_header
echo "/* Generated by php-ext-embed don't edit it */" >> $ext_embed_files_header
echo "" >> $ext_embed_files_header
echo "#ifndef _PHP_EXT_EMBED_${php_ext_upper_name}_" >> $ext_embed_files_header
echo "#define _PHP_EXT_EMBED_${php_ext_upper_name}_" >> $ext_embed_files_header
echo "" >> $ext_embed_files_header
echo "php_ext_lib_entry ext_$1_embed_files[[]] = {" >> $ext_embed_files_header
php_ext_embed_libs=
case $host_alias in
*darwin* | *bsd*[)]
MD5_CMD=md5
;;
*[)]
MD5_CMD=md5sum
;;
esac
for ac_src in $sources; do
if test -f "$ac_src"; then
dummy_filename="extension-embed://$1/$ac_src"
section_name=ext.`echo $dummy_filename | $MD5_CMD`
section_name=`echo $section_name | cut -c1-16`
echo " {" >> $ext_embed_files_header
echo " \"$1\"", >> $ext_embed_files_header
echo " \"$ac_src\"", >> $ext_embed_files_header
echo " \"$dummy_filename\"", >> $ext_embed_files_header
echo " \"$section_name\"", >> $ext_embed_files_header
echo " 1", >> $ext_embed_files_header
echo " }," >> $ext_embed_files_header
PHP_GLOBAL_OBJS="$PHP_GLOBAL_OBJS $ac_src"
shared_objects_$1="$shared_objects_$1 $ac_src"
case $host_alias in
*darwin*[)]
dnl Append to LDFLAGS for now There is no way to hook it link stage with needed flags :(
LDFLAGS="$LDFLAGS -Wl,-sectcreate,__text,${section_name},${ac_src}"
;;
*[)]
php_ext_embed_libs="$php_ext_embed_libs --add-section "${section_name}=${ac_src}""
;;
esac
else
AC_MSG_WARN([lib file $ac_src not found, ignored])
fi
done
echo " {NULL, NULL, NULL, NULL}" >> $ext_embed_files_header
echo "};" >> $ext_embed_files_header
echo "" >> $ext_embed_files_header
echo "#endif" >> $ext_embed_files_header
])