#!/bin/sh

tce-load -w compiletc  libX11-dev libXft-dev ncursesw-utils sstrip squashfs-tools
tce-load -i compiletc  libX11-dev libXft-dev ncursesw-utils sstrip squashfs-tools

cd /tmp
sudo rm -rf st st-doc st-0.8.4 st.tcz* st-doc.tcz*

#wget http://dl.suckless.org/st/st-0.8.4.tar.gz

tar x -zf st-0.8.4.tar.gz

cd st-0.8.4

cat << EOF | patch
--- config.def.h.orig
+++ config.def.h
@@ -54,7 +54,7 @@
  * low minlatency will tear/flicker more, as it can "detect" idle too early.
  */
 static double minlatency = 8;
-static double maxlatency = 33;
+static double maxlatency = 12;
 
 /*
  * blinking timeout (set to 0 to disable blinking) for the terminal blinking
@@ -96,24 +96,24 @@
 /* Terminal colors (16 first used in escape sequence) */
 static const char *colorname[] = {
 	/* 8 normal colors */
-	"black",
-	"red3",
-	"green3",
-	"yellow3",
-	"blue2",
-	"magenta3",
-	"cyan3",
-	"gray90",
+	"#000000",
+	"#c00000",
+	"#00c000",
+	"#c0c000",
+	"#0000c0",
+	"#c000c0",
+	"#00c0c0",
+	"#c0c0c0",
 
 	/* 8 bright colors */
-	"gray50",
-	"red",
-	"green",
-	"yellow",
-	"#5c5cff",
-	"magenta",
-	"cyan",
-	"white",
+	"#404040",
+	"#ff0000",
+	"#00ff00",
+	"#ffff00",
+	"#0000ff",
+	"#ff00ff",
+	"#00ffff",
+	"#ffffff",
 
 	[255] = 0,
 
EOF

CFLAGS=" -flto -march=i486 -mtune=i686 -Os -pipe -fno-plt"
LDFLAGS="-Wl,-O1"

export CFLAGS LDFLAGS

CC=gcc make
make DESTDIR="/tmp/st" install

tic -sx -o /tmp/st/usr/local/share/terminfo st.info

cd /tmp

sstrip /tmp/st/usr/local/bin/st

cd /tmp/st/usr/local/share/terminfo/s/
rm -f st st-bs st-bs-256color st-meta st-meta-256color st-mono


mkdir -p /tmp/st-doc/usr/local/share
mv /tmp/st/usr/local/share/man /tmp/st-doc/usr/local/share

mkdir -p /tmp/st-doc/usr/local/share/doc/st
cp /tmp/st-0.8.4/LICENSE /tmp/st-doc/usr/local/share/doc/st


DIRS="st st-doc"

for N in $DIRS
do
  cd /tmp/"$N"
  find  -not -type d > ../"$N".tcz.list
  sed -i -e 's/^\.//' ../"$N".tcz.list
  cd /tmp
  sudo chown -R root:root "$N"
  if [ -d "$N"/usr/local/tce.installed ]
  then
    sudo chmod 0775 "$N"/usr/local/tce.installed
    sudo chown  root:staff "$N"/usr/local/tce.installed
    sudo chmod 0755 "$N"/usr/local/tce.installed/*
    sudo chown  tc:staff "$N"/usr/local/tce.installed/*
  fi
  mksquashfs "$N" "$N".tcz
  md5sum "$N".tcz > "$N".tcz.md5.txt
done

echo libXft.tcz > st.tcz.dep
echo man.tcz > st-doc.tcz.dep

