Fix non-subversion build from debian source package
[senf.git] / SConstruct
1 # -*- python -*-
2
3 import sys, glob, os.path, datetime, pwd, time
4 sys.path.append('senfscons')
5 import SENFSCons
6
7 ###########################################################################
8
9 # Load utilities and setup libraries
10 SENFSCons.UseBoost()
11 SENFSCons.UseSTLPort()
12 env = SENFSCons.MakeEnvironment()
13
14 env.Help("""
15 Additional top-level build targets:
16
17 all_tests    Build and run unit tests for all modules
18 all_docs     Build documentation for all modules
19 all          Build everything
20 install_all  Install SENF into $PREFIX
21 deb          Build debian source and binary package
22 debsrc       Build debian source package
23 debbin       Build debian binary package
24 """)
25
26 if os.environ.get('debian_build'):
27     rev = os.popen("dpkg-parsechangelog | awk '/^Version:/{print $2}'").read().strip()
28 else:
29     rev = 'r' + os.popen("svnversion").read().strip().lower()
30
31 # Configure build
32 env.Append(
33    CPPPATH = [ '#' ],
34    LIBS = [ 'iberty', '$BOOSTREGEXLIB' ],
35    DOXY_XREF_TYPES = [ 'bug', 'fixme', 'todo', 'idea' ],
36    DOXY_HTML_XSL = '#/doclib/html-munge.xsl',
37    ENV = { 'TODAY' : str(datetime.date.today()),
38            'REVISION' : rev,
39            'LOGNAME' : os.environ['LOGNAME'] # needed by the debian build scripts
40            },
41 )
42
43 Export('env')
44
45 # Build modules (that is, instruct to build ... the build happens later)
46 SConscript(glob.glob("*/SConscript"))
47
48 SENFSCons.StandardTargets(env)
49 SENFSCons.GlobalTargets(env)
50 SENFSCons.Doxygen(env)
51
52 SENFSCons.DoxyXRef(env,
53                    HTML_HEADER = '#/doclib/doxy-header-overview.html',
54                    HTML_FOOTER = '#/doclib/doxy-footer.html')
55
56 def updateRevision(target, source, env):
57     rev = env['ENV']['REVISION'][1:]
58     if ':' in rev:
59         print
60         print "Working copy not clean. Run 'svn update'"
61         print
62         return 1
63     if 'm' in rev and not ARGUMENTS.get('force_deb'):
64         print
65         print "Working copy contains local changes. Commit first"
66         print
67         return 1
68     if 's' in rev:
69         rev = rev[:-1]
70     if 'm' in rev:
71         rev = rev[:-1]
72     changelog = file('debian/changelog.template').read() % {
73         'rev': rev,
74         'user': pwd.getpwuid(os.getuid()).pw_gecos.split(',')[0].strip(),
75         'date': time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()) }
76     file('debian/changelog','w').write(changelog)
77
78 if not os.environ.get('debian_build'):
79     env.AlwaysBuild(
80         env.Alias('deb', [], [ updateRevision,
81                                "dpkg-buildpackage -us -uc -rfakeroot -I.svn" ]))
82
83     env.AlwaysBuild(
84         env.Alias('debsrc', [], [ updateRevision,
85                                   "dpkg-buildpackage -us -uc -rfakeroot -S -I.svn" ]))
86
87     env.AlwaysBuild(
88         env.Alias('debbin', [], [ updateRevision,
89                                   "dpkg-buildpackage -us -uc -rfakeroot -nc" ]))
90
91 # Create Doxyfile.local if not cleaning and the file does not exist
92 # otherwise doxygen will barf on this non-existent file
93 if not env.GetOption('clean') and not os.path.exists("Doxyfile.local"):
94     Execute(Touch("Doxyfile.local"))