-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_intree_bin.pl
62 lines (56 loc) · 1.83 KB
/
build_intree_bin.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl
use strict; use warnings;
use feature 'say';
use File::Path qw(make_path);
my $destdir = $ARGV[0];
my $bindir = "$destdir/script";
my @formats = (
# bat
{
'out' => "$destdir/bin_cmd",
'name' => sub { return $_[0].'.bat';},
'writefilecontents' => sub {
my ($fh, $scriptname) = @_;
print $fh '@echo off'."\r\n";
print $fh "where /q perl\r\n";
print $fh "IF ERRORLEVEL 1 (\r\n";
print $fh 'SET "PERLEXE=C:\Program Files\Git\usr\bin\perl.exe"' . "\r\n";
print $fh ") ELSE (\r\n";
print $fh 'SET "PERLEXE=perl"' . "\r\n";
print $fh ")\r\n";
print $fh '"%PERLEXE%" "-I" "%~dp0..\lib" "%~dp0..\script'."\\" . $scriptname . '" %*'."\r\n";
}
},
# sh
{
'out' => "$destdir/bin_sh",
'name' => sub { return $_[0];},
'writefilecontents' => sub {
my ($fh, $scriptname) = @_;
print $fh '#!/bin/sh'."\n";
print $fh 'SCRIPTLOC=$(dirname $0)'."\n";
print $fh 'exec perl -I "$SCRIPTLOC/../lib" "$SCRIPTLOC/../script/'. $scriptname.'" "$@"'."\n";
my $perm = (stat $fh)[2] & 07777;
chmod($perm | 0111, $fh);
}
}
);
# create the open directories
foreach my $format (@formats) {
make_path($format->{out});
}
# loop through the scripts
opendir(my $dh, $bindir) || die "Can't open $bindir: $!";
while (readdir $dh) {
next if($_ =~ /^\.{1,2}$/);
# make the wrapper scripts
foreach my $format (@formats) {
my $outpath = $format->{out}."/".$format->{name}($_);
say "converting $bindir/$_ to $outpath";
open(my $fh, '>', $outpath) or die("Error creating bat");
$format->{writefilecontents}($fh, $_);
close($fh);
}
}
closedir $dh;
say "Wrote all files";