2012-03-26 20:57:53 +00:00
|
|
|
use strict;
|
|
|
|
|
|
|
|
use FindBin qw($Bin);
|
|
|
|
|
|
|
|
sub build_bin {
|
|
|
|
my $target = shift;
|
|
|
|
$ENV{GOBIN} = find_gobin();
|
2013-01-20 20:33:35 +00:00
|
|
|
print STDERR "Building $target ...\n";
|
|
|
|
system("go", "install", "-v", $target) and die "go install $target failed";
|
2012-03-26 20:57:53 +00:00
|
|
|
$target =~ s!.+/!!;
|
|
|
|
my $bin = "$ENV{GOBIN}/$target";
|
2012-04-23 00:50:13 +00:00
|
|
|
unless (-e $bin) {
|
|
|
|
die "Expected binary $bin doesn't exist after installing target $target\n";
|
|
|
|
}
|
2012-03-26 20:57:53 +00:00
|
|
|
system("chmod", "+x", $bin) unless -x $bin;
|
|
|
|
return $bin;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub find_bin {
|
|
|
|
my $target = shift;
|
|
|
|
$target =~ s!.+/!!;
|
2012-03-27 17:37:21 +00:00
|
|
|
my $bin = find_gobin();
|
|
|
|
return "$bin/$target";
|
2012-03-26 20:57:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub find_gobin {
|
|
|
|
my $env = `go env`;
|
|
|
|
# Note: ignoring cross-compiling environments (GOHOSTOS,
|
|
|
|
# GOHOSTARCH) for now at least.
|
|
|
|
my ($GOARCH) = $env =~ /^GOARCH=\"(.+)\"/m;
|
|
|
|
my ($GOOS) = $env =~ /^GOOS=\"(.+)\"/m;
|
|
|
|
die "Failed to find GOARCH and/or GOOS" unless $GOARCH && $GOOS;
|
|
|
|
my $bin = "$Bin/gopath/bin/${GOOS}_${GOARCH}";
|
|
|
|
mkdir $bin, 0755 unless -d $bin;
|
|
|
|
return $bin;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|