autogen.sh 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #! /bin/sh
  2. #
  3. # Run 'autoreconf' to build 'configure', 'Makefile.in' and other configure
  4. # control files.
  5. #
  6. # The first time this is run on a GIT checkout the only files that exist are
  7. # configure.ac and Makefile.am; all of the autotools support scripts are
  8. # missing. They are instantiated with autoreconf --force --install.
  9. #
  10. # For regular ("tarball") distributions all the files should exist. We do not
  11. # want them to be updated *under any circumstances*. It should never be
  12. # necessary to run autogen.sh because ./configure --enable-maintainer-mode says
  13. # what to do if Makefile.am or configure.ac are changed.
  14. #
  15. # It is *probably* OK to update the files on a GIT checkout, because they have
  16. # come from the local tools, but leave that to the user who is assumed to know
  17. # whether it is ok or required.
  18. #
  19. # This script is intended to work without arguments, there are, however, hidden
  20. # arguments (a) for use while testing the script and (b) to fix up systems that
  21. # have been broken. If (b) is required the script prompts for the correct
  22. # options. For this reason the options are *NOT* documented in the help; this
  23. # is deliberate; UTSL.
  24. #
  25. clean=
  26. maintainer=
  27. while test $# -gt 0
  28. do
  29. case "$1" in
  30. --maintainer)
  31. maintainer=1;;
  32. --clean)
  33. clean=1;;
  34. *)
  35. exec >&2
  36. echo "$0: usage: ./autogen.sh"
  37. if test -d .git
  38. then
  39. echo " ./autogen.sh generates the configure script and"
  40. echo " Makefile.in, or refreshes them after changes to Makefile.am"
  41. echo " or configure.ac. You may prefer to just run autoreconf."
  42. elif test -z "$maintainer"
  43. then
  44. echo " DO NOT RUN THIS SCRIPT."
  45. echo " If you need to change Makefile.am or configure.ac then you"
  46. echo " also need to run ./configure --enable-maintainer-mode and"
  47. echo " use the appropriate autotools, *NOT* this script, to update"
  48. echo " everything, please check the documentation of autoreconf."
  49. echo " WARNING: libpng is intentionally generated with a known,"
  50. echo " fixed, set of autotools. It is known *NOT* to work with"
  51. echo " the collection of autotools distributed on highly reputable"
  52. echo " operating systems."
  53. echo " Remember: autotools is GNU software, you are expected to"
  54. echo " pay for support."
  55. else
  56. echo " You have run autogen.sh with --maintainer enabled and you"
  57. echo " are not using a GIT distribution, then you have given an"
  58. echo " unrecognized argument. This is not good. --maintainer"
  59. echo " switches off any assumptions that you might not know what"
  60. echo " you are doing."
  61. fi
  62. exit 1;;
  63. esac
  64. shift
  65. done
  66. #
  67. # First check for a set of the autotools files; if absent then this is assumed
  68. # to be a GIT version and the local autotools must be used. If present this
  69. # is a tarball distribution and the script should not be used. If partially
  70. # present bad things are happening.
  71. #
  72. # The autotools generated files:
  73. libpng_autotools_files="Makefile.in aclocal.m4 config.guess config.h.in
  74. config.sub configure depcomp install-sh ltmain.sh missing\
  75. test-driver"
  76. #
  77. # Files generated by versions of configue >2.68 or automake >1.13 (i.e. later
  78. # versions than those required by configure.ac):
  79. libpng_autotools_extra="compile config.h.in~"
  80. #
  81. # These are separate because 'maintainer-clean' does not remove them.
  82. libpng_libtool_files="scripts/libtool.m4 scripts/ltoptions.m4\
  83. scripts/ltsugar.m4 scripts/ltversion.m4 scripts/lt~obsolete.m4"
  84. libpng_autotools_dirs="autom4te.cache" # not required
  85. #
  86. # The configure generated files:
  87. libpng_configure_files="Makefile config.h config.log config.status\
  88. libpng-config libpng.pc libtool stamp-h1"
  89. libpng_configure_dirs=".deps"
  90. #
  91. # We must remove the configure generated files as well as the autotools
  92. # generated files if autotools are regenerated because otherwise if configure
  93. # has been run without "--enable-maintainer-mode" make can do a partial update
  94. # of Makefile. These functions do the two bits of cleaning.
  95. clean_autotools(){
  96. rm -rf $libpng_autotools_files $libpng_libtool_files $libpng_autotools_dirs
  97. rm -rf $libpng_autotools_extra
  98. }
  99. clean_configure(){
  100. rm -rf $libpng_configure_files $libpng_configure_dirs
  101. }
  102. #
  103. # Clean: remove everything (this is to help with testing)
  104. if test -n "$clean"
  105. then
  106. clean_configure
  107. if test -n "$maintainer"
  108. then
  109. clean_autotools
  110. fi
  111. exit 0
  112. fi
  113. #
  114. # Validate the distribution.
  115. libpng_autotools_file_found=
  116. libpng_autotools_file_missing=
  117. for file in $libpng_autotools_files
  118. do
  119. if test -f "$file"
  120. then
  121. libpng_autotools_file_found=1
  122. else
  123. libpng_autotools_file_missing=1
  124. fi
  125. done
  126. #
  127. # Presence of one of these does not *invalidate* missing, but absence
  128. # invalidates found.
  129. for file in $libpng_libtool_files
  130. do
  131. if test ! -f "$file"
  132. then
  133. libpng_autotools_file_missing=1
  134. fi
  135. done
  136. #
  137. # The cache directory doesn't matter - it will be regenerated and does not exist
  138. # anyway in a tarball.
  139. #
  140. # Either everything is missing or everything is there, the --maintainer option
  141. # just changes this so that the mode is set to generate all the files.
  142. mode=
  143. if test -z "$libpng_autotools_file_found" -o -n "$maintainer"
  144. then
  145. mode="autoreconf"
  146. else
  147. if test -n "$libpng_autotools_file_missing"
  148. then
  149. mode="broken"
  150. else
  151. mode="configure"
  152. fi
  153. fi
  154. #
  155. # So:
  156. case "$mode" in
  157. autoreconf)
  158. # Clean in case configure files exist
  159. clean_configure
  160. clean_autotools
  161. # Everything must be initialized, so use --force
  162. if autoreconf --warnings=all --force --install
  163. then
  164. missing=
  165. for file in $libpng_autotools_files
  166. do
  167. test -f "$file" || missing=1
  168. done
  169. # ignore the cache directory
  170. test -z "$missing" || {
  171. exec >&2
  172. echo "autoreconf was run, but did not produce all the expected"
  173. echo "files. It is likely that your autotools installation is"
  174. echo "not compatible with that expected by libpng."
  175. exit 1
  176. }
  177. else
  178. exec >&2
  179. echo "autoreconf failed: your version of autotools is incompatible"
  180. echo "with this libpng version. Please use a distributed archive"
  181. echo "(which includes the autotools generated files) and run configure"
  182. echo "instead."
  183. exit 1
  184. fi;;
  185. configure)
  186. if test -d .git
  187. then
  188. exec >&2
  189. echo "ERROR: running autoreconf on an initialized sytem"
  190. echo " This is not necessary; it is only necessary to remake the"
  191. echo " autotools generated files if Makefile.am or configure.ac"
  192. echo " change and make does the right thing with:"
  193. echo
  194. echo " ./configure --enable-maintainer-mode."
  195. echo
  196. echo " You can run autoreconf yourself if you don't like maintainer"
  197. echo " mode and you can also just run autoreconf -f -i to initialize"
  198. echo " everything in the first place; this script is only for"
  199. echo " compatibility with prior releases."
  200. exit 1
  201. else
  202. exec >&2
  203. echo "autogen.sh is intended only to generate 'configure' on systems"
  204. echo "that do not have it. You have a complete 'configure', if you"
  205. echo "need to change Makefile.am or configure.ac you also need to"
  206. echo "run configure with the --enable-maintainer-mode option."
  207. exit 1
  208. fi;;
  209. broken)
  210. exec >&2
  211. echo "Your system has a partial set of autotools generated files."
  212. echo "autogen.sh is unable to proceed. The full set of files is"
  213. echo "contained in the libpng 'tar' distribution archive and you do"
  214. echo "not need to run autogen.sh if you use it."
  215. exit 1;;
  216. esac