1#!/bin/sh
2# Run this to generate all the initial makefiles, etc.
3# Shamelessly copied from Glade
4
5DIE=0
6
7if test -d m4local ; then
8  :
9else
10  echo "Directory \`m4local' does not exist.  Creating it."
11  if test -e m4local ; then
12    echo "**Error**: A file \`m4local' exists and is not a directory."
13    echo "Please remove it."
14    DIE=1
15  fi
16  mkdir m4local
17fi
18
19if test -d m4 ; then
20  rm -rf m4
21elif test -e m4 ; then
22  echo "**Error**: A file \`m4local' exists and is not a directory."
23  echo "Please remove it."
24  exit 1
25fi
26
27mkdir m4
28
29# shellcheck disable=SC2006,SC2154
30test -f "$srcdir/configure.ac" && sed "s/XXXRELEASE_DATE=XXX/RELEASE_DATE=\"`date '+%d %b %Y'`\"/" "$srcdir/m4extra/stp_release.m4.in" > "$srcdir/m4/stp_release.m4"
31
32# Make sure all of our auto* bits are up to date.
33autoreconf -ivf
34
35# shellcheck disable=SC2006
36libtoolv=`libtool --version | head -1 | sed 's,.*[      ]\([0-9][0-9]*\.[0-9][0-9]*\(\.[0-9][0-9]*\)\?\).*[a-z]*\([   ]?.*\|\)$,\1,'`
37if [ -n "$libtoolv" ] ; then
38# shellcheck disable=SC2006
39  libtool_major=`echo "$libtoolv" | awk -F. '{print $1}'`
40# shellcheck disable=SC2006
41  libtool_minor=`echo "$libtoolv" | awk -F. '{print $2}'`
42# shellcheck disable=SC2006,SC2034
43  libtool_point=`echo "$libtoolv" | awk -F. '{print $3}'`
44  if [ "$libtool_major" -le 1 ] && [ "$libtool_minor" -lt 5 ] ; then
45    libtool_err=1
46  fi
47else
48  libtool_err=1
49fi
50
51if [ -z "`type -p glib-mkenums`" ] ; then
52  echo
53  echo "**Error**: You must have \`glib2-mkenums' installed to create a"
54  echo "Gutenprint distribution.  This is usually distributed in the"
55  echo "glib2-devel, glib2-dev, or similar package."
56  DIE=1
57fi
58
59if [ -n "$libtool_err" ] ; then
60  echo
61  echo "**Warning**: You should have \`libtool' 1.5 or newer installed to"
62  echo "create a Gutenprint distribution.  Earlier versions of libtool do"
63  echo "not generate correct code for all platforms."
64  echo "Get ftp://ftp.gnu.org/pub/gnu/libtool/libtool-1.5.tar.gz"
65  echo "(or a newer version if it is available)"
66  DIE=1
67fi
68
69(autoconf --version) < /dev/null > /dev/null 2>&1 || {
70  echo
71  echo "**Error**: You must have \`autoconf' installed to"
72  echo "create a Gutenprint distribution."
73  echo "Download the appropriate package for your distribution,"
74  echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
75  DIE=1
76}
77
78test -f "$srcdir/ChangeLog" || echo > "$srcdir/ChangeLog"
79
80(grep "^AM_PROG_LIBTOOL" "$srcdir/configure.ac" >/dev/null) && {
81  (libtool --version) < /dev/null > /dev/null 2>&1 || {
82    echo
83    echo "**Error**: You must have \`libtool' installed to"
84    echo "create a Gutenprint distribution."
85    echo "Get ftp://ftp.gnu.org/pub/gnu/libtool/libtool-1.5.tar.gz"
86    echo "(or a newer version if it is available)"
87    DIE=1
88  }
89}
90
91grep "^AM_GNU_GETTEXT" "$srcdir/configure.ac" >/dev/null && {
92  grep "sed.*POTFILES" "$srcdir/configure.ac" >/dev/null || \
93  (gettext --version) < /dev/null > /dev/null 2>&1 || {
94    echo
95    echo "**Error**: You must have \`gettext' installed to"
96    echo "create a Gutenprint distribution."
97    echo "Get ftp://ftp.gnu.org/pub/gnu/gettext/gettext-0.16.tar.gz"
98    echo "(or a newer version if it is available)"
99    DIE=1
100  }
101}
102
103(pkg-config --version) < /dev/null > /dev/null 2>&1 || {
104  echo
105  echo "**Error**: You must have \`pkg-config' installed to"
106  echo "create a Gutenprint distribution."
107  echo "Download the appropriate package for your distribution,"
108  echo "or get the source tarball at http://www.freedesktop.org/"
109  DIE=1
110}
111
112
113#### MRS: The following now only generates a warning, since earlier
114####      versions of gettext *do* work, they just don't create the
115####      right uninstall code.
116
117# shellcheck disable=SC2006
118gettextv=`gettext --version | head -1 | awk '{print $NF}'`
119gettext_err=1
120if [ -n "$gettextv" ] ; then
121# shellcheck disable=SC2006
122  gettext_major=`echo "$gettextv" | awk -F. '{print $1}'`
123# shellcheck disable=SC2006
124  gettext_minor=`echo "$gettextv" | awk -F. '{print $2}'`
125# shellcheck disable=SC2006,SC2034
126  gettext_point=`echo "$gettextv" | awk -F. '{print $3}'`
127  if [ "$gettext_major" -gt 0 ] || [ "$gettext_minor" -ge 16 ] ; then
128    gettext_err=
129  fi
130fi
131if [ -n "$gettext_err" ] ; then
132  echo
133  echo "**Warning**: You must have \`gettext' 0.16 or newer installed to"
134  echo "create a Gutenprint distribution.  Earlier versions of gettext do"
135  echo "not generate the correct 'make uninstall' code."
136  echo "Get ftp://ftp.gnu.org/gnu/gettext/gettext-0.16.tar.gz"
137  echo "(or a newer version if it is available)"
138fi
139
140(autopoint --version) < /dev/null > /dev/null 2>&1 || {
141  echo
142  echo "**Error**: You must have \`autopoint' installed to"
143  echo "create a Gutenprint distribution."
144  echo "Get ftp://ftp.gnu.org/pub/gnu/gettext/gettext-0.16.tar.gz"
145  echo "(or a newer version if it is available)"
146  DIE=1
147  NO_AUTOMAKE=yes
148}
149
150(automake --version) < /dev/null > /dev/null 2>&1 || {
151  echo
152  echo "**Error**: You must have \`automake' installed to"
153  echo "create a Gutenprint distribution."
154  echo "Get ftp://ftp.gnu.org/pub/gnu/automake/automake-1.7.tar.gz"
155  echo "(or a newer version if it is available)"
156  DIE=1
157  NO_AUTOMAKE=yes
158}
159
160
161# if no automake, don't bother testing for aclocal
162test -n "$NO_AUTOMAKE" || (aclocal --version) < /dev/null > /dev/null 2>&1 || {
163  echo
164  echo "**Error**: Missing \`aclocal'.  The version of \`automake'"
165  echo "installed doesn't appear recent enough."
166  echo "Get ftp://ftp.gnu.org/pub/gnu/automake/automake-1.7.tar.gz"
167  echo "(or a newer version if it is available)"
168  DIE=1
169}
170
171# Check first for existence and then for proper version of Jade >= 1.2.1
172
173jade_err=0
174
175# Exists?
176command -V jade >/dev/null 2>&1 || jade_err=1
177
178# Proper rev?
179test "$jade_err" -eq 0 && {
180#  echo "Checking for proper revision of jade..."
181# shellcheck disable=SC2006
182  jade_version=`jade -v < /dev/null 2>&1 | grep -i "jade\"? version" | awk -F\" '{print $2}'`
183
184  # jade:I: "openjade" version "1.3.2"
185  if [ -z "$jade_version" ] ; then
186# shellcheck disable=SC2006
187    jade_version=`jade -v < /dev/null 2>&1 | grep -i 'jade"* version' | sed 's/"//g' | awk '{print $NF}'`
188  fi
189  if [ -z "$jade_version" ] ; then
190    jade -v < /dev/null 2>&1
191    jade_err=1
192  else
193# shellcheck disable=SC2006
194    jade_version_major=`echo "$jade_version" | awk -F. '{print $1}'`
195# shellcheck disable=SC2006
196    jade_version_minor=`echo "$jade_version" | awk -F. '{print $2}'`
197# shellcheck disable=SC2006
198    jade_version_point=`echo "$jade_version" | awk -F. '{print $3}'`
199
200    test "$jade_version_major" -ge 1 || jade_err=1
201
202    test "$jade_version_minor" -lt 2 || {
203	test "$jade_version_minor" -eq 2 -a "$jade_version_point" -lt 1
204      } && jade_err=1
205  fi
206}
207test "$jade_err" -gt 0 && {
208  echo
209  echo "***Warning***: You must have \"Jade\" version 1.2.1 or"
210  echo "newer installed to build the Gutenprint user's guide."
211  echo "Get ftp://ftp.jclark.com/pub/jade/jade-1.2.1.tar.gz"
212  echo "(or a newer version if available)"
213  echo
214}
215
216# Check for existence of dvips
217
218command -V dvips >/dev/null 2>&1 || {
219  echo
220  echo "***Warning***: You must have \"dvips\" installed to"
221  echo "build the Gutenprint user's guide."
222  echo
223}
224
225# Check for existence of jadetex
226
227command -V jadetex >/dev/null 2>&1 || {
228  echo
229  echo "***Warning***: You must have \"jadetex\" version 3.5 or"
230  echo "newer installed to build the Gutenprint user's guide."
231  echo "Get ftp://prdownloads.sourceforge.net/jadetex/jadetex-3.5.tar.gz"
232  echo "(or a newer version if available)"
233  echo
234}
235
236# Check for OpenJade >= 1.3
237
238openjade_err=0
239
240# Exists?
241command -V openjade >/dev/null 2>&1 || openjade_err=1
242
243# Proper rev?
244test "$openjade_err" -eq 0 && {
245#  echo "Checking for proper revision of openjade..."
246# shellcheck disable=SC2006
247  openjade_version=`openjade -v < /dev/null 2>&1 | sed 's/"//g' | grep -i "openjade version" | awk -F ' ' '{print $4}'`
248  if [ -n "$openjade_version" ] ; then
249# shellcheck disable=SC2006
250    openjade_version_major=`echo "$openjade_version" | awk -F. '{print $1}'`
251# shellcheck disable=SC2006
252    openjade_version_minor=`echo "$openjade_version" | awk -F. '{print $2}'`
253# shellcheck disable=SC2006
254    openjade_version_minor=`echo "$openjade_version_minor" | awk -F- '{print $1}' | sed -e 's/\([0-9][0-9]*\).*/\1/'`
255
256    if [ "$openjade_version_major" -lt 1 ] ; then
257      openjade_error=1
258    elif [ "$openjade_version_major" -eq 1 ] && [ "$openjade_version_minor" -lt 3 ] ; then
259      openjade_error=1
260    fi
261  else
262    openjade_err=1
263  fi
264
265  test "$openjade_err" -eq 1 && {
266    echo " "
267    echo "***Warning***: You must have \"OpenJade\" version 1.3 or"
268    echo "newer installed to build the Gutenprint user's guide."
269    echo "Get http://download.sourceforge.net/openjade/openjade-1.3.tar.gz"
270    echo "(or a newer version if available)"
271    echo " "
272  }
273}
274
275command -V db2html >/dev/null 2>&1 || {
276  echo " "
277  echo "***Warning***: You must have \"db2html\" installed to"
278  echo "build the Gutenprint user's guide."
279  echo "This usually comes from packages named docbook-utils or docbook-toys."
280  echo " "
281}
282
283command -V db2pdf >/dev/null 2>&1 || {
284  echo " "
285  echo "***Warning***: You must have \"db2pdf\" installed to"
286  echo "build the Gutenprint user's guide."
287  echo "This usually comes from packages named docbook-utils-pdf"
288  echo "or docbook-toys."
289  echo " "
290}
291
292# Check first for existence and then for proper version of sgmltools-lite >=3.0.2
293
294sgmltools_err=0
295
296# Exists?
297command -V sgmltools >/dev/null 2>&1
298test $? -ne 0 && sgmltools_err=1
299
300# Proper rev?
301test "$sgmltools_err" -eq 0 && {
302#  echo "Checking for proper revision of sgmltools..."
303# shellcheck disable=SC2006
304  sgmltools_version=`sgmltools --version | awk '{print $3}'`
305
306  if [ -n "$sgmltools_version" ] ; then
307# shellcheck disable=SC2006
308    sgmltools_version_major=`echo "$sgmltools_version" | awk -F. '{print $1}'`
309# shellcheck disable=SC2006
310    sgmltools_version_minor=`echo "$sgmltools_version" | awk -F. '{print $2}'`
311# shellcheck disable=SC2006
312    sgmltools_version_point=`echo "$sgmltools_version" | awk -F. '{print $3}'`
313
314    test "$sgmltools_version_major" -ge 3 || sgmltools_err=1
315    test "$sgmltools_version_minor" -gt 0 ||
316      (test "$sgmltools_version_minor" -eq 0 -a "$sgmltools_version_point" -ge 2) ||
317      sgmltools_err=1
318  else
319    sgmltools_err=1
320  fi
321}
322
323test "$sgmltools_err" -eq 1 && {
324  echo " "
325  echo "***Warning***: You must have \"sgmltools-lite\" version 3.0.2"
326  echo "or newer installed to build the Gutenprint user's guide."
327  echo "Get https://sourceforge.net/projects/sgmltools-lite/files/latest/download"
328  echo "(or a newer version if available)"
329  echo " "
330}
331
332# Check for convert
333
334command -V convert >/dev/null 2>&1
335test $? -ne 0 && {
336  echo " "
337  echo "***Warning***: You must have \"convert\" installed to"
338  echo "build the Gutenprint user's guide."
339  echo "\"convert\" comes from the ImageMagick software package."
340  echo "Go to http://imagemagick.sourceforge.net/http and get"
341  echo "the file ImageMagick-5.3.1.tar.gz"
342  echo "(or a newer version if available)"
343  echo " "
344}
345
346# Check for docbook version 4
347# Note workaround for Fedora installation
348# Include path for Fedora Docbook. A bit circuitous, but Fedora appends
349# a bunch of extra stuff to the name of the directory-- including the
350# version of Fedora (eg -fc9).  We don't want to test for every version
351# of Fedora and modern bourne shells won't expand the glob (*);
352# therefore, we do a `find` first and then test to see if there are any
353# results.
354
355if test -d /usr/share/sgml/docbook ;  then
356# shellcheck disable=SC2006
357  fedora_docbook=`find /usr/share/sgml/docbook -type d -name 'sgml-dtd-4.*' -print`
358fi
359
360{
361  test -d "/usr/share/sgml/docbook_4" || test -d "/usr/share/sgml/docbook/dtd/4.0" || test -d "/usr/share/sgml/docbook/dtd/4.1" || test -d "/usr/share/sgml/docbook_4.1" || test -n "$fedora_docbook"
362} || {
363  echo " "
364  echo "***Warning***: You must have Docbook v4 installed to"
365  echo "build the Gutenprint user's guide."
366  echo " "
367}
368
369if test "$DIE" -eq 1; then
370  exit 1
371fi
372
373if test -z "$*"; then
374  echo "**Warning**: I am going to run \`configure' with no arguments."
375  echo "If you wish to pass any to it, please specify them on the"
376  # shellcheck disable=SC1117
377  echo "\`$0\' command line."
378  echo
379fi
380
381case $CC in
382xlc )
383  am_opt=--include-deps;;
384esac
385
386# We don't have subdirectories.  We don't want any untarred directories that
387# contain configure.ac files to mess things up for us.
388coin="$srcdir/configure.ac"
389# shellcheck disable=SC2006
390dr=`dirname "$coin"`
391if test -f "$dr/NO-AUTO-GEN"; then
392  echo skipping "$dr" -- flagged as no auto-gen
393else
394  echo processing "$dr"
395# shellcheck disable=SC2006
396  macrodirs=`sed -n -e 's,^dnl AM_ACLOCAL_INCLUDE(\(.*\)),\1,gp' < "$coin"`
397  ( cd "$dr"
398    aclocalinclude="$ACLOCAL_FLAGS"
399    for k in $macrodirs; do
400      if test -d "$k"; then
401	aclocalinclude="$aclocalinclude -I $k"
402      ##else
403      ##  echo "**Warning**: No such directory \`$k'.  Ignored."
404      fi
405    done
406    if grep "^AM_GNU_GETTEXT" configure.ac >/dev/null; then
407      if grep "sed.*POTFILES" configure.ac >/dev/null; then
408	: #do nothing -- we still have an old unmodified configure.ac
409      else
410	echo "Creating $dr/aclocal.m4 ..."
411	rm -f aclocal.m4
412	test -r aclocal.m4 || touch aclocal.m4
413	# We've removed po/ChangeLog from the repository.  Version
414	# 0.10.40 of gettext appends an entry to the ChangeLog every time
415	# anyone runs autogen.sh.  Since developers do that a lot, and
416	# then proceed to commit their entire sandbox, we wind up with
417	# an ever-growing po/ChangeLog that generates conflicts on
418	# a routine basis.  There's no good reason for this.
419	echo 'This ChangeLog is redundant. Please see the main ChangeLog for i18n changes.' > po/ChangeLog
420	echo >> po/ChangeLog
421	echo 'This file is present only to keep po/Makefile.in.in happy.' >> po/ChangeLog
422	echo "Running autopoint...  Ignore non-fatal messages."
423	autopoint --force
424	# shellcheck disable=SC2181
425	if [ $? -ne 0 ] ; then
426	    echo 'Autopoint failed!'
427	    exit 1
428	fi
429	echo "Making $dr/aclocal.m4 writable ..."
430	test -r "$dr/aclocal.m4" && chmod u+w "$dr/aclocal.m4"
431      fi
432    fi
433    if grep "^AM_PROG_LIBTOOL" configure.ac >/dev/null; then
434      echo "Running libtoolize..."
435      libtoolize --force --copy
436      # shellcheck disable=SC2181
437      if [ $? -ne 0 ] ; then
438	  echo 'Libtoolize failed!'
439	  exit 1
440      fi
441    fi
442    echo "Running aclocal $aclocalinclude ..."
443    # shellcheck disable=SC2086
444    aclocal $aclocalinclude
445    # shellcheck disable=SC2181
446    if [ $? -ne 0 ] ; then
447	echo 'aclocal failed!'
448	exit 1
449    fi
450    if grep "^AM_CONFIG_HEADER" configure.ac >/dev/null; then
451      echo "Running autoheader..."
452      autoheader
453      # shellcheck disable=SC2181
454      if [ $? -ne 0 ] ; then
455	  echo 'autoheader failed!'
456	  exit 1
457      fi
458    fi
459    echo "Running automake --gnu $am_opt ..."
460    automake --add-missing --force-missing --copy --gnu $am_opt
461    # shellcheck disable=SC2181
462    if [ $? -ne 0 ] ; then
463	echo 'automake failed!'
464	exit 1
465    fi
466    echo "Running autoconf ..."
467    autoconf
468    # shellcheck disable=SC2181
469    if [ $? -ne 0 ] ; then
470	echo 'autoconf failed!'
471	exit 1
472    fi
473  ) || exit 1
474fi
475
476conf_flags="--enable-maintainer-mode" #--enable-iso-c
477
478if test -z "$NOCONFIGURE"; then
479  echo Running "$srcdir/configure" $conf_flags "$@" ...
480  "$srcdir/configure" $conf_flags "$@" \
481  && echo Now type \`make\' to compile "$PKG_NAME" || exit 1
482else
483  echo Skipping configure process.
484fi
485