xref: /PHP-7.4/scripts/phpize.in (revision a6daded1)
11e1e3436SJan Lehnardt#!/bin/sh
2f2f8d38eSSascha Schumann
31e1e3436SJan Lehnardt# Variable declaration
4fbc947f4SStig Bakkenprefix='@prefix@'
5438cc7f2SRasmus Lerdorfdatarootdir='@datarootdir@'
6058205b6Sfoobarexec_prefix="`eval echo @exec_prefix@`"
7058205b6Sfoobarphpdir="`eval echo @libdir@`/build"
8058205b6Sfoobarincludedir="`eval echo @includedir@`/php"
95989ae5dSSascha Schumannbuilddir="`pwd`"
1068724e24SfoobarSED="@SED@"
1120c43285Sfoobar
124e7064d1SPeter KokotFILES_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"
134e7064d1SPeter KokotFILES="run-tests*.php"
141c32d751SPeter KokotCLEAN_FILES="$FILES *.o *.lo *.la .libs/ build/ modules/ \
151c32d751SPeter Kokot	config.nice configure configure.ac \
164e7064d1SPeter Kokot	config.h config.h.in conftest* libtool config.cache autom4te.cache/ \
17ee5fd96eSfoobar	config.log config.status Makefile Makefile.fragments Makefile.objects confdefs.h \
18da629d88Sfoobar	run-tests*.php tests/*.diff tests/*.exp tests/*.log tests/*.out tests/*.php"
195989ae5dSSascha Schumann
201e1e3436SJan Lehnardt# function declaration
211e1e3436SJan Lehnardtphpize_usage()
221e1e3436SJan Lehnardt{
231e1e3436SJan Lehnardt  echo "Usage: $0 [--clean|--help|--version|-v]"
241e1e3436SJan Lehnardt}
251e1e3436SJan Lehnardt
261e1e3436SJan Lehnardtphpize_no_configm4()
271e1e3436SJan Lehnardt{
281e1e3436SJan Lehnardt  if test $@ -eq 1; then
291e1e3436SJan Lehnardt    clean=" --clean"
301e1e3436SJan Lehnardt  fi
311e1e3436SJan Lehnardt
321e1e3436SJan Lehnardt  echo "Cannot find config.m4. "
331e1e3436SJan Lehnardt  echo "Make sure that you run '$0$clean' in the top level source directory of the module"
3437c329d7SPeter Kokot  echo
351e1e3436SJan Lehnardt}
361e1e3436SJan Lehnardt
371e1e3436SJan Lehnardtphpize_clean()
381e1e3436SJan Lehnardt{
391e1e3436SJan Lehnardt  echo "Cleaning.."
401e1e3436SJan Lehnardt  for i in $CLEAN_FILES; do
4198f245e5Sfoobar    if test -f "$i"; then
4298f245e5Sfoobar      rm -f $i
4398f245e5Sfoobar    elif test -d "$i"; then
4498f245e5Sfoobar      rm -rf $i
4598f245e5Sfoobar    fi
461e1e3436SJan Lehnardt  done
471e1e3436SJan Lehnardt}
481e1e3436SJan Lehnardt
491e1e3436SJan Lehnardtphpize_check_configm4()
501e1e3436SJan Lehnardt{
511e1e3436SJan Lehnardt  if test ! -r config.m4; then
521e1e3436SJan Lehnardt     phpize_no_configm4 $@
531e1e3436SJan Lehnardt    exit 1
541e1e3436SJan Lehnardt  fi
551e1e3436SJan Lehnardt
561e1e3436SJan Lehnardt}
571e1e3436SJan Lehnardt
581e1e3436SJan Lehnardtphpize_get_api_numbers()
591e1e3436SJan Lehnardt{
601e1e3436SJan Lehnardt  # extracting API NOs:
6168724e24Sfoobar  PHP_API_VERSION=`grep '#define PHP_API_VERSION' $includedir/main/php.h|$SED 's/#define PHP_API_VERSION//'`
6268724e24Sfoobar  ZEND_MODULE_API_NO=`grep '#define ZEND_MODULE_API_NO' $includedir/Zend/zend_modules.h|$SED 's/#define ZEND_MODULE_API_NO//'`
6368724e24Sfoobar  ZEND_EXTENSION_API_NO=`grep '#define ZEND_EXTENSION_API_NO' $includedir/Zend/zend_extensions.h|$SED 's/#define ZEND_EXTENSION_API_NO//'`
641e1e3436SJan Lehnardt}
651e1e3436SJan Lehnardt
661e1e3436SJan Lehnardtphpize_print_api_numbers()
671e1e3436SJan Lehnardt{
681e1e3436SJan Lehnardt  phpize_get_api_numbers
691e1e3436SJan Lehnardt  echo "Configuring for:"
701e1e3436SJan Lehnardt  echo "PHP Api Version:        "$PHP_API_VERSION
711e1e3436SJan Lehnardt  echo "Zend Module Api No:     "$ZEND_MODULE_API_NO
721e1e3436SJan Lehnardt  echo "Zend Extension Api No:  "$ZEND_EXTENSION_API_NO
731e1e3436SJan Lehnardt}
741e1e3436SJan Lehnardt
75058205b6Sfoobarphpize_check_build_files()
761e1e3436SJan Lehnardt{
77058205b6Sfoobar  if test ! -d "$phpdir"; then
78058205b6Sfoobar    cat <<EOF
79058205b6SfoobarCannot find build files at '$phpdir'. Please check your PHP installation.
801e1e3436SJan Lehnardt
811e1e3436SJan LehnardtEOF
82058205b6Sfoobar    exit 1
83058205b6Sfoobar  fi
84eae5e432SJani Taskinen
85eae5e432SJani Taskinen  case "$phpdir" in
86eae5e432SJani Taskinen  *\ * | *\	*)
87eae5e432SJani Taskinen    cat <<EOF
88eae5e432SJani TaskinenInvalid source path '$phpdir'. Whitespace is not allowed in source path.
89eae5e432SJani Taskinen
90eae5e432SJani TaskinenEOF
91eae5e432SJani Taskinen    exit 1;;
92eae5e432SJani Taskinen  esac
93eae5e432SJani Taskinen
94eae5e432SJani Taskinen  case "$builddir" in
95eae5e432SJani Taskinen  *\ * | *\	*)
96eae5e432SJani Taskinen    cat <<EOF
97eae5e432SJani TaskinenInvalid build path '$builddir'. Whitespace is not allowed in build path.
98eae5e432SJani Taskinen
99eae5e432SJani TaskinenEOF
100eae5e432SJani Taskinen      exit 1;;
101eae5e432SJani Taskinen  esac
1021e1e3436SJan Lehnardt}
1031e1e3436SJan Lehnardt
1041e1e3436SJan Lehnardtphpize_check_shtool()
1051e1e3436SJan Lehnardt{
106f4f844afSJan Lehnardt  test -x "$builddir/build/shtool" || chmod +x "$builddir/build/shtool"
1071e1e3436SJan Lehnardt
108f4f844afSJan Lehnardt  if test ! -x "$builddir/build/shtool"; then
109058205b6Sfoobar    cat <<EOF
11037c329d7SPeter Kokotshtool at '$builddir/build/shtool' does not exist or is not executable.
11137c329d7SPeter KokotMake sure that the file exists and is executable and then rerun this script.
112058205b6Sfoobar
113058205b6SfoobarEOF
1141e1e3436SJan Lehnardt    exit 1
115e2e53b65Sfoobar  else
116e2e53b65Sfoobar    php_shtool=$builddir/build/shtool
1171e1e3436SJan Lehnardt  fi
1181e1e3436SJan Lehnardt}
1191e1e3436SJan Lehnardt
120e2e53b65Sfoobarphpize_check_autotools()
121e2e53b65Sfoobar{
122e2e53b65Sfoobar  test -z "$PHP_AUTOCONF" && PHP_AUTOCONF=autoconf
123e2e53b65Sfoobar  test -z "$PHP_AUTOHEADER" && PHP_AUTOHEADER=autoheader
12437c329d7SPeter Kokot
125df5d6fc0SJani Taskinen  if test ! -x "$PHP_AUTOCONF" && test ! -x "`$php_shtool path $PHP_AUTOCONF`"; then
126f3ee713aSfoobar    cat <<EOF
127758ff2f9SJon PariseCannot find autoconf. Please check your autoconf installation and the
1283078bbabSJon Parise\$PHP_AUTOCONF environment variable. Then, rerun this script.
129e2e53b65Sfoobar
130e2e53b65SfoobarEOF
131e2e53b65Sfoobar    exit 1
132e2e53b65Sfoobar  fi
133df5d6fc0SJani Taskinen  if test ! -x "$PHP_AUTOHEADER" && test ! -x "`$php_shtool path $PHP_AUTOHEADER`"; then
134f3ee713aSfoobar    cat <<EOF
135758ff2f9SJon PariseCannot find autoheader. Please check your autoconf installation and the
1363078bbabSJon Parise\$PHP_AUTOHEADER environment variable. Then, rerun this script.
137e2e53b65Sfoobar
138e2e53b65SfoobarEOF
139e2e53b65Sfoobar    exit 1
140e2e53b65Sfoobar  fi
141e2e53b65Sfoobar}
1421e1e3436SJan Lehnardt
1431e1e3436SJan Lehnardtphpize_copy_files()
1441e1e3436SJan Lehnardt{
1451e1e3436SJan Lehnardt  test -d build || mkdir build
14637c329d7SPeter Kokot
147536e7448SJan Lehnardt  (cd "$phpdir" && cp $FILES_BUILD "$builddir"/build)
148f4f844afSJan Lehnardt  (cd "$phpdir" && cp $FILES "$builddir")
1491e1e3436SJan Lehnardt}
1501e1e3436SJan Lehnardt
1511e1e3436SJan Lehnardtphpize_replace_prefix()
1521e1e3436SJan Lehnardt{
15368724e24Sfoobar  $SED \
1541e1e3436SJan Lehnardt  -e "s#@prefix@#$prefix#" \
1552fe9208eSBrian Evans  < "$phpdir/phpize.m4" > configure.ac
1561e1e3436SJan Lehnardt}
1571e1e3436SJan Lehnardt
1581e1e3436SJan Lehnardtphpize_autotools()
1591e1e3436SJan Lehnardt{
160*f9db3576SPeter Kokot  # Remove aclocal.m4 if present. It is automatically included by autoconf but
161*f9db3576SPeter Kokot  # not used by the PHP build system since PHP 7.4.
162*f9db3576SPeter Kokot  rm -f aclocal.m4
163*f9db3576SPeter Kokot
164e2e53b65Sfoobar  $PHP_AUTOCONF   || exit 1
165e2e53b65Sfoobar  $PHP_AUTOHEADER || exit 1
1661e1e3436SJan Lehnardt}
1671e1e3436SJan Lehnardt
1681e1e3436SJan Lehnardt# Main script
1691e1e3436SJan Lehnardt
17037c329d7SPeter Kokotcase "$1" in
171f6cafd60Sfoobar  # Cleanup
172063e4e25Sfoobar  --clean)
1731e1e3436SJan Lehnardt    phpize_check_configm4 1
1741e1e3436SJan Lehnardt    phpize_clean
1751e1e3436SJan Lehnardt    exit 0
176063e4e25Sfoobar    ;;
1771e1e3436SJan Lehnardt
178f6cafd60Sfoobar  # Usage
179063e4e25Sfoobar  --help)
1801e1e3436SJan Lehnardt    phpize_usage
1811e1e3436SJan Lehnardt    exit 0
182063e4e25Sfoobar    ;;
1831e1e3436SJan Lehnardt
1841e1e3436SJan Lehnardt  # Version
1851e1e3436SJan Lehnardt  --version|-v)
1861e1e3436SJan Lehnardt    phpize_print_api_numbers
1871e1e3436SJan Lehnardt    exit 0
1881e1e3436SJan Lehnardt  ;;
1891e1e3436SJan Lehnardt
1901e1e3436SJan Lehnardt  # Default
191f6cafd60Sfoobar  *)
1921e1e3436SJan Lehnardt     phpize_check_configm4 0
19320c43285Sfoobar
194058205b6Sfoobar     phpize_check_build_files
195058205b6Sfoobar
19622843351SDerick Rethans     phpize_print_api_numbers
19722843351SDerick Rethans
1981e1e3436SJan Lehnardt     phpize_copy_files
199f2f8d38eSSascha Schumann
2001e1e3436SJan Lehnardt     phpize_replace_prefix
201f2f8d38eSSascha Schumann
2021e1e3436SJan Lehnardt     phpize_check_shtool
2031e1e3436SJan Lehnardt
204e2e53b65Sfoobar     phpize_check_autotools
205e2e53b65Sfoobar
206e2e53b65Sfoobar     phpize_autotools
2071e1e3436SJan Lehnardt     ;;
2081e1e3436SJan Lehnardtesac
2091e1e3436SJan Lehnardt
21022843351SDerick Rethansexit 0
211