summaryrefslogtreecommitdiff
path: root/agen5/mk-stamps.sh
blob: 1c841f53885dcc9f3064471a286fefa961a0ed1e (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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#! /bin/echo This_file_must_be_sourced,_not_executed
#
# agen5/mk-stamps.sh
#
##  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 script rebuilds sources not kept in the GIT repository.
#  These files are distributed, so it is not necessary to invoke
#  AutoGen before building AutoGen.

#  "make" will invoke this file with the name of the desired output
#  as an argument.  We do this here rather than in the make file
#  because some of the rules are complex and we don't want to
#  deal with the dual update problem.

if test -z "$mainpid"
then
    . ${top_srcdir}/config/bootstrap.shlib
    . ${top_builddir}/config/shdefs
fi

set_defaults()
{
    local AGnam=autogen
    local GDnam=getdefs
    local CLnam=columns
    local AGdir=agen5
    local GDdir=getdefs
    local CLdir=columns
    local f n b v

    for v in AG GD CL
    do
        eval f=\${${v}exe}
        eval n=\${${v}nam}
        eval b=${top_builddir}/\${${v}dir}/\${${v}nam}
        if test -x "$b"
        then
            f=$b

        elif ! test -x "$f"
        then
            f=`command -v $n`
            test -x "${f}" || die "$n is required"
        fi
        eval $v=$f
        export $v
    done

    if ! test -x ${AGexe}
    then
        run_ag() {
            touch stamp-${1}
            touch ${target}
        }
    fi

    #  Make sure we have a default for top build and source.
    #  Some of the templates need this information.
    #
    local verdata=`${EGREP} '^AG_' ${top_srcdir}/VERSION | \
       sed 's,^\(AG[^=]*\)\(.*\),\1\2 export \1,'`
    eval "${verdata}"

    #  disable any $HOME defaults
    #
    HOME=/dev/null
    SHELL=${POSIX_SHELL-/bin/sh}

    ${VERBOSE:-false} && set -x || :
    #  Ensure complete success or a noticable failure
    #
    set -e
}

# # # # # # # # # # # # # # # # # # #
#
# Make the definition parser
#
make_parse()
{
    local opts=''

    test ${#DEBUG_ENABLED} -gt 0 && \
        opts=-DDEBUG_ENABLED

    run_ag parse ${opts} defParse.def
}

# # # # # # # # # # # # # # # # # # #
#
# Make the pseudo-macro processing Finite State Machine
#
make_cgi()
{
    run_ag cgi cgi.def
}

make_pseudo()
{
    run_ag pseudo pseudo.def
    rm -f .fsm.*
}

# # # # # # # # # # # # # # # # # # #
#
# Make the expression processing code
#
# NOTE: the expr.test test extracts this function!!
#
make_exprini()
{
    #  funcCase.c must be first file in list.
    #  It has the exparg attribute names.
    #
    exec 3> expr.cfg
    cat >&3 <<- _EOConfig_
	defs-to-get gfunc
	template    snarf
	srcfile
	assign      two-phase = yes
	assign      group     = ag
	output      expr.def
	subblock    exparg    = arg_name,arg_desc,arg_optional,arg_list
	_EOConfig_

    test ${#DEBUG_ENABLED} -gt 0 && \
        printf '%-15s %s\n' assign 'debug-enabled = true' >&3

    for f in func*.c exp*.c agShell.c
    do echo input ${f} ; done >&3
    exec 3>&-

    echo ${GDexe} load=expr.cfg
    set +e
    ( SHELL=sh ${GDexe} load=expr.cfg ${files} 2>&1 ) | \
      ${EGREP} -v 'no copies of pattern' >&2
    set -e
    run_ag exprini expr.def
    rmlist=${rmlist}\ expr.cfg
}

# # # # # # # # # # # # # # # # # # #
#
#  Make the directive.h header
#
make_directive()
{
    cat > directive.cfg <<- _EOConfig_
	defs-to-get    directive
	template       directive
	output         directive.def
	linenum
	_EOConfig_

    ${GDexe} load=directive.cfg ${srcdir}/defDirect.c
    run_ag directive -t30 directive.def
    rmlist=${rmlist}\ directive.cfg
}

# # # # # # # # # # # # # # # # # # #
#
# Construct the texinfo doc
#
make_texi()
{
    eopt="-Tagtexi-cmd.tpl -DLEVEL=chapter -binvoke-autogen"
    run_ag texi ${eopt} ${srcdir}/opts.def
}

# # # # # # # # # # # # # # # # # # #
#
# Construct the ag-text strings
#
make_ag_text()
{
    run_ag ag_text ${srcdir}/ag-text.def
}

# # # # # # # # # # # # # # # # # # #
#
# Construct the man page
#
make_fmem()
{
    ${GDexe} templ=agman3.tpl linenum output=fmemopen.def ${srcdir}/fmemopen.c
    run_ag fmem fmemopen.def
}

make_man()
{
    run_ag man -Tagman-cmd -DMAN_SECTION=1 ${srcdir}/opts.def
}

# # # # # # # # # # # # # # # # # # #
#
# Construct the function tables
#
make_func()
{
    local files=`${GREP} -l '/\*=macfunc' *.c`
    local opts='srcfile linenum defs=macfunc listattr=alias'

    ${GDexe} output=functions.def template=functions.tpl ${opts} ${files}
    run_ag func functions.def
}

make_gver()
{
    test -f guile-iface.def || make_func
    run_ag gver guile-iface.def
}

dispatch()
{
    if test -d "${DEPDIR}"
    then DEPFILE=./${DEPDIR}/stamp-${1}.d
    else DEPFILE=''
    fi
    eval make_${1}
}

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
#  M A I N
#
PS4='>stmp-${FUNCNAME}> '
set_defaults ${1+"$@"}

#  FOR each output target,
#   DO the appropriate rule...
#
for t
do
    echo Re-building "$t"
    case "$t" in
    stamp-* )
        dispatch ${t#stamp-} ;;

    defParse-fsm.c | defParse-fsm.h )
        dispatch parse ;;

    opts.[ch] )
        dispatch opts ;;

    expr.h | expr.def | expr.ini )
        dispatch exprini ;;

    directive.def | directive.h )
        dispatch directive ;;

    autogen.texi | autogen.menu )
        dispatch texi ;;

    autogen.1 | fmemopen.3 )
        dispatch man ;;

    proto.h )
        dispatch proto ;;

    functions.h )
        dispatch func ;;

    *)  if test `type -t $t` = function 2>/dev/null 1>&2
        then dispatch $t
        else die "Don't know how to make $t"
        fi ;;
    esac
done
assemble_Makefile

rm -f $rmlist ag-*.log

trap '' 0

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

# end of agen5/bootstrap.dir