forked from epics-modules/xxx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.pl
146 lines (123 loc) · 2.95 KB
/
release.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# FILENAME... release.pl
#
# USAGE... This PERL script is used in conjunction with a start_epics_xxx
# script to setup environment variables for medm. It defaults to
# csh output, but a switch enables bash output (second form below).
#
# ORIGINAL AUTHOR: Ron Sluiter
#
# SYNOPSIS... perl release.pl (<ioctop> directory)
# perl -s release.pl -form=bash (<ioctop> directory)
#
#
#
# MODIFICATION LOG...
# 03/25/04 rls Support for GATEWAY environment variable.
# 04/08/04 rls Bug fix for spaces between macro and '=' sign; e.g. MPF = /home/mpf.
# 01/25/08 rls Support "include" entries without a macro; e.g. "include /home/ioc/configure/MASTER_RELEASE"
# 01/29/08 rls Bug fix; "($macro) =" line is wrong.
# 04/06/11 daa Add bash output format support.
# 03/20/15 kcl Rewrite to use recursive function, allows in-place resolution of included files
# 03/02/17 kmp Also look for macros in optional include files
#
#Version: $Revision$
#Modified By: $Author$
#Last Modified: $Date$
use Env;
$top = $ARGV[0];
sub Parse
{
my ($file, $applications) = @_;
if (-r "$file")
{
open(my $fh, "$file") or die "Cannot open $file\n";
while ($line = <$fh>)
{
next if ( $line =~ /\s*#/ );
chomp($line);
$line =~ s/\r//g;
$_ = $line;
#test for "include" command
($prefix,$post) = /(.*)\s* (.*)/;
if ($prefix eq "include" || $prefix eq "-include")
{
($prefix,$macro,$post) = /(.*)\s* \s*\$\((.*)\)(.*)/;
if ($macro eq "")
{
#true if no macro is present
#the following looks for
#prefix = post
($prefix,$post) = /(.*)\s* \s*(.*)/;
}
else
{
$base = $applications{$macro};
if ($base eq "")
{
#print "error: $macro was not previously defined\n";
}
else
{
$post = $base . $post;
}
}
Parse($post, $applications);
}
else
{
#the following looks for
#prefix = $(macro)post
($prefix,$macro,$post) = /(.*)\s*=\s*\$\((.*)\)(.*)/;
if ($macro eq "")
{
#true ifno macro is present
#the following looks for
#prefix = post
($prefix,$post) = /(.*)\s*=\s*(.*)/;
}
else
{
$base = $applications{$macro};
if ($base eq "")
{
#print "error: $macro was not previously defined\n";
}
else
{
$post = $base . $post;
}
}
$prefix =~ s/^\s+|\s+$//g; # strip leading and trailing whitespace.
if ("$prefix" ne "")
{
$applications{"$prefix"} = "$post";
}
}
}
close $fh;
}
}
my $applications;
$applications{"TOP"} = $top;
if ($ENV{GATEWAY} ne "")
{
# Add GATEWAY to macro list.
$applications{GATEWAY} = $ENV{GATEWAY};
}
$format = 0;
if ($form eq "bash")
{
$format = 1;
}
Parse("$top/configure/RELEASE", $applications);
foreach $key (keys %applications)
{
if ($format == 1)
{
print "$key=$applications{$key}\n";
}
else
{
print "set $key = $applications{$key}\n";
}
}