[deps]
musl
kernel-headers

[main]
filesize=1045868
sha512=38108a94118b56c6f3982e692beb1068c52f9aecd74447d6b552b77fae5e365eab72b4781bdf07d9696ac89d54371c1cae8cc0363de510b53988302acef50dba

[mirrors]
http://dl.suckless.org/tools/9base-6.tar.gz

[build]
mbwc_fix() {
        local file=$1
        echo '#include "mbwc.h"' > $file
        cat troff/$file >> $file
        mv $file troff/$file
}
for i in n1.c t11.c n10.c mbwc.c ; do mbwc_fix $i ; done

cat << EOF > lib9/getdents.h
#ifndef GETDENT_HACK
#include <unistd.h>
int getdents(int fd, void *buf, size_t len);
#endif
EOF


echo "PREFIX = /" >>config.mk
# the dc calculator, called by bc, assumes a signed char,
# which is not true for ARM. it fails on "4 - 3" resp. "4 3 -ps."
# without -fsigned-char.
echo "CFLAGS += -fsigned-char -D_GNU_SOURCE -DPLAN9PORT -D__USE_MISC -include getdents.h" >>config.mk

sed -i 's/__linux__/__not_linux__/;s/__sun__/__linux__/' lib9/dirread.c
sed -i '/sys.termios.h/d' lib9/readcons.c
sed -i '/^.touch./d' Makefile  # we don't have futimes

make -j$MAKE_THREADS || exit 1

# only install things not sufficently well-provided by busybox
for f in ascii bc cleanname dc ed factor fmt freq getflags hoc join \
         look mk mtime pbd primes rc read sam troff unicode
do
  make -C $f DESTDIR="$butch_install_dir" install || exit 1
done

cd "$butch_install_dir/bin"
ln -sf troff nroff
