blob: 9af34bde24b2d1c8d1f042c5c71031cbf78d8cdd [file] [log] [blame]
Glenn Randers-Pehrson917648e2004-12-02 18:14:51 -06001#! /bin/sh
Glenn Randers-Pehrsonc3d51c12006-03-02 07:23:18 -06002#
John Bowlerda2194c2012-01-25 08:30:24 -06003# Run 'autoreconf' to build 'configure', 'Makefile.in' and other configure
4# control files.
John Bowlere0446492012-01-27 12:49:15 -06005#
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
Glenn Randers-Pehrsonfecdd462013-10-13 17:14:48 -050012# necessary to run autogen.sh because ./configure --enable-maintainer-mode says
13# what to do if Makefile.am or configure.ac are changed.
John Bowlere0446492012-01-27 12:49:15 -060014#
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
Glenn Randers-Pehrsonfecdd462013-10-13 17:14:48 -050020# arguments (a) for use while testing the script and (b) to fix up systems that
John Bowlere0446492012-01-27 12:49:15 -060021# 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#
25clean=
26maintainer=
John Bowlerda2194c2012-01-25 08:30:24 -060027while test $# -gt 0
28do
29 case "$1" in
John Bowlere0446492012-01-27 12:49:15 -060030 --maintainer)
31 maintainer=1;;
Glenn Randers-Pehrsona2218a42010-09-14 16:06:08 -050032
John Bowlere0446492012-01-27 12:49:15 -060033 --clean)
34 clean=1;;
John Bowlerda2194c2012-01-25 08:30:24 -060035
36 *)
John Bowlere0446492012-01-27 12:49:15 -060037 exec >&2
38 echo "$0: usage: ./autogen.sh"
39 if test -d .git
40 then
41 echo " ./autogen.sh generates the configure script and"
42 echo " Makefile.in, or refreshes them after changes to Makefile.am"
43 echo " or configure.ac. You may prefer to just run autoreconf."
44 elif test -z "$maintainer"
45 then
46 echo " DO NOT RUN THIS SCRIPT."
47 echo " If you need to change Makefile.am or configure.ac then you"
48 echo " also need to run ./configure --enable-maintainer-mode and"
49 echo " use the appropriate autotools, *NOT* this script, to update"
50 echo " everything, please check the documentation of autoreconf."
51 echo " WARNING: libpng is intentionally generated with a known,"
52 echo " fixed, set of autotools. It is known *NOT* to work with"
53 echo " the collection of autotools distributed on highly reputable"
54 echo " operating systems."
55 echo " Remember: autotools is GNU software, you are expected to"
56 echo " pay for support."
57 else
58 echo " You have run autogen.sh with --maintainer enabled and you"
59 echo " are not using a GIT distribution, then you have given an"
60 echo " unrecognized argument. This is not good. --maintainer"
61 echo " switches off any assumptions that you might not know what"
62 echo " you are doing."
63 fi
64 exit 1;;
John Bowlerda2194c2012-01-25 08:30:24 -060065 esac
66
67 shift
68done
John Bowlere0446492012-01-27 12:49:15 -060069#
70# First check for a set of the autotools files; if absent then this is assumed
71# to be a GIT version and the local autotools must be used. If present this
72# is a tarball distribution and the script should not be used. If partially
73# present bad things are happening.
74#
75# The autotools generated files:
76libpng_autotools_files="Makefile.in aclocal.m4 config.guess config.h.in\
John Bowler34ac3692013-10-06 11:29:55 -050077 config.sub configure depcomp install-sh ltmain.sh missing test-driver"
78#
79# Files generated by versions of configue >2.68 or automake >1.13 (i.e. later
Glenn Randers-Pehrsonfecdd462013-10-13 17:14:48 -050080# versions than those required by configure.ac):
John Bowler34ac3692013-10-06 11:29:55 -050081libpng_autotools_extra="compile"
John Bowlere0446492012-01-27 12:49:15 -060082#
83# These are separate because 'maintainer-clean' does not remove them.
84libpng_libtool_files="scripts/libtool.m4 scripts/ltoptions.m4\
85 scripts/ltsugar.m4 scripts/ltversion.m4 scripts/lt~obsolete.m4"
John Bowlerda2194c2012-01-25 08:30:24 -060086
John Bowlere0446492012-01-27 12:49:15 -060087libpng_autotools_dirs="autom4te.cache" # not required
88#
89# The configure generated files:
90libpng_configure_files="Makefile config.h config.log config.status\
91 libpng-config libpng.pc libtool stamp-h1"
92
93libpng_configure_dirs=".deps"
94#
95# We must remove the configure generated files as well as the autotools
96# generated files if autotools are regenerated because otherwise if configure
97# has been run without "--enable-maintainer-mode" make can do a partial update
98# of Makefile. These functions do the two bits of cleaning.
99clean_autotools(){
100 rm -rf $libpng_autotools_files $libpng_libtool_files $libpng_autotools_dirs
John Bowler34ac3692013-10-06 11:29:55 -0500101 rm -rf $libpng_autotools_extra
John Bowlere0446492012-01-27 12:49:15 -0600102}
103
104clean_configure(){
105 rm -rf $libpng_configure_files $libpng_configure_dirs
106}
107#
108# Clean: remove everything (this is to help with testing)
109if test -n "$clean"
John Bowlerda2194c2012-01-25 08:30:24 -0600110then
John Bowlere0446492012-01-27 12:49:15 -0600111 clean_configure
112 if test -n "$maintainer"
John Bowlerda2194c2012-01-25 08:30:24 -0600113 then
John Bowlere0446492012-01-27 12:49:15 -0600114 clean_autotools
John Bowlerda2194c2012-01-25 08:30:24 -0600115 fi
John Bowlere0446492012-01-27 12:49:15 -0600116
117 exit 0
John Bowlerda2194c2012-01-25 08:30:24 -0600118fi
John Bowlere0446492012-01-27 12:49:15 -0600119#
120# Validate the distribution.
121libpng_autotools_file_found=
122libpng_autotools_file_missing=
123for file in $libpng_autotools_files
124do
125 if test -f "$file"
126 then
127 libpng_autotools_file_found=1
128 else
129 libpng_autotools_file_missing=1
130 fi
131done
132#
133# Presence of one of these does not *invalidate* missing, but absence
134# invalidates found.
135for file in $libpng_libtool_files
136do
137 if test ! -f "$file"
138 then
139 libpng_autotools_file_missing=1
140 fi
141done
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600142#
John Bowlere0446492012-01-27 12:49:15 -0600143# The cache directory doesn't matter - it will be regenerated and does not exist
144# anyway in a tarball.
145#
146# Either everything is missing or everything is there, the --maintainer option
147# just changes this so that the mode is set to generate all the files.
148mode=
149if test -z "$libpng_autotools_file_found" -o -n "$maintainer"
150then
151 mode="autoreconf"
152else
153 if test -n "$libpng_autotools_file_missing"
154 then
155 mode="broken"
156 else
157 mode="configure"
158 fi
159fi
160#
161# So:
162case "$mode" in
163 autoreconf)
164 # Clean in case configure files exist
165 clean_configure
166 clean_autotools
167 # Everything must be initialized, so use --force
168 if autoreconf --warnings=all --force --install
169 then
170 missing=
171 for file in $libpng_autotools_files
172 do
173 test -f "$file" || missing=1
174 done
175 # ignore the cache directory
176 test -z "$missing" || {
177 exec >&2
178 echo "autoreconf was run, but did not produce all the expected"
179 echo "files. It is likely that your autotools installation is"
180 echo "not compatible with that expected by libpng."
181 exit 1
182 }
183 else
184 exec >&2
185 echo "autoreconf failed: your version of autotools is incompatible"
186 echo "with this libpng version. Please use a distributed archive"
187 echo "(which includes the autotools generated files) and run configure"
188 echo "instead."
189 exit 1
190 fi;;
191
192 configure)
193 if test -d .git
194 then
195 exec >&2
196 echo "ERROR: running autoreconf on an initialized sytem"
197 echo " This is not necessary; it is only necessary to remake the"
198 echo " autotools generated files if Makefile.am or configure.ac"
199 echo " change and make does the right thing with:"
200 echo
201 echo " ./configure --enable-maintainer-mode."
202 echo
203 echo " You can run autoreconf yourself if you don't like maintainer"
204 echo " mode and you can also just run autoreconf -f -i to initialize"
205 echo " everything in the first place; this script is only for"
Glenn Randers-Pehrsonfecdd462013-10-13 17:14:48 -0500206 echo " compatibility with prior releases."
John Bowlere0446492012-01-27 12:49:15 -0600207 exit 1
208 else
209 exec >&2
210 echo "autogen.sh is intended only to generate 'configure' on systems"
211 echo "that do not have it. You have a complete 'configure', if you"
212 echo "need to change Makefile.am or configure.ac you also need to"
213 echo "run configure with the --enable-maintainer-mode option."
214 exit 1
215 fi;;
216
217 broken)
218 exec >&2
219 echo "Your system has a partial set of autotools generated files."
220 echo "autogen.sh is unable to proceed. The full set of files is"
Glenn Randers-Pehrson871b1d02013-03-02 14:58:22 -0600221 echo "contained in the libpng 'tar' distribution archive and you do"
222 echo "not need to run autogen.sh if you use it."
John Bowlere0446492012-01-27 12:49:15 -0600223 exit 1;;
224esac