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