createProjVersHeader.py 1.1 KB
Newer Older
marcocle's avatar
marcocle committed
1
2
3
4
5
6
7
8
9
def main():
    import os, sys, re
    if len(sys.argv) != 4:
        print "ERROR: Usage %s <project> <version> <outputfile>"%sys.argv[0]
        exit(1)
    
    project, version, outputfile = sys.argv[1:]
    print "Creating %s for %s %s"%(outputfile, project, version) 
    
hmd's avatar
hmd committed
10
11
12
    m = re.match("(v|([A-Za-z]+\-))(?P<maj_ver>[0-9]+)(r|\-)(?P<min_ver>[0-9]+)(?:(p|\-)(?P<pat_ver>[0-9]+))?",version)
    majver = int(m.groupdict()['maj_ver'])
    minver = int(m.groupdict()['min_ver'])
marcocle's avatar
marcocle committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
    
    outdir = os.path.dirname(outputfile)
    if not os.path.exists(outdir):
        print "Creating directory", outdir
        os.makedirs(outdir)
    
    open(outputfile,"w").write(
    """#ifndef %(proj)s_VERSION
/* Automatically generated file: do not modify! */
#ifndef CALC_GAUDI_VERSION
#define CALC_GAUDI_VERSION(maj,min) (((maj) << 16) + (min))
#endif
#define %(proj)s_MAJOR_VERSION %(maj)d
#define %(proj)s_MINOR_VERSION %(min)d
#define %(proj)s_VERSION CALC_GAUDI_VERSION(%(proj)s_MAJOR_VERSION,%(proj)s_MINOR_VERSION)
#endif
"""%{ 'proj': project.upper(), 'min': minver, 'maj': majver })

if __name__ == "__main__":
    main()