xref: /PHP-8.0/scripts/phpize.in (revision e11d3b16)
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_API_VERSION=`grep '#define PHP_API_VERSION' $includedir/main/php.h|$SED 's/#define PHP_API_VERSION//'`
63  ZEND_MODULE_API_NO=`grep '#define ZEND_MODULE_API_NO' $includedir/Zend/zend_modules.h|$SED 's/#define ZEND_MODULE_API_NO//'`
64  ZEND_EXTENSION_API_NO=`grep '#define ZEND_EXTENSION_API_NO' $includedir/Zend/zend_extensions.h|$SED 's/#define ZEND_EXTENSION_API_NO//'`
65}
66
67phpize_print_api_numbers()
68{
69  phpize_get_api_numbers
70  echo "Configuring for:"
71  echo "PHP Api Version:        "$PHP_API_VERSION
72  echo "Zend Module Api No:     "$ZEND_MODULE_API_NO
73  echo "Zend Extension Api No:  "$ZEND_EXTENSION_API_NO
74}
75
76phpize_check_build_files()
77{
78  if test ! -d "$phpdir"; then
79    cat <<EOF
80Cannot find build files at '$phpdir'. Please check your PHP installation.
81
82EOF
83    exit 1
84  fi
85
86  case "$phpdir" in
87  *\ * | *\	*)
88    cat <<EOF
89Invalid source path '$phpdir'. Whitespace is not allowed in source path.
90
91EOF
92    exit 1;;
93  esac
94
95  case "$builddir" in
96  *\ * | *\	*)
97    cat <<EOF
98Invalid build path '$builddir'. Whitespace is not allowed in build path.
99
100EOF
101      exit 1;;
102  esac
103}
104
105phpize_check_shtool()
106{
107  test -x "$builddir/build/shtool" || chmod +x "$builddir/build/shtool"
108
109  if test ! -x "$builddir/build/shtool"; then
110    cat <<EOF
111shtool at '$builddir/build/shtool' does not exist or is not executable.
112Make sure that the file exists and is executable and then rerun this script.
113
114EOF
115    exit 1
116  else
117    php_shtool=$builddir/build/shtool
118  fi
119}
120
121phpize_check_autotools()
122{
123  test -z "$PHP_AUTOCONF" && PHP_AUTOCONF=autoconf
124  test -z "$PHP_AUTOHEADER" && PHP_AUTOHEADER=autoheader
125
126  if test ! -x "$PHP_AUTOCONF" && test ! -x "`$php_shtool path $PHP_AUTOCONF`"; then
127    cat <<EOF
128Cannot find autoconf. Please check your autoconf installation and the
129\$PHP_AUTOCONF environment variable. Then, rerun this script.
130
131EOF
132    exit 1
133  fi
134  if test ! -x "$PHP_AUTOHEADER" && test ! -x "`$php_shtool path $PHP_AUTOHEADER`"; then
135    cat <<EOF
136Cannot find autoheader. Please check your autoconf installation and the
137\$PHP_AUTOHEADER environment variable. Then, rerun this script.
138
139EOF
140    exit 1
141  fi
142}
143
144phpize_copy_files()
145{
146  test -d build || mkdir build
147
148  (cd "$phpdir" && cp $FILES_BUILD "$builddir"/build)
149  (cd "$phpdir" && cp $FILES "$builddir")
150}
151
152phpize_replace_prefix()
153{
154  $SED \
155  -e "s#@prefix@#$prefix#" \
156  < "$phpdir/phpize.m4" > configure.ac
157}
158
159phpize_autotools()
160{
161  # Remove aclocal.m4 if present. It is automatically included by autoconf but
162  # not used by the PHP build system since PHP 7.4.
163  rm -f aclocal.m4
164
165  $PHP_AUTOCONF   || exit 1
166  $PHP_AUTOHEADER || exit 1
167}
168
169# Main script
170
171case "$1" in
172  # Cleanup
173  --clean)
174    phpize_check_configm4 1
175    phpize_clean
176    exit 0
177    ;;
178
179  # Usage
180  --help)
181    phpize_usage
182    exit 0
183    ;;
184
185  # Version
186  --version|-v)
187    phpize_print_api_numbers
188    exit 0
189  ;;
190
191  # Default
192  *)
193     phpize_check_configm4 0
194
195     phpize_check_build_files
196
197     phpize_print_api_numbers
198
199     phpize_copy_files
200
201     phpize_replace_prefix
202
203     phpize_check_shtool
204
205     phpize_check_autotools
206
207     phpize_autotools
208     ;;
209esac
210
211exit 0
212