Debian Codegraph @

wscript

raw
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright 2010 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 #
20 # Modified by Colomban Wendling <ban(at)herbesfolles(dot)org> 2010
21 #
22
23 """
24 This is a WAF build script (http://code.google.com/p/waf/).
25 Requires WAF 1.5.7 and Python 2.4 (or later).
26 """
27
28
29 import Build
30 import Options
31 import Utils
32 import sys
33 import os
34 import tempfile
35
36
37 APPNAME = 'ctpl'
38 VERSION = '0.3.5'
39 LTVERSION = '2.3.0' # emulate Libtool version
40
41 srcdir = '.'
42 blddir = '_build_'
43
44
45 HEADERS = [
46 'src/ctpl.h',
47 'src/ctpl-environ.h',
48 'src/ctpl-eval.h',
49 'src/ctpl-io.h',
50 'src/ctpl-input-stream.h',
51 'src/ctpl-lexer.h',
52 'src/ctpl-lexer-expr.h',
53 'src/ctpl-output-stream.h',
54 'src/ctpl-parser.h',
55 'src/ctpl-token.h',
56 'src/ctpl-value.h',
57 'src/ctpl-version.h']
58
59 LIBRARY_SOURCES = '''
60 src/ctpl-environ.c
61 src/ctpl-eval.c
62 src/ctpl-i18n.c
63 src/ctpl-io.c
64 src/ctpl-input-stream.c
65 src/ctpl-lexer.c
66 src/ctpl-lexer-expr.c
67 src/ctpl-mathutils.c
68 src/ctpl-output-stream.c
69 src/ctpl-parser.c
70 src/ctpl-stack.c
71 src/ctpl-token.c
72 src/ctpl-value.c
73 src/ctpl-version.c'''
74
75
76 CTPL_SOURCES = ['src/ctpl.c']
77
78
79 def configure(conf):
80
81 def conf_define_from_opt(define_name, opt_name, default_value, quote=1):
82 if opt_name:
83 if isinstance(opt_name, bool):
84 opt_name = 1
85 conf.define(define_name, opt_name, quote)
86 elif default_value:
87 conf.define(define_name, default_value, quote)
88
89 conf.check_tool('compiler_cc')
90 is_win32 = target_is_win32(conf.env)
91
92 # check for cxx after the header and function checks have been done to ensure they are
93 # checked with cc not cxx
94 conf.check_tool('misc')
95
96 # GTK / GIO version check
97 conf.check_cfg(package='glib-2.0', atleast_version='2.10.0', uselib_store='GLIB',
98 mandatory=True, args='--cflags --libs')
99 conf.check_cfg(package='gio-2.0', uselib_store='GIO', args='--cflags --libs', mandatory=True)
100 conf.check_cfg(package='gio-2.0', atleast_version='2.24.0', uselib_store='GIO_2_24', args='--cflags --libs', mandatory=False)
101 conf.check_cfg(package='gio-unix-2.0', uselib_store='GIO_UNIX', args='--cflags --libs', mandatory=False)
102 conf.check_cfg(package='gio-windows-2.0', uselib_store='GIO_WINDOWS', args='--cflags --libs', mandatory=False)
103
104 # Windows specials
105 if is_win32:
106 if conf.env['PREFIX'] == tempfile.gettempdir():
107 # overwrite default prefix on Windows (tempfile.gettempdir() is the Waf default)
108 conf.define('PREFIX', os.path.join(conf.srcdir, '%s-%s' % (APPNAME, VERSION)), 1)
109 conf.define('DOCDIR', os.path.join(conf.env['PREFIX'], 'doc'), 1)
110 conf.define('BINDIR', os.path.join(conf.env['PREFIX'], 'bin'), 1)
111 conf.define('LIBDIR', os.path.join(conf.env['PREFIX'], 'lib'), 1)
112 # DATADIR is defined in objidl.h, so we remove it from config.h but keep it in env
113 conf.undefine('DATADIR')
114 conf.env['DATADIR'] = os.path.join(conf.env['PREFIX'], 'data')
115 # we don't need -fPIC when compiling on or for Windows
116 if '-fPIC' in conf.env['shlib_CCFLAGS']:
117 conf.env['shlib_CCFLAGS'].remove('-fPIC')
118 conf.env.append_value('program_LINKFLAGS', '-mwindows')
119 else:
120 conf.env['DATADIR'] = os.path.join(conf.env['PREFIX'], 'share')
121 conf_define_from_opt('DOCDIR', Options.options.docdir,
122 os.path.join(conf.env['DATADIR'], 'doc'))
123 conf_define_from_opt('LIBDIR', Options.options.libdir,
124 os.path.join(conf.env['PREFIX'], 'lib'))
125 conf_define_from_opt('MANDIR', Options.options.mandir,
126 os.path.join(conf.env['DATADIR'], 'man'))
127
128 conf.define('CTPL_DATADIR', 'data' if is_win32 else conf.env['DATADIR'], 1)
129 conf.define('CTPL_DOCDIR', conf.env['DOCDIR'], 1)
130 conf.define('CTPL_LIBDIR', '' if is_win32 else conf.env['LIBDIR'], 1)
131 conf.define('CTPL_PREFIX', '' if is_win32 else conf.env['PREFIX'], 1)
132 conf.define('PACKAGE', APPNAME, 1)
133 conf.define('VERSION', VERSION, 1)
134 conf.define('GETTEXT_PACKAGE', VERSION, 1)
135 conf.define('LOCALEDIR', os.path.join(conf.env['DATADIR'], 'locale'), 1)
136
137 conf.write_config_header('config.h')
138
139 Utils.pprint('BLUE', 'Summary:')
140 print_message(conf, 'Install CTPL ' + VERSION + ' in', conf.env['PREFIX'])
141
142 # FIXME: this one should not be defined for the ctpl program
143 conf.env.append_value('CCFLAGS', '-DCTPL_COMPILATION')
144
145 conf.env.append_value('CCFLAGS', '-DHAVE_CONFIG_H')
146 conf.env.append_value('CCFLAGS', '-Wall')
147 #~ conf.env.append_value('CCFLAGS', '-Werror')
148
149
150 def set_options(opt):
151 opt.tool_options('compiler_cc')
152
153 if 'configure' in sys.argv:
154 # Paths
155 opt.add_option('--mandir', type='string', default='',
156 help='man documentation', dest='mandir')
157 opt.add_option('--docdir', type='string', default='',
158 help='documentation root', dest='docdir')
159 opt.add_option('--libdir', type='string', default='',
160 help='object code libraries', dest='libdir')
161
162
163 def build(bld):
164 is_win32 = target_is_win32(bld.env)
165
166 # libctpl.so, ctpl.dll
167 bld.new_task_gen(
168 features = 'cc cshlib',
169 source = LIBRARY_SOURCES,
170 includes = '. src',
171 name = 'ctpl_lib',
172 target = 'ctpl',
173 vnum = LTVERSION,
174 uselib = 'GLIB GIO',
175 export_incdirs = '.'
176 )
177
178 # CTPL
179 # ctpl.c doesn't build on Windows currently because of g_unix_output_stream_new()
180 bld.new_task_gen(
181 features = 'cc cprogram',
182 name = 'ctpl_utility',
183 target = 'ctpl',
184 source = CTPL_SOURCES,
185 includes = '. src',
186 uselib = 'GLIB GIO_2_24 ' + ['GIO_UNIX','GIO_WINDOWS'][is_win32],
187 uselib_local = 'ctpl_lib'
188 )
189
190 # ctpl.1
191 bld.install_files('${MANDIR}/man1', 'data/ctpl.1')
192
193 # ctpl.pc
194 bld.new_task_gen(
195 features = 'subst',
196 source = 'data/ctpl.pc.in',
197 target = 'ctpl.pc',
198 dict = { 'VERSION' : VERSION,
199 'prefix': bld.env['PREFIX']},
200 install_path = '${LIBDIR}/pkgconfig'
201 )
202
203 ###
204 # Install files
205 ###
206 # Headers
207 bld.install_files('${PREFIX}/include/ctpl', HEADERS)
208 # Docs
209 base_dir = '${PREFIX}' if is_win32 else '${DOCDIR}/ctpl'
210 ext = '.txt' if is_win32 else ''
211 html_dir = '' if is_win32 else 'html/'
212 for f in ('AUTHORS', 'COPYING', 'ChangeLog', 'README', 'NEWS', 'TODO', 'THANKS'):
213 if os.path.exists(f):
214 bld.install_as("%s/%s%s" % (base_dir, uc_first(f, is_win32), ext), f)
215 html_docsrcdir = 'docs/reference/ctpl/html'
216 if not os.path.isdir(html_docsrcdir):
217 print("** Documentation not found, it will not be installed.")
218 else:
219 for f in os.listdir(html_docsrcdir):
220 bld.install_files('${DOCDIR}/../gtk-doc/html/ctpl/', os.path.join(html_docsrcdir, f))
221 # add a symlink in the docdir
222 bld.symlink_as('${DOCDIR}/ctpl/html', '../../gtk-doc/html/ctpl/')
223
224
225 def print_message(conf, msg, result, color = 'GREEN'):
226 conf.check_message_1(msg)
227 conf.check_message_2(result, color)
228
229
230 def uc_first(s, is_win32):
231 if is_win32:
232 return s.title()
233 return s
234
235
236 def target_is_win32(env):
237 if sys.platform == 'win32':
238 return True
239 if env and 'CC' in env:
240 cc = env['CC']
241 if not isinstance(cc, str):
242 cc = ''.join(cc)
243 return cc.find('mingw') != -1
244 return False