3 import sys, glob, os.path, datetime, pwd, time, fnmatch
4 sys.path.append('senfscons')
7 ###########################################################################
9 # This hack is needed for SCons V 0.96.1 compatibility. In current SCons versions
10 # we can just use 'env.AlwaysBuild(env.Alias(target), [], action)'
11 def PhonyTarget(env, target, action):
12 env.AlwaysBuild(env.Command(target + '.phony', 'SConstruct', env.Action(action)))
13 env.Alias(target, target + '.phony')
15 def updateRevision(target, source, env):
16 rev = env['ENV']['REVISION'][1:]
19 print "Working copy not clean. Run 'svn update'"
22 if 'm' in rev and not ARGUMENTS.get('force_deb'):
24 print "Working copy contains local changes. Commit first"
31 changelog = file('debian/changelog.template').read() % {
33 'user': pwd.getpwuid(os.getuid()).pw_gecos.split(',')[0].strip(),
34 'date': time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()) }
35 file('debian/changelog','w').write(changelog)
38 try: return os.stat(f).st_size > 0
39 except OSError: return False
41 def checkLocalConf(target, source, env):
42 if [ True for f in env['CONFIG_FILES'] if nonemptyFile(f) ]:
44 print "You have made local modifications to one of the following local configuration"
46 for f in env['CONFIG_FILES']:
49 print "Building a debian package would remove those files."
51 print "To continue, remove the offending file(s) and try again. Alternatively,"
52 print "build a source package using 'scons debsrc' and may then build debian"
53 print "binary packages from this source-package without disrupting your local"
54 print "configuration."
58 def getLibDepends(script):
60 return os.popen("perl -0777 -n -e '$,=\" \"; print $1=~m/'\"'\"'([^'\"'\"']*)'\"'\"'/g if /LIBS\s*=\s*\[([^\]]*)\]/' %s" % script).read().split()
62 # Original topological sort code written by Ofer Faigon
63 # (www.bitformation.com) and used with permission
64 def topological_sort(items, partial_order):
65 """Perform topological sort.
66 items is a list of items to be sorted.
67 partial_order is a list of pairs. If pair (a,b) is in it, it means
68 that item a should appear before item b.
69 Returns a list of the items in one of the possible orders, or None
70 if partial_order contains a loop.
72 def add_node(graph, node):
73 if not graph.has_key(node):
75 def add_arc(graph, fromnode, tonode):
76 graph[fromnode].append(tonode)
77 graph[tonode][0] = graph[tonode][0] + 1
81 for a,b in partial_order:
83 roots = [node for (node,nodeinfo) in graph.items() if nodeinfo[0] == 0]
84 while len(roots) != 0:
87 for child in graph[root][1:]:
88 graph[child][0] = graph[child][0] - 1
89 if graph[child][0] == 0:
92 if len(graph.items()) != 0:
93 raise RuntimeError, "Loop detected in partial_order"
95 ###########################################################################
96 # Load utilities and setup libraries and configure build
99 SENFSCons.UseSTLPort()
100 env = SENFSCons.MakeEnvironment()
103 Additional top-level build targets:
105 prepare Create all source files not part of the repository
106 all_tests Build and run unit tests for all modules
107 all_docs Build documentation for all modules
109 install_all Install SENF into $PREFIX
110 deb Build debian source and binary package
111 debsrc Build debian source package
112 debbin Build debian binary package
113 linklint Check links of doxygen documentation with 'linklint'
114 fixlinks Fix broken links in doxygen documentation
117 if os.environ.get('debian_build'):
118 rev = os.popen("dpkg-parsechangelog | awk '/^Version:/{print $2}'").read().strip()
120 rev = 'r' + os.popen("svnversion").read().strip().lower()
122 logname = os.environ.get('LOGNAME')
124 logname = pwd.getpwuid(os.getuid()).pw_name
126 def configFilesOpts(target, source, env, for_signature):
127 return [ '-I%s' % os.path.split(f)[1] for f in env['CONFIG_FILES'] ]
130 CPPPATH = [ '#/include' ],
131 LIBS = [ 'iberty', '$BOOSTREGEXLIB', '$BOOSTFSLIB' ],
132 DOXY_XREF_TYPES = [ 'bug', 'fixme', 'todo', 'idea' ],
133 DOXY_HTML_XSL = '#/doclib/html-munge.xsl',
134 ENV = { 'TODAY' : str(datetime.date.today()),
136 'LOGNAME' : logname, # needed by the debian build scripts
137 'CONCURRENCY_LEVEL' : env.GetOption('num_jobs') or "1",
140 CONFIG_FILES = [ 'Doxyfile.local', 'SConfig', 'local_config.hh' ],
141 CONFIG_FILES_OPTS = configFilesOpts,
142 CLEAN_PATTERNS = [ '*.pyc', 'semantic.cache', '.sconsign', '.sconsign.dblite' ],
143 BUILDPACKAGE_COMMAND = "dpkg-buildpackage -us -uc -rfakeroot -I.svn $CONFIG_FILES_OPTS",
144 TOP_INCLUDES = [ 'Packets', 'PPI', 'Scheduler', 'Socket', 'Utils',
145 'config.hh', 'local_config.hh' ]
150 # Create Doxyfile.local otherwise doxygen will barf on this non-existent file
151 if not env.GetOption('clean') and not os.path.exists("Doxyfile.local"):
152 Execute(Touch("Doxyfile.local"))
154 # Create local_config.h
155 if not env.GetOption('clean') and not os.path.exists("local_config.hh"):
156 Execute(Touch("local_config.hh"))
158 ###########################################################################
159 # Define build targets
161 # Before defining any targets, check wether this is the first build in
162 # pristine directory tree. If so, call 'scons prepare' so the dependencies
163 # created later are correct
165 if not env.GetOption('clean') and not os.path.exists(".prepare-stamp") \
166 and not os.environ.get("SCONS") and COMMAND_LINE_TARGETS != [ 'prepare' ]:
167 env.Execute([ "scons prepare" ])
169 env.Clean('all', '.prepare-stamp')
171 # Not nice, but until we get to fixing the dependency jungle
172 # concerning generated sources ...
176 for script in glob.glob("*/SConscript"):
177 depends = getLibDepends(script)
178 script = script.split('/',1)[0]
179 scripts.append(script)
180 dependencies += [ (dep, script) for dep in depends ]
182 for subdir in topological_sort(scripts, dependencies):
183 SConscript(os.path.join(subdir, "SConscript"))
185 SENFSCons.StandardTargets(env)
186 SENFSCons.GlobalTargets(env)
187 SENFSCons.Doxygen(env)
188 SENFSCons.DoxyXRef(env,
189 HTML_HEADER = '#/doclib/doxy-header-overview.html',
190 HTML_FOOTER = '#/doclib/doxy-footer.html')
192 SENFSCons.InstallIncludeFiles(env, [ 'config.hh' ])
194 # Build combined library 'libsenf'
195 libsenf = env.Library(
196 SENFSCons.LibPath('senf'),
197 Flatten([ env.File(SENFSCons.LibPath(lib)).sources for lib in env['ALLLIBS'] ]))
199 env.Clean('all', 'libsenf.a')
200 env.Alias('default', 'libsenf.a')
202 env.Alias('install_all', env.Install('$LIBINSTALLDIR', libsenf))
204 env.Clean('all', [ os.path.join(path,f)
205 for path, subdirs, files in os.walk('.')
206 for pattern in env['CLEAN_PATTERNS']
207 for f in fnmatch.filter(files,pattern) ])
209 PhonyTarget(env, 'deb', [
212 "$BUILDPACKAGE_COMMAND",
215 PhonyTarget(env, 'debsrc', [
217 "$BUILDPACKAGE_COMMAND -S",
220 PhonyTarget(env, 'debbin', [
223 "$BUILDPACKAGE_COMMAND -nc",
226 PhonyTarget(env, 'linklint', [
228 'linklint -doc linklint -limit 99999999 `find -type d -name html -printf "/%P/@ "`',
229 '[ ! -r linklint/errorX.html ] || python linklint_addnames.py <linklint/errorX.html >linklint/errorX.html.new',
230 '[ ! -r linklint/errorX.html.new ] || mv linklint/errorX.html.new linklint/errorX.html',
231 '[ ! -r linklint/errorAX.html ] || python linklint_addnames.py <linklint/errorAX.html >linklint/errorAX.html.new',
232 '[ ! -r linklint/errorAX.html.new ] || mv linklint/errorAX.html.new linklint/errorAX.html',
233 'echo -e "\\nLokal link check results: linklint/index.html\\nRemote link check results: linklint/urlindex.html\\n"',
236 PhonyTarget(env, 'fixlinks', [
237 'python doclib/fix-links.py -v -s .svn -s linklint -s debian linklint/errorX.txt linklint/errorAX.txt',
240 PhonyTarget(env, 'prepare', [])
242 env.Clean('all', env.Dir('linklint'))
244 env.Clean('all','.prepare-stamp')
245 if not env.GetOption('clean') and not os.path.exists(".prepare-stamp"):
246 Execute(Touch(".prepare-stamp"))