Rev 3022 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3022 | Rev 4055 | ||
---|---|---|---|
1 | #!/usr/bin/env python |
1 | #!/usr/bin/env python |
2 | # |
2 | # |
3 | # Copyright (c) 2006 Ondrej Palkovsky |
3 | # Copyright (c) 2006 Ondrej Palkovsky |
- | 4 | # Copyright (c) 2009 Martin Decky |
|
4 | # All rights reserved. |
5 | # All rights reserved. |
5 | # |
6 | # |
6 | # Redistribution and use in source and binary forms, with or without |
7 | # Redistribution and use in source and binary forms, with or without |
7 | # modification, are permitted provided that the following conditions |
8 | # modification, are permitted provided that the following conditions |
8 | # are met: |
9 | # are met: |
9 | # |
10 | # |
10 | # - Redistributions of source code must retain the above copyright |
11 | # - Redistributions of source code must retain the above copyright |
11 | # notice, this list of conditions and the following disclaimer. |
12 | # notice, this list of conditions and the following disclaimer. |
12 | # - Redistributions in binary form must reproduce the above copyright |
13 | # - Redistributions in binary form must reproduce the above copyright |
13 | # notice, this list of conditions and the following disclaimer in the |
14 | # notice, this list of conditions and the following disclaimer in the |
14 | # documentation and/or other materials provided with the distribution. |
15 | # documentation and/or other materials provided with the distribution. |
15 | # - The name of the author may not be used to endorse or promote products |
16 | # - The name of the author may not be used to endorse or promote products |
16 | # derived from this software without specific prior written permission. |
17 | # derived from this software without specific prior written permission. |
17 | # |
18 | # |
18 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | # |
29 | # |
29 | """ |
30 | """ |
30 | HelenOS configuration script |
31 | HelenOS configuration system |
31 | """ |
32 | """ |
32 | import sys |
33 | import sys |
33 | import os |
34 | import os |
34 | import re |
35 | import re |
35 | import commands |
36 | import commands |
- | 37 | import xtui |
|
36 | 38 | ||
37 | INPUT = sys.argv[1] |
39 | INPUT = sys.argv[1] |
38 | OUTPUT = 'Makefile.config' |
40 | MAKEFILE = 'Makefile.config' |
39 | TMPOUTPUT = 'Makefile.config.tmp' |
41 | MACROS = 'config.h' |
- | 42 | DEFS = 'config.defs' |
|
40 | 43 | ||
469 | 278 | ||
470 | def main(): |
279 | def main(): |
471 | defaults = {} |
280 | defaults = {} |
472 | try: |
- | |
473 | dlg = Dialog() |
281 | ask_names = [] |
474 | except NotImplementedError: |
- | |
475 | dlg = NoDialog() |
- | |
476 | 282 | ||
477 | if len(sys.argv) >= 3 and sys.argv[2]=='default': |
- | |
478 | defmode = True |
283 | # Parse configuration file |
479 | else: |
- | |
480 | defmode = False |
284 | parse_config(INPUT, ask_names) |
481 | 285 | ||
482 | # Default run will update the configuration file |
- | |
483 | # with newest options |
286 | # Read defaults from previous run |
484 | if os.path.exists(OUTPUT): |
287 | if os.path.exists(MAKEFILE): |
485 | read_defaults(OUTPUT, defaults) |
288 | read_defaults(MAKEFILE, defaults) |
486 | 289 | ||
487 | # Get ARCH from command line if specified |
290 | # Default mode: only check defaults and regenerate configuration |
488 | if len(sys.argv) >= 4: |
291 | if ((len(sys.argv) >= 3) and (sys.argv[2] == 'default')): |
489 | defaults['ARCH'] = sys.argv[3] |
292 | if (check_choices(defaults, ask_names)): |
490 | defaults['PLATFORM'] = sys.argv[3] |
293 | create_output(MAKEFILE, MACROS, DEFS, defaults, ask_names) |
- | 294 | return 0 |
|
491 | 295 | ||
492 | # Get COMPILER from command line if specified |
296 | # Check mode: only check defaults |
493 | if len(sys.argv) >= 5: |
297 | if ((len(sys.argv) >= 3) and (sys.argv[2] == 'check')): |
494 | defaults['COMPILER'] = sys.argv[4] |
298 | if (check_choices(defaults, ask_names)): |
- | 299 | return 0 |
|
- | 300 | return 1 |
|
495 | 301 | ||
- | 302 | screen = xtui.screen_init() |
|
- | 303 | try: |
|
- | 304 | selname = None |
|
- | 305 | while True: |
|
- | 306 | ||
496 | # Get CONFIG_DEBUG from command line if specified |
307 | # Cancel out all defaults which have to be deduced |
497 | if len(sys.argv) >= 6: |
308 | for varname, vartype, name, choices, cond in ask_names: |
- | 309 | if ((vartype == 'y') and (defaults.has_key(varname)) and (defaults[varname] == '*')): |
|
498 | defaults['CONFIG_DEBUG'] = sys.argv[5] |
310 | defaults[varname] = None |
499 | 311 | ||
- | 312 | options = [] |
|
- | 313 | opt2row = {} |
|
- | 314 | position = None |
|
- | 315 | cnt = 0 |
|
500 | # Get MACHINE/IMAGE from command line if specified |
316 | for varname, vartype, name, choices, cond in ask_names: |
- | 317 | ||
- | 318 | if ((cond) and (not check_condition(cond, defaults, ask_names))): |
|
- | 319 | continue |
|
- | 320 | ||
501 | if len(sys.argv) >= 7: |
321 | if (varname == selname): |
- | 322 | position = cnt |
|
- | 323 | ||
502 | defaults['MACHINE'] = sys.argv[6] |
324 | if (not defaults.has_key(varname)): |
- | 325 | default = None |
|
- | 326 | else: |
|
503 | defaults['IMAGE'] = sys.argv[6] |
327 | default = defaults[varname] |
504 | 328 | ||
505 | # Dry run only with defaults |
329 | if (vartype == 'choice'): |
506 | varnames = parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults) |
330 | # Check if the default is an acceptable value |
507 | # If not in default mode, present selection of all possibilities |
331 | if ((default) and (not default in [choice[0] for choice in choices])): |
508 | if not defmode: |
332 | default = None |
- | 333 | defaults.pop(varname) |
|
- | 334 | ||
509 | defopt = 0 |
335 | # If there is just one option, use it |
510 | while 1: |
336 | if (len(choices) == 1): |
511 | # varnames contains variable names that were in the |
337 | defaults[varname] = choices[0][0] |
- | 338 | continue |
|
- | 339 | ||
512 | # last question set |
340 | if (default == None): |
513 | choices = [ (x[1],defaults[x[0]]) for x in varnames ] |
341 | options.append("? %s --> " % name) |
- | 342 | else: |
|
514 | res = dlg.menu('Configuration',choices,('save','Save'),defopt) |
343 | options.append(" %s [%s] --> " % (name, default)) |
- | 344 | elif (vartype == 'y'): |
|
- | 345 | defaults[varname] = '*' |
|
- | 346 | continue |
|
515 | if res == 'save': |
347 | elif (vartype == 'y/n'): |
- | 348 | if (default == None): |
|
- | 349 | default = 'y' |
|
- | 350 | defaults[varname] = default |
|
516 | parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults) |
351 | options.append(" <%s> %s " % (yes_no(default), name)) |
- | 352 | elif (vartype == 'n/y'): |
|
517 | break |
353 | if (default == None): |
- | 354 | default = 'n' |
|
- | 355 | defaults[varname] = default |
|
518 | # transfer description back to varname |
356 | options.append(" <%s> %s " % (yes_no(default), name)) |
- | 357 | else: |
|
- | 358 | raise RuntimeError("Unknown variable type: %s" % vartype) |
|
- | 359 | ||
519 | for i,(vname,descr) in enumerate(varnames): |
360 | opt2row[cnt] = (varname, vartype, name, choices) |
- | 361 | ||
- | 362 | cnt += 1 |
|
- | 363 | ||
- | 364 | (button, value) = xtui.choice_window(screen, 'HelenOS configuration', 'Choose configuration option', options, position) |
|
- | 365 | ||
520 | if res == descr: |
366 | if (button == 'cancel'): |
521 | defopt = i |
367 | return 'Configuration canceled' |
- | 368 | ||
522 | break |
369 | if (not opt2row.has_key(value)): |
523 | # Ask the user a simple question, produce output |
370 | raise RuntimeError("Error selecting value: %s" % value) |
- | 371 | ||
524 | # as if the user answered all the other questions |
372 | (selname, seltype, name, choices) = opt2row[value] |
- | 373 | ||
- | 374 | if (not defaults.has_key(selname)): |
|
- | 375 | default = None |
|
- | 376 | else: |
|
525 | # with default answer |
377 | default = defaults[selname] |
- | 378 | ||
526 | varnames = parse_config(INPUT, TMPOUTPUT, dlg, defaults, |
379 | if (button == 'done'): |
527 | askonly=varnames[i][0]) |
380 | if (check_choices(defaults, ask_names)): |
- | 381 | break |
|
528 | 382 | else: |
|
- | 383 | xtui.error_dialog(screen, 'Error', 'Some options have still undefined values. These options are marked with the "?" sign.') |
|
- | 384 | continue |
|
529 | 385 | ||
530 | if os.path.exists(OUTPUT): |
386 | if (seltype == 'choice'): |
- | 387 | defaults[selname] = subchoice(screen, name, choices, default) |
|
- | 388 | elif ((seltype == 'y/n') or (seltype == 'n/y')): |
|
531 | os.unlink(OUTPUT) |
389 | if (defaults[selname] == 'y'): |
532 | os.rename(TMPOUTPUT, OUTPUT) |
390 | defaults[selname] = 'n' |
533 | 391 | else: |
|
534 | if not defmode and dlg.yesno('Rebuild everything?') == 'y': |
392 | defaults[selname] = 'y' |
- | 393 | finally: |
|
- | 394 | xtui.screen_done(screen) |
|
- | 395 | ||
535 | os.execlp('make','make','clean','build') |
396 | create_output(MAKEFILE, MACROS, DEFS, defaults, ask_names) |
- | 397 | return 0 |
|
536 | 398 | ||
537 | if __name__ == '__main__': |
399 | if __name__ == '__main__': |
538 | main() |
400 | sys.exit(main()) |
539 | 401 |