aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Leich <email@froggs.de>2015-03-23 21:07:42 +0100
committerTobias Leich <email@froggs.de>2015-03-23 21:07:42 +0100
commitda6cb959ac96ba230178cd173ddee7e38fb35bbf (patch)
treed9c95cd65db17dff08542c6cda2b49028b82aa85
parent3df9a6fc4419887ec530a4353f5e00c85cbe3cbd (diff)
create windows .bat files for each script in bin/
-rw-r--r--tools/build/bin-install.pl53
1 files changed, 47 insertions, 6 deletions
diff --git a/tools/build/bin-install.pl b/tools/build/bin-install.pl
index ed493ba..27ef6ec 100644
--- a/tools/build/bin-install.pl
+++ b/tools/build/bin-install.pl
@@ -9,11 +9,25 @@ die "Usage: $0 <perl6_binary> <destination_path> <source_files>"
unless $p6bin && $dest;
for my $filename (@files) {
- open my $IN, '<', $filename
- or die "Cannot read file '$filename' for installing it: $!";
my $basename = (File::Spec->splitpath($filename))[2];
- open my $OUT, '>', "$dest/$basename"
- or die "Cannot write file '$dest/$basename' for installing it: $!";
+ copy_file($filename, $basename);
+
+ if ($^O eq 'MSWin32') {
+ create_windows_bat("$basename.bat");
+ copy_file($filename, "$basename-$post");
+ create_windows_bat("$basename-$post.bat");
+ }
+ else {
+ create_shell_wrapper($basename);
+ }
+}
+
+sub copy_file {
+ my ($infile, $outfile) = @_;
+ open my $IN, '<', $infile
+ or die "Cannot read file '$infile' for installing it: $!";
+ open my $OUT, '>', "$dest/$outfile"
+ or die "Cannot write file '$dest/$outfile' for installing it: $!";
while (<$IN>) {
if ($. == 1 && /^#!/) {
# https://github.com/rakudo/star/issues/42
@@ -25,9 +39,13 @@ for my $filename (@files) {
print { $OUT } $_;
}
}
- close $OUT or die "Error while closing file '$dest/$basename': $!";
+ close $OUT or die "Error while closing file '$dest/$outfile': $!";
close $IN;
- chmod 0755, "$dest/$basename";
+ chmod 0755, "$dest/$outfile";
+}
+
+sub create_shell_wrapper {
+ my ($basename) = @_;
open my $ALIAS, '>', "$dest/$basename-$post"
or die "Cannot write file '$dest/$basename-$post' for installing it: $!";
printf { $ALIAS } <<'EOA', $p6bin, $dest, $basename;
@@ -37,3 +55,26 @@ EOA
close $ALIAS or die "Error while closing file '$dest/$basename-$post': $!";
chmod 0755, "$dest/$basename-$post";
}
+
+sub create_windows_bat {
+ my ($basename) = @_;
+ open my $ALIAS, '>', "$dest/$basename"
+ or die "Cannot write file '$dest/$basename' for installing it: $!";
+ printf { $ALIAS } <<'EOA', $p6bin, $p6bin;
+@rem = '--*-Perl-*--
+@echo off
+if "%%OS%%" == "Windows_NT" goto WinNT
+%s "%%~dpn0" %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9
+goto endofperl
+:WinNT
+%s "%%~dpn0" %%*
+if NOT "%%COMSPEC%%" == "%%SystemRoot%%\system32\cmd.exe" goto endofperl
+if %%errorlevel%% == 9009 echo You do not have Perl in your PATH.
+if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
+goto endofperl
+@rem ';
+__END__
+:endofperl
+EOA
+ close $ALIAS or die "Error while closing file '$dest/$basename': $!";
+}