#!/bin/bash
# I have (one) useful perl script from Font::TTF::Scripts, ttf2config.pl,
# which I use for working out what a font covers.  It needs Font::TTF
# which requires IO::String.  Contains 'fret' which requires Text::PDF
# at runtime.  Fontforge appears to be able to extract ttf files from ttc.
#------------------------------------------------------------------
set -e
# KM_STAGE will be general-something or desktopN
export KM_STAGE=desktop-extra

# work out where the script lives, to find its directory, and hence its clients
# strip off last '/' and the following name
KM_SCRIPTS=${0%/*}
echo "will look for client scripts in $KM_SCRIPTS"

. /misc/hostfile
. /misc/packages

#make the functions script noisy to report what it will do
KM_VERBOSE=verbose
. ${KM_SCRIPTS}/functions
# and quieten it for the rest of the build
unset KM_VERBOSE

# report which branch we are on
km_show_branch
# start timing now that the functions have been read
km_set_start

# ppc64 cannot build glibc if all 32-bit (makeinfo problem)
# so ensure it is pretending to be ppc32.
if [ $(uname -m) = "ppc64" ]; then
	echo "please use linux32 before trying to run this"
	exit 2
fi


CFLAGS='-O2'
CXXFLAGS='-O2'
export CFLAGS CXXFLAGS LDFLAGS

# set $KM_ARCH to ppc if appropriate, for ppc (endian) patches
KM_ARCH=`uname -m`

test -n "$KM_HOST"

# prefer to build in /scratch, if possible
echo "testing if /scratch/working exists"
if [ -d /scratch ]; then
	mountpoint /scratch >/dev/null 2>&1 || mountpoint /scratch/working >/dev/null 2>&1
	if [ $? -ne 0 ]; then
		echo "please mount /scratch"
		exit 2
	else
		mkdir -p /scratch/working
		KM_WHERE=/scratch/working
	fi
else
	KM_WHERE=/usr/src
fi &&

# need to export variables here
export KM_ARCH KM_BOX KM_HOST KM_LOGDIRECTORY KM_SCRIPTS KM_WHERE
export LC_ALL=C

mkdir -pv $KM_LOGDIR

km_build	IO-String		${KM_SCRIPTS}/perl.d/IO-String

km_build	Font-TTF		${KM_SCRIPTS}/perl.d/Font-TTF

km_build	Font-TTF-Scripts	${KM_SCRIPTS}/perl.d/Font-TTF-Scripts

km_build	Text-PDF		${KM_SCRIPTS}/perl.d/Text-PDF

km_build	fontforge		${KM_SCRIPTS}/extra.d/fontforge

km_driverscript_timings

