summaryrefslogtreecommitdiff
path: root/win32/config_sh.PL
blob: a5c6c0dec8b04ff18bd1ab211729a2a188878484 (plain)
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
# take a semicolon separated path list and turn it into a quoted
# list of paths that Text::Parsewords will grok
sub mungepath {
    my $p = shift;
    # remove leading/trailing semis/spaces
    $p =~ s/^[ ;]+//;
    $p =~ s/[ ;]+$//;
    $p =~ s/'/"/g;
    my @p = map { $_ = "\"$_\"" if /\s/ and !/^".*"$/; $_ } split /;/, $p;
    return join(' ', @p);
}

my %opt;
while (@ARGV && $ARGV[0] =~ /^([\w_]+)=(.*)$/)
 {
  $opt{$1}=$2;
  shift(@ARGV);
 }

$opt{VERSION} = $];
$opt{INST_VER} =~ s|~VERSION~|$]|g;
if ($] =~ /^(\d+)\.(\d\d\d)?(\d\d)?$/) { # should always be true
  $opt{PERL_REVISION} = $1;
  $opt{PERL_VERSION} = int($2 || 0);
  $opt{PERL_SUBVERSION} = $3 || '00';
}
else {
  die "Can't parse perl version ($])";
}

$opt{'cf_by'} = $ENV{USERNAME} unless $opt{'cf_by'};
$opt{'cf_email'} = $opt{'cf_by'} . '@' . (gethostbyname('localhost'))[0]
	unless $opt{'cf_email'};
$opt{'usemymalloc'} = 'y' if $opt{'d_mymalloc'} eq 'define';

$opt{libpth} = mungepath($opt{libpth}) if exists $opt{libpth};
$opt{incpath} = mungepath($opt{incpath}) if exists $opt{incpath};

while (<>)
 {
  s/~([\w_]+)~/$opt{$1}/g;
  if (/^([\w_]+)=(.*)$/) {
    my($k,$v) = ($1,$2);
    # this depends on cf_time being empty in the template (or we'll get a loop)
    if ($k eq 'cf_time') {
      $_ = "$k='" . localtime(time) . "'\n" if $v =~ /^\s*'\s*'/;
    }
    elsif (exists $opt{$k}) {
      $_ = "$k='$opt{$k}'\n";
    }
  }
  print;
 }