Better SENF configuration support (local_config.hh)
[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 = [ '#' ],
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 )
94
95 Export('env')
96
97 # Create Doxyfile.local if not cleaning and the file does not exist
98 # otherwise doxygen will barf on this non-existent file
99 if not env.GetOption('clean') and not os.path.exists("Doxyfile.local"):
100     Execute(Touch("Doxyfile.local"))
101
102 # Create local_config.h
103 if not env.GetOption('clean') and not os.path.exists("local_config.hh"):
104     Execute(Touch("local_config.hh"))
105
106 ###########################################################################
107 # Define build targets
108
109 SConscript(glob.glob("*/SConscript"))
110
111 SENFSCons.StandardTargets(env)
112 SENFSCons.GlobalTargets(env)
113 SENFSCons.Doxygen(env)
114 SENFSCons.DoxyXRef(env,
115                    HTML_HEADER = '#/doclib/doxy-header-overview.html',
116                    HTML_FOOTER = '#/doclib/doxy-footer.html')
117
118 SENFSCons.InstallIncludeFiles(env, [ 'config.hh' ])
119
120 # Build combined library 'libsenf'
121 libsenf = env.Library(
122     SENFSCons.LibPath('senf'),
123     Flatten([ env.File(SENFSCons.LibPath(lib)).sources for lib in env['ALLLIBS'] ]))
124 env.Default(libsenf)
125 env.Alias('install_all', env.Install('$LIBINSTALLDIR', libsenf))
126
127 env.AlwaysBuild(
128     env.Alias('deb', [], [ checkLocalConf,
129                            updateRevision,
130                            "$BUILDPACKAGE_COMMAND" ]))
131
132 env.AlwaysBuild(
133     env.Alias('debsrc', [], [ updateRevision,
134                               "$BUILDPACKAGE_COMMAND -S" ]))
135
136 env.AlwaysBuild(
137     env.Alias('debbin', [], [ checkLocalConf,
138                               updateRevision,
139                               "$BUILDPACKAGE_COMMAND -nc" ]))
140
141 env.Clean('all', [ os.path.join(path,f)
142                    for path, subdirs, files in os.walk('.')
143                    for pattern in env['CLEAN_PATTERNS']
144                    for f in fnmatch.filter(files,pattern) ])