head	1.2;
access;
symbols
	fourth_edition:1.2;
locks
	grog:1.2; strict;
comment	@# @;


1.2
date	96.01.03.11.09.36;	author grog;	state Exp;
branches;
next	1.1;

1.1
date	95.12.16.10.59.05;	author grog;	state Exp;
branches;
next	;


desc
@Script to make a makefile for individual chapters of the short book
@


1.2
log
@Checkpoint 4 January 1996
@
text
@# Create the file book.make, which is included by the main
# Makefile.  This is needed because each chapter depends
# on the previous chapter (due to the possibility of changed
# page numbers), so we need to build a chain of dependencies.
#
# Usage:
#   $0 Preface Chapters
#
# $Id: makeshortbookmakefile,v 1.1 1995/12/16 10:59:05 grog Exp grog $
#
# $Log: makeshortbookmakefile,v $
# Revision 1.1  1995/12/16  10:59:05  grog
# Initial revision
#
# Revision 1.3  1995/12/11  14:14:23  grog
# Checkpoint 12 December
#
# Revision 1.2  1995/12/04  19:00:20  grog
# First final draft
#
# Revision 1.1  1995/10/31  16:03:38  grog
# Initial revision
#
#
# HEIGHT is the real height of the paper
HEIGHT=8.5i
# WIDTH should be 1.7" less than the real width of the paper
WIDTH=5.05i
parms=$*		# save the original parameters
headerstyle=2		# footer on first page, header on following
roffopts="-rex=\${EXAMPLE-SIZE} -r\$\$\$\$ -rL${HEIGHT} -rW${WIDTH} -rN$headerstyle"

echo >book.make "# Makefile generated automatically by $0 on `date`"
echo >>book.make '# Do not edit this file'
echo >>book.make
echo >>book.make HEIGHT = ${HEIGHT}
echo >>book.make WIDTH  = ${WIDTH}

# base=`basename $1 .ps`		# $1 is preface, by convention
# realtarget=Chapter/$base.ps
# echo >>book.make $1 Chapter/$1: '	Xref' $base.mm global.mm \${MACROFILE}
# # echo >>book.make '	@@echo' TARGET: \$@@
# echo >>book.make '	' @@echo +++ Formatting $base to Chapter/00-$base.ps
# echo >>book.make '	' @@\(echo \".af PN i\"\; gsoelim global.mm $base.mm\) \| stripcond short \| \\
# echo >>book.make '	'  \${PIC} \| \${TBL} \| \\
# echo >>book.make '	' groff $roffopts -mpic \${MACROFILE} -  \\
# echo >>book.make '	' \>Chapter/00-$base.ps 2\>Toc/$base
# echo >>book.make '	'@@-egrep -v ^\'Chapter\|File\|\>\<\'  Toc/$base
# echo >>book.make '	'@@echo 1 '>' Toc/$base.firstafter
# echo >>book.make '	'@@rm -f $realtarget\; ln Chapter/00-$base.ps $realtarget
# echo >>book.make

previous=preface.ps
while [ "$1" != "" ]; do
  base=`basename $1 .ps`
  realtarget=Chapter/$base.ps
  startpage=Toc/`basename $previous .ps`.firstafter	# file with start page number
  echo >> book.make $1 Chapter/$1:  Chapter/$previous $base.mm global.mm \${MACROFILE}
