source: rtems/bootstrap @ a4570829

5
Last change on this file since a4570829 was 4dfeba3, checked in by Amaan Cheval <amaan.cheval@…>, on 03/09/18 at 15:38:31

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
RevLine 
[22fb90e4]1#!/bin/sh
[9b8baa1]2#
[e619c28]3# helps bootstrapping, when checked out from CVS
4# requires GNU autoconf and GNU automake
[9b8baa1]5#
[e619c28]6# this is not meant to be exported outside the source tree
[65c6425]7#
[e619c28]8# NOTE: Inspired by libtool's autogen script
[65c6425]9#
[e619c28]10# to be run from the toplevel directory of RTEMS'
11# source tree
12
13progname=`basename $0`
[df49c60]14top_srcdir=`dirname $0`
15
[2afb22b]16LC_ALL=C
17export LC_ALL
18
[22fb90e4]19verbose=""
[e619c28]20quiet="false"
[fba17c9e]21mode="autoreconf"
[aa96f47]22force=0
[e619c28]23
24usage()
25{
[7e03d10]26  echo
[77fff592]27  echo "usage: ${progname} [-c|-p|-h] [-q][-v]"
[7e03d10]28  echo
29  echo "options:"
[8cdb582]30  echo "        -c .. clean, remove all aclocal/autoconf/automake generated files"
[77fff592]31  echo "        -h .. display this message and exit"
[2afb22b]32  echo "        -H .. regenerate headers.am files"
[77fff592]33  echo "        -q .. quiet, don't display directories"
34  echo "        -v .. verbose, pass -v to autotools"
[7e03d10]35  echo
[22fb90e4]36  exit 1
[e619c28]37}
38
[282cb9c]39generate_bspdir_acinclude()
40{
41cat << EOF > acinclude.m4~
[1d3713ef]42# RTEMS_CHECK_BSPDIR(RTEMS_BSP_FAMILY)
[282cb9c]43AC_DEFUN([RTEMS_CHECK_BSPDIR],
44[
[1d3713ef]45  case "\$1" in
[282cb9c]46EOF
47
[31285e1e]48for i in `echo */make | tr " " "\n" | LANG=C LC_COLLATE=C sort`; do
[282cb9c]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
[22fb90e4]62  echo "acinclude.m4 is unchanged"
[282cb9c]63else
64  cp acinclude.m4~ acinclude.m4
65fi
66rm -f acinclude.m4~
67}
68
[76d527ec]69if test ! -f $top_srcdir/aclocal/version.m4; then
[7e03d10]70  echo "${progname}:"
[76d527ec]71  echo "        Installation problem: Can't find file aclocal/version.m4"
[22fb90e4]72  exit 1
[7e03d10]73fi
74
[e619c28]75while test $# -gt 0; do
76case $1 in
[7e03d10]77-h|--he|--hel|--help)
78  usage ;;
[e619c28]79-q|--qu|--qui|--quie|--quiet)
[22fb90e4]80  quiet="true"
[e619c28]81  shift;;
82-v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
[22fb90e4]83  verbose="-v"
[e619c28]84  shift;;
[8cdb582]85-c|--cl|--cle|--clea|--clean)
[22fb90e4]86  mode="clean"
[8cdb582]87  shift;;
[aa96f47]88-f|--fo|--for|--forc|--force)
89  force=`expr $force + 1`
90  shift;;
[2afb22b]91-H|--headers)
92  mode="headers"
[77fff592]93  shift;;
[3031e6c]94-r|--re|--rec|--reco|--recon|--reconf)
[22fb90e4]95  mode="autoreconf"
[3031e6c]96  shift;;
[fba17c9e]97-g|--ge|--gen|--gene|--gener|--genera|--generat|--generate)
[22fb90e4]98  mode="generate"
[fba17c9e]99  shift;;
[22fb90e4]100-*) echo "unknown option $1"
[e619c28]101  usage ;;
[22fb90e4]102*) echo "invalid parameter $1"
[e619c28]103  usage ;;
104esac
105done
106
[8cdb582]107case $mode in
[2afb22b]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"
[4dfeba3]155            printf "\ninclude%sdir = \$(includedir)/$dir\n" "$am_dir" >> "$tmp"
[2afb22b]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
[4dfeba3]164          echo "include_HEADERS += include/bspopts.h" >> "$tmp"
[2afb22b]165        fi
166      done
167    done
168    cd "$base"
169    diff -q "$tmp" "$i/${hdr}headers.am" || mv "$tmp" "$i/${hdr}headers.am"
[77fff592]170  done
[2afb22b]171  rm -f "$tmp"
[77fff592]172  ;;
173
[8cdb582]174generate)
[d854517]175  AUTOCONF=${AUTOCONF-autoconf}
[58fd5ab]176  if test -z "$AUTOCONF"; then
177    echo "You must have autoconf installed to run $program"
[0b22af6]178    exit 1
[58fd5ab]179  fi
[22fb90e4]180
[0b22af6]181  AUTOHEADER=${AUTOHEADER-autoheader}
182  if test -z "$AUTOHEADER"; then
183    echo "You must have autoconf installed to run $program"
184    exit 1
[58fd5ab]185  fi
[22fb90e4]186
[d854517]187  AUTOMAKE=${AUTOMAKE-automake}
[58fd5ab]188  if test -z "$AUTOMAKE"; then
189    echo "You must have automake installed to run $program"
[0b22af6]190    exit 1
[58fd5ab]191  fi
[22fb90e4]192
[0b22af6]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
[df49c60]199  case $top_srcdir in
[ec6968b]200  /* ) aclocal_dir=$top_srcdir
[df49c60]201    ;;
[ec6968b]202  *) aclocal_dir=`pwd`/$top_srcdir
[df49c60]203    ;;
204  esac
205
[e712997]206  confs=`find . \( -name 'configure.in' -o -name 'configure.ac' \) -print`
[8cdb582]207  for i in $confs; do
[22fb90e4]208  dir=`dirname $i`
209  configure=`basename $i`
210  ( test "$quiet" = "true" || echo "$dir"
211    cd $dir
[282cb9c]212    test -n "`grep RTEMS_CHECK_BSPDIR ${configure}`" && \
[22fb90e4]213      generate_bspdir_acinclude
[ec6968b]214    pat="s,\$(RTEMS_TOPdir),${aclocal_dir},g"
215    aclocal_args=`grep '^[ ]*ACLOCAL_AMFLAGS' Makefile.am | \
[22fb90e4]216      sed -e 's%.*ACLOCAL_AMFLAGS.*\=[ ]*%%g' -e $pat `
[0b22af6]217    test "$verbose" = "-v" && echo "${ACLOCAL} $aclocal_args"
[22fb90e4]218    ${ACLOCAL} $aclocal_args
[0b22af6]219    test -n "`grep CONFIG_HEADER ${configure}`" && ${AUTOHEADER} \
[22fb90e4]220      && test "$verbose" = "-v" && echo "${AUTOHEADER}"
[0b22af6]221    test -n "`grep RTEMS_BSP_CONFIGURE ${configure}`" && ${AUTOHEADER} \
[22fb90e4]222      && test "$verbose" = "-v" && echo "${AUTOHEADER}"
223    test -f Makefile.am && ${AUTOMAKE} -a -c $verbose
224    ${AUTOCONF}
[76ee648c]225    test -f Makefile.am && test -n "`grep 'stamp-h\.in' Makefile.in`" \
226      && echo timestamp > stamp-h.in
[8cdb582]227  )
228  done
229  ;;
[df49c60]230
[3031e6c]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
[22fb90e4]240  dir=`dirname $i`
241  configure=`basename $i`
242  ( test "$quiet" = "true" || echo "$dir"
243    cd $dir
[3031e6c]244    test -n "`grep RTEMS_CHECK_BSPDIR ${configure}`" && \
[22fb90e4]245      generate_bspdir_acinclude
246    ${AUTORECONF} -i --no-recursive $verbose
[3031e6c]247    test -f Makefile.am && test -n "`grep 'stamp-h\.in' Makefile.in`" \
248      && echo timestamp > stamp-h.in
249  )
250  done
251  ;;
252
[8cdb582]253clean)
254  test "$quiet" = "true" || echo "removing automake generated Makefile.in files"
[22fb90e4]255  files=`find . -name 'Makefile.am' -print | sed -e 's%\.am%\.in%g'`
256  for i in $files; do
[aa96f47]257    if test -f $i; then
258      rm -f $i
[22fb90e4]259      test "$verbose" = "-v" && echo "$i"
260    fi
[aa96f47]261  done
[8cdb582]262
263  test "$quiet" = "true" || echo "removing configure files"
[22fb90e4]264  files=`find . -name 'configure' -print`
265  for i in $files; do
[aa96f47]266    if test -f $i; then
267      rm -f $i
268      test "$verbose" = "-v" && echo "$i"
[22fb90e4]269    fi
[aa96f47]270  done
[22fb90e4]271
[aa96f47]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`
[22fb90e4]289      for i in $files; do
[aa96f47]290        if test -f $i; then
291          rm -f $i
292          test "$verbose" = "-v" && echo "$i"
[22fb90e4]293        fi
[aa96f47]294      done
295    done
296  fi
297
[8cdb582]298  test "$quiet" = "true" || echo "removing aclocal.m4 files"
[22fb90e4]299  files=`find . -name 'aclocal.m4' -print`
300  test "$verbose" = "-v" && test -n "$files" && echo "$files"
301  for i in $files; do
[aa96f47]302    if test -f $i; then
303      rm -f $i
[22fb90e4]304      test "$verbose" = "-v" && echo "$i"
305    fi
[aa96f47]306  done
[8cdb582]307
308  find . -name '*~' -print | xargs rm -f
[a5a0db4]309  find . -name 'bspopts.h.in' -print | xargs rm -f
[8cdb582]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
[76ee648c]314  find . -name 'config.cache' -print | xargs rm -f
[6693a68]315  find . -name 'Makefile' -print | xargs rm -f
[8cdb582]316  find . -name '.deps' -print | xargs rm -rf
[76ee648c]317  find . -name '.libs' -print | xargs rm -rf
318  find . -name 'stamp-h.in' | xargs rm -rf
[282cb9c]319  find . -name 'autom4te*.cache' | xargs rm -rf
[8cdb582]320  ;;
321esac
[cf0ed46]322
323exit 0
Note: See TracBrowser for help on using the repository browser.