xref: /PHP-7.1/scripts/phpize.in (revision 447b41f6)
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="mkdep.awk scan_makefile_in.awk shtool libtool.m4 ax_check_compile_flag.m4"
13FILES="acinclude.m4 Makefile.global config.sub config.guess ltmain.sh run-tests*.php"
14CLEAN_FILES="$FILES *.o *.lo *.la .libs/ build/ modules/ install-sh \
15	mkinstalldirs missing config.nice config.sub config.guess configure configure.in \
16	aclocal.m4 config.h config.h.in conftest* ltmain.sh 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  (cd "$builddir" && cat acinclude.m4 ./build/libtool.m4 > aclocal.m4)
150}
151
152phpize_replace_prefix()
153{
154  $SED \
155  -e "s#@prefix@#$prefix#" \
156  < "$phpdir/phpize.m4" > configure.in
157}
158
159phpize_autotools()
160{
161  $PHP_AUTOCONF   || exit 1
162  $PHP_AUTOHEADER || exit 1
163}
164
165# Main script
166
167case "$1" in
168  # Cleanup
169  --clean)
170    phpize_check_configm4 1
171    phpize_clean
172    exit 0
173    ;;
174
175  # Usage
176  --help)
177    phpize_usage
178    exit 0
179    ;;
180
181  # Version
182  --version|-v)
183    phpize_print_api_numbers
184    exit 0
185  ;;
186
187  # Default
188  *)
189     phpize_check_configm4 0
190
191     phpize_check_build_files
192
193     phpize_print_api_numbers
194
195     phpize_copy_files
196
197     phpize_replace_prefix
198
199     touch install-sh mkinstalldirs missing
200
201     phpize_check_shtool
202
203     phpize_check_autotools
204
205     phpize_autotools
206     ;;
207esac
208
209exit 0
210