# echo >>book.make '	@@echo' TARGET: \$@@
  echo >>book.make '	' @@title=$base\; \\
  echo >>book.make '	 ' read \< $startpage page\; \\
  echo >>book.make '	 ' echo -n \"+++ Chapter \$\$title starts on page \$\$page \"\; \\
  echo >>book.make '	' \(echo \".pn \$\$page\"\; gsoelim global.mm \$\$title.mm\) \| stripcond short \| \\
  echo >>book.make '	  ' \${PIC} \| \${TBL} \| \\
  echo >>book.make '	  ' groff $roffopts -mpic \${MACROFILE} -  \\
  echo >>book.make '	  ' \>$realtarget.tmp 2\>Toc/\$\$title\; \\
  echo >>book.make '	' exitcode=\$\$?\; \\
  echo >>book.make '	' mv $realtarget.tmp $realtarget\; \\
  echo >>book.make '	' chapter=\`awk \< Toc/\$\$title \'/Chapter/ {chapter = \$\$2}\; END {print chapter}\'\`\; \\
  echo >>book.make '	' chapter=\`basename \$\$chapter ,\`\; \\
  echo >>book.make '	' startpage=\$\$page\; \\
  echo >>book.make '	' page=\`awk \< $realtarget \'/%%Page:/ {page=\$\$2 }\; END {print page}\'\`\; \\
  echo >>book.make '	' if [ \$\$chapter -lt 10 ]\; then \\
  echo >>book.make '	  ' filename=Chapter/0\$\$chapter-\$\$title.ps\; \\
  echo >>book.make '	' else \\
  echo >>book.make '	  ' filename=Chapter/\$\$chapter-\$\$title.ps\; \\
  echo >>book.make '	' fi\; \\
  echo >>book.make '	' echo -n \"and ends on page \$\$page \"\; \\
  echo >>book.make '	' page=\`expr \$\$page + 1\`\; \\
  echo >>book.make '	' echo  \\\(\`expr \$\$page - \$\$startpage\` pages\\\): \$\$filename\; \\
  echo >>book.make '	' if [ \`expr \$\$page % 2 \` -eq 0 ]\; then \\
  echo >>book.make '	  ' echo \"    \(Last page is blank\)\"\; \\
  echo >>book.make '	  ' page=\`expr \$\$page + 1\`\; \\
  echo >>book.make '	' fi\; \\
  echo >>book.make '	' echo \$\$page \> Toc/\$\$title.firstafter\; \\
  echo >>book.make '	' egrep -v ^\'Chapter\|File\|\>\<\'  Toc/\$\$title\; \\
  echo >>book.make '	' rm -f \$\$filename\; \\
  echo >>book.make '	' ln $realtarget \$\$filename\; \\
  echo >>book.make '	' if [ \$\$exitcode -ne 0 ]\; then \\
  echo >>book.make '	  ' echo \"*** Exit code \$\$exitcode - format aborted\"\; \\
  echo >>book.make '	' fi
  echo >>book.make
  if [ "$2" = "" ]; then
    echo >> book.make all: '	' Chapter Toc Chapter/$base.ps Book.Toc
  fi
  previous=$1
  shift
done

lastchapter=$base		# for index
startpage=Toc/`basename $previous .ps`.firstafter	# file with start page number of index
# Table of contents, preface and index
echo >>book.make
for base in toc preface index; do
   realtarget=Chapter/$base.ps
   echo >>book.make $base.ps Chapter/$base.ps: '	Xref' $base.mm global.mm \${MACROFILE}
   # echo >>book.make '	@@echo' TARGET: \$@@
   echo >>book.make '	' @@echo +++ Formatting $base to Chapter/$base.ps
   if [ "$base" = "index" ]; then		     # arabic page numbers
     echo >>book.make '	 ' @@read \< $startpage page\; \\
     echo >>book.make '	' \(echo \".pn \$\$page\"\; gsoelim global.mm $base.mm\) \| stripcond long \| \\
   else if [ "$base" = "toc" ]; then
     echo >>book.make '	' @@\(gsoelim global.mm $base.mm\) \| \\
   else				# preface
# We have a problem with the preface.  Its page number depends on the size of 
# the table of contents, which depends on the rest of the book down to the
# preface: a perfect circular dependency.  Bet that it won't change too much,
# and ignore the dependency.
     echo >>book.make '	 ' @@read \< Toc/toc.firstafter page\; \\
     echo >>book.make '	' \(echo \".pn \$\$page\"\; gsoelim global.mm $base.mm\) \| stripcond long \| \\
   fi; fi
   echo >>book.make '	'  \${PIC} \| \${TBL} \| \\
   echo >>book.make '	' groff $roffopts -mpic \${MACROFILE} -  \\
   echo >>book.make '	' \>Chapter/$base.ps 2\>Toc/$base
   echo >>book.make '	'@@-egrep -v ^\'Chapter\|File\|\>\<\'  Toc/$base
   if [ "$base" = "toc" ]; then
     echo >>book.make '	' page=\`awk \< $realtarget \'/%%Page:/ {page=\$\$2 }\; END {print page}\'\`\; \\
     echo >>book.make '	' page=\`expr \$\$page + 1\`\; \\
     echo >>book.make '	' if [ \`expr \$\$page % 2 \` -eq 0 ]\; then \\
     echo >>book.make '	  ' page=\`expr \$\$page + 1\`\; \\
     echo >>book.make '	' fi\; \\
     echo >>book.make '	' echo \$\$page \> Toc/$base.firstafter\; \\
   else if [ "$base" = "preface" ]; then
     echo >>book.make '	'@@echo 1 '>' Toc/$base.firstafter
   fi; fi
   echo >>book.make
done

@


1.1
log
@Initial revision
@
text
@d9 1
a9 1
# $Id: makebookmakefile,v 1.3 1995/12/11 14:14:23 grog Exp $
d11 4
a14 1
# $Log: makebookmakefile,v $
d25 4
a29 2
pagelength=${HEIGHT}		# value to set page length to
pagewidth=${WIDTH}		# and width
d31 1
a31 1
roffopts="-rex=\${EXAMPLE-SIZE} -r\$\$\$\$ -rL$pagelength -rW$pagewidth -rN$headerstyle"
d36 2
@
