Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | # -*- perl -*- |
2 | ||
3 | package Midas::Configure; | |
4 | use strict; | |
5 | ||
6 | use File::Spec; | |
7 | use Data::Dumper; | |
8 | ||
9 | use Midas::Paths; | |
10 | use Midas::Globals; | |
11 | use Midas::Error; | |
12 | ||
13 | require Midas::Command; | |
14 | ||
15 | require Exporter; | |
16 | our @ISA = qw(Exporter); | |
17 | our @EXPORT = qw(configure init_config add_cpp_defines); | |
18 | our @EXPORT_OK = qw(); | |
19 | ||
20 | ||
21 | my %default_config = | |
22 | ( | |
23 | verbose => 1, | |
24 | ||
25 | cpp_includes => { | |
26 | diagroot => ['verif/diag/assembly/include'], | |
27 | startdir => ['.'], | |
28 | builddir => ['.'], | |
29 | abs => [], | |
30 | }, | |
31 | cpp_defines => [ 'GOLDFINGER=1' | |
32 | ], | |
33 | m4_includes => { | |
34 | diagroot => [], | |
35 | startdir => ['.'], | |
36 | builddir => ['.'], | |
37 | abs => [], | |
38 | }, | |
39 | ||
40 | addphdr => 0, | |
41 | ||
42 | cleanup => 1, | |
43 | force_cleanup => 0, | |
44 | ||
45 | link_paths => { | |
46 | diagroot => ['verif/diag'], | |
47 | startdir => ['.'], | |
48 | builddir => [], | |
49 | abs => [], | |
50 | }, | |
51 | ||
52 | csrc_includes => { | |
53 | diagroot => ['verif/diag/c'], | |
54 | startdir => ['.'], | |
55 | builddir => [], | |
56 | abs => [], | |
57 | }, | |
58 | ||
59 | c_includes => { | |
60 | diagroot => ['verif/diag/c/include'], | |
61 | startdir => ['.'], | |
62 | builddir => ['.'], | |
63 | abs => [], | |
64 | }, | |
65 | ||
66 | # Default build directory (this is used as a default for the State | |
67 | # version, which is the one that really gets used). Can be full | |
68 | # path or relative to starting directory. | |
69 | ||
70 | build_dir => './build', | |
71 | ||
72 | # Full path or relative to build_dir | |
73 | local_src => 'diag.src', | |
74 | local_s => 'diag.s', | |
75 | local_pl => 'diag.pl', | |
76 | local_cpp => 'diag.cpp', | |
77 | local_m4 => 'diag.m4', | |
78 | local_ldscr => 'diag*.ld_scr', | |
79 | local_exe => 'diag*.exe', | |
80 | local_image => 'mem.image', | |
81 | local_events => 'diag.ev', | |
82 | local_symtab => 'symbol.tbl', | |
83 | local_goldfinger => 'diag.goldfinger', | |
84 | local_directives => 'diag.midas', | |
85 | ||
86 | local_cmdfile => '.midas_args', | |
87 | local_oldcmdfile => '.midas_args.old', | |
88 | local_oldm4 => '.midas.diag.m4.old', | |
89 | ||
90 | intermed_files => [qw(local_src local_s local_pl local_cpp local_m4 | |
91 | local_ldscr local_goldfinger local_directives | |
92 | sec*.s sec*.o | |
93 | )], | |
94 | ||
95 | force_build => 0, | |
96 | ||
97 | allow_tsb_conflicts => 0, | |
98 | allow_empty_sections => 0, | |
99 | allow_illegal_page_sizes => 0, | |
100 | allow_duplicate_tags => 0, | |
101 | allow_misaligned_tsb_base => 0, | |
102 | gen_all_tsbs => 0, | |
103 | compress_image => 1, | |
104 | env_zero => 1, | |
105 | build_threads => 3, | |
106 | ||
107 | goldfinger_cmd => 'goldfinger', | |
108 | goldfinger_version => '1.07', | |
109 | ||
110 | default_radix => 'decimal', | |
111 | ||
112 | product_files => { | |
113 | required => [qw(local_s local_image local_events | |
114 | local_symtab local_exe)], | |
115 | optional => [qw(local_pl)], | |
116 | clean => [qw(local_image local_events | |
117 | local_symtab local_exe)], | |
118 | }, | |
119 | copy_products => 0, | |
120 | ||
121 | cat_cmd => 'gcat', | |
122 | diff_cmd => 'diff', | |
123 | ||
124 | ||
125 | # If 1, use only full paths. Otherwise use relative paths wherever | |
126 | # possible to make output more clear. | |
127 | full_paths => 0, | |
128 | ||
129 | # Default MMU type | |
130 | mmu_type => 'niagara', | |
131 | ttefmt => 'sun4v', | |
132 | tsbtagfmt => 'tagaccess', | |
133 | ||
134 | ||
135 | pal_cmd => 'pal', | |
136 | pal_opt => [], | |
137 | pal_diag_args => [], | |
138 | ||
139 | cpp_cmd => 'bw_cpp', | |
140 | cpp_opt => ['-B -P'], | |
141 | ||
142 | m4_cmd => 'bw_m4', | |
143 | m4_opt => [], | |
144 | ||
145 | as_cmd => 'g_as', | |
146 | as_opt => ['-xarch=v9b'], | |
147 | ||
148 | ld_cmd => 'g_ld', | |
149 | ld_opt => ['-b elf64-sparc', '-no-warn-mismatch', | |
150 | '--no-check-sections'], | |
151 | ||
152 | gcc_cmd => 'gcc', | |
153 | gcc_opt => ['-m64', '-nostdinc', '-fno-common', '-fno-builtin'], | |
154 | ||
155 | perl_cmd => 'perl', | |
156 | ); | |
157 | ||
158 | ||
159 | ############################################################################## | |
160 | ||
161 | sub init_config { | |
162 | my $def_config= \%default_config; | |
163 | ||
164 | Midas::Command::chat "init_config, project is $PROJECT.\n"; | |
165 | my $dumper = Data::Dumper->new([$def_config]); | |
166 | ||
167 | $dumper->Purity(1)->Deepcopy(1); | |
168 | my $new_config = eval "no strict; " . $dumper->Dump; | |
169 | ||
170 | Midas::Command::fatal("Deepcopy of config failed!: $@\n", M_CODE) if $@; | |
171 | ||
172 | %CONFIG = %{ $new_config }; | |
173 | ||
174 | { | |
175 | package Config_Sandbox; | |
176 | our %PROJ_CONFIG; | |
177 | unless(my $return = do $Midas::Globals::CONFIG_FILE) { | |
178 | Midas::Command::chat | |
179 | ("WARNING! Can't parse config file ". | |
180 | "'$Midas::Globals::CONFIG_FILE': $@\n". | |
181 | "Using defaults.\n", 1) if $@; | |
182 | Midas::Command::chat | |
183 | ("WARNING! Can't find config file ". | |
184 | "'$Midas::Globals::CONFIG_FILE': $!\n". | |
185 | "Using defaults.\n", 1) unless defined $return; | |
186 | } else { | |
187 | if(exists $PROJ_CONFIG{$Midas::Globals::PROJECT}) { | |
188 | Midas::Command::chat | |
189 | ("Setting project defaults for project ". | |
190 | "'$Midas::Globals::PROJECT'.\n"); | |
191 | foreach my $key (keys %{ $PROJ_CONFIG{$Midas::Globals::PROJECT} } ) { | |
192 | $Midas::Globals::CONFIG{$key} = | |
193 | $PROJ_CONFIG{$Midas::Globals::PROJECT}{$key}; | |
194 | } | |
195 | } else { | |
196 | Midas::Command::chat("WARNING! No project config for project ". | |
197 | "'$Midas::Globals::PROJECT'.\n". | |
198 | "Using defaults.\n", 1); | |
199 | } | |
200 | } | |
201 | } | |
202 | ||
203 | ||
204 | (my $MAJOR_VERSION = $Midas::VERSION) =~ s/\..*$//; | |
205 | (my $MINOR_VERSION = $Midas::VERSION) =~ s/^.*\.//; | |
206 | ||
207 | add_cpp_defines( | |
208 | "MIDAS_VERSION=$Midas::VERSION", | |
209 | "MIDAS_MAJOR_VERS=$MAJOR_VERSION", | |
210 | "MIDAS_MINOR_VERS=$MINOR_VERSION" | |
211 | ); | |
212 | ||
213 | # Make Path's version of full_paths a *reference* to the Configure version. | |
214 | # This way, when one changes, they both change. Ditto for verbose. | |
215 | Midas::Paths::configure(full_paths => \$CONFIG{full_paths}); | |
216 | Midas::Command::configure(verbose => \$CONFIG{verbose}); | |
217 | } | |
218 | ||
219 | ############################################################################## | |
220 | ||
221 | sub configure { | |
222 | my %args = @_; | |
223 | ||
224 | foreach my $key (keys %args) { | |
225 | $CONFIG{$key} = $args{$key}; | |
226 | } | |
227 | ||
228 | return %CONFIG; | |
229 | } | |
230 | ||
231 | ############################################################################## | |
232 | ||
233 | sub add_cpp_includes { | |
234 | my @includes = @_; | |
235 | $CONFIG{cpp_includes}{abs} = [] unless exists $CONFIG{cpp_includes}{abs}; | |
236 | unshift @{$CONFIG{cpp_includes}{abs}}, @includes; | |
237 | } | |
238 | ||
239 | ############################################################################## | |
240 | ||
241 | sub add_m4_includes { | |
242 | my @includes = @_; | |
243 | $CONFIG{m4_includes}{abs} = [] unless exists $CONFIG{m4_includes}{abs}; | |
244 | unshift @{$CONFIG{m4_includes}{abs}}, @includes; | |
245 | } | |
246 | ||
247 | ############################################################################## | |
248 | ||
249 | sub add_link_includes { | |
250 | my @includes = @_; | |
251 | $CONFIG{link_path}{abs} = [] unless exists $CONFIG{link_path}{abs}; | |
252 | unshift @{$CONFIG{link_path}{abs}}, @includes; | |
253 | } | |
254 | ||
255 | ############################################################################## | |
256 | ||
257 | sub add_csrc_includes { | |
258 | my @includes = @_; | |
259 | $CONFIG{csrc_includes}{abs} = [] unless exists $CONFIG{csrc_includes}{abs}; | |
260 | unshift @{$CONFIG{csrc_includes}{abs}}, @includes; | |
261 | } | |
262 | ||
263 | ############################################################################## | |
264 | ||
265 | sub add_cpp_defines { | |
266 | my @defines = @_; | |
267 | push @{$CONFIG{cpp_defines}}, @defines; | |
268 | } | |
269 | ||
270 | ############################################################################## | |
271 | ||
272 | sub add_pal_diag_args { | |
273 | my @args = @_; | |
274 | push @{$CONFIG{pal_diag_args}}, @args; | |
275 | } | |
276 | ||
277 | ############################################################################## | |
278 | ||
279 | sub append_configuration { | |
280 | my %args = @_; | |
281 | foreach my $key (keys %args) { | |
282 | if(ref $CONFIG{$key}) { | |
283 | if(ref $CONFIG{$key} eq 'ARRAY') { | |
284 | push @{$CONFIG{$key}}, @{$args{$key}}; | |
285 | } else { | |
286 | Midas::Command::fatal | |
287 | ("Only know how to append configuration to arrays (not $key).\n"); | |
288 | } | |
289 | } else { | |
290 | Midas::Command::fatal("Can't append to scalar key $key\n", M_CODE); | |
291 | } | |
292 | } | |
293 | } | |
294 | ||
295 | ############################################################################## | |
296 | ############################################################################## | |
297 | 1; |