use alienfile;

plugin 'PkgConfig' => 'udunits';

share {
	requires 'Alien::gmake' => 0.14;

	plugin Download => (
		url => 'https://artifacts.unidata.ucar.edu/service/rest/repository/browse/downloads-udunits/',
		version => qr/udunits-([\d\.]+)\.tar\.gz/,
	);


	plugin Extract => 'tar.gz';

	plugin 'Build::Autoconf';

	build [
		"%{configure}",
		'%{make}',
		'%{make} install',
	];

	# There is no pkg-config .pc file in the original upstream version.
	after 'gather' => sub {
		my($build) = @_;
		my $prefix = $build->runtime_prop->{prefix};

		my $cflags = do {
			'-I' . File::Spec->catfile($prefix, qw(include))
		};
		my $libs = do {
			my $path = '-L' . File::Spec->catfile($prefix, qw(lib));

			join ' ', (
				$path,
				'-ludunits2',
				( $^O eq 'darwin' || $^O eq 'MSWin32' ? '-lexpat' : '')
			);
		};

		$build->runtime_prop->{cflags}        = $cflags;
		$build->runtime_prop->{cflags_static} = $cflags;
		$build->runtime_prop->{libs}          = $libs;
		$build->runtime_prop->{libs_static}   = $libs;
	};
};
