use alienfile;

plugin 'PkgConfig' => 'libzmq';

# http://zeromq.org/
share {
	my $prefer_cmake = 0;
	if( $prefer_cmake ) {
		requires 'Alien::cmake3';
	}

	plugin Download => (
		url => 'https://github.com/zeromq/libzmq/releases',
		version => qr/zeromq-([\d\.]+)\.tar\.gz/,
	);

	plugin Extract => 'tar.gz';

	my $enable_static = $^O ne 'MSWin32';
	my $enable_tests = 0;
	if( $prefer_cmake ) {
		plugin 'Build::CMake';
		build [
			[ '%{cmake}', -G => '%{cmake_generator}',
				'-DCMAKE_INSTALL_PREFIX:PATH=%{.install.prefix}',
				"-DBUILD_STATIC=@{[ $enable_static ? 'ON' : 'OFF' ]}",
				"-DZMQ_BUILD_TESTS=@{[ $enable_tests ? 'ON' : 'OFF' ]}",
				qw(-S .),
				qw(-B build),
			],
			[ '%{make}', qw( -C build ) ],
			[ '%{make}', qw( -C build ), 'install' ],
		];
	} else {
		plugin 'Build::Autoconf';
		my $should_stub_tests = $^O eq 'MSWin32';
		my @make_stub_tests = $should_stub_tests
			? ( "noinst_LIBRARIES=" )
			: ();
		build [
			join(' ',
				'%{configure}',
				( $enable_static ? '--enable-static' : '--disable-static' ),
				'--enable-shared',
			),
			[ '%{make}', @make_stub_tests ],
			[ '%{make}', 'install', @make_stub_tests ],
		];
	}

	plugin 'Gather::Dino';
};
