]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - makeversion.py
- Added missing prey.xml for win32 setup
[xonotic/netradiant.git] / makeversion.py
1 # Copyright (C) 1999-2006 Id Software, Inc. and contributors.
2 # For a list of contributors, see the accompanying CONTRIBUTORS file.
3
4 # This file is part of GtkRadiant.
5
6 # GtkRadiant is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # GtkRadiant is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with GtkRadiant; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
20
21 # version and about message management
22 # NOTE: this module is meant to be used on all platforms, it is not SCons centric
23
24 # version:
25 # input:
26 #   include/version.default
27 # output:
28 #   include/version.h include/RADIANT_MAJOR include/RADIANT_MINOR
29 #   the header is used by C/C++ code, the straight text file by setup
30
31 # about message
32 #   for non-official builds, we have a default message
33 #   otherwise, use environment variable $RADIANT_ABOUTMSG
34 # input:
35 #   file pointed to by $RADIANT_ABOUTMSG if exists
36 #   else include/aboutmsg.default
37 # ouput:
38 #   include/aboutmsg.h
39
40 import sys, re, string, os
41
42 import svn
43
44 def get_version():
45   # version
46   f = open('include/version.default', 'r')
47   buffer = f.read()
48   line = string.split(buffer, '\n')[0]
49   f.close()
50   sys.stdout.write("version: %s\n" % line)
51   exp = re.compile('^1\\.([^\\.]*)\\.([0-9]*)')
52   (major, minor) = exp.findall(line)[0]
53   sys.stdout.write("minor: %s major: %s\n" % (minor, major))
54   return (line, major, minor)  
55
56 # you can pass an optional message to append to aboutmsg
57 def radiant_makeversion(append_about, root = os.getcwd()):
58   (line, major, minor) = get_version()
59   f = open(os.path.join(root, 'include/version.h'), 'w')
60   f.write('// generated header, see makeversion.py\n')
61   f.write('#define RADIANT_VERSION "%s"\n' % line)
62   f.write('#define RADIANT_MINOR_VERSION "%s"\n' % minor)
63   f.write('#define RADIANT_MAJOR_VERSION "%s"\n' % major)
64   f.close()
65   f = open(os.path.join(root, 'include/RADIANT_MINOR'), 'w')
66   f.write(minor)
67   f.close()
68   f = open(os.path.join(root, 'include/RADIANT_MAJOR'), 'w')
69   f.write(major)
70   f.close()
71   f = open(os.path.join(root, 'include/version'), 'w')
72   f.write(line)
73   f.close()
74   # aboutmsg
75   aboutfile = os.path.join(root, 'include/aboutmsg.default')
76   if ( os.environ.has_key('RADIANT_ABOUTMSG') ):
77     aboutfile = os.environ['RADIANT_ABOUTMSG']
78   line = None
79   if os.path.isfile(aboutfile):
80     sys.stdout.write("about message is in %s\n" % aboutfile)
81     f = open(aboutfile, 'r')
82     line = f.readline()
83     f.close()
84     if line.endswith("\n"):
85       line = line[:-1]
86   else:
87     line = "Custom build based on revision " + str(svn.getRevision(os.getcwd()))
88   # optional additional message
89   if ( not append_about is None ):
90     line += append_about
91   sys.stdout.write("about: %s\n" % line)
92   f = open(os.path.join(root, 'include/aboutmsg.h'), 'w')
93   f.write('// generated header, see makeversion.py\n')
94   f.write('#define RADIANT_ABOUTMSG "%s"\n' % line)
95   f.close()
96
97 # can be used as module (scons build), or by direct call
98 if __name__ == '__main__':
99   root = os.path.dirname(__file__)
100   if not os.path.isabs(root):
101     root = os.getcwd()
102   radiant_makeversion(None, root)