make-version.py 985 Bytes
Newer Older
1
#!@PYTHON@
Han-Wen Nienhuys's avatar
Han-Wen Nienhuys committed
2 3 4
import re
import sys

5 6
PROGRAM = sys.argv[0]
VERSION = sys.argv[1]
Han-Wen Nienhuys's avatar
Han-Wen Nienhuys committed
7
defs = []
8
for i in open (VERSION).readlines ():
9 10 11 12
    i = re.sub ('#.*','', i)
    m  = re.search ('([^ =]*)[\t ]*=[ \t]*([^ \t]*)[ \t]*\n', i)
    if m:
        defs.append ((m.group (1), m.group (2)))
Han-Wen Nienhuys's avatar
Han-Wen Nienhuys committed
13

Han-Wen Nienhuys's avatar
Han-Wen Nienhuys committed
14
sys.stdout.write (r'''
15
/*
16 17
 Automatically generated from %(VERSION)s
 by %(PROGRAM)s.
18
*/
Han-Wen Nienhuys's avatar
Han-Wen Nienhuys committed
19 20
#ifndef VERSION_HH
#define VERSION_HH
21
''' % vars ())
Han-Wen Nienhuys's avatar
Han-Wen Nienhuys committed
22

23
for name, expansion in defs:
24 25
    # GUILE leaks autoconf data into userspace. 
    sys.stdout.write (r'''
26 27 28 29 30
#ifdef %(name)s
#undef %(name)s
#endif /* %(name)s */
#define %(name)s "%(expansion)s"
''' % vars ())
31
    
Han-Wen Nienhuys's avatar
Han-Wen Nienhuys committed
32
if ('MY_PATCH_LEVEL', '') in defs:
33
    sys.stdout.write (r'''
34 35 36 37
#define NO_MY_PATCHLEVEL
#define TOPLEVEL_VERSION MAJOR_VERSION "." MINOR_VERSION "." PATCH_LEVEL
''')
else:
38
    sys.stdout.write (r'''
39 40
#define TOPLEVEL_VERSION MAJOR_VERSION "." MINOR_VERSION "." PATCH_LEVEL "." MY_PATCH_LEVEL
''')
Jan Nieuwenhuizen's avatar
Jan Nieuwenhuizen committed
41

Han-Wen Nienhuys's avatar
Han-Wen Nienhuys committed
42
sys.stdout.write(r'''
43
#endif /* VERSION_HH */
Han-Wen Nienhuys's avatar
Han-Wen Nienhuys committed
44
''')
45