Subversion Repositories HelenOS

Rev

Rev 3386 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3386 Rev 4153
Line 1... Line 1...
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:
Line 25... Line 26...
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'
-
 
43
PRECONF = 'defaults'
40
 
44
 
469
 
322
 
470
def main():
323
def main():
471
    defaults = {}
324
    defaults = {}
472
    try:
325
    ask_names = []
-
 
326
   
473
        dlg = Dialog()
327
    # Parse configuration file
474
    except NotImplementedError:
328
    parse_config(INPUT, ask_names)
-
 
329
   
475
        dlg = NoDialog()
330
    # Read defaults from previous run
-
 
331
    if os.path.exists(MAKEFILE):
-
 
332
        read_defaults(MAKEFILE, defaults)
476
 
333
   
-
 
334
    # Default mode: only check defaults and regenerate configuration
477
    if len(sys.argv) >= 3 and sys.argv[2]=='default':
335
    if ((len(sys.argv) >= 3) and (sys.argv[2] == 'default')):
478
        defmode = True
336
        if (check_choices(defaults, ask_names)):
-
 
337
            create_output(MAKEFILE, MACROS, DEFS, defaults, ask_names)
479
    else:
338
            return 0
-
 
339
   
480
        defmode = False
340
    # Check mode: only check defaults
-
 
341
    if ((len(sys.argv) >= 3) and (sys.argv[2] == 'check')):
-
 
342
        if (check_choices(defaults, ask_names)):
-
 
343
            return 0
-
 
344
        return 1
481
 
345
   
-
 
346
    screen = xtui.screen_init()
-
 
347
    try:
-
 
348
        selname = None
-
 
349
        position = None
-
 
350
        while True:
-
 
351
           
482
    # Default run will update the configuration file
352
            # Cancel out all defaults which have to be deduced
-
 
353
            for varname, vartype, name, choices, cond in ask_names:
-
 
354
                if ((vartype == 'y') and (defaults.has_key(varname)) and (defaults[varname] == '*')):
483
    # with newest options
355
                    defaults[varname] = None
-
 
356
           
484
    if os.path.exists(OUTPUT):
357
            options = []
-
 
358
            opt2row = {}
-
 
359
            cnt = 1
-
 
360
           
485
        read_defaults(OUTPUT, defaults)
361
            options.append("  --- Load preconfigured defaults ... ")
486
 
362
           
487
    # Get ARCH from command line if specified
363
            for varname, vartype, name, choices, cond in ask_names:
-
 
364
               
-
 
365
                if ((cond) and (not check_condition(cond, defaults, ask_names))):
-
 
366
                    continue
-
 
367
               
488
    if len(sys.argv) >= 4:
368
                if (varname == selname):
-
 
369
                    position = cnt
-
 
370
               
489
        defaults['ARCH'] = sys.argv[3]
371
                if (not defaults.has_key(varname)):
-
 
372
                    default = None
-
 
373
                else:
490
        defaults['PLATFORM'] = sys.argv[3]
374
                    default = defaults[varname]
491
   
375
               
-
 
376
                if (vartype == 'choice'):
492
    # Get COMPILER from command line if specified
377
                    # Check if the default is an acceptable value
-
 
378
                    if ((default) and (not default in [choice[0] for choice in choices])):
493
    if len(sys.argv) >= 5:
379
                        default = None
494
        defaults['COMPILER'] = sys.argv[4]
380
                        defaults.pop(varname)
495
   
381
                   
496
    # Get CONFIG_DEBUG from command line if specified
382
                    # If there is just one option, use it
497
    if len(sys.argv) >= 6:
383
                    if (len(choices) == 1):
498
        defaults['CONFIG_DEBUG'] = sys.argv[5]
384
                        defaults[varname] = choices[0][0]
-
 
385
                        continue
499
   
386
                   
-
 
387
                    if (default == None):
500
    # Get MACHINE/IMAGE from command line if specified
388
                        options.append("?     %s --> " % name)
-
 
389
                    else:
-
 
390
                        options.append("      %s [%s] --> " % (name, default))
501
    if len(sys.argv) >= 7:
