xref: /PHP-8.3/buildconf (revision c0755463)
1#!/bin/sh
2#
3# A wrapper around Autoconf that generates files to build PHP on *nix systems.
4
5PHP_AUTOCONF=${PHP_AUTOCONF:-autoconf}
6PHP_AUTOHEADER=${PHP_AUTOHEADER:-autoheader}
7force=0
8debug=0
9
10# Go to project root.
11cd "$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)" || exit
12
13php_extra_version=$(grep '^AC_INIT(' configure.ac) || exit
14case "$php_extra_version" in
15  *-dev*)
16    dev=1
17    ;;
18  *)
19    dev=0
20    ;;
21esac
22
23while test $# -gt 0; do
24  if test "$1" = "-h" || test "$1" = "--help"; then
25    cat << HELP
26PHP buildconf
27
28A wrapper around the autoconf and autoheader that generate files for building
29PHP on *nix systems (configure and main/php_config.h.in). The configure script
30is used to customize the PHP build based on the provided options and system. PHP
31releases downloaded from PHP.net already include the configure script so
32installing Autoconf and running buildconf is not needed. For the PHP sources
33from the Git repository, buildconf is used for generating a new configure script
34and required files.
35
36SYNOPSIS:
37  buildconf [<options>]
38
39OPTIONS:
40  -f, --force     Regenerate configure files in PHP release packages.
41  --debug         Display warnings emitted by Autoconf.
42  -h, --help      Display this help.
43
44ENVIRONMENT:
45  The following optional variables are supported:
46
47  PHP_AUTOCONF    Overrides the path to autoconf tool.
48                  PHP_AUTOCONF=/path/to/autoconf ./buildconf
49  PHP_AUTOHEADER  Overrides the path to autoheader tool.
50                  PHP_AUTOHEADER=/path/to/autoheader ./buildconf
51HELP
52    exit 0
53  fi
54
55  if test "$1" = "-f" || test "$1" = "--force"; then
56    force=1
57  fi
58
59  if test "$1" = "--debug"; then
60    debug=1
61  fi
62
63  shift
64done
65
66if test "$dev" = "0" && test "$force" = "0"; then
67  if test -f "configure" && test -f "main/php_config.h.in"; then
68    echo "buildconf: The configure script is already built. All done."
69    echo "           Run ./configure to proceed with customizing the PHP build."
70    exit 0
71  else
72    echo "buildconf: Configure files are missing." >&2
73    echo "           Run ./buildconf --force to create a configure script." >&2
74    exit 1
75  fi
76fi
77
78echo "buildconf: Checking installation"
79
80# Get minimum required autoconf version from the configure.ac file.
81min_version=$(sed -n 's/AC_PREREQ(\[\(.*\)\])/\1/p' configure.ac)
82
83# Check if autoconf exists.
84ac_version=$($PHP_AUTOCONF --version 2>/dev/null|head -n 1|sed -e 's/^[^0-9]*//' -e 's/[^0-9.]*$//')
85
86if test -z "$ac_version"; then
87  echo "buildconf: autoconf not found." >&2
88  echo "           You need autoconf version $min_version or newer installed" >&2
89  echo "           to build PHP from Git." >&2
90  exit 1
91fi
92
93# Check autoconf version.
94set -f; IFS='.'; set -- $ac_version; set +f; IFS=' '
95ac_version_num="$(expr ${1} \* 10000 + ${2} \* 100)"
96set -f; IFS='.'; set -- $min_version; set +f; IFS=' '
97min_version_num="$(expr ${1} \* 10000 + ${2} \* 100)"
98
99if test "$ac_version_num" -lt "$min_version_num"; then
100  echo "buildconf: autoconf version $ac_version found." >&2
101  echo "           You need autoconf version $min_version or newer installed" >&2
102  echo "           to build PHP from Git." >&2
103  exit 1
104else
105  echo "buildconf: autoconf version $ac_version (ok)"
106fi
107
108if test "$force" = "1"; then
109  echo "buildconf: Forcing buildconf. The configure files will be regenerated."
110fi
111
112# Clean cache and explicitly remove all targets if present. Remove also
113# aclocal.m4 if present. It is automatically included by autoconf but not used
114# by the PHP build system since PHP 7.4.
115echo "buildconf: Cleaning cache and configure files"
116rm -rf \
117  aclocal.m4 \
118  autom4te.cache \
119  config.cache \
120  configure \
121  main/php_config.h.in
122
123if test "$debug" = "1"; then
124  autoconf_flags="-f -Wall"
125  autoheader_flags="-Wall"
126else
127  autoconf_flags="-f"
128  autoheader_flags=""
129fi
130
131echo "buildconf: Rebuilding configure"
132$PHP_AUTOCONF $autoconf_flags
133
134echo "buildconf: Rebuilding main/php_config.h.in"
135$PHP_AUTOHEADER $autoheader_flags
136
137echo "buildconf: Run ./configure to proceed with customizing the PHP build."
138