abinfo "Building nvramtool ..."
make CFLAGS="-DCMOS_HAL=1 -I." -C util/nvramtool

if [[ "${CROSS:-$ARCH}" = "amd64" ]]; then
    for i in amdfwtool ifdtool intelmetool \
             inteltool intelvbttool ectool superiotool; do
        abinfo "Building $i ..."
        make -C util/$i
    done

    abinfo "Building msrtool ..."
    cd "$SRCDIR"/util/msrtool
    abinfo "Appending -fcommon to fix msrtool ..."
    export CFLAGS="-fcommon"
    ./configure --prefix=/usr
    make
    abinfo "Unsetting -fcommon after msrtool ..."
    unset CFLAGS
    cd "$SRCDIR"
fi

for i in cbfstool cbmem; do
    abinfo "Building $i ..."
    make -C util/$i       
done

abinfo "Creating directories ..."
install -dv "$PKGDIR"/usr/bin
install -dv "$PKGDIR"/usr/share
install -dv "$PKGDIR"/usr/share/man/man1

if [[ "${CROSS:-$ARCH}" = "amd64" ]]; then
for i in amdfwtool ifdtool intelvbttool; do
    abinfo "Installing $i ..."
    install -Dvm755 "$SRCDIR"/util/${i}/${i} \
        "$PKGDIR"/usr/bin
done

abinfo "Installing msrtool ..."
make -C util/msrtool DESTDIR="$PKGDIR" \
    PREFIX=/usr install

for i in intelmetool inteltool; do
    abinfo "Installing $i ..."
    make DESTDIR="$PKGDIR" \
         PREFIX=/usr -C util/$i install
done

abinfo "Installing ectool ..."
make PREFIX="$PKGDIR"/usr -C util/ectool install

for i in nvramtool superiotool; do
    abinfo "Installing $i ..."
    make DESTDIR="$PKGDIR" \
         PREFIX=/usr -C util/$i install
done
fi

for i in cbfstool cbmem; do
    abinfo "Installing $i ..."
    install -Dvm755 "$SRCDIR"/util/${i}/${i} \
        "$PKGDIR"/usr/bin
done

for i in nvramtool; do
    abinfo "Installing $i ..."
    make DESTDIR="$PKGDIR" \
         PREFIX=/usr -C util/$i install
done

abinfo "Moving /usr/sbin => /usr/bin ..."
cp -av "$PKGDIR"/usr/sbin/* \
    "$PKGDIR"/usr/bin/
rm -rv "$PKGDIR"/usr/sbin

abinfo "Installing README ..."
mkdir -pv "$PKGDIR"/usr/share/doc/coreboot-utils
cp -v "$SRCDIR"/README* \
   "$PKGDIR"/usr/share/doc/coreboot-utils/
