xref: /php-src/scripts/phpize.in (revision c3c4b535)
1#!/bin/sh
2
3# Variable declaration
4prefix='@prefix@'
5datarootdir='@datarootdir@'
6exec_prefix="`eval echo @exec_prefix@`"
7phpdir="`eval echo @libdir@`/build"
8includedir="`eval echo @includedir@`/php"
9builddir="`pwd`"
10SED="@SED@"
11
12FILES_BUILD="php.m4 shtool libtool.m4 ax_check_compile_flag.m4 ax_gcc_func_attribute.m4 php_cxx_compile_stdcxx.m4 pkg.m4 \
13    config.guess config.sub ltmain.sh Makefile.global gen_stub.php"
14FILES="run-tests*.php"
15CLEAN_FILES="$FILES *.o *.lo *.la .libs/ build/ modules/ \
16	config.nice configure configure.ac \
17	config.h config.h.in conftest* libtool config.cache autom4te.cache/ \
18	config.log config.status Makefile Makefile.fragments Makefile.objects confdefs.h \
19	run-tests*.php tests/*.diff tests/*.exp tests/*.log tests/*.out tests/*.php"
20
21# function declaration
22phpize_usage()
23{
24  echo "Usage: $0 [--clean|--help|--version|-v]"
25}
26
27phpize_no_configm4()
28{
29  if test $@ -eq 1; then
30    clean=" --clean"
31  fi
32
33  echo "Cannot find config.m4. "
34  echo "Make sure that you run '$0$clean' in the top level source directory of the module"
35  echo
36}
37
38phpize_clean()
39{
40  echo "Cleaning.."
41  for i in $CLEAN_FILES; do
42    if test -f "$i"; then
43      rm -f $i
44    elif test -d "$i"; then
45      rm -rf $i
46    fi
47  done
48}
49
50phpize_check_configm4()
51{
52  if test ! -r config.m4; then
53     phpize_no_configm4 $@
54    exit 1
55  fi
56
57}
58
59phpize_get_api_numbers()
60{
61  # extracting API NOs:
62  PHP_MINOR_VERSION=`grep '#define PHP_MINOR_VERSION' $includedir/main/php_version.h|$SED 's/#define PHP_MINOR_VERSION //'`
63  PHP_MAJOR_VERSION=`grep '#define PHP_MAJOR_VERSION' $includedir/main/php_version.h|$SED 's/#define PHP_MAJOR_VERSION//'`
64  PHP_API_VERSION=`grep '#define PHP_API_VERSION' $includedir/main/php.h|$SED 's/#define PHP_API_VERSION//'`
65  ZEND_MODULE_API_NO=`grep '#define ZEND_MODULE_API_NO' $includedir/Zend/zend_modules.h|$SED 's/#define ZEND_MODULE_API_NO//'`
66  ZEND_EXTENSION_API_NO=`grep '#define ZEND_EXTENSION_API_NO' $includedir/Zend/zend_extensions.h|$SED 's/#define ZEND_EXTENSION_API_NO//'`
67}
68
69phpize_print_api_numbers()
70{
71  phpize_get_api_numbers
72  echo "Configuring for:"
73  echo "PHP Version:            ${PHP_MAJOR_VERSION}.${PHP_MINOR_VERSION}"
74  echo "PHP Api Version:        "$PHP_API_VERSION
75  echo "Zend Module Api No:     "$ZEND_MODULE_API_NO
76  echo "Zend Extension Api No:  "$ZEND_EXTENSION_API_NO
77}
78
79phpize_check_build_files()
80{
81  if test ! -d "$phpdir"; then
82    cat <<EOF
83Cannot find build files at '$phpdir'. Please check your PHP installation.
84
85EOF
86    exit 1
87  fi
88
89  case "$phpdir" in
90  *\ * | *\	*)
91    cat <<EOF
92Invalid source path '$phpdir'. Whitespace is not allowed in source path.
93
94EOF
95    exit 1;;
96  esac
97
98  case "$builddir" in
99  *\ * | *\	*)
100    cat <<EOF
101Invalid build path '$builddir'. Whitespace is not allowed in build path.
102
103EOF
104      exit 1;;
105  esac
106}
107
108phpize_check_shtool()
109{
110  test -x "$builddir/build/shtool" || chmod +x "$builddir/build/shtool"
111
112  if test ! -x "$builddir/build/shtool"; then
113    cat <<EOF
114shtool at '$builddir/build/shtool' does not exist or is not executable.
115Make sure that the file exists and is executable and then rerun this script.
116
117EOF
118    exit 1
119  else
120    php_shtool=$builddir/build/shtool
121  fi
122}
123
124phpize_check_autotools()
125{
126  test -z "$PHP_AUTOCONF" && PHP_AUTOCONF=autoconf
127  test -z "$PHP_AUTOHEADER" && PHP_AUTOHEADER=autoheader
128
129  if test ! -x "$PHP_AUTOCONF" && test ! -x "`$php_shtool path $PHP_AUTOCONF`"; then
130    cat <<EOF
131Cannot find autoconf. Please check your autoconf installation and the
132\$PHP_AUTOCONF environment variable. Then, rerun this script.
133
134EOF
135    exit 1
136  fi
137  if test ! -x "$PHP_AUTOHEADER" && test ! -x "`$php_shtool path $PHP_AUTOHEADER`"; then
138    cat <<EOF
139Cannot find autoheader. Please check your autoconf installation and the
140\$PHP_AUTOHEADER environment variable. Then, rerun this script.
141
142EOF
143    exit 1
144  fi
145}
146
147phpize_copy_files()
148{
149  test -d build || mkdir build
150
151  (cd "$phpdir" && cp $FILES_BUILD "$builddir"/build)
152  (cd "$phpdir" && cp $FILES "$builddir")
153}
154
155phpize_replace_prefix()
156{
157  $SED \
158  -e "s#@prefix@#$prefix#" \
159  < "$phpdir/phpize.m4" > configure.ac
160}
161
162phpize_autotools()
163{
164  # Remove aclocal.m4 if present. It is automatically included by autoconf but
165  # not used by the PHP build system since PHP 7.4.
166  rm -f aclocal.m4
167
168  $PHP_AUTOCONF   || exit 1
169  $PHP_AUTOHEADER || exit 1
170}
171
172# Main script
173
174case "$1" in
175  # Cleanup
176  --clean)
177    phpize_check_configm4 1
178    phpize_clean
179    exit 0
180    ;;
181
182  # Usage
183  --help)
184    phpize_usage
185    exit 0
186    ;;
187
188  # Version
189  --version|-v)
190    phpize_print_api_numbers
191    exit 0
192  ;;
193
194  # Default
195  *)
196     phpize_check_configm4 0
197
198     phpize_check_build_files
199
200     phpize_print_api_numbers
201
202     phpize_copy_files
203
204     phpize_replace_prefix
205
206     phpize_check_shtool
207
208     phpize_check_autotools
209
210     phpize_autotools
211     ;;
212esac
213
214exit 0
215