minor fixes for clang++
[senf.git] / debian / SConscript
1 # -*- python -*-
2
3 Import('env')
4 import SENFSCons, os, os.path, pwd, time, string
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 = ''
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 not version:
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     if rev == 'rexported':
69         rev = os.popen("gitsvnversion").read().strip().lower()
70
71 logname = os.environ.get('LOGNAME')
72 if not logname:
73     logname = pwd.getpwuid(os.getuid()).pw_name
74
75 def dpkgIgnoredFilesOpts(target, source, env, for_signature):
76     return [ '-I%s' % (('/' in f) and (os.path.split(os.getcwd())[1])+f or f)
77              for f in env.subst('$DPKG_IGNORED_FILES').split() ]
78
79 if env.has_key('REVISION'):
80     rev = env['REVISION']
81 # else:
82 #     rev = "(Version %s)" % rev
83
84 env.Append( ENV = { 
85     'REVISION': rev,
86     'LOGNAME' : logname, # needed by the debian build scripts
87     'CONCURRENCY_LEVEL' : env.GetOption('num_jobs') or "1",
88     'SCONS' : 1,
89 })
90
91 env.Replace(                    
92     LOCAL_CONFIG_FILES = [ '/Doxyfile.local', '/SConscript.local', '/senf/local_config.hh' ],
93     DPKG_IGNORED_FILES = [ '$LOCAL_CONFIG_FILES', '.svn', '.git', '.gitignore', '/_templates', 
94                            '/TODO', '.project', '.cproject', '.dir.el', '/.project.el' ],
95     DPKG_IGNORED_FILES_OPTS = dpkgIgnoredFilesOpts,
96     BUILDPACKAGE_COMMAND = "dpkg-buildpackage -us -uc -rfakeroot $DPKG_IGNORED_FILES_OPTS",
97 )
98
99 env.PhonyTarget('deb', [], [
100     checkLocalConf,
101     updateRevision,
102     "$BUILDPACKAGE_COMMAND",
103     "fakeroot ./debian/rules clean"
104 ])
105
106 env.PhonyTarget('debsrc', [], [
107     updateRevision,
108     "$BUILDPACKAGE_COMMAND -S",
109 ])
110
111 env.PhonyTarget('debbin', [], [
112     checkLocalConf,
113     updateRevision,
114     "$BUILDPACKAGE_COMMAND -b -nc",
115     "fakeroot ./debian/rules debclean"
116 ])
117
118 if not os.environ.get('debian_build'):
119     env.Clean(env.Alias('all'), '#/debian/changelog')