Improve handling of SConfig and Doxyfile.local in debian build
[senf.git] / SConstruct
1 # -*- python -*-
2
3 import sys, glob, os.path, datetime, pwd, time, fnmatch
4 sys.path.append('senfscons')
5 import SENFSCons
6
7 ###########################################################################
8
9 def updateRevision(target, source, env):
10     rev = env['ENV']['REVISION'][1:]
11     if ':' in rev:
12         print
13         print "Working copy not clean. Run 'svn update'"
14         print
15         return 1
16     if 'm' in rev and not ARGUMENTS.get('force_deb'):
17         print
18         print "Working copy contains local changes. Commit first"
19         print
20         return 1
21     if 's' in rev:
22         rev = rev[:-1]
23     if 'm' in rev:
24         rev = rev[:-1]
25     changelog = file('debian/changelog.template').read() % {
26         'rev': rev,
27         'user': pwd.getpwuid(os.getuid()).pw_gecos.split(',')[0].strip(),
28         'date': time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()) }
29     file('debian/changelog','w').write(changelog)
30
31 def nonemptyFile(f):
32     try: return os.stat(f).st_size > 0
33     except OSError: return False
34
35 def checkLocalConf(target, source, env):
36     if nonemptyFile('SConfig') or nonemptyFile('Doxyfile.local'):
37         print
38         print "You have made local modifications to 'SConfig' and/or 'Doxyfile.local'."
39         print "Building a debian package would remove those files."
40         print
41         print "To continue, remove the offending file(s) and try again. Alternatively,"
42         print "build a source package using 'scons debsrc' and may then build debian"
43         print "binary packages from this source-package without disrupting your print local"
44         print "configuration."
45         print
46         return 1
47
48 ###########################################################################
49 # Load utilities and setup libraries and configure build
50
51 SENFSCons.UseBoost()
52 SENFSCons.UseSTLPort()
53 env = SENFSCons.MakeEnvironment()
54
55 env.Help("""
56 Additional top-level build targets:
57
58 all_tests    Build and run unit tests for all modules
59 all_docs     Build documentation for all modules
60 all          Build everything
61 install_all  Install SENF into $PREFIX
62 deb          Build debian source and binary package
63 debsrc       Build debian source package
64 debbin       Build debian binary package
65 """)
66
67 if os.environ.get('debian_build'):
68     rev = os.popen("dpkg-parsechangelog | awk '/^Version:/{print $2}'").read().strip()
69 else:
70     rev = 'r' + os.popen("svnversion").read().strip().lower()
71
72 logname = os.environ.get('LOGNAME')
73 if not logname:
74     logname = pwd.getpwuid(os.getuid()).pw_name
75
76 env.Append(
77    CPPPATH = [ '#' ],
78    LIBS = [ 'iberty', '$BOOSTREGEXLIB' ],
79    DOXY_XREF_TYPES = [ 'bug', 'fixme', 'todo', 'idea' ],
80    DOXY_HTML_XSL = '#/doclib/html-munge.xsl',
81    ENV = { 'TODAY' : str(datetime.date.today()),
82            'REVISION' : rev,
83            'LOGNAME' : logname, # needed by the debian build scripts
84            'CONCURRENCY_LEVEL' : env.GetOption('num_jobs') or "1"
85            },
86    CLEAN_PATTERNS = [ '*.pyc', 'semantic.cache', '.sconsign', '.sconsign.dblite' ],
87    BUILDPACKAGE_COMMAND = "dpkg-buildpackage -us -uc -rfakeroot -I.svn -IDoxyfile.local -ISConfig",
88 )
89
90 Export('env')
91
92 # Create Doxyfile.local if not cleaning and the file does not exist
93 # otherwise doxygen will barf on this non-existent file
94 if not env.GetOption('clean') and not os.path.exists("Doxyfile.local"):
95     Execute(Touch("Doxyfile.local"))
96
97 ###########################################################################
98 # Define build targets
99
100 SConscript(glob.glob("*/SConscript"))
101
102 SENFSCons.StandardTargets(env)
103 SENFSCons.GlobalTargets(env)
104 SENFSCons.Doxygen(env)
105 SENFSCons.DoxyXRef(env,
106                    HTML_HEADER = '#/doclib/doxy-header-overview.html',
107                    HTML_FOOTER = '#/doclib/doxy-footer.html')
108
109 # Build combined library 'libsenf'
110 libsenf = env.Library(
111     SENFSCons.LibPath('senf'),
112     Flatten([ env.File(SENFSCons.LibPath(lib)).sources for lib in env['ALLLIBS'] ]))
113 env.Default(libsenf)
114 env.Alias('install_all', env.Install('$LIBINSTALLDIR', libsenf))
115
116 env.AlwaysBuild(
117     env.Alias('deb', [], [ checkLocalConf,
118                            updateRevision,
119                            "$BUILDPACKAGE_COMMAND" ]))
120
121 env.AlwaysBuild(
122     env.Alias('debsrc', [], [ updateRevision,
123                               "$BUILDPACKAGE_COMMAND -S" ]))
124
125 env.AlwaysBuild(
126     env.Alias('debbin', [], [ checkLocalConf,
127                               updateRevision,
128                               "$BUILDPACKAGE_COMMAND -nc" ]))
129
130 env.Clean('all', [ os.path.join(path,f)
131                    for path, subdirs, files in os.walk('.')
132                    for pattern in env['CLEAN_PATTERNS']
133                    for f in fnmatch.filter(files,pattern) ])