#!/bin/sh
#
ME=$(readlink -f "$0")
MEDIR=${ME%/*}

EXT=rxvt

. $MEDIR/phase-default-init.sh

DEPS="xorg-proto Xorg-7.7-dev fontconfig-dev libXft-dev ncurses-utils"

. $MEDIR/phase-default-deps.sh
. $MEDIR/phase-cc-opts-no-flto-excp.sh

export LDFLAGS="-lm"

for a in urxvt-patches/*.patch; do
	patch -p 0 < $a
done

./configure \
	--prefix=/usr/local \
	--localstatedir=/var \
	--enable-xft \
	--enable-transparency \
	--disable-perl \
	--with-x \
	--enable-256-color \
	|| exit

. $MEDIR/phase-default-make.sh

make install DESTDIR=$TCZ-doc

chmod -R ug+w $TCZ-doc

mkdir -p $TCZ/usr/local/bin

cat << EOF > $TCZ/usr/local/bin/rxvt-unicode
#!/bin/busybox sh

######################################################
# rxvt xterm wrapper for Tiny Core Linux
######################################################

urxvt +tr "\$@"
EOF
chmod 755 $TCZ/usr/local/bin/rxvt-unicode

mkdir -p $TCZ/usr/local/share/applications

cat << EOF > $TCZ/usr/local/share/applications/rxvt.desktop
[Desktop Entry]
Encoding=UTF-8
Name=Rxvt-Unicode Terminal
Comment=Use the command line
GenericName=Terminal
Exec=urxvt
Terminal=false
Type=Application
#StartupNotify=true
Keywords=console;command line;execute;
X-FullPathIcon=/usr/local/share/pixmaps/rxvt.png
Icon=rxvt
OnlyShowIn=Old;
Categories=System;
EOF

mkdir -p $TCZ/usr/local/share/pixmaps

cp $BASE/contrib/rxvt.png $TCZ/usr/local/share/pixmaps/rxvt.png
chmod 644 $TCZ/usr/local/share/pixmaps/rxvt.png

mkdir -p $TCZ/usr/local/tce.installed

cat << EOF > $TCZ/usr/local/tce.installed/rxvt
#!/bin/sh
[ -f /usr/local/bin/xterm ] || ln -s /usr/local/bin/rxvt-unicode /usr/local/bin/xterm
EOF

cp $TCZ-doc/usr/local/bin/urxvt $TCZ/usr/local/bin

mkdir -p $TCZ/usr/local/share/terminfo
tic -x -o $TCZ/usr/local/share/terminfo doc/etc/rxvt-unicode.terminfo
#chmod 644 $TCZ/usr/local/share/terminfo/r/rxvt-unicode

. $MEDIR/phase-default-strip.sh
. $MEDIR/phase-default-set-perms.sh

sudo chown -R root.staff $TCZ/usr/local/tce.installed
sudo chmod -R 775 $TCZ/usr/local/tce.installed

. $MEDIR/phase-default-squash-tcz.sh

