New version from texlive
[mplib] / src / texk / kpathsea / mktextfm
1 #!/bin/sh
2 # original mktextfm -- make a new TFM file, because one wasn't found.
3
4 # (If you change or delete the word `original' on the previous line,
5 # installation won't write this script over yours.)
6
7 # te@dbs.uni-hannover.de, kb@mail.tug.org, and infovore@xs4all.nl.
8 # Public domain.
9
10 version='$Id: mktextfm,v 1.27 2004/07/03 19:25:15 olaf Exp $'
11 progname=`echo $0 | sed 's%.*/%%'`
12 usage="Usage: $progname [--destdir DESTDIR] FONT.
13
14 Makes a TFM file for FONT, if possible. Use DESTDIR for the root of where
15 to install into, either the absolute directory name to use (if it starts
16 with a /) or relative to the default DESTDIR (if not)."
17
18 # Handle non-positional options, except for --version/--help
19 while test $# -gt 0; do
20   case "$1" in
21     --destdir) shift; DEST="$1"; shift ;;
22     --destdir=*) DEST=`echo "$1" | sed 's/--destdir=//'`; shift ;;
23     --version|-version) break ;;
24     --help|-help) break ;;
25     *) break ;;
26   esac
27 done
28
29 # Common code for all scripts.
30 : ${MT_TEXMFMAIN=`kpsewhich --expand-path='$TEXMFMAIN'`}
31 : ${MT_MKTEX_OPT=`kpsewhich --format='web2c files' mktex.opt`}
32 test -n "$MT_MKTEX_OPT" || MT_MKTEX_OPT="$MT_TEXMFMAIN/web2c/mktex.opt"
33 if test ! -f "$MT_MKTEX_OPT"; then
34   echo "$progname: Cannot find mktex.opt; check your installation." >&2
35   exit 1
36 fi
37
38 . "$MT_MKTEX_OPT"
39
40 # Where do potential mf driver files go?
41 case "$MT_FEATURES" in
42   *nomfdrivers*)
43      : ${MT_MFDESTDIR=`pwd`}
44      export MT_MFDESTDIR;;
45 esac
46
47 # start of redirection stdout -> stderr, stdin <- /dev/null
48 (
49
50 NAME=`basename "$1" .tfm`
51 MAG=0
52 #DEST="$2"
53 DPI=$BDPI
54
55 OIFS=$IFS; IFS=$SEP
56 set x `"$MT_MKTEXNAM" $NAME $DPI $MODE $DEST`; shift
57 IFS=$OIFS
58
59 PKDEST="$1"
60 TFMDEST="$2"
61 PKDESTDIR=`echo "$PKDEST" | sed 's%/[^/][^/]*$%%'` # can't rely on dirname
62 TFMDESTDIR=`echo "$TFMDEST" | sed 's%/[^/][^/]*$%%'`
63 PKNAME=`basename "$PKDEST"`
64 TFMNAME=$NAME.tfm
65 GFNAME=$NAME.$DPI'gf'
66
67 if test -r "$TFMDESTDIR/$TFMNAME"; then
68   echo "$progname: $TFMDESTDIR/$TFMNAME already exists." >&2
69   echo "$TFMDESTDIR/$TFMNAME" >$STDOUT
70   "$MT_MKTEXUPD" "$TFMDESTDIR" $TFMNAME
71   exit
72 fi
73
74 # Try to create the destdir first. Do not create fonts, if this fails.
75 "$MT_MKTEXDIR" "$TFMDESTDIR"
76 if test ! -d "$TFMDESTDIR"; then
77   echo "$progname: mktexdir $TFMDESTDIR failed."
78   exit 1
79 fi
80
81 # Check if this font is supported by hbf2gf else use metafont.
82 if (hbf2gf -q -t $NAME) >/dev/null 2>&1; then
83   cmd="hbf2gf -g $NAME $DPI"
84 else
85   # determine the progname of metafont to use; prefer mf-nowin.
86   if (mf-nowin --version) >/dev/null 2>&1; then
87     MF="mf-nowin -progname=mf"
88   else
89     MF=mf
90   fi
91
92   cmd="$MF \mode:=$MODE; mag:=$MAG; nonstopmode; input $NAME"
93 fi
94
95 echo "$progname: Running $cmd"
96 $cmd </dev/null || {
97   # Don't abort if only "Strange path", "bad pos" or "angle(0,0)"
98   # errors occurr.
99   grep '^!' $NAME.log | sort >$$.errs 2>/dev/null
100   grep '^! Strange path' $$.errs >$$.strange 2>/dev/null
101   grep '^! bad pos.' $$.errs >$$.badpos 2>/dev/null
102   grep '^! angle(0,0) is taken as zero.' $$.errs >$$.angle 2>/dev/null
103   cat $$.badpos $$.strange $$.angle | sort > $$.errs_accept
104   if cmp $$.errs $$.errs_accept >/dev/null 2>&1; then
105     test -s $$.strange >/dev/null 2>&1 \
106       && echo "$progname: warning: \`$cmd' caused strange path errors." >&2
107     test -s $$.badpos >/dev/null 2>&1 \
108       && echo "$progname: warning: \`$cmd' caused bad pos errors." >&2
109     test -s $$.angle >/dev/null 2>&1 \
110       && echo "$progname: warning: \`$cmd' caused angle(0,0) errors." >&2
111   else
112     echo "$progname: \`$cmd' failed." >&2
113     test -s $NAME.log && mv -f $NAME.log "$KPSE_DOT"
114     exit 1;
115   fi
116 }
117
118 # hbf2gf just produces a .pl file:
119 test -r ./$NAME.pl && pltotf ./$NAME.pl $TFMNAME
120 test -r $TFMNAME || { echo "$progname: \`$cmd' failed to make $TFMNAME."; exit 1; }
121
122 # Install the TFM file carefully, since others may be working simultaneously.
123 # Use cp when mv fails, since DOS will fail mv for deeply-nested directories.
124 mv $TFMNAME "$TFMDESTDIR/tfm$$.tmp" 2>/dev/null \
125   || cp $TFMNAME "$TFMDESTDIR/tfm$$.tmp" || exit 1
126 cd "$TFMDESTDIR" || exit 1
127 chmod `kpsestat -xst,go-w .` tfm$$.tmp
128 test -r $TFMNAME || mv tfm$$.tmp $TFMNAME || exit 1
129
130 # OK, success with the TFM.
131 "$MT_MKTEXUPD" "$TFMDESTDIR" $TFMNAME
132 echo "$TFMDESTDIR/$TFMNAME" >$STDOUT
133 echo "$progname: $TFMDESTDIR/$TFMNAME: successfully generated." >&2
134
135 # Since we probably made a GF(->PK) file, too, may as well install it if
136 # it's needed.
137 cd $TEMPDIR
138 if test -r $GFNAME && test ! -f "$PKDESTDIR/$PKNAME"; then
139   gftopk ./$GFNAME $PKNAME || exit 1
140   "$MT_MKTEXDIR" "$PKDESTDIR"
141   mv $PKNAME "$PKDESTDIR/pk$$.tmp" 2>/dev/null \
142     || cp $PKNAME "$PKDESTDIR/pk$$.tmp" || exit 1
143   cd "$PKDESTDIR" || exit 1
144   if test -f $PKNAME; then
145     rm -f pk$$.tmp
146   else
147     chmod `kpsestat -xst,go-w .` pk$$.tmp
148     mv pk$$.tmp $PKNAME
149     "$MT_MKTEXUPD" "$PKDESTDIR" $PKNAME
150   fi
151 fi
152 ) 1>&2 </dev/null