Subversion Repositories HelenOS

Rev

Rev 4341 | Rev 4343 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4341 Rev 4342
Line 35... Line 35...
35
import re
35
import re
36
import commands
36
import commands
37
import xtui
37
import xtui
38
 
38
 
39
INPUT = sys.argv[1]
39
INPUT = sys.argv[1]
40
OUTPUT = 'Makefile.config'
40
MAKEFILE = 'Makefile.config'
-
 
41
MACROS = 'config.h'
-
 
42
DEFS = 'config.defs'
41
 
43
 
42
def read_defaults(fname, defaults):
44
def read_defaults(fname, defaults):
43
    "Read saved values from last configuration run"
45
    "Read saved values from last configuration run"
44
   
46
   
45
    inf = file(fname,'r')
47
    inf = file(fname, 'r')
46
   
48
   
47
    for line in inf:
49
    for line in inf:
48
        res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
50
        res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
49
        if (res):
51
        if (res):
50
            defaults[res.group(1)] = res.group(2)
52
            defaults[res.group(1)] = res.group(2)
Line 214... Line 216...
214
        if (not defaults.has_key(varname)):
216
        if (not defaults.has_key(varname)):
215
            return False
217
            return False
216
   
218
   
217
    return True
219
    return True
218
 
220
 
219
def create_output(fname, defaults, ask_names):
221
def create_output(mkname, mcname, dfname, defaults, ask_names):
220
    "Create output configuration"
222
    "Create output configuration"
221
   
223
   
-
 
224
    revision = commands.getoutput('svnversion . 2> /dev/null')
222
    outf = file(fname, 'w')
225
    timestamp = commands.getoutput('date "+%Y-%m-%d %H:%M:%S"')
223
   
226
   
-
 
227
    outmk = file(mkname, 'w')
-
 
228
    outmc = file(mcname, 'w')
-
 
229
    outdf = file(dfname, 'w')
-
 
230
   
-
 
231
    outmk.write('#########################################\n')
-
 
232
    outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
-
 
233
    outmk.write('#########################################\n\n')
-
 
234
   
-
 
235
    outmc.write('/***************************************\n')
-
 
236
    outmc.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
-
 
237
    outmc.write(' ***************************************/\n\n')
-
 
238
   
224
    outf.write('#########################################\n')
239
    outdf.write('#########################################\n')
225
    outf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
240
    outdf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
226
    outf.write('#########################################\n\n')
241
    outdf.write('#########################################\n\n')
-
 
242
    outdf.write('CONFIG_DEFS =')
227
   
243
   
228
    for varname, vartype, name, choices, cond in ask_names:
244
    for varname, vartype, name, choices, cond in ask_names:
229
        if ((cond) and (not check_condition(cond, defaults, ask_names))):
245
        if ((cond) and (not check_condition(cond, defaults, ask_names))):
230
            continue
246
            continue
231
       
247
       
232
        if (not defaults.has_key(varname)):
248
        if (not defaults.has_key(varname)):
233
            default = ''
249
            default = ''
234
        else:
250
        else:
235
            default = defaults[varname]
251
            default = defaults[varname]
236
       
252
       
237
        outf.write('# %s\n%s = %s\n\n' % (name, varname, default))
253
        outmk.write('# %s\n%s = %s\n\n' % (name, varname, default))
-
 
254
       
-
 
255
        if ((vartype == "y") or (vartype == "y/n") or (vartype == "n/y")):
-
 
256
            if (default == "y"):
-
 
257
                outmc.write('/* %s */\n#define %s\n\n' % (name, varname))
-
 
258
                outdf.write(' -D%s' % varname)
-
 
259
        else:
-
 
260
            outmc.write('/* %s */\n#define %s %s\n\n' % (name, varname, default))
-
 
261
            outdf.write(' -D%s=%s' % (varname, default))
-
 
262
   
-
 
263
    outmk.write('REVISION = %s\n' % revision)
-
 
264
    outmk.write('TIMESTAMP = %s\n' % timestamp)
238
   
265
   
