# 1998 09 03  Mouse

# Make sure $LOCALROOT is set - for simplicity below, to avoid constantly
#   writing ${LOCALROOT:-/local}.
: ${LOCALROOT:=/local}

# Unpack the .gz files into X11-R6.4p3
# Skip the v if desired; skip the S if not using mouse tar.

mkdir X11-R6.4p3
cd X11-R6.4p3
gunzip < ../DIST/tog-1.tar.gz | tar xvfpS -
gunzip < ../DIST/tog-2.tar.gz | tar xvfpS -
gunzip < ../DIST/tog-3.tar.gz | tar xvfpS -

# Apply fixes
patch -p < ../DIST/fix-01
patch -p < ../DIST/fix-02
patch -p < ../DIST/fix-03

# Apply various other patches; see patches.doc for info about them.
( cd ../patches/xc ; find . -type f -print ) | sed -e 's;^./;;' |
while read fn
do
	< ../patches/xc/$fn patch xc/$fn
	rm -f xc/$fn.orig
done
( cd ../patches.localized/xc ; find . -type f -print ) | sed -e 's;^./;;' |
while read fn
do
	cat ../patches.localized/xc/$fn | sed -e "s;@@LOCALROOT@@;$LOCALROOT;g" | patch xc/$fn
	rm -f xc/$fn.orig
done

# Normalize permissions.
find . -type d ! -perm 0775 -print | xargs chmod 775
find . -type f -perm 0111/0 ! -perm 0664 -print | xargs chmod 664
find . -type f ! -perm 0111/0 ! -perm 0775 -print | xargs chmod 775

# Libraries need to be visible here during the build before the install,
#  or things like xkbcomp don't work.  (Ignore errors from these commands;
#  the commands are carefully chosen to either error out or DTRT.)
rm $LOCALROOT/.lib/X11-R6.4p3 2>/dev/null
[ -d $LOCALROOT/.lib/X11-R6.4p3 ] || ln -s $LOCALROOT/src/X11/X11-R6.4p3/xc/exports/lib $LOCALROOT/.lib/X11-R6.4p3 2>/dev/null

# Do the build!
cd xc
(
case "$LD_LIBRARY_PATH" in
	"")	LD_LIBRARY_PATH=$LOCALROOT/src/X11/X11-R6.4p3/xc/exports/lib:$LOCALROOT/lib:/usr/lib ;;
	*)	LD_LIBRARY_PATH=$LOCALROOT/src/X11/X11-R6.4p3/xc/exports/lib:"$LD_LIBRARY_PATH" ;;
esac
export LD_LIBRARY_PATH
# On at least one architecture (next68k), it is very hard to get
#  BOOTSTRAPCFLAGS set everywhere it needs to be with less than this.
BOOTSTRAPCFLAGS=-D`uname -m`
export BOOTSTRAPCFLAGS
make World
)

# Remove the symlink we may have made above
rm $LOCALROOT/.lib/X11-R6.4p3 2>/dev/null

# Install it
make install
make install.man

# Fix up installation bug that installs xterm setuid even if not root
chmod 711 $LOCALROOT/.bin/X11-R6.4p3/xterm

cd ../..

exit 0
# Fix up the font server config file:
cat final-patch-fs-config | sed -e "s;@@LOCALROOT@@;$LOCALROOT;g" | patch $LOCALROOT/.lib/X11-R6.4p3/X11/fs/config
rm -f $LOCALROOT/.lib/X11-R6.4p3/X11/fs/config.orig

# If utmp entries are desired for xterm, then as root,
# chown root $LOCALROOT/.bin/X11-R6.4p3/xterm
# chmod 4711 $LOCALROOT/.bin/X11-R6.4p3/xterm

# Clean up
#	cd ..
#	rm -rf X11-R6.4p3
