source: rtems/bootstrap @ a4570829

5
Last change on this file since a4570829 was 4dfeba3, checked in by Amaan Cheval <amaan.cheval@…>, on Mar 9, 2018 at 3:38:31 PM

bootstrap: Use printf instead of echo -e for POSIX shells

On POSIX compliant shells, echo does not have the -e option.
This causes the "-e" to be echoed as well, causing potential buggy
build processes.

Example shell session:

-> % sh
$ echo -e "foo bar"
-e foo bar
$

According to POSIX, "\$" should be fine regardless due to the use of
double-quotes[1]. However, since printf is recommended over echo anyway,
we replace "echo -e" with printf where required.

[1] http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_02_03

  • Property mode set to 100755
File size: 8.0 KB
Line 
1#!/bin/sh
2#
3# helps bootstrapping, when checked out from CVS
4# requires GNU autoconf and GNU automake
5#
6# this is not meant to be exported outside the source tree
7#
8# NOTE: Inspired by libtool's autogen script
9#
10# to be run from the toplevel directory of RTEMS'
11# source tree
12
13progname=`basename $0`
14top_srcdir=`dirname $0`
15
16LC_ALL=C
17export LC_ALL
18
19verbose=""
20quiet="false"
21mode="autoreconf"
22force=0
23
24usage()
25{
26  echo
27  echo "usage: ${progname} [-c|-p|-h] [-q][-v]"
28  echo
29  echo "options:"
30  echo "        -c .. clean, remove all aclocal/autoconf/automake generated files"
31  echo "        -h .. display this message and exit"
32  echo "        -H .. regenerate headers.am files"
33  echo "        -q .. quiet, don't display directories"
34  echo "        -v .. verbose, pass -v to autotools"
35  echo
36  exit 1
37}
38
39generate_bspdir_acinclude()
40{
41cat << EOF > acinclude.m4~
42# RTEMS_CHECK_BSPDIR(RTEMS_BSP_FAMILY)
43AC_DEFUN([RTEMS_CHECK_BSPDIR],
44[
45  case "\$1" in
46EOF
47
48for i in `echo */make | tr " " "\n" | LANG=C LC_COLLATE=C sort`; do
49  d=`dirname $i`
50cat << EOF >> acinclude.m4~
51  $d )
52    AC_CONFIG_SUBDIRS([$d]);;
53EOF
54done
55cat << EOF >> acinclude.m4~
56  *)
57    AC_MSG_ERROR([Invalid BSP]);;
58  esac
59])
60EOF
61if cmp -s acinclude.m4 acinclude.m4~ 2>/dev/null; then
62  echo "acinclude.m4 is unchanged"
63else
64  cp acinclude.m4~ acinclude.m4
65fi
66rm -f acinclude.m4~
67}
68
69if test ! -f $top_srcdir/aclocal/version.m4; then
70  echo "${progname}:"
71  echo "        Installation problem: Can't find file aclocal/version.m4"
72  exit 1
73fi
74
75while test $# -gt 0; do
76case $1 in
77-h|--he|--hel|--help)
78  usage ;;
79-q|--qu|--qui|--quie|--quiet)
80  quiet="true"
81  shift;;
82-v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
83  verbose="-v"
84  shift;;
85-c|--cl|--cle|--clea|--clean)
86  mode="clean"
87  shift;;
88-f|--fo|--for|--forc|--force)
89  force=`expr $force + 1`
90  shift;;
91-H|--headers)
92  mode="headers"
93  shift;;
94-r|--re|--rec|--reco|--recon|--reconf)
95  mode="autoreconf"
96  shift;;
97-g|--ge|--gen|--gene|--gener|--genera|--generat|--generate)
98  mode="generate"
99  shift;;
100-*) echo "unknown option $1"
101  usage ;;
102*) echo "invalid parameter $1"
103  usage ;;
104esac
105done
106
107case $mode in
108headers)
109  if test "." != "$top_srcdir"; then
110    echo "To generate the headers.am you must call the script via \"./$progname -H\""
111    exit 1
112  fi
113  base="$PWD"
114  tmp="$base/headers.am.new"
115  for i in cpukit/include cpukit/score/cpu/*/include bsps/include bsps/*/include bsps/*/*/include ; do
116    dir=""
117    am_dir=""
118    echo '## This file was generated by "./boostrap -H".' > "$tmp"
119    case $i in
120      cpukit/include)
121        hdr="../"
122        inc="include/"
123        ;;
124      cpukit/score/cpu/*/include)
125        hdr="../"
126        inc=`echo $i | cut -d'/' -f5-`
127        inc="$inc/"
128        ;;
129      bsps/*/*/include)
130        hdr="../"
131        inc="../../../../../../$i/"
132        ;;
133      bsps/*/include)
134        hdr="../"
135        inc="../../../../../$i/"
136        ;;
137      bsps/include)
138        hdr="../"
139        inc="../../$i/"
140        ;;
141      *)
142        hdr=""
143        inc=""
144        ;;
145    esac
146    cd $i
147    for b in `find -type d | sort` ; do
148      for j in `find $b -mindepth 1 -maxdepth 1 -name '*.h' -or -name '*.inc' | sed 's%^\.%%' | sed 's%^/%%' | sort` ; do
149        d=`dirname $j`
150        if test x$d != x$dir ; then
151          dir=$d
152          if test x$d != x. ; then
153            am_dir=`echo $dir | sed 's%[/-]%_%g'`
154            am_dir="_$am_dir"
155            printf "\ninclude%sdir = \$(includedir)/$dir\n" "$am_dir" >> "$tmp"
156          else
157            am_dir=""
158            echo "" >> "$tmp"
159          fi
160          echo "include${am_dir}_HEADERS =" >> "$tmp"
161        fi
162        echo "include${am_dir}_HEADERS += $inc$j" >> "$tmp"
163        if test $j = bsp.h ; then
164          echo "include_HEADERS += include/bspopts.h" >> "$tmp"
165        fi
166      done
167    done
168    cd "$base"
169    diff -q "$tmp" "$i/${hdr}headers.am" || mv "$tmp" "$i/${hdr}headers.am"
170  done
171  rm -f "$tmp"
172  ;;
173
174generate)
175  AUTOCONF=${AUTOCONF-autoconf}
176  if test -z "$AUTOCONF"; then
177    echo "You must have autoconf installed to run $program"
178    exit 1
179  fi
180
181  AUTOHEADER=${AUTOHEADER-autoheader}
182  if test -z "$AUTOHEADER"; then
183    echo "You must have autoconf installed to run $program"
184    exit 1
185  fi
186
187  AUTOMAKE=${AUTOMAKE-automake}
188  if test -z "$AUTOMAKE"; then
189    echo "You must have automake installed to run $program"
190    exit 1
191  fi
192
193  ACLOCAL=${ACLOCAL-aclocal}
194  if test -z "$ACLOCAL"; then
195    echo "You must have automake installed to run $program"
196    exit 1
197  fi
198
199  case $top_srcdir in
200  /* ) aclocal_dir=$top_srcdir
201    ;;
202  *) aclocal_dir=`pwd`/$top_srcdir
203    ;;
204  esac
205
206  confs=`find . \( -name 'configure.in' -o -name 'configure.ac' \) -print`
207  for i in $confs; do
208  dir=`dirname $i`
209  configure=`basename $i`
210  ( test "$quiet" = "true" || echo "$dir"
211    cd $dir
212    test -n "`grep RTEMS_CHECK_BSPDIR ${configure}`" && \
213      generate_bspdir_acinclude
214    pat="s,\$(RTEMS_TOPdir),${aclocal_dir},g"
215    aclocal_args=`grep '^[ ]*ACLOCAL_AMFLAGS' Makefile.am | \
216      sed -e 's%.*ACLOCAL_AMFLAGS.*\=[ ]*%%g' -e $pat `
217    test "$verbose" = "-v" && echo "${ACLOCAL} $aclocal_args"
218    ${ACLOCAL} $aclocal_args
219    test -n "`grep CONFIG_HEADER ${configure}`" && ${AUTOHEADER} \
220      && test "$verbose" = "-v" && echo "${AUTOHEADER}"
221    test -n "`grep RTEMS_BSP_CONFIGURE ${configure}`" && ${AUTOHEADER} \
222      && test "$verbose" = "-v" && echo "${AUTOHEADER}"
223    test -f Makefile.am && ${AUTOMAKE} -a -c $verbose
224    ${AUTOCONF}
225    test -f Makefile.am && test -n "`grep 'stamp-h\.in' Makefile.in`" \
226      && echo timestamp > stamp-h.in
227  )
228  done
229  ;;
230
231autoreconf)
232  AUTORECONF=${AUTORECONF-autoreconf}
233  if test -z "$AUTORECONF"; then
234    echo "You must have autoreconf installed to run $program"
235    exit 1
236  fi
237
238  confs=`find . -name 'configure.ac' -print`
239  for i in $confs; do
240  dir=`dirname $i`
241  configure=`basename $i`
242  ( test "$quiet" = "true" || echo "$dir"
243    cd $dir
244    test -n "`grep RTEMS_CHECK_BSPDIR ${configure}`" && \
245      generate_bspdir_acinclude
246    ${AUTORECONF} -i --no-recursive $verbose
247    test -f Makefile.am && test -n "`grep 'stamp-h\.in' Makefile.in`" \
248      && echo timestamp > stamp-h.in
249  )
250  done
251  ;;
252
253clean)
254  test "$quiet" = "true" || echo "removing automake generated Makefile.in files"
255  files=`find . -name 'Makefile.am' -print | sed -e 's%\.am%\.in%g'`
256  for i in $files; do
257    if test -f $i; then
258      rm -f $i
259      test "$verbose" = "-v" && echo "$i"
260    fi
261  done
262
263  test "$quiet" = "true" || echo "removing configure files"
264  files=`find . -name 'configure' -print`
265  for i in $files; do
266    if test -f $i; then
267      rm -f $i
268      test "$verbose" = "-v" && echo "$i"
269    fi
270  done
271
272  if test $force -gt 0; then
273    needles=""
274    if test $force -gt 1; then
275      # Manually maintained
276      needles="$needles config.sub"
277      needles="$needles config.guess"
278    fi
279    if test $force -gt 0; then
280      # Inherited from automake
281      needles="$needles compile"
282      needles="$needles depcomp"
283      needles="$needles install-sh"
284      needles="$needles missing"
285      needles="$needles mdate-sh"
286    fi
287    for j in $needles; do
288      files=`find . -name "$j" -print`
289      for i in $files; do
290        if test -f $i; then
291          rm -f $i
292          test "$verbose" = "-v" && echo "$i"
293        fi
294      done
295    done
296  fi
297
298  test "$quiet" = "true" || echo "removing aclocal.m4 files"
299  files=`find . -name 'aclocal.m4' -print`
300  test "$verbose" = "-v" && test -n "$files" && echo "$files"
301  for i in $files; do
302    if test -f $i; then
303      rm -f $i
304      test "$verbose" = "-v" && echo "$i"
305    fi
306  done
307
308  find . -name '*~' -print | xargs rm -f
309  find . -name 'bspopts.h.in' -print | xargs rm -f
310  find . -name '*.orig' -print | xargs rm -f
311  find . -name '*.rej' -print | xargs rm -f
312  find . -name 'config.status' -print | xargs rm -f
313  find . -name 'config.log' -print | xargs rm -f
314  find . -name 'config.cache' -print | xargs rm -f
315  find . -name 'Makefile' -print | xargs rm -f
316  find . -name '.deps' -print | xargs rm -rf
317  find . -name '.libs' -print | xargs rm -rf
318  find . -name 'stamp-h.in' | xargs rm -rf
319  find . -name 'autom4te*.cache' | xargs rm -rf
320  ;;
321esac
322
323exit 0
Note: See TracBrowser for help on using the repository browser.