391
                elif (vartype == 'y'):
502
        defaults['MACHINE'] = sys.argv[6]
392
                    defaults[varname] = '*'
-
 
393
                    continue
-
 
394
                elif (vartype == 'n'):
503
        defaults['IMAGE'] = sys.argv[6]
395
                    defaults[varname] = 'n'
504
 
396
                    continue
-
 
397
                elif (vartype == 'y/n'):
505
    # Dry run only with defaults
398
                    if (default == None):
-
 
399
                        default = 'y'
506
    varnames = parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults)
400
                        defaults[varname] = default
507
    # If not in default mode, present selection of all possibilities
401
                    options.append("  <%s> %s " % (yes_no(default), name))
508
    if not defmode:
402
                elif (vartype == 'n/y'):
509
        defopt = 0
403
                    if (default == None):
510
        while 1:
404
                        default = 'n'
511
            # varnames contains variable names that were in the
405
                        defaults[varname] = default
512
            # last question set
406
                    options.append("  <%s> %s " % (yes_no(default), name))
-
 
407
                else:
513
            choices = [ (x[1],defaults[x[0]]) for x in varnames ]
408
                    raise RuntimeError("Unknown variable type: %s" % vartype)
-
 
409
               
514
            res = dlg.menu('Configuration',choices,('save','Save'),defopt)
410
                opt2row[cnt] = (varname, vartype, name, choices)
-
 
411
               
-
 
412
                cnt += 1
-
 
413
           
515
            if res == 'save':
414
            if (position >= options):
-
 
415
                position = None
-
 
416
           
516
                parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults)
417
            (button, value) = xtui.choice_window(screen, 'HelenOS configuration', 'Choose configuration option', options, position)
-
 
418
           
517
                break
419
            if (button == 'cancel'):
518
            # transfer description back to varname
420
                return 'Configuration canceled'
-
 
421
           
519
            for i,(vname,descr) in enumerate(varnames):
422
            if (button == 'done'):
520
                if res == descr:
423
                if (check_choices(defaults, ask_names)):
-
 
424
                    break
-
 
425
                else:
-
 
426
                    xtui.error_dialog(screen, 'Error', 'Some options have still undefined values. These options are marked with the "?" sign.')
521
                    defopt = i
427
                    continue
-
 
428
           
522
                    break
429
            if (value == 0):
523
            # Ask the user a simple question, produce output
430
                read_preconfigured(PRECONF, MAKEFILE, screen, defaults)
-
 
431
                position = 1
-
 
432
                continue
-
 
433
           
524
            # as if the user answered all the other questions
434
            position = None
525
            # with default answer
435
            if (not opt2row.has_key(value)):
526
            varnames = parse_config(INPUT, TMPOUTPUT, dlg, defaults,
436
                raise RuntimeError("Error selecting value: %s" % value)
-
 
437
           
527
                                    askonly=varnames[i][0])
438
            (selname, seltype, name, choices) = opt2row[value]
-
 
439
           
-
 
440
            if (not defaults.has_key(selname)):
-
 
441
                    default = None
528
       
442
            else:
-
 
443
                default = defaults[selname]
529
   
444
           
530
    if os.path.exists(OUTPUT):
445
            if (seltype == 'choice'):
-
 
446
                defaults[selname] = subchoice(screen, name, choices, default)
-
 
447
            elif ((seltype == 'y/n') or (seltype == 'n/y')):
531
        os.unlink(OUTPUT)
448
                if (defaults[selname] == 'y'):
532
    os.rename(TMPOUTPUT, OUTPUT)
449
                    defaults[selname] = 'n'
533
   
450
                else:
534
    if not defmode and dlg.yesno('Rebuild everything?') == 'y':
451
                    defaults[selname] = 'y'
-
 
452
    finally:
-
 
453
        xtui.screen_done(screen)
-
 
454
   
535
        os.execlp('make','make','clean','build')
455
    create_output(MAKEFILE, MACROS, DEFS, defaults, ask_names)
-
 
456
    return 0
536
 
457
 
537
if __name__ == '__main__':
458
if __name__ == '__main__':
538
    main()
459
    sys.exit(main())