#!/bin/sh

# $NetBSD: wrapper.sh,v 1.3 2016/02/29 13:51:28 jperkin Exp $

BINDIR='/usr/pkg'
CFLAGS='-O2 -D_FORTIFY_SOURCE=2 -I/usr/pkg/include -I/usr/include'
LDFLAGS='-L/usr/pkg/lib -Wl,-R/usr/pkg/lib -L/usr/lib -Wl,-R/usr/lib'
WRAPPEE='ocamlcp'

if echo "$@" | grep ' -c ' >/dev/null || [ "${WRAPPEE}" = "ocamlmklib" ]; then
	flags="${CFLAGS}"
else
	flags="${CFLAGS} ${LDFLAGS}"
fi

for f in ${flags}
do
	MLFLAGS="${MLFLAGS} -ccopt ${f}"
done

if [ "${WRAPPEE}" = "ocamlmklib" ]; then
	MLFLAGS="${MLFLAGS} ${LDFLAGS}"
fi

exec "/usr/pkg/bin/${WRAPPEE}" ${MLFLAGS} "$@"
