Combine all boot build stuff in a single scons tool
[senf.git] / debian / SConscript
1 # -*- python -*-
2
3 Import('env')
4 import SENFSCons, os
5
6 ###########################################################################
7
8 def updateRevision(target, source, env):
9     rev = env['ENV']['REVISION'][1:]
10     if ':' in rev:
11         print
12         print "Working copy not clean. Run 'svn update'"
13         print
14         return 1
15     if 'm' in rev and not ARGUMENTS.get('force_deb'):
16         print
17         print "Working copy contains local changes. Commit first"
18         print
19         return 1
20     if 's' in rev:
21         rev = rev[:-1]
22     if 'm' in rev:
23         rev = rev[:-1]
24     url = None
25     for line in os.popen("svn info"):
26         elts=line.split(':',1)
27         if elts[0] == 'URL':
28             url = elts[1].strip()
29     version = None
30     if '/tags/' in url:
31         version = url.rsplit('/',1)[-1].split('_',1)[0]
32         if version[0] not in string.digits:
33             version = None
34     if version is None:
35         version = '1:0r%s' % rev
36     changelog = file('debian/changelog.template').read() % {
37         'version': version,
38         'rev': rev,
39         'user': pwd.getpwuid(os.getuid()).pw_gecos.split(',')[0].strip(),
40         'date': time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()) }
41     file('debian/changelog','w').write(changelog)
42
43 def nonemptyFile(f):
44     try: return os.stat(f).st_size > 0
45     except OSError: return False
46
47 def checkLocalConf(target, source, env):
48     if [ True for f in env['LOCAL_CONFIG_FILES'] if nonemptyFile(f) ]:
49         print
50         print "You have made local modifications to one of the following local configuration"
51         print "files:"
52         for f in env['LOCAL_CONFIG_FILES']:
53             print "    ",f
54         print
55         print "Building a debian package would remove those files."
56         print
57         print "To continue, remove the offending file(s) and try again. Alternatively,"
58         print "build a source package using 'scons debsrc' and may then build debian"
59         print "binary packages from this source-package without disrupting your local"
60         print "configuration."
61         print
62         return 1
63
64 if os.environ.get('debian_build'):
65     rev = os.popen("dpkg-parsechangelog | awk '/^Version:/{print $2}'").read().strip()
66 else:
67     rev = 'r' + os.popen("svnversion").read().strip().lower()
68
69 logname = os.environ.get('LOGNAME')
70 if not logname:
71     logname = pwd.getpwuid(os.getuid()).pw_name
72
73 def dpkgIgnoredFilesOpts(target, source, env, for_signature):
74     return [ '-I%s' % (('/' in f) and (os.path.split(os.getcwd())[1])+f or f)
75              for f in env.subst('$DPKG_IGNORED_FILES').split() ]
76
77 env.Append( ENV = { 
78     'REVISION': rev,
79     'LOGNAME' : logname, # needed by the debian build scripts
80     'CONCURRENCY_LEVEL' : env.GetOption('num_jobs') or "1",
81     'SCONS' : 1,
82 })
83
84 env.Replace(                    
85     LOCAL_CONFIG_FILES = [ '/Doxyfile.local', '/SConfig', '/local_config.hh' ],
86     DPKG_IGNORED_FILES = [ '$LOCAL_CONFIG_FILES', '.svn', '/_templates' ],
87     DPKG_IGNORED_FILES_OPTS = dpkgIgnoredFilesOpts,
88     BUILDPACKAGE_COMMAND = "dpkg-buildpackage -us -uc -rfakeroot $DPKG_IGNORED_FILES_OPTS",
89 )
90
91 env.PhonyTarget('deb', [], [
92     checkLocalConf,
93     updateRevision,
94     "$BUILDPACKAGE_COMMAND",
95     "fakeroot ./debian/rules debclean"
96 ])
97
98 env.PhonyTarget('debsrc', [], [
99     updateRevision,
100     "$BUILDPACKAGE_COMMAND -S",
101 ])
102
103 env.PhonyTarget('debbin', [], [
104     checkLocalConf,
105     updateRevision,
106     "$BUILDPACKAGE_COMMAND -b",
107     "fakeroot ./debian/rules debclean"
108 ])
109