Add support vor CONCURRENCY_LEVEL and 'scons -j <n>' to debian build
[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            'CONCURRENCY_LEVEL' : env.GetOption('num_jobs') or "1"
41            },
42 )
43
44 Export('env')
45
46 # Build modules (that is, instruct to build ... the build happens later)
47 SConscript(glob.glob("*/SConscript"))
48
49 SENFSCons.StandardTargets(env)
50 SENFSCons.GlobalTargets(env)
51 SENFSCons.Doxygen(env)
52
53 SENFSCons.DoxyXRef(env,
54                    HTML_HEADER = '#/doclib/doxy-header-overview.html',
55                    HTML_FOOTER = '#/doclib/doxy-footer.html')
56
57 def updateRevision(target, source, env):
58     rev = env['ENV']['REVISION'][1:]
59     if ':' in rev:
60         print
61         print "Working copy not clean. Run 'svn update'"
62         print
63         return 1
64     if 'm' in rev and not ARGUMENTS.get('force_deb'):
65         print
66         print "Working copy contains local changes. Commit first"
67         print
68         return 1
69     if 's' in rev:
70         rev = rev[:-1]
71     if 'm' in rev:
72         rev = rev[:-1]
73     changelog = file('debian/changelog.template').read() % {
74         'rev': rev,
75         'user': pwd.getpwuid(os.getuid()).pw_gecos.split(',')[0].strip(),
76         'date': time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()) }
77     file('debian/changelog','w').write(changelog)
78
79 if not os.environ.get('debian_build'):
80     env.AlwaysBuild(
81         env.Alias('deb', [], [ updateRevision,
82                                "dpkg-buildpackage -us -uc -rfakeroot -I.svn" ]))
83
84     env.AlwaysBuild(
85         env.Alias('debsrc', [], [ updateRevision,
86                                   "dpkg-buildpackage -us -uc -rfakeroot -S -I.svn" ]))
87
88     env.AlwaysBuild(
89         env.Alias('debbin', [], [ updateRevision,
90                                   "dpkg-buildpackage -us -uc -rfakeroot -nc" ]))
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"))