1 |
#!/usr/bin/perl -w |
2 |
|
3 |
# In config.local, __DEFS__ section must precede __MAKE__ section |
4 |
|
5 |
use constant kSTATUSOK => 0; |
6 |
use constant kSTATUSCONF => 1; |
7 |
|
8 |
use constant kUNKSECTION => 0; |
9 |
use constant kDEFSSECTION => 1; |
10 |
use constant kMAKESECTION => 2; |
11 |
|
12 |
use constant kCUSTMK => "custom.mk"; |
13 |
|
14 |
my($line); |
15 |
my($section); |
16 |
my($status); |
17 |
my($tmp); |
18 |
my($beginning); |
19 |
my($locdir); |
20 |
my($varname); |
21 |
my($mach); |
22 |
my($varvalu); |
23 |
my(%platmaps) = (); |
24 |
my(%machmaps) = (); |
25 |
|
26 |
$status = kSTATUSOK; |
27 |
$section = kUNKSECTION; |
28 |
$tmp = $ARGV[0]; |
29 |
$locdir = $ARGV[1]; |
30 |
|
31 |
if (open(CONFLOC, "<$tmp")) |
32 |
{ |
33 |
$tmp = kCUSTMK; |
34 |
if (!open(CUSTMK, ">>$locdir/$tmp")) |
35 |
{ |
36 |
print STDERR "Can't open file '$tmp' for writing.\n" |
37 |
} |
38 |
else |
39 |
{ |
40 |
$beginning = 1; |
41 |
|
42 |
while (defined($line = <CONFLOC>)) |
43 |
{ |
44 |
chomp($line); |
45 |
|
46 |
if ($line =~ /^\#/ || $line =~ /^\s*$/) |
47 |
{ |
48 |
next; |
49 |
} |
50 |
|
51 |
if ($line =~ /__DEFS__/) |
52 |
{ |
53 |
$section = kDEFSSECTION; |
54 |
next; |
55 |
} |
56 |
elsif ($line =~ /__MAKE__/) |
57 |
{ |
58 |
$section = kMAKESECTION; |
59 |
next; |
60 |
} |
61 |
|
62 |
if ($section == kDEFSSECTION || $section == kMAKESECTION) |
63 |
{ |
64 |
# Put all config.local key-value pairs in custom.mk too. Some of these will be |
65 |
# used by the make system. There is an unaddressed problem: The config.local |
66 |
# for NetDRMS has key names that do not match the key names for an SDP |
67 |
# checkout. The SDP names match the names of the defines used in the source code, |
68 |
# but NetDRMS do not match anything. gen_init.csh maps these names to the |
69 |
# names used by the source code. |
70 |
# |
71 |
# Currently, the only key-value pair needed by the make system is SUMS_TAPE_AVAILABLE, |
72 |
# which in fact IS named identically in all three places (SDP config.local, NetDRMS |
73 |
# config.local, and in the source code). |
74 |
$mach = ""; |
75 |
|
76 |
if ($line =~ /\s*(\S+)\s+(\S+)/) |
77 |
{ |
78 |
$varname = $1; |
79 |
$varvalu = $2; |
80 |
|
81 |
if ($varname =~ /(\S+):(\S+)/) |
82 |
{ |
83 |
$varname = $1; |
84 |
$mach = $2; |
85 |
} |
86 |
|
87 |
if (length($mach) == 0) |
88 |
{ |
89 |
print CUSTMK "$varname = $varvalu\n"; |
90 |
} |
91 |
} |
92 |
elsif ($line =~ /\s*(\S+)\s*/) |
93 |
{ |
94 |
$varname = $1; |
95 |
|
96 |
if ($varname =~ /(\S+):(\S+)/) |
97 |
{ |
98 |
$varname = $1; |
99 |
$mach = $2; |
100 |
} |
101 |
|
102 |
if (length($mach) == 0) |
103 |
{ |
104 |
print CUSTMK "$varname = \n"; |
105 |
} |
106 |
} |
107 |
else |
108 |
{ |
109 |
print STDERR "Invalid line '$line' in configuration file.\n"; |
110 |
$status = kSTATUSCONF; |
111 |
last; |
112 |
} |
113 |
|
114 |
# deal with mach-specific |
115 |
if (length($mach) > 0) |
116 |
{ |
117 |
if (SupportedPlat($mach)) |
118 |
{ |
119 |
$platmaps{$mach}{$varname} = $varvalu; |
120 |
} |
121 |
else |
122 |
{ |
123 |
$machmaps{$mach}{$varname} = $varvalu; |
124 |
} |
125 |
} |
126 |
} |
127 |
else |
128 |
{ |
129 |
print STDERR "Invalid configuration file format.\n"; |
130 |
$status = kSTATUSCONF; |
131 |
} |
132 |
} |
133 |
|
134 |
# Write out machine-specific key-value pairs |
135 |
my(%map); |
136 |
|
137 |
foreach $mach (keys(%platmaps)) |
138 |
{ |
139 |
%map = %{$platmaps{$mach}}; |
140 |
|
141 |
# There are two special machine 'types' - X86_64 and IA32; they refer to |
142 |
# the two supported linux-CPU types, linux_x86_64 and linux_ia32 as |
143 |
# identified by $JSOC_MACHINE |
144 |
if ($mach =~ /x86_64/i) |
145 |
{ |
146 |
print CUSTMK 'ifeq ($(JSOC_MACHINE), linux_x86_64)' . "\n"; |
147 |
} |
148 |
elsif ($mach =~ /ia32/i) |
149 |
{ |
150 |
print CUSTMK 'ifeq ($(JSOC_MACHINE), linux_ia32)' . "\n"; |
151 |
} |
152 |
elsif ($mach =~ /ia64/i) |
153 |
{ |
154 |
print CUSTMK 'ifeq ($(JSOC_MACHINE), linux_ia64)' . "\n"; |
155 |
} |
156 |
|
157 |
foreach $varname (keys(%map)) |
158 |
{ |
159 |
$varvalu = $map{$varname}; |
160 |
print CUSTMK "$varname = $varvalu\n"; |
161 |
} |
162 |
|
163 |
print CUSTMK "endif\n"; |
164 |
} |
165 |
|
166 |
foreach $mach (keys(%machmaps)) |
167 |
{ |
168 |
%map = %{$machmaps{$mach}}; |
169 |
|
170 |
# The MACH make variable is passed in as part of the make command-line: |
171 |
# make MACH='N02' |
172 |
# This will override the supported platform types. |
173 |
print CUSTMK "ifeq (\$(MACH), $mach)\n"; |
174 |
|
175 |
foreach $varname (keys(%map)) |
176 |
{ |
177 |
$varvalu = $map{$varname}; |
178 |
print CUSTMK "$varname = $varvalu\n"; |
179 |
} |
180 |
|
181 |
print CUSTMK "endif\n"; |
182 |
} |
183 |
|
184 |
|
185 |
close(CUSTMK); |
186 |
} |
187 |
|
188 |
close(CONFLOC); |
189 |
} |
190 |
|
191 |
exit($status); |
192 |
|
193 |
sub SupportedPlat |
194 |
{ |
195 |
my($plat) = $_[0]; |
196 |
|
197 |
if ($plat =~ /^x86_64$/i || $plat =~ /^ia32$/i || $plat =~ /^ia64$/i) |
198 |
{ |
199 |
return 1; |
200 |
} |
201 |
else |
202 |
{ |
203 |
return 0; |
204 |
} |
205 |
} |