[XeTeX] Patches for XeTeX installation scripts (XeTeX on FreeBSD + more)

Nikola Lecic nlecic at EUnet.yu
Sun Jul 8 05:25:35 CEST 2007


Hello,

Here is what I use to compile XeTeX-dev on my FreeBSD system. I
arranged all necessary modifications and increased verbosity of the
scripts.

Jonathan, do you find some of these changes/additions reasonable?
Although I separated the FreeBSD specific additions, I hope that you
might find useful to include some of them by default (I included some
of them as proposals). In fact, I added a lot of comments and several
questions I'd like to know the answers to, so it's better not to repeat
them here.

I hope this can be a humble contribution towards more *nix-universal
'configure/make/make install' procedure. As for FreeBSD, the full
integration would be Porting; AFAIK the Porting of TL is an ongoing
process, and I'll try to find out what the maintainer is currently
doing. (I'll also propose the addition of what should be, say,
print/xetex-devel port.) In meantime this will do the job.

(Note: This works on FreeBSD with standard TL installation, and I
tested it thoroughly. I don't know about other *BSDs, but I'm sure it
will work as is. Besides that, I haven't tested it with the standard
FreeBSD teTeX install from Ports. Since I have at home FreeBSD only, I
couldn't test if patched scripts still work on Linux etc.)

Nikola Lečić

===================== installation scripts patch =====================
diff -ru xetex-devel-original/build-xetex xetex-devel/build-xetex
--- xetex-devel-original/build-xetex	Sun Jul  8 03:07:52 2007
+++ xetex-devel/build-xetex	Sun Jul  8 04:10:22 2007
@@ -3,8 +3,24 @@
 # Top-level script to compile xetex (and xdv2pdf on OS X)
 # from the source tree as found in Subversion
 
+echo "###### CONFIGURING XETEX"
+
+GNUMAKE="make"
+SHELLCMD="bash"
+if [ "`uname`" = "FreeBSD" ]; then
+	# This is necessary, make = BSD make.
+	GNUMAKE=`which gmake`
+	if [ ! -e "${GNUMAKE}" ]; then
+		echo "### There is no gmake in your system. Install devel/gmake."
+		exit
+	fi
+	# Avoiding bash as the third-party application; although it seems
+       	# to be used in compiling...
+	SHELLCMD="sh"
+fi
+
 # do some cleanup if needed
-test ! -f Makefile || make clean
+test ! -f Makefile || ${GNUMAKE} clean
 rm -rf Work
 find . -name config.cache -print -exec rm -f {} \;
 
@@ -14,27 +30,51 @@
 test -d libs/icu-xetex -o -L libs/icu-xetex || ln -fs icu-release-3-6-source libs/icu-xetex
 
 # run the configure script, which will create a Work subtree
-bash ./runConfigure.sh
+${SHELLCMD} ./runConfigure.sh
+
+echo "###### BUILDING LIBRARIES AND XETEX"
 
 # make libraries first (not handled by the xetex makefile)
 if [ "`uname`" = "Darwin" ]; then
 	LIBS="teckit icu-xetex graphite-engine freetype2"
+elif [ "`uname`" = "FreeBSD" ]; then
+	# A bit easier, building libraries without --with-system-* only
+	LIBS=`find Work/libs -type d -maxdepth 1 -mindepth 1 | \
+		  sed -e 's/Work\/libs\///'`
 else
 	LIBS="teckit icu-xetex graphite-engine freetype2 libpng xpdf"
 fi
+echo "### Libs to be build: ${LIBS}"
 for f in ${LIBS}; do
-	(cd Work/libs/${f} && make)
+	(cd Work/libs/${f} && ${GNUMAKE})
 done
 
 # make the xetex binary
-(cd Work/texk/web2c && make web2cdir=`dirname \`kpsewhich texmf.cnf\`` xetex)
+	# -------
+	# This is the copy of determining the presence of symlinks in
+	# web2c path as reported by kpsewhich (as used in runConfigure.sh);
+	# it would be nice if there is a more elegant way to pass it here.
+	KPSEWHICH=`which kpsewhich`
+	PREFIX=`echo ${KPSEWHICH} | sed -e 's!/bin/.*!/!;'`
+	REALPATHPREFIX=`realpath ${PREFIX}`
+	WEB2CDIR=`dirname \`kpsewhich texmf.cnf\``
+	if [ "`echo ${WEB2CDIR} | sed -e 's!${REALPATHPREFIX}!!'`" = "${WEB2CDIR}" ]; then
+		TMPSUBST="echo ${WEB2CDIR} | sed -e 's!${REALPATHPREFIX}/!${PREFIX}!'"
+		WEB2CDIR=`eval ${TMPSUBST}`
+		echo "### (Repetition) WEB2CDIR seems to contain symlink; honouring it."
+	fi
+	# -------
+echo "### Making xetex binary using: 'cd Work/texk/web2c && ${GNUMAKE} web2cdir=${WEB2CDIR} xetex'"
+(cd Work/texk/web2c && ${GNUMAKE} web2cdir=${WEB2CDIR} xetex)
 PRODUCTS=Work/texk/web2c/xetex
 
-# xdv2pdf is for Mac OS X only, don't try to build on Linux
+# xdv2pdf is for Mac OS X only, don't try to build on Linux or *BSD.
 if [ "`uname`" = "Darwin" ]; then
-	(cd Work/texk/xdv2pdf && make all)
+	(cd Work/texk/xdv2pdf && ${GNUMAKE} all)
 	PRODUCTS="${PRODUCTS} Work/texk/xdv2pdf/xdv2pdf Work/texk/xdv2pdf/T1Wrap"
 fi
 
 # show the executables we made (assuming the build was successful)
+echo "### Products built successfully:"
+find ${PRODUCTS} -type f -exec strip {} \;
 ls -l ${PRODUCTS}
diff -ru xetex-devel-original/install-xetex xetex-devel/install-xetex
--- xetex-devel-original/install-xetex	Sun Jul  8 03:07:52 2007
+++ xetex-devel/install-xetex	Sun Jul  8 03:52:03 2007
@@ -1,4 +1,9 @@
-#!/bin/bash
+#!/bin/sh
+# I'd propose using sh here, avoiding bash as a third-party application
+# on *BSDs; I think that proposed command replacements allows
+# avoiding bash elsewhere, too.
+# If it's not preferred, then this should be conditionally set
+# if uname = "FreeBSD".
 
 # FIXME: this should all be replaced by "make install" eventually,
 # as part of proper integration with the TeX Live build
@@ -6,12 +11,15 @@
 # script to install xetex (and xdv2pdf on OS X)
 # from the binaries created by build-xetex
 
-# this is intended for the Linux version; on OS X, we build installer packages
+# this is intended for the Linux and *BSD version;
+# on OS X, we build installer packages
 
 # to be run from the top level dir of the xetex tree, after ./build-xetex
 
 # set -o xtrace
 
+echo "###### INSTALLING XETEX"
+
 filelist=Work/xetex-installed-files
 
 if [ -f ${filelist} ]; then rm ${filelist}; fi
@@ -26,15 +34,20 @@
 if [ ! -x "${texbin}" ]; then
 	echo "### error: existing tex binary couldn't be found"
 	exit 100
+else
+	echo "### TeX binary = ${texbin}"
 fi
 if [ -L ${texbin} ]; then
 	texbin=`readlink ${texbin}`
+	echo "### TeX binary (${texbin}) seems to be symlinked."
 fi
 texbindir=`dirname ${texbin}`
+echo "### TeX bin directory = ${texbindir}"
 
 # copy the xetex binary to the same dir as standard tex
 cp -pf Work/texk/web2c/xetex ${texbindir}/xetex
 echo ${texbindir}/xetex >> ${filelist}
+
 if [ -e Work/texk/xdv2pdf/xdv2pdf ]; then
 	programs="xdv2pdf T1Wrap"
 	for f in ${programs}; do
@@ -45,11 +58,34 @@
 
 # copy our texmf additions into the local texmf tree
 texmflocal=`kpsewhich --var-value TEXMFLOCAL`
-if [ "x${texmflocal}" == "x" ]; then
+# Again, == don't work in BSD sh; I hope that '-e' is sufficient:
+if [ ! -e ${texmflocal} ]; then
 	# if --var-value didn't work, try to find the definition in the texmf.cnf file
 	CNF=`kpsewhich texmf.cnf`
-	texmflocal=`sed -rne "s/^[ \t]*TEXMFLOCAL[ \t]*=[ \t]*(\/[^ \t]+).*/\1/p" ${CNF}`
-fi
+	echo ${CNF}
+	if [ "`uname`" = "FreeBSD" ]; then
+		CNF="TEXMFLOCAL    =   sdfsdfsf"
+		# That sed command will not work with BSD sed.
+		# I propose using awk instead. I think this
+		# awk command will work everywhere and
+		# that it can replace 'sed -rne ...' in all cases.
+		# I assumed that output (CNF) is in this case
+		# something like this:
+		# '   TEXMFLOCAL    =      /p/a/t/h'
+		texmflocal=`echo ${CNF} | awk -F "=[ \t]*" '{print $2}'`
+	else
+		texmflocal=`sed -rne "s/^[ \t]*TEXMFLOCAL[ \t]*=[ \t]*(\/[^ \t]+).*/\1/p" ${CNF}`
+	fi
+fi
+# Figuring out whether texmflocal contains symlinks (as we did in
+# runConfigure.sh and build-xetex) is not necessary here, since this
+# path is used just for mechanical copying, _except_ for texhash.
+# Does texhash's behaviour differ depending on whether the path it
+# uses respects symlinks?
+# 
+# What fmtutil does depends however on kpsewhich, which is beyond
+# the scope of this installation script.
+echo "### Using TEXMFLOCAL = ${texmflocal}"
 
 mkdir -p ${texmflocal}
 if [ -d texmf/.svn ]; then
@@ -70,8 +106,23 @@
 echo ${texmflocal}/web2c/xetex.pool >> ${filelist}
 
 # update kpathsearch databases because we've installed a bunch of stuff
+echo "### Running texhash"
 texhash ${texmflocal}
 
 # this will build the format files on the system where this script is run;
 # for packaged binary installations, we must repeat this on the target
+
 sh ./rebuild-formats
+echo "### All done. You installed xetex successfully. Newly installed files are:"
+cat ${filelist}
+echo "### Output of 'xetex --version:'"
+xetex --version
+
+echo "### NOTE: If you have locally installed xe(la)tex.fmt"
+echo "### (~/.texlive2007/texmf-var/web2c/xetex/ is TeXLive's"
+echo "### default directory), then you can expect the following"
+echo "### error when run your new xetex for the first time:"
+echo "###     [...]/xelatex.fmt doesn't match xetex.pool"
+echo "###     (Fatal format file error; I'm stymied)"
+echo "### You should delete the old .fmt files."
+# Is installing new local .fmt's using fmtutil --enablefmt/--byfmt necessary?
diff -ru xetex-devel-original/rebuild-formats xetex-devel/rebuild-formats
--- xetex-devel-original/rebuild-formats	Sun Jul  8 03:07:52 2007
+++ xetex-devel/rebuild-formats	Sun Jul  8 03:52:08 2007
@@ -1,4 +1,5 @@
-#!/bin/bash
+#!/bin/sh
+# The same comment as in install-xetex
 
 # script to create initial xetex and xelatex formats, after installation
 
@@ -6,7 +7,10 @@
 
 # ensure our entries are present in fmtutil.cnf
 fmtutil_cnf=`kpsewhich --format="web2c files" fmtutil.cnf`
-if [ "`fgrep -c xetex ${fmtutil_cnf}`" == "0" ]; then
+# if [ "`fgrep -c xetex ${fmtutil_cnf}`" == "0" ]; then
+# Again, == is not correct in *BSD sh; I hope the following command is
+# sufficient here (and that it will work everywhere):
+if [ ! "`grep xetex ${fmtutil_cnf}`" ]; then
 	cat >> ${fmtutil_cnf} <<-__EOT__;
 
 	# XeTeX formats
@@ -17,6 +21,7 @@
 fi
 
 # find the existing tex binary, possibly following a symlink
+# ok, symlinks are honoured with which(1)
 texbin=`which tex`
 if [ -L ${texbin} ]; then
 	texbin=`readlink ${texbin}`
@@ -32,14 +37,25 @@
 patch -N -r /tmp/fmtutilpatch.rej -p0 `which fmtutil` < fmtutil.tetex-2.patch >/dev/null 2>&1
 
 # use system-wide setup if available
-fmtutil=`type -p fmtutil-sys` || fmtutil=`type -p fmtutil`
+# This can't run with BSD sh; I hope that the following
+# is what was intended:
+# fmtutil=`type -p fmtutil-sys` || fmtutil=`type -p fmtutil`
+fmtutil=`which fmtutil-sys`
+if [ ! -e "${fmtutil}" ]; then
+	fmtutil=`which fmtutil`
+	echo "### Can't find system-wide fmtutil; using ${fmtutil}"
+else
+	echo "### Using system-wide fmtutil: ${fmtutil}"
+fi
 
 formats="xetex xelatex"
 for f in ${formats}; do
 # enable our entries if necessary (in case of pre-existing disabled ones)
+	echo "### Running fmtutil for format ${f}"
 	${fmtutil} --enablefmt ${f}
 	${fmtutil} --byfmt ${f}
 done
 
 # create symlinks for the newly-built formats
+echo "### Creating symlinks for the newly-built formats"
 texlinks --silent
diff -ru xetex-devel-original/runConfigure.sh xetex-devel/runConfigure.sh
--- xetex-devel-original/runConfigure.sh	Sun Jul  8 03:07:52 2007
+++ xetex-devel/runConfigure.sh	Sun Jul  8 03:51:54 2007
@@ -18,17 +18,63 @@
 else
 	PREFIX=`echo ${KPSEWHICH} | sed -e 's!/bin/.*!/!;'`
 	HYPHEN=`kpsewhich hyphen.tex`
-	if [ "${HYPHEN}x" == "x" ]; then
+	if [ ! -f "${HYPHEN}" ]; then
 		echo "### hyphen.tex not found -- are you sure you have teTeX installed?"
 	else
 		DATADIR=`echo ${HYPHEN} | sed -e 's!/texmf.*!/!;'`
 	fi
 fi
+# kpsewhich always returns realpath(1) and ignores symlinks
+# whilst which(1) honours symlinks. Therefore the following can be useful,
+# since maybe it's not very nice to mix real/non-real paths in configure.
+# (In the case of standard TL installation, PREFIX and DATADIR are identical.)
+# Of course, it would be better if kpsewhich could return non-realpath.
+REALPATHPREFIX=`realpath ${PREFIX}`
+if [ "`echo ${DATADIR} | sed -e 's!${REALPATHPREFIX}!!'`" = "${DATADIR}" ]; then
+	TMPSUBST="echo ${DATADIR} | sed -e 's!${REALPATHPREFIX}/!${PREFIX}!'"
+	DATADIR=`eval ${TMPSUBST}`
+	echo "### DATADIR seems to contain symlink; honouring it."
+fi
+WEB2CDIR=`dirname \`kpsewhich texmf.cnf\``
+if [ "`echo ${WEB2CDIR} | sed -e 's!${REALPATHPREFIX}!!'`" = "${WEB2CDIR}" ]; then
+	TMPSUBST="echo ${WEB2CDIR} | sed -e 's!${REALPATHPREFIX}/!${PREFIX}!'"
+	WEB2CDIR=`eval ${TMPSUBST}`
+	echo "### WEB2CDIR seems to contain symlink; honouring it."
+fi
+echo "### Using paths:"
+echo "###   PREFIX          = ${PREFIX}"
+echo "###   PREFIX realpath = ${REALPATHPREFIX}"
+echo "###   DATADIR         = ${DATADIR}"
+echo "###   WEB2CDIR        = ${WEB2CDIR}"
 
 # run the TeX Live configure script
 echo "### running TeX Live configure script as:"
-echo "../configure --prefix=${PREFIX} --datadir=${DATADIR} --with-system-zlib"
-../configure --prefix=${PREFIX} --datadir=${DATADIR} --with-system-zlib || exit
+if [ "`uname`" = "FreeBSD" ]; then
+	# Required system libraries are part of the following FreeBSD ports:
+	# pnglib	--> graphics/png
+	# freetype2	--> print/freetype2
+	# zlib		--> graphics/imlib2
+	# xpdf		--> (?? not an option?)
+	# These are their default positions in FreeBSD:
+	LOCALBASE=/usr/local
+	SYSTEM_LIBS_PATHS="--with-system-freetype2 \
+                           --with-freetype2-libdir=${LOCALBASE}/lib \
+                           --with-freetype2-include=${LOCALBASE}/include \
+                           --with-fontconfig=${LOCALBASE} \
+                           --with-system-pnglib \
+                           --with-pnglib-libdir=${LOCALBASE}/lib \
+                           --with-system-zlib \
+                           --with-zlib-dir=${LOCALBASE}/lib/imlib2/loaders"
+	# He who doesn't want to use system libraries can delete SYSTEM_LIBS_PATHS;
+	# of course, this will not be the choice when XeTeX becomes a FreeBSD
+	# port; all needed libraries will then be dependencies and handled
+	# automatically by the Ports System. In meantime...
+	CONFIGURECMD="../configure --prefix=${PREFIX} --datadir=${DATADIR} ${SYSTEM_LIBS_PATHS}"
+else
+	CONFIGURECMD="../configure --prefix=${PREFIX} --datadir=${DATADIR} --with-system-zlib"
+fi
+echo ${CONFIGURECMD}
+${CONFIGURECMD} || exit
 
 if [ "`uname`" = "Darwin" ]; then
   if [ "`uname -p`" = "powerpc" ]; then
======================================================================


More information about the XeTeX mailing list