summaryrefslogtreecommitdiff
path: root/doc/mk-agen-texi.sh
blob: 559ff139778f77ade979934fc4079199c167e3ff (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
299
300
301
302
303
#! /bin/sh

# Time-stamp:        "2012-05-13 13:52:48 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/>.

d=`dirname $0`
d=`cd $d ; pwd`
prog=${d}/`basename $0`
parent_pid=$$

die()
{
  exec 2>&8 1>&2 8>&-
  echo "mk-agen-texi FAILED: $*"
  echo
  cat ${LOG_FILE}
  trap : EXIT
  echo leaving ${TMPDIR} in place
  kill -TERM ${parent_pid}
  exit 1
}

set_config_values()
{
  TMPDIR=`pwd`/ag-texi-$$.d
  rm -rf ag-texi-*.d
  mkdir ${TMPDIR} || die "cannot make ${TMPDIR} directory"
  export TMPDIR

  case "$-" in
  *x* ) trap "echo 'saved tmp dir:  ${TMPDIR}';chmod 777 ${TMPDIR}" EXIT
        VERBOSE=true ;;
  *   ) trap "rm -rf ${TMPDIR}" EXIT
        VERBOSE=false ;;
  esac

  LOG_FILE=${TMPDIR}/texi.log

  exec 8>&2 2> ${LOG_FILE}

  nl='
' ht='	'
  . ${top_builddir}/config/shdefs

  test -z "${MAKE}"   && MAKE=`which make`

  srcdir=`cd ${srcdir} >/dev/null ; pwd`
  INCLUDES="${DEFS} "`

    for d in ${top_srcdir} ${top_builddir} \
             ${top_builddir}/autoopts ${top_srcdir}/autoopts
    do
      (\cd ${d} && pwd) 2>/dev/null
    done | \
      sort -u | \
      sed s/^/-I/ `

  CFLAGS="${INCLUDES} "`echo ${CFLAGS} | \
    ${SED:-sed} -e "s/-Werror[^ ${ht}]*//g;s/-Wextra//g"`

  LIBS=-L`
    test -d ${top_builddir}/autoopts/.libs \
      && echo ${top_builddir}/autoopts/.libs \
      || echo ${top_builddir}/autoopts
    `" $LIBS"

  export CC CFLAGS LIBS MAKE LOG_FILE TMPDIR
}

setup_exports()
{
  # Now auto-export variables:
  #
  set -a

  PATH=${top_builddir}/columns:${PATH}
  timer=`expr ${AG_TIMEOUT} '*' 5`
  d=`find ${top_builddir}/autoopts -type f -name libopts.a -print`
  test -f "$d" || die "Cannot locate libopts.a"
  LIBS="$d ${LIBS}"

  eval `${EGREP} '^AG_[A-Z_]*' ${top_srcdir}/VERSION`

  AGsrc=${top_srcdir}/agen5
  OPTIONS_DEF=${AGsrc}/opts.def
  GETDEF_SRC=`${FGREP} -l '/*=' ${AGsrc}/*.[ch] ${AGsrc}/*.scm`

  AGEN_TEXI=${top_builddir}/agen5/invoke-autogen.texi
  DOC_TEXT=${top_srcdir}/doc/autogen-texi.txt

  ADDON_TEXI="
    ${top_builddir}/columns/invoke-columns.texi
    ${top_builddir}/getdefs/invoke-getdefs.texi
    ${top_builddir}/xml2ag/invoke-xml2ag.texi
    ${top_srcdir}/doc/snprintfv.texi"

  DOC_INCLUDES="
    ${AGsrc}/defParse-fsm.c
    ${AGsrc}/opts.h
    ${top_builddir}/autoopts/libopts.texi
    ${top_srcdir}/doc/autogen-intro.texi
    ${AGEN_TEXI}"

  DOC_TEMPLATE=${top_builddir}/doc/auto_gen.tpl

  DOC_DEPENDS=`
    echo ${DOC_TEMPLATE} ${OPTIONS_DEF} ${ADDON_MENU} ${ADDON_TEXI} \
         ${DOC_INCLUDES} ${GETDEF_SRC}  ${DOC_TEXT}`

  set +a
}

