#!/bin/sh -ue
NAME=gptfdisk
VERSION=1.0.10
RELEASE=1
SOURCE="https://downloads.sourceforge.net/project/gptfdisk/gptfdisk/${VERSION}/gptfdisk-${VERSION}.tar.gz"

build() {
	msg "patching curses include for netbsd-curses..."
	sed -i 's|<ncursesw/ncurses.h>|<curses.h>|' gptcurses.cc || die "curses patch failed"

	msg "building gptfdisk..."
	gmake TARGET=linux \
		CXX="${CXX:-c++}" \
		CXXFLAGS="$CXXFLAGS -Wall -D_FILE_OFFSET_BITS=64" \
		LDFLAGS="$LDFLAGS" \
		CGDISK_LDLIBS="-lcurses -lterminfo" || die "gmake failed"

	msg "installing gptfdisk..."
	mkdir -p "$PKG$PREFIX/bin" "$PKG$PREFIX/share/man/man8" || die "mkdir failed"

	for bin in gdisk cgdisk sgdisk fixparts; do
		install -m 755 "$bin" "$PKG$PREFIX/bin/" || die "failed to install $bin"
	done

	for man in gdisk.8 cgdisk.8 sgdisk.8 fixparts.8; do
		install -m 644 "$man" "$PKG$PREFIX/share/man/man8/" || die "failed to install $man"
	done
}

. ${0%/*}/../../libsh/libdmake.sh
