summaryrefslogtreecommitdiff
path: root/config/bootstrap.shlib
blob: b88e60590802c7e82a2558511d3642d635a22d17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#! /bin/echo This_file_must_be_sourced,_not_executed
# config/bootstrap.local --- maintainer's bootstrap script
#
# Author:            Bruce Korb <bkorb@gnu.org>
# Time-stamp:        "2012-05-12 20:07:23 bkorb"
##
##  This file is part of AutoGen.
##  AutoGen Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
##
##  AutoGen is free software: you can redistribute it and/or modify it
##  under the terms of the GNU General Public License as published by the
##  Free Software Foundation, either version 3 of the License, or
##  (at your option) any later version.
##
##  AutoGen is distributed in the hope that it will be useful, but
##  WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
##  See the GNU General Public License for more details.
##
##  You should have received a copy of the GNU General Public License along
##  with this program.  If not, see <http://www.gnu.org/licenses/>.

# This file contains various utility functions for the "bootstrap" scripts
# that are scattered about.

mainpid=$$

die() {
    echo "bootstrap failure:  $*" >&2
    kill -9 ${mainpid}
    exit 1
}

doit ()
{
    if test "x$1" != x:
    then
        echo "RUN:  $*"
        eval "$@" || exit 1
    fi
}

case `set -o` in
*posix*) set -o posix  ;;
*) exec bash $0 ${1+"$@"} ;;
esac

case "${SHELL}" in
*[akz]sh) : ;;
*)
  while : ; do
    SHELL=`which bash 2>/dev/null`
    test -x "${SHELL}" && break

    SHELL=`which ksh 2>/dev/null`
    test -x "${SHELL}" && break

    SHELL=/usr/xpg4/bin/sh
    test -x "${SHELL}" && break

    SHELL=`which sh 2>/dev/null`
    test -x "${SHELL}" && break

    die "unable to determine which shell to use"
  done
  ;;
esac

case "${VERBOSE}" in
[tTyY1]* ) VERBOSE=true ;;
[fFnN0]* ) VERBOSE=false ;;
* )
    case "$-" in
    *x* )  VERBOSE=true ;;
    *   )  VERBOSE=false ;;
    esac
esac

if ${VERBOSE}
then setx=set\ -x dashx=-x ; set -x
else setx=:       dashx=   ; set +x
fi

test -n "${BASH_VERSION}" || {
    local() {
        "$@"
    }
}

test -z "${BASH_VERSION}" && local() { : ; }
# Setup run_ag
tpl_dir='-L'$(\cd ${top_srcdir}/autoopts/tpl && pwd)' -L'$(
    \cd ${top_builddir}/autoopts/tpl && pwd)
typeset -r tpl_dir

if ${VERBOSE}
then
    # vgopts='--suppressions=/old-home/bkorb/ag/valgrind.conf --leak-check=yes'
    # valgrind ${vgopts} --log-file=${vgfile} \

    run_ag()
    {
        local tag=${1} ; shift
        # local vgfile=/tmp/vglog/${tag}-%p.txt
        local tfile='>>'ag-${tag}-$$.log
        if test -n "$DEPFILE"
        then tag="-MTstamp-${tag} -MF${DEPFILE} -MP"
        else tag="-MFstamp-${tag} -MP"
        fi
        tag="${tag} --trace=every --trace-out=${tfile}"

        MALLOC_CHECK_=2 \
            ${AGexe} ${tpl_dir} ${tag} "$@" || die "FAILED: ${AGexe} $*"
    }
else
    run_ag()
    {
        # local vgfile=/tmp/vglog/${1}-%p.txt
        if test -n "$DEPFILE"
        then tag="-MTstamp-${1} -MF${DEPFILE} -MP"
        else tag="-MFstamp-${1} -MP"
        fi
        shift

        echo ${AGexe} ${tpl_dir} ${tag} "$@"
        ${AGexe} ${tpl_dir} ${tag} "$@" || die "FAILED: ${AGexe} $*"
    }
fi

