3 import sys, glob, os.path, datetime, pwd, time, fnmatch
4 sys.path.append('senfscons')
7 ###########################################################################
9 def updateRevision(target, source, env):
10 rev = env['ENV']['REVISION'][1:]
13 print "Working copy not clean. Run 'svn update'"
16 if 'm' in rev and not ARGUMENTS.get('force_deb'):
18 print "Working copy contains local changes. Commit first"
25 changelog = file('debian/changelog.template').read() % {
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)
32 try: return os.stat(f).st_size > 0
33 except OSError: return False
35 def checkLocalConf(target, source, env):
36 if [ True for f in env['CONFIG_FILES'] if nonemptyFile(f) ]:
38 print "You have made local modifications to 'SConfig' and/or 'Doxyfile.local'."
39 print "Building a debian package would remove those files."
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."
48 ###########################################################################
49 # Load utilities and setup libraries and configure build
52 SENFSCons.UseSTLPort()
53 env = SENFSCons.MakeEnvironment()
56 Additional top-level build targets:
58 all_tests Build and run unit tests for all modules
59 all_docs Build documentation for all modules
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
67 if os.environ.get('debian_build'):
68 rev = os.popen("dpkg-parsechangelog | awk '/^Version:/{print $2}'").read().strip()
70 rev = 'r' + os.popen("svnversion").read().strip().lower()
72 logname = os.environ.get('LOGNAME')
74 logname = pwd.getpwuid(os.getuid()).pw_name
76 def configFilesOpts(target, source, env, for_signature):
77 return [ '-I%s' % os.path.split(f)[1] for f in env['CONFIG_FILES'] ]
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()),
86 'LOGNAME' : logname, # needed by the debian build scripts
87 'CONCURRENCY_LEVEL' : env.GetOption('num_jobs') or "1"
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' ]
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"))
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"))
108 ###########################################################################
109 # Define build targets
111 SConscript(glob.glob("*/SConscript"))
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')
120 SENFSCons.InstallIncludeFiles(env, [ 'config.hh' ])
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'] ]))
127 env.Alias('install_all', env.Install('$LIBINSTALLDIR', libsenf))
130 env.Alias('deb', [], [ checkLocalConf,
132 "$BUILDPACKAGE_COMMAND" ]))
135 env.Alias('debsrc', [], [ updateRevision,
136 "$BUILDPACKAGE_COMMAND -S" ]))
139 env.Alias('debbin', [], [ checkLocalConf,
141 "$BUILDPACKAGE_COMMAND -nc" ]))
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) ])