#!/bin/sh -e

export CFLAGS="$CFLAGS -fcommon"
export PERL5LIB="$PWD/usr/lib/perl5/vendor_perl/5.32.0/x86_64-linux-thread-multi"
export PATH="$PATH:$PWD/xxd"

# Give the Makefile busybox compatible arguments.
sed -i "s|$(Q)$(INSTALL) -T|$(Q)$(INSTALL) -Dm755|g" \
    netsurf/frontends/framebuffer/Makefile

for p in html-parser html-tagset; do (
    cd "$p"

    perl Makefile.PL INSTALLDIRS=vendor

    make
    make DESTDIR="$PWD/.." install
) done

# Build standalone xxd to remove VIM requirement
cc xxd/xxd.c -o xxd/xxd

make                   \
    LIBDIR=lib         \
    INCLUDEDIR=include \
    PREFIX=/usr        \
    TARGET=gtk2

make                   \
    LIBDIR=lib         \
    INCLUDEDIR=include \
    PREFIX=/usr        \
    TARGET=gtk2        \
    DESTDIR="$1"       \
    install