# We have our executables and texi's.  Collect the definitions:
#
run_getdefs()
{
  gd_cfg=${TMPDIR}/getdefs.cfg
  exec 3> ${gd_cfg}
  cat >&3 <<-  EOCat
	output      ${TMPDIR}/${GEN_BASE}.def
	copy        ${OPTIONS_DEF}
	srcfile
	linenum
	template    auto_gen.tpl
	assign      ag-texi = invoke-autogen.texi
	subblock    exparg  = arg_name,arg_desc,arg_optional,arg_list
	EOCat

  tf=invoke-autogen.texi
  test -f ${tf} || ln -s ${AGEN_TEXI} ${tf}

  for f in ${ADDON_TEXI}
  do
    tf=`basename ${f}`
    case "$tf" in
    invoke-* ) : ;;
    * ) tf=invoke-$tf ;;
    esac
    test -f ${tf} || ln -s ${f} ${tf}
    echo "assign      addon-texi = ${tf}"
  done >&3

  for f in ${GETDEF_SRC}
  do
    echo "input      " ${f}
  done >&3
  exec 3>&-
  echo + ${GDexe} load-opt=${gd_cfg} >&8
  ${GDexe} load-opt=${gd_cfg} || die cannot run ${GDexe}
}

sanity_check()
{
  # Make sure the executables are there
  #
  test -x ${AGexe} || (cd `dirname ${AGexe}` ; ${MAKE}) || exit 0
  test -x ${GDexe} || (cd `dirname ${GDexe}` ; ${MAKE}) || exit 0
  test -x ${CLexe} || (cd `dirname ${CLexe}` ; ${MAKE}) || exit 0
  PATH="`dirname ${AGexe}`:`dirname ${CLexe}`:$PATH"

  # See to it that the .texi files have been generated, too.
  #
  for f in ${ADDON_TEXI} ${AGEN_TEXI} \
           ${top_builddir}/autoopts/libopts.texi
  do
    test -f ${f} || (
      cd `dirname ${f}`
      ${MAKE} `basename ${f}` >&2
      test $? -ne 0 && die MAKE of ${f} failed.
    )
  done

  # Make sure we have all our sources and generate the doc
  #
  for f in ${DOC_DEPENDS}
  do test -f ${f} || die cannot find doc file: ${f}
     test -f `basename $f` || ln -s $f .
  done

  cmd=${AGexe}
  ${VERBOSE} && cmd=${cmd}" --trace=every --trace-out=>>${TMPDIR}/ag.log"
}

build_agdoc() {
  #  Validate everything:
  #
  set_config_values
  setup_exports
  sanity_check
  run_getdefs

  VERBOSE=true

  env >&2
  {
    cat <<- _EOF_
	timeout     ${timer}
	templ-dirs  ${srcdir}
	templ-dirs  ${top_srcdir}/autoopts/tpl
	base-name   ${GEN_BASE}
	make-dep    F ${GEN_BASE}.dep
	make-dep    P
	_EOF_
    ${VERBOSE} && false && {
      echo 'trace       every'
      echo "trace-out   >>${TMPDIR}/ag.log"
    }
  } > ${TMPDIR}/ag.ini

  opts="--load-opts=${TMPDIR}/ag.ini"
  cmd=`echo "${cmd}" ${opts} ${TMPDIR}/${GEN_BASE}.def`
  echo "${PS4:-+} " ${cmd} >&8

  ${cmd} || {
    cat ${TMPDIR}/ag.ini ${TMPDIR}/ag.log
    die could not regenerate doc
  } >&2

  test -f ${GEN_BASE}.texi || die "MISSING: ${GEN_BASE}.texi"

  exec 2>&8 8>&-
}

build_gnudocs()
{
  local sedcmd='/^@author @email/ {
    s/.*{//
    s/}.*//
    s/@@*/@/g
    p
    q
  }'

  case "X$-" in
    *x* ) local dashx=-x ;;
    *   ) local dashx=   ;;
  esac

  title=`sed -n 's/^@title  *//p' agdoc.texi`
  email=--email' '`sed -n "$sedcmd" agdoc.texi`
  opts="--texi2html ${email}"
  PS4='>${FUNCNAME:-gd}> ' ${SHELL} ${dashx} \
    ${top_srcdir}/config/gendocs.sh $opts autogen "$title"
}

mk_autogen_texi() {
  tfile=autogen.texi
  page_style=\
'\internalpagesizes{46\baselineskip}{6in}{-.25in}{-.25in}{\bindingoffset}{36pt}%'

  cat > ${tfile}$$ <<- _EOF_
	\\input texinfo
	@ignore
	${page_style}
	@end ignore
	@c %**start of header
	@setfilename ${tfile%.texi}.info
	@include ${GEN_BASE}.texi
	_EOF_

  if test -f ${tfile} && cmp -s ${tfile} ${tfile}$$
  then rm -f ${tfile}$$
  else mv -f ${tfile}$$ ${tfile}
  fi
}

GEN_BASE=agdoc
test "X$1" = X--force && {
  rm -f agdoc.texi
  shift
}
test -f agdoc.texi || build_agdoc
mk_autogen_texi

case "$1" in
gnudocs | gnudoc ) build_gnudocs ;;
* )
esac

exit 0

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