forked from therion/therion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeconfig.pl
47 lines (39 loc) · 822 Bytes
/
makeconfig.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
# read make file
open(MF,"Makefile");
@mflines = <MF>;
close(MF);
# backup makefile
open(MFB,">Makefile~");
print MFB @mflines;
close(MFB);
open(MF,">Makefile");
$insidecfg = 0;
$insideprm = 0;
$config = $ARGV[0];
$param = $ARGV[1];
foreach $ln (@mflines) {
if ($ln =~ /^\s*\#\s*$config\s+CONFIG\s*$/) {
$insidecfg = 1;
}
if ($ln =~ /^\s*\#\s*$config\s+ENDCONFIG\s*$/) {
$insidecfg = 0;
}
if ($insidecfg && ($ln =~ /^\s*\#\s*$config\s+$param\s*$/)) {
$insideprm = 1;
} elsif ($insidecfg && ($ln =~ /^\s*\#\s*$config\s+\S+\s*$/)) {
$insideprm = 0;
}
if ($ln =~ /\S/) {
if ($insidecfg) {
if ($insideprm) {
$ln =~ s/^\s*\#\#//;
} else {
if ($ln =~ /^\s*[^\#]/) {
$ln = "##$ln";
}
}
}
}
print MF $ln;
}
close(MF);