Add 'include/senf' directory
[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 [ True for f in env['CONFIG_FILES'] if nonemptyFile(f) ]:
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 def configFilesOpts(target, source, env, for_signature):
77     return [ '-I%s' % os.path.split(f)[1] for f in env['CONFIG_FILES'] ]
78
79 env.Append(
80    CPPPATH = [ '#/include' ],
81    LIBS = [ 'iberty', '$BOOSTREGEXLIB' ],
82    DOXY_XREF_TYPES = [ 'bug', 'fixme', 'todo', 'idea' ],
83    DOXY_HTML_XSL = '#/doclib/html-munge.xsl',
84    ENV = { 'TODAY' : str(datetime.date.today()),
85            'REVISION' : rev,
86            'LOGNAME' : logname, # needed by the debian build scripts
87            'CONCURRENCY_LEVEL' : env.GetOption('num_jobs') or "1"
88            },
89    CONFIG_FILES = [ 'Doxyfile.local', 'SConfig', 'local_config.hh' ],
90    CONFIG_FILES_OPTS = configFilesOpts,
91    CLEAN_PATTERNS = [ '*.pyc', 'semantic.cache', '.sconsign', '.sconsign.dblite' ],
92    BUILDPACKAGE_COMMAND = "dpkg-buildpackage -us -uc -rfakeroot -I.svn $CONFIG_FILES_OPTS",
93    TOP_INCLUDES = [ 'Packets', 'PPI', 'Scheduler', 'Socket', 'Utils',
94                     'config.hh', 'local_config.hh' ]
95 )
96
97 Export('env')
98
99 # Create Doxyfile.local if not cleaning and the file does not exist
100 # otherwise doxygen will barf on this non-existent file
101 if not env.GetOption('clean') and not os.path.exists("Doxyfile.local"):
102     Execute(Touch("Doxyfile.local"))
103
104 # Create local_config.h
105 if not env.GetOption('clean') and not os.path.exists("local_config.hh"):
106     Execute(Touch("local_config.hh"))
107
108 ###########################################################################
109 # Define build targets
110
111 SConscript(glob.glob("*/SConscript"))
112
113 SENFSCons.StandardTargets(env)
114 SENFSCons.GlobalTargets(env)
115 SENFSCons.Doxygen(env)
116 SENFSCons.DoxyXRef(env,
117                    HTML_HEADER = '#/doclib/doxy-header-overview.html',
118                    HTML_FOOTER = '#/doclib/doxy-footer.html')
119
120 SENFSCons.InstallIncludeFiles(env, [ 'config.hh' ])
121
122 # Build combined library 'libsenf'
123 libsenf = env.Library(
124     SENFSCons.LibPath('senf'),
125     Flatten([ env.File(SENFSCons.LibPath(lib)).sources for lib in env['ALLLIBS'] ]))
126 env.Default(libsenf)
127 env.Alias('install_all', env.Install('$LIBINSTALLDIR', libsenf))
128
129 env.AlwaysBuild(
130     env.Alias('deb', [], [ checkLocalConf,
131                            updateRevision,
132                            "$BUILDPACKAGE_COMMAND" ]))
133
134 env.AlwaysBuild(
135     env.Alias('debsrc', [], [ updateRevision,
136                               "$BUILDPACKAGE_COMMAND -S" ]))
137
138 env.AlwaysBuild(
139     env.Alias('debbin', [], [ checkLocalConf,
140                               updateRevision,
141                               "$BUILDPACKAGE_COMMAND -nc" ]))
142
143 env.Clean('all', [ os.path.join(path,f)
144                    for path, subdirs, files in os.walk('.')
145                    for pattern in env['CLEAN_PATTERNS']
146                    for f in fnmatch.filter(files,pattern) ])