22a95af9deafdd47a83bb755414294b325f24266
[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 env.Append(
57    CPPPATH = [ '#' ],
58    LIBS = [ 'iberty', '$BOOSTREGEXLIB' ],
59    DOXY_XREF_TYPES = [ 'bug', 'fixme', 'todo', 'idea' ],
60    DOXY_HTML_XSL = '#/doclib/html-munge.xsl',
61    ENV = { 'TODAY' : str(datetime.date.today()),
62            'REVISION' : rev,
63            'LOGNAME' : os.environ['LOGNAME'], # needed by the debian build scripts
64            'CONCURRENCY_LEVEL' : env.GetOption('num_jobs') or "1"
65            },
66 )
67
68 Export('env')
69
70 # Create Doxyfile.local if not cleaning and the file does not exist
71 # otherwise doxygen will barf on this non-existent file
72 if not env.GetOption('clean') and not os.path.exists("Doxyfile.local"):
73     Execute(Touch("Doxyfile.local"))
74
75 ###########################################################################
76 # Define build targets
77
78 SConscript(glob.glob("*/SConscript"))
79
80 SENFSCons.StandardTargets(env)
81 SENFSCons.GlobalTargets(env)
82 SENFSCons.Doxygen(env)
83 SENFSCons.DoxyXRef(env,
84                    HTML_HEADER = '#/doclib/doxy-header-overview.html',
85                    HTML_FOOTER = '#/doclib/doxy-footer.html')
86
87 # Build combined library 'libsenf'
88 libsenf = env.Library(
89     SENFSCons.LibPath('senf'),
90     Flatten([ env.File(SENFSCons.LibPath(lib)).sources for lib in env['ALLLIBS'] ]))
91 env.Default(libsenf)
92 env.Alias('install_all', env.Install('$LIBINSTALLDIR', libsenf))
93
94 env.AlwaysBuild(
95     env.Alias('deb', [], [ updateRevision,
96                            "dpkg-buildpackage -us -uc -rfakeroot -I.svn" ]))
97
98 env.AlwaysBuild(
99     env.Alias('debsrc', [], [ updateRevision,
100                               "dpkg-buildpackage -us -uc -rfakeroot -S -I.svn" ]))
101
102 env.AlwaysBuild(
103     env.Alias('debbin', [], [ updateRevision,
104                               "dpkg-buildpackage -us -uc -rfakeroot -nc" ]))