beta-0.89.2
[luatex.git] / source / texk / kpathsea / mktextfm
blob46e30a9c5dce1d635eb34bea70ae60fc2acc15ea
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 # Primarily written by Thomas Esser, Karl Berry, and Olaf Weber.
8 # Public domain.
10 version='$Id: mktextfm 34656 2014-07-18 23:38:50Z karl $'
11 progname=`echo $0 | sed 's%.*/%%'`
13 # preferentially use subprograms from our own directory.
14 mydir=`echo "$0" | sed 's,/[^/]*$,,'`
15 mydir=`cd "$mydir" && pwd`
16 PATH="$mydir:$PATH"; export PATH
18 usage="Usage: $progname [--destdir DESTDIR] FONT.
20 Makes a TFM file for FONT, if possible. Use DESTDIR for the root of where
21 to install into, either the absolute directory name to use (if it starts
22 with a /) or relative to the default DESTDIR (if not).
24 Report bugs to: tex-k@tug.org
25 TeX Live home page: <http://tug.org/texlive/>
28 # Handle non-positional options, except for --version/--help
29 while test $# -gt 0; do
30 case "$1" in
31 --destdir) shift; DEST="$1"; shift ;;
32 --destdir=*) DEST=`echo "$1" | sed 's/--destdir=//'`; shift ;;
33 --version|-version) break ;;
34 --help|-help) break ;;
35 *) break ;;
36 esac
37 done
39 # Common code for all scripts.
40 : ${MT_TEXMFMAIN=`kpsewhich --expand-path='$TEXMFMAIN'`}
41 : ${MT_MKTEX_OPT=`kpsewhich --format='web2c files' mktex.opt`}
42 test -n "$MT_MKTEX_OPT" || MT_MKTEX_OPT="$MT_TEXMFMAIN/web2c/mktex.opt"
43 if test ! -f "$MT_MKTEX_OPT"; then
44 echo "$progname: Cannot find mktex.opt; check your installation." >&2
45 exit 1
48 . "$MT_MKTEX_OPT"
50 # Where do potential mf driver files go?
51 case "$MT_FEATURES" in
52 *nomfdrivers*)
53 : ${MT_MFDESTDIR=`pwd`}
54 export MT_MFDESTDIR;;
55 esac
57 # start of redirection stdout -> stderr, stdin <- /dev/null
60 NAME=`basename "$1" .tfm`
61 MAG=1 # mag=0 fails with larm1000.mf
62 #DEST="$2"
63 DPI=$BDPI
65 OIFS=$IFS; IFS=$SEP
66 set x `"$MT_MKTEXNAM" $NAME $DPI $MODE $DEST`; shift
67 IFS=$OIFS
69 PKDEST="$1"
70 TFMDEST="$2"
71 PKDESTDIR=`echo "$PKDEST" | sed 's%/[^/][^/]*$%%'` # can't rely on dirname
72 TFMDESTDIR=`echo "$TFMDEST" | sed 's%/[^/][^/]*$%%'`
73 PKNAME=`basename "$PKDEST"`
74 TFMNAME=$NAME.tfm
75 GFNAME=$NAME.$DPI'gf'
77 if test -r "$TFMDESTDIR/$TFMNAME"; then
78 echo "$progname: $TFMDESTDIR/$TFMNAME already exists." >&2
79 echo "$TFMDESTDIR/$TFMNAME" >$STDOUT
80 "$MT_MKTEXUPD" "$TFMDESTDIR" $TFMNAME
81 exit
84 # Try to create the destdir first. Do not create fonts, if this fails.
85 "$MT_MKTEXDIR" "$TFMDESTDIR"
86 if test ! -d "$TFMDESTDIR"; then
87 echo "$progname: mktexdir $TFMDESTDIR failed."
88 exit 1
91 # Check if this font is supported by hbf2gf else use metafont.
92 if (hbf2gf -q -t $NAME) >/dev/null 2>&1; then
93 cmd="hbf2gf -g $NAME $DPI"
94 else
95 # determine the progname of metafont to use; prefer mf-nowin.
96 if (mf-nowin --version) >/dev/null 2>&1; then
97 MF="mf-nowin -progname=mf"
98 else
99 MF=mf
102 cmd="$MF \mode:=$MODE; mag:=$MAG; nonstopmode; input $NAME"
105 echo "$progname: Running $cmd"
106 $cmd </dev/null || {
107 # Don't abort if only "Strange path", "bad pos" or "angle(0,0)"
108 # errors occurr.
109 grep '^!' $NAME.log | sort >$$.errs 2>/dev/null
110 grep '^! Strange path' $$.errs >$$.strange 2>/dev/null
111 grep '^! bad pos.' $$.errs >$$.badpos 2>/dev/null
112 grep '^! angle(0,0) is taken as zero.' $$.errs >$$.angle 2>/dev/null
113 cat $$.badpos $$.strange $$.angle | sort > $$.errs_accept
114 if cmp $$.errs $$.errs_accept >/dev/null 2>&1; then
115 test -s $$.strange >/dev/null 2>&1 \
116 && echo "$progname: warning: \`$cmd' caused strange path errors." >&2
117 test -s $$.badpos >/dev/null 2>&1 \
118 && echo "$progname: warning: \`$cmd' caused bad pos errors." >&2
119 test -s $$.angle >/dev/null 2>&1 \
120 && echo "$progname: warning: \`$cmd' caused angle(0,0) errors." >&2
121 else
122 echo "$progname: \`$cmd' failed." >&2
123 test -s $NAME.log && mv -f $NAME.log "$KPSE_DOT"
124 exit 1;
128 # hbf2gf just produces a .pl file:
129 test -r ./$NAME.pl && pltotf ./$NAME.pl $TFMNAME
130 test -r $TFMNAME || { echo "$progname: \`$cmd' failed to make $TFMNAME."; exit 1; }
132 # Install the TFM file carefully, since others may be working simultaneously.
133 # Use cp when mv fails, since DOS will fail mv for deeply-nested directories.
134 mv $TFMNAME "$TFMDESTDIR/tfm$$.tmp" 2>/dev/null \
135 || cp $TFMNAME "$TFMDESTDIR/tfm$$.tmp" || exit 1
136 cd "$TFMDESTDIR" || exit 1
137 chmod `kpsestat -xst,go-w .` tfm$$.tmp
138 test -r $TFMNAME || mv tfm$$.tmp $TFMNAME || exit 1
140 # OK, success with the TFM.
141 "$MT_MKTEXUPD" "$TFMDESTDIR" $TFMNAME
142 echo "$TFMDESTDIR/$TFMNAME" >$STDOUT
143 echo "$progname: $TFMDESTDIR/$TFMNAME: successfully generated." >&2
145 # Since we probably made a GF(->PK) file, too, may as well install it if
146 # it's needed.
147 cd $TEMPDIR
148 if test -r $GFNAME && test ! -f "$PKDESTDIR/$PKNAME"; then
149 gftopk ./$GFNAME $PKNAME || exit 1
150 "$MT_MKTEXDIR" "$PKDESTDIR"
151 mv $PKNAME "$PKDESTDIR/pk$$.tmp" 2>/dev/null \
152 || cp $PKNAME "$PKDESTDIR/pk$$.tmp" || exit 1
153 cd "$PKDESTDIR" || exit 1
154 if test -f $PKNAME; then
155 rm -f pk$$.tmp
156 else
157 chmod `kpsestat -xst,go-w .` pk$$.tmp
158 mv pk$$.tmp $PKNAME
159 "$MT_MKTEXUPD" "$PKDESTDIR" $PKNAME
162 ) 1>&2 </dev/null