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