1#!/bin/sh
2#                                                   -*-Shell-script-*-
3# Developer helper script for setting up gEDA build environment
4# Copyright (C) 2009  Peter Brett <peter@peter-b.co.uk>
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20#####################################################################
21# Setup variables
22#####################################################################
23
24ac_script=configure.ac
25am_version=1.11.0
26aclocal_flags="$ACLOCAL_FLAGS -I m4"
27tooldir=build-tools
28podirs="libgeda/po gschem/po gattrib/po"
29
30srcdir=`dirname $0`
31if test "x$srcdir" = x ; then srcdir=.; fi
32
33script_name=`echo $0 | sed -e's:.*/::'`
34
35#####################################################################
36# Define some functions
37#####################################################################
38
39# check_dist_file FILENAME
40# ------------------------
41# Check that a file that should be provided by the tarball or git
42# checkout is present.
43check_dist_file() {
44  printf "checking for $srcdir/$1 ... " >&2
45  if test -f "$srcdir/$1" ; then
46    echo yes >&2
47  else
48    echo no >&2
49    cat >&2 <<EOF
50
51$script_name: $srcdir/$1 is missing. Check that your source tarball
52or git checkout is intact.
53
54EOF
55    ! :
56  fi
57}
58
59# check_tool TOOLS PKG [URL]
60# --------------------------
61# Check that a build tool is present. TOOLS is a list of candidates to
62# search for in the path, and PKG is the package which provides the
63# tool. If URL is specified, recommend to the user that he get obtain
64# the package there. Prints the location of the tool on standard
65# output.
66check_tool() {
67  for tool in $1; do
68    printf "checking for $tool ... " >&2
69    found_tool=`which $tool 2> /dev/null` && break
70    echo no >&2
71  done
72  if test "x$found_tool" != x ; then
73    echo $found_tool >&2
74    echo $found_tool
75  else
76    echo >&2
77    echo "$script_name: You must have $2 installed." >&2
78    if test "x$3" != x ; then
79      cat >&2 <<EOF
80
81If your operating system distribution doesn't provide a package, you
82can get download it from <$3>.
83
84EOF
85    fi
86    ! : # false
87  fi
88}
89
90# run_tool TOOL [ARG]...
91# ----------------------
92# Run TOOL with the given ARGs.
93run_tool() {
94  echo "$script_name: running $1 ..."
95  if "$@"; then
96    :
97  else
98    echo "***Error*** $script_name: $1 failed with exit status $?"
99    ! : # false
100  fi
101}
102
103# autopoint_fix [PO_DIR]...
104# ------------------------
105# GNU gettext has a tool called autopoint which is used for copying
106# the gettext build infrastructure into the package. Unfortunately,
107# some versions of autopoint only recognize the top level po directory
108# -- which gEDA doesn't use at all.
109#
110# To get around this, when we run autopoint we check if it's created
111# the top-level po directory.  If it has, we copy the files to po
112# directories that we actually use.
113#
114# N.b. when this function is called we've cd'd into $srcdir.
115autopoint_fix() {
116  top_po="po"
117
118  # For safety, refuse to continue if the top level po dir exists.
119  if test -d $top_po; then
120    echo "***Error*** $script_name: $top_po exists. Remove it and re-run $script_name"
121    ! : #false
122  elif run_tool $AUTOPOINT --force; then
123    if test -d $top_po; then
124      {
125        for d in $podirs; do
126          echo "$script_name: copying gettext files to $d ..."
127          cp -p $top_po/* $d || break
128        done
129      } && rm -rf $top_po
130    fi
131  else
132    exit $?
133  fi
134}
135
136#####################################################################
137# Do some checks for directories and tools
138#####################################################################
139
140check_dist_file $ac_script || die=1
141check_dist_file $tooldir/desktop-i18n &&
142  DESKTOP_I18N=$tooldir/desktop-i18n || die=1
143
144AUTOCONF=`check_tool autoconf "GNU autoconf" ftp://ftp.gnu.org/pub/gnu/` 2>&1 || die=1
145
146AUTOHEADER=`check_tool autoheader "GNU autoconf" ftp://ftp.gnu.org/pub/gnu/` 2>&1 || die=1
147
148AUTOMAKE=`check_tool automake "GNU automake" ftp://ftp.gnu.org/pub/gnu/` 2>&1 || die=1
149
150ACLOCAL=`check_tool aclocal "GNU automake" ftp://ftp.gnu.org/pub/gnu/` 2>&1 || die=1
151
152LIBTOOLIZE=`check_tool "libtoolize glibtoolize" "GNU libtool" "ftp://ftp.gnu.org/pub/gnu/"` 2>&1 || die=1
153
154AUTOPOINT=`check_tool autopoint "GNU gettext" "http://www.gnu.org/software/gettext"` 2>&1 || die=1
155
156#####################################################################
157# Check automake version
158#####################################################################
159
160# Exit now if we don't have automake at all
161if test "x$AUTOMAKE" = x ; then
162  echo "***Error*** $script_name: Some required tools could not be found."
163  exit $die
164fi
165
166printf "checking for automake >= $am_version ... "
167am_have_version=`$AUTOMAKE --version | sed -n -e 's:[^0-9]* \([0-9]*\.[0-9]*\.*[0-9]*\).*$:\1:p'`
168echo $am_have_version
169
170need_major=`echo $am_version | awk -F . '{print $1}'`
171need_minor=`echo $am_version | awk -F . '{print $2}'`
172need_point=`echo $am_version | awk -F . '{print $3}'`
173
174have_major=`echo $am_have_version | awk -F . '{print $1}'`
175have_minor=`echo $am_have_version | awk -F . '{print $2}'`
176have_point=`echo $am_have_version | awk -F . '{print $3}'`
177
178if test "x$have_point" = x; then have_point="0"; fi
179
180if test $need_major -gt $have_major ||
181  test $need_major -eq $have_major -a $need_minor -gt $have_minor ||
182  test $need_major -eq $have_major -a $need_minor -eq $have_minor \
183       -a $need_point -gt $have_point; then
184  cat >&2 <<EOF
185
186You have Automake $am_have_version installed, but Automake $am_version
187or later is required.
188
189If your operating system doesn't provide a package, you can download
190it from ftp://ftp.gnu.org/pub/gnu/
191
192EOF
193  die=1
194fi
195
196#####################################################################
197# Die if checks failed
198#####################################################################
199
200if test "x$die" != x ; then
201  echo "***Error*** $script_name: Some required tools could not be found."
202  exit $die
203fi
204
205#####################################################################
206# Run tools
207#####################################################################
208
209( cd $srcdir &&
210  autopoint_fix &&
211  run_tool "$DESKTOP_I18N" --setup &&
212  run_tool "$LIBTOOLIZE" --force --copy &&
213  run_tool "$ACLOCAL" $aclocal_flags &&
214  run_tool "$AUTOHEADER" &&
215  run_tool "$AUTOMAKE" -Wall --copy --add-missing --gnu &&
216  run_tool "$AUTOCONF" )
217