#!/bin/sh -e

# The wpa_supplicant package is built statically using
# libnl-tiny which is a minimal version of libnl maintained
# by OpenWRT.
sed -i 's^rc^-r -o^g' libnl/Makefile
make CC="${CC:-cc}" ALL_LIBS=libnl-tiny.a -C libnl RANLIB=true

# The CFLAGS must be set to link to the above locally built
# libnl-tiny library.
export CFLAGS="$CFLAGS -I$PWD/libnl/include -L$PWD/libnl -lnl-tiny"
export CFLAGS="$CFLAGS -static -D_GNU_SOURCE -DLIBNL1_COMPAT"

cd wpa_supplicant

sed -i 's/$(CC) -c/$(CC)/g' Makefile

make LIBDIR=/usr/lib BINDIR=/usr/bin DRV_LIBS="$CFLAGS" CC="${CC:-cc}"
make LIBDIR=/usr/lib BINDIR=/usr/bin DESTDIR="$1" install

install -Dm644 -t "$1/usr/share/man/man8" doc/docbook/*.8
install -Dm644 -t "$1/usr/share/man/man5" doc/docbook/*.5
