buildconf 3.9 KB

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