239
    outf.write('REVISION = %s\n' % commands.getoutput('svnversion . 2> /dev/null'))
266
    outmc.write('#define REVISION %s\n' % revision)
-
 
267
    outmc.write('#define TIMESTAMP %s\n' % timestamp)
-
 
268
   
240
    outf.write('TIMESTAMP = %s\n' % commands.getoutput('date "+%Y-%m-%d %H:%M:%S"'))
269
    outdf.write(' "-DREVISION=%s" "-DTIMESTAMP=%s"\n' % (revision, timestamp))
-
 
270
   
-
 
271
    outmk.close()
-
 
272
    outmc.close()
241
    outf.close()
273
    outdf.close()
242
 
274
 
243
def main():
275
def main():
244
    defaults = {}
276
    defaults = {}
245
    ask_names = []
277
    ask_names = []
246
   
278
   
247
    # Parse configuration file
279
    # Parse configuration file
248
    parse_config(INPUT, ask_names)
280
    parse_config(INPUT, ask_names)
249
   
281
   
250
    # Read defaults from previous run
282
    # Read defaults from previous run
251
    if os.path.exists(OUTPUT):
283
    if os.path.exists(MAKEFILE):
252
        read_defaults(OUTPUT, defaults)
284
        read_defaults(MAKEFILE, defaults)
253
   
285
   
254
    # Default mode: only check defaults and regenerate configuration
286
    # Default mode: only check defaults and regenerate configuration
255
    if ((len(sys.argv) >= 3) and (sys.argv[2] == 'default')):
287
    if ((len(sys.argv) >= 3) and (sys.argv[2] == 'default')):
256
        if (check_choices(defaults, ask_names)):
288
        if (check_choices(defaults, ask_names)):
257
            create_output(OUTPUT, defaults, ask_names)
289
            create_output(MAKEFILE, MACROS, DEFS, defaults, ask_names)
258
            return 0
290
            return 0
259
   
291
   
260
    # Check mode: only check defaults
292
    # Check mode: only check defaults
261
    if ((len(sys.argv) >= 3) and (sys.argv[2] == 'check')):
293
    if ((len(sys.argv) >= 3) and (sys.argv[2] == 'check')):
262
        if (check_choices(defaults, ask_names)):
294
        if (check_choices(defaults, ask_names)):
Line 291... Line 323...
291
                        default = None
323
                        default = None
292
                        defaults.pop(varname)
324
                        defaults.pop(varname)
293
                   
325
                   
294
                    # If there is just one option, use it
326
                    # If there is just one option, use it
295
                    if (len(choices) == 1):
327
                    if (len(choices) == 1):
296
                        default = choices[0][0]
328
                        defaults[varname] = choices[0][0]
297
                        defaults[varname] = default
329
                        continue
298
                   
330
                   
299
                    options.append("     %s [%s] --> " % (name, default))
331
                    options.append("     %s [%s] --> " % (name, default))
-
 
332
                elif (vartype == 'y'):
-
 
333
                    defaults[varname] = 'y'
-
 
334
                    continue
300
                elif (vartype == 'y/n'):
335
                elif (vartype == 'y/n'):
301
                    if (default == None):
336
                    if (default == None):
302
                        default = 'y'
337
                        default = 'y'
303
                        defaults[varname] = default
338
                        defaults[varname] = default
304
                    options.append(" <%s> %s " % (yes_no(default), name))
339
                    options.append(" <%s> %s " % (yes_no(default), name))
Line 344... Line 379...
344
                else:
379
                else:
345
                    defaults[selname] = 'y'
380
                    defaults[selname] = 'y'
346
    finally:
381
    finally:
347
        xtui.screen_done(screen)
382
        xtui.screen_done(screen)
348
   
383
   
349
    create_output(OUTPUT, defaults, ask_names)
384
    create_output(MAKEFILE, MACROS, DEFS, defaults, ask_names)
350
    return 0
385
    return 0
351
 
386
 
352
if __name__ == '__main__':
387
if __name__ == '__main__':
353
    sys.exit(main())
388
    sys.exit(main())