trap 'die "trapped exit signal"' 0

test "X${CDPATH}" = X || {
    ( unset CDPATH ) > /dev/null 2>&1 && unset CDPATH || CDPATH=''
}

nl=$'\n'
ht=$'\t'
GREP=$(command -v grep)
EGREP=${GREP}\ -E
FGREP=${GREP}\ -F

export setx dashx VERBOSE nl ht

# # # # # # # # # # # # # # # # # # #
#
# Make the option processing files:
#
make_opts()
{
    # Make the option processing files:
    #
    if [ -z "${AGexe}" ]
    then
      test "X${BOOTSTRAP}" = X \
        && echo "Cannot locate ${AG}.  Giving up"
      if [ -f opts.h ] && [ -f opts.c ]
      then exit 0 ; else exit 1 ; fi
    fi
    run_ag opts ${DEBUG_OPTS} *opts.def
}

# # # # # # # # # # # # # # # # # # #
#
#  Make the proto.h header & make sure the static proc declarations
#  are all current at the top of each module.
#
make_proto()
{
    local target=stamp-proto temp_proto=proto-h$$ proto_h=proto.h
    echo '#' stamped `date` > ${target}-$$

    exec 5> $temp_proto

    local files=`ls -1 *.c | grep -v 'fsm\.c$'`
    local dirname=
    local base_dir=`basename \`pwd\``
    local marker=`echo ${base_dir} | tr a-z A-Z`_PROTO_H_GUARD
    local ct=0

    cat >&5 <<- _EOF_
	/* -*- buffer-read-only: t -*- vi: set ro:
	 *
	 * Prototypes for ${base_dir}
	 * Generated `date`
	 */
	#ifndef ${marker}
	#define ${marker} 1

	#ifndef LOCAL
	#  define LOCAL extern
	#  define REDEF_LOCAL 1
	#else
	#  undef  REDEF_LOCAL
	#endif
	_EOF_

    for f in ${files}
    do
        test ! -f ${f} && echo "not a file:  $f" >&2 && continue
        ct=`echo \`egrep '(START|END)-STATIC-FORWARD' $f | wc -l\` `

        case ${ct} in
        ( 2 )
            rm -f $f.[XY]

            exec 4> $f.X
            sed '/START-STATIC-FORWARD/q' $f >&4
            sed -n '/END-STATIC-FORWARD/,$p' $f > $f.Y
            sed -n '/^static /,/^{/p' $f.Y | \
                sed 's/^{.*//;s/)$/);/;$d' >&4
            cat $f.Y >&4
            exec 4>&-

            if cmp $f.X $f > /dev/null 2>&1
            then :
            else echo WARNING: ${f} has been updated >&2
                mv -f $f.X $f ; fi

            rm -f $f.[XY]
            ;;

        ( 0 ) : ;;
        ( * )
            echo "bad marker line count:" $ct in $f >&2
            continue
        esac

        ct=`echo \`egrep '^LOCAL ' $f | wc -l\` `
        test $ct -eq 0 && continue

        echo $'/*\n *  Extracted from '$f$'\n */' >&5
        sed -n '/^LOCAL /,/^{/p' $f | \
            sed 's/)$/);/;s/^{.*//' >&5
    done

    cat >&5 <<- _EOF_
	#ifdef REDEF_LOCAL
	#  undef LOCAL
	#  define LOCAL
	#endif
	#endif /* ${marker} */
	_EOF_
    exec 5>&-

    if cmp -s ${temp_proto} ${proto_h}
    then
        rm -f ${temp_proto}
        if test -f 
        then
            rm -f ${target}-$$
        else
            mv -f ${target}-$$  ${target}
            touch ${proto_h}
        fi
    else
        mv -f ${temp_proto} ${proto_h}
        mv -f ${target}-$$  ${target}
    fi
}

# Local Variables:
# mode:shell-script
# sh-indentation:4
# sh-basic-offset:4
# indent-tabs-mode: nil
# End:

# bootstrap.shlib ends here