8739426fd072a3a74bfb87b796f3dffbdefbf3c4
[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 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
32 ###########################################################################
33 # Load utilities and setup libraries and configure build
34
35 SENFSCons.UseBoost()
36 SENFSCons.UseSTLPort()
37 env = SENFSCons.MakeEnvironment()
38
39 env.Help("""
40 Additional top-level build targets:
41
42 all_tests    Build and run unit tests for all modules
43 all_docs     Build documentation for all modules
44 all          Build everything
45 install_all  Install SENF into $PREFIX
46 deb          Build debian source and binary package
47 debsrc       Build debian source package
48 debbin       Build debian binary package
49 """)
50
51 if os.environ.get('debian_build'):
52     rev = os.popen("dpkg-parsechangelog | awk '/^Version:/{print $2}'").read().strip()
53 else:
54     rev = 'r' + os.popen("svnversion").read().strip().lower()
55
56 logname = os.environ.get('LOGNAME')
57 if not logname:
58     logname = pwd.getpwuid(os.getuid()).pw_name
59
60 env.Append(
61    CPPPATH = [ '#' ],
62    LIBS = [ 'iberty', '$BOOSTREGEXLIB' ],
63    DOXY_XREF_TYPES = [ 'bug', 'fixme', 'todo', 'idea' ],
64    DOXY_HTML_XSL = '#/doclib/html-munge.xsl',
65    ENV = { 'TODAY' : str(datetime.date.today()),
66            'REVISION' : rev,
67            'LOGNAME' : logname, # needed by the debian build scripts
68            'CONCURRENCY_LEVEL' : env.GetOption('num_jobs') or "1"
69            },
70 )
71
72 Export('env')
73
74 # Create Doxyfile.local if not cleaning and the file does not exist
75 # otherwise doxygen will barf on this non-existent file
76 if not env.GetOption('clean') and not os.path.exists("Doxyfile.local"):
77     Execute(Touch("Doxyfile.local"))
78
79 ###########################################################################
80 # Define build targets
81
82 SConscript(glob.glob("*/SConscript"))
83
84 SENFSCons.StandardTargets(env)
85 SENFSCons.GlobalTargets(env)
86 SENFSCons.Doxygen(env)
87 SENFSCons.DoxyXRef(env,
88                    HTML_HEADER = '#/doclib/doxy-header-overview.html',
89                    HTML_FOOTER = '#/doclib/doxy-footer.html')
90
91 # Build combined library 'libsenf'
92 libsenf = env.Library(
93     SENFSCons.LibPath('senf'),
94     Flatten([ env.File(SENFSCons.LibPath(lib)).sources for lib in env['ALLLIBS'] ]))
95 env.Default(libsenf)
96 env.Alias('install_all', env.Install('$LIBINSTALLDIR', libsenf))
97
98 env.AlwaysBuild(
99     env.Alias('deb', [], [ updateRevision,
100                            "dpkg-buildpackage -us -uc -rfakeroot -I.svn" ]))
101
102 env.AlwaysBuild(
103     env.Alias('debsrc', [], [ updateRevision,
104                               "dpkg-buildpackage -us -uc -rfakeroot -S -I.svn" ]))
105
106 env.AlwaysBuild(
107     env.Alias('debbin', [], [ updateRevision,
108                               "dpkg-buildpackage -us -uc -rfakeroot -nc" ]))