#!/bin/sh
# Build script for feh (plain Makefile - no configure, no pkg-config use).
# Deps: imlib2, libX11, libXinerama, libpng - all under $PREFIX.
# feh's config.mk hardcodes LDLIBS (-lm -lpng -lX11 -lImlib2) with no -I/-L
# of its own, relying on the compiler's default search paths - which does
# NOT include $PREFIX/include or $PREFIX/lib on Hammerhead. Supply those
# via CFLAGS/LDFLAGS in the environment (config.mk's CFLAGS uses `?=`/`+=`
# so an exported CFLAGS is picked up as the base and appended to).
# curl=0 exif=0 per the task brief (no libcurl/libexif ports); xinerama=1
# (libXinerama is ported).
#
# verscmp=0: feh defaults verscmp=1 (assumes glibc's GNU strverscmp()),
# but illumos libc has no strverscmp() at all (not even hidden behind
# __EXTENSIONS__ - it's a pure GNU extension). With verscmp=0 feh's own
# Makefile pulls in its bundled strverscmp.c fallback implementation
# instead, avoiding the "implicit declaration of function 'strverscmp'"
# build failure.
set -e
cd "$SRCDIR"

export CFLAGS="-I$PREFIX/include -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS"
export LDFLAGS="-L$PREFIX/lib -R$PREFIX/lib"

gmake CC=gcc PREFIX="$PREFIX" curl=0 exif=0 xinerama=1 verscmp=0

gmake PREFIX="$PREFIX" DESTDIR="$PKGDIR" curl=0 exif=0 xinerama=1 verscmp=0 install
