use alienfile;

plugin 'PkgConfig' => (
	pkg_name => 'poppler',
	minimum_version => '0.52.0',
);

requires 'Alien::gmake';
requires 'Alien::Build::Plugin::Gather::Dino';
requires 'Alien::OpenJPEG';
requires 'Env::ShellWords' => '0.01';
requires 'Path::Tiny' => 0;
use Env qw($LDFLAGS);

# https://poppler.freedesktop.org/
share {
	plugin Download => (
		url => 'https://poppler.freedesktop.org/releases.html',
		version => qr/poppler-([\d.]+)\.tar\.xz/,
	);

	plugin Extract => 'tar.xz';

	# warn is fine here because this is part of configure-time
	eval {
		require Alien::OpenJPEG;
		$LDFLAGS .= ' ' . Alien::OpenJPEG->libs;
	} or warn "Unable to add to \$LDFLAGS ($LDFLAGS): $@";
	plugin 'Build::SearchDep' => (
		aliens => [ qw( Alien::OpenJPEG ) ],
	);


	patch sub {
		my($splash_bitmap) = Path::Tiny->new('splash/SplashBitmap.h');
		$splash_bitmap->edit_lines(sub {
			s{\Qpoppler/GfxState.h\E}{GfxState.h}g;
		});
	};

	plugin 'Build::Autoconf' => ();
	build [
		[ '%{configure} --enable-xpdf-headers' ],
		[ '%{gmake}' ], # , 'V=1'
		[ '%{gmake}', 'install' ],
	];

	plugin 'Gather::Dino';
};
