xref: /PHP-7.4/buildconf (revision ef165b44)
1cc5e008bSZeev Suraski#!/bin/sh
278ab79b9SPeter Kokot#
378ab79b9SPeter Kokot# A wrapper around Autoconf that generates files to build PHP on *nix systems.
4cc5e008bSZeev Suraski
502c1f329SPeter KokotPHP_AUTOCONF=${PHP_AUTOCONF:-autoconf}
602c1f329SPeter KokotPHP_AUTOHEADER=${PHP_AUTOHEADER:-autoheader}
778ab79b9SPeter Kokotforce=0
878ab79b9SPeter Kokotdebug=0
978ab79b9SPeter Kokot
1078ab79b9SPeter Kokot# Go to project root.
1178ab79b9SPeter Kokotcd $(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
1278ab79b9SPeter Kokot
13afd52f9dSPeter Kokotphp_extra_version=$(grep '^AC_INIT(' configure.ac)
14afd52f9dSPeter Kokotcase "$php_extra_version" in
15afd52f9dSPeter Kokot  *-dev*)
167575a5e1Sfoobar    dev=1
177575a5e1Sfoobar    ;;
187575a5e1Sfoobar  *)
197575a5e1Sfoobar    dev=0
207575a5e1Sfoobar    ;;
210eb79196SWez Furlongesac
220eb79196SWez Furlong
23e4c61428Sfoobarwhile test $# -gt 0; do
2478ab79b9SPeter Kokot  if test "$1" = "-h" || test "$1" = "--help"; then
2578ab79b9SPeter Kokot    cat << HELP
2678ab79b9SPeter KokotPHP buildconf
2778ab79b9SPeter Kokot
2878ab79b9SPeter KokotA wrapper around the autoconf and autoheader that generate files for building
294e7064d1SPeter KokotPHP on *nix systems (configure and main/php_config.h.in). The configure script
304e7064d1SPeter Kokotis used to customize the PHP build based on the provided options and system. PHP
314e7064d1SPeter Kokotreleases downloaded from PHP.net already include the configure script so
324e7064d1SPeter Kokotinstalling Autoconf and running buildconf is not needed. For the PHP sources
334e7064d1SPeter Kokotfrom the Git repository, buildconf is used for generating a new configure script
344e7064d1SPeter Kokotand required files.
3578ab79b9SPeter Kokot
3678ab79b9SPeter KokotSYNOPSIS:
3778ab79b9SPeter Kokot  buildconf [<options>]
3878ab79b9SPeter Kokot
3978ab79b9SPeter KokotOPTIONS:
40*ef165b44SPeter Kokot  -f, --force     Regenerate configure files in PHP release packages.
4178ab79b9SPeter Kokot  --debug         Display warnings emitted by Autoconf.
4278ab79b9SPeter Kokot  -h, --help      Display this help.
4378ab79b9SPeter Kokot
4478ab79b9SPeter KokotENVIRONMENT:
4578ab79b9SPeter Kokot  The following optional variables are supported:
4678ab79b9SPeter Kokot
4778ab79b9SPeter Kokot  PHP_AUTOCONF    Overrides the path to autoconf tool.
4878ab79b9SPeter Kokot                  PHP_AUTOCONF=/path/to/autoconf ./buildconf
4978ab79b9SPeter Kokot  PHP_AUTOHEADER  Overrides the path to autoheader tool.
5078ab79b9SPeter Kokot                  PHP_AUTOHEADER=/path/to/autoheader ./buildconf
5178ab79b9SPeter KokotHELP
5278ab79b9SPeter Kokot    exit 0
5378ab79b9SPeter Kokot  fi
5478ab79b9SPeter Kokot
5576df951eSPeter Kokot  if test "$1" = "-f" || test "$1" = "--force"; then
5678ab79b9SPeter Kokot    force=1
57e4c61428Sfoobar  fi
588a7784d4SSascha Schumann
5952e00b8fSfoobar  if test "$1" = "--debug"; then
6078ab79b9SPeter Kokot    debug=1
6152e00b8fSfoobar  fi
6252e00b8fSfoobar
63e4c61428Sfoobar  shift
645278f12eSSascha Schumanndone
65bca90b07SJames Cox
66*ef165b44SPeter Kokotif test "$dev" = "0" && test "$force" = "0"; then
67*ef165b44SPeter Kokot  if test -f "configure" && test -f "main/php_config.h.in"; then
68*ef165b44SPeter Kokot    echo "buildconf: The configure script is already built. All done."
69*ef165b44SPeter Kokot    echo "           Run ./configure to proceed with customizing the PHP build."
7078ab79b9SPeter Kokot    exit 0
7178ab79b9SPeter Kokot  else
72*ef165b44SPeter Kokot    echo "buildconf: Configure files are missing." >&2
73*ef165b44SPeter Kokot    echo "           Run ./buildconf --force to create a configure script." >&2
7478ab79b9SPeter Kokot    exit 1
7578ab79b9SPeter Kokot  fi
7678ab79b9SPeter Kokotfi
7778ab79b9SPeter Kokot
78c79eb107SPeter Kokotecho "buildconf: Checking installation"
79c79eb107SPeter Kokot
80c79eb107SPeter Kokot# Get minimum required autoconf version from the configure.ac file.
81c79eb107SPeter Kokotmin_version=$(sed -n 's/AC_PREREQ(\[\(.*\)\])/\1/p' configure.ac)
82c79eb107SPeter Kokot
83c79eb107SPeter Kokot# Check if autoconf exists.
84c79eb107SPeter Kokotac_version=$($PHP_AUTOCONF --version 2>/dev/null|head -n 1|sed -e 's/^[^0-9]*//' -e 's/[a-z]* *$//')
85c79eb107SPeter Kokot
86c79eb107SPeter Kokotif test -z "$ac_version"; then
87c79eb107SPeter Kokot  echo "buildconf: autoconf not found." >&2
88c79eb107SPeter Kokot  echo "           You need autoconf version $min_version or newer installed" >&2
89c79eb107SPeter Kokot  echo "           to build PHP from Git." >&2
90c79eb107SPeter Kokot  exit 1
91c79eb107SPeter Kokotfi
92c79eb107SPeter Kokot
93c79eb107SPeter Kokot# Check autoconf version.
94c79eb107SPeter Kokotset -f; IFS='.'; set -- $ac_version; set +f; IFS=' '
95c79eb107SPeter Kokotac_version_num="$(expr ${1} \* 10000 + ${2} \* 100)"
96c79eb107SPeter Kokotset -f; IFS='.'; set -- $min_version; set +f; IFS=' '
97c79eb107SPeter Kokotmin_version_num="$(expr ${1} \* 10000 + ${2} \* 100)"
98c79eb107SPeter Kokot
99c79eb107SPeter Kokotif test "$ac_version_num" -lt "$min_version_num"; then
100c79eb107SPeter Kokot  echo "buildconf: autoconf version $ac_version found." >&2
101c79eb107SPeter Kokot  echo "           You need autoconf version $min_version or newer installed" >&2
102c79eb107SPeter Kokot  echo "           to build PHP from Git." >&2
103c79eb107SPeter Kokot  exit 1
104c79eb107SPeter Kokotelse
105c79eb107SPeter Kokot  echo "buildconf: autoconf version $ac_version (ok)"
106c79eb107SPeter Kokotfi
107c79eb107SPeter Kokot
108*ef165b44SPeter Kokotif test "$force" = "1"; then
109*ef165b44SPeter Kokot  echo "buildconf: Forcing buildconf. The configure files will be regenerated."
1100eb79196SWez Furlongfi
11115c95605SChristopher Jones
112*ef165b44SPeter Kokot# Clean cache and explicitly remove all targets if present. Remove also
113*ef165b44SPeter Kokot# aclocal.m4 if present. It is automatically included by autoconf but not used
114*ef165b44SPeter Kokot# by the PHP build system since PHP 7.4.
115*ef165b44SPeter Kokotecho "buildconf: Cleaning cache and configure files"
116*ef165b44SPeter Kokotrm -rf \
117*ef165b44SPeter Kokot  aclocal.m4 \
118*ef165b44SPeter Kokot  autom4te.cache \
119*ef165b44SPeter Kokot  config.cache \
120*ef165b44SPeter Kokot  configure \
121*ef165b44SPeter Kokot  main/php_config.h.in
12278ab79b9SPeter Kokot
12378ab79b9SPeter Kokotif test "$debug" = "1"; then
12402c1f329SPeter Kokot  autoconf_flags="-f -Wall"
125*ef165b44SPeter Kokot  autoheader_flags="-Wall"
126996c9d85Sfoobarelse
12702c1f329SPeter Kokot  autoconf_flags="-f"
128*ef165b44SPeter Kokot  autoheader_flags=""
129996c9d85Sfoobarfi
13002c1f329SPeter Kokot
131*ef165b44SPeter Kokotecho "buildconf: Rebuilding configure"
132*ef165b44SPeter Kokot$PHP_AUTOCONF $autoconf_flags
133*ef165b44SPeter Kokot
134*ef165b44SPeter Kokotecho "buildconf: Rebuilding main/php_config.h.in"
135*ef165b44SPeter Kokot$PHP_AUTOHEADER $autoheader_flags
136*ef165b44SPeter Kokot
137*ef165b44SPeter Kokotecho "buildconf: Run ./configure to proceed with customizing the PHP build."
138