2 # Waf utilities for easily building standard unixey packages/libraries
3 # Licensed under the GNU GPL v2 or later, see COPYING file for details.
4 # Copyright (C) 2008 Dave Robillard
5 # Copyright (C) 2008 Nedko Arnaudov <nedko@arnaudov.name>
14 Configure
.g_maxlen
= 55
17 # Only run autowaf hooks once (even if sub projects call several times)
23 def set_options(opt
, docs_available
= True, dev_available
= True, lv2_available
= True):
24 "Add standard autowaf options if they havn't been added yet"
31 g_features
['docs'] = docs_available
32 g_features
['dev'] = dev_available
33 g_features
['lv2'] = lv2_available
35 opt
.tool_options('compiler_cc')
36 opt
.tool_options('compiler_cxx')
37 opt
.add_option('--debug', action
='store_true', default
=False, dest
='debug',
38 help="Build debuggable binaries [Default: False]")
39 opt
.add_option('--strict', action
='store_true', default
=False, dest
='strict',
40 help="Use strict compiler flags and show all warnings [Default: False]")
41 if g_features
['docs']:
42 opt
.add_option('--build-docs', action
='store_true', default
=False, dest
='build_docs',
43 help="Build documentation - requires doxygen [Default: False]")
44 opt
.add_option('--bundle', action
='store_true', default
=False,
45 help="Build a self-contained bundle [Default: False]")
46 opt
.add_option('--bindir', type='string', help="Executable programs [Default: PREFIX/bin]")
48 opt
.add_option('--libdir', type='string', help="Libraries [Default: PREFIX/lib]")
49 opt
.add_option('--includedir', type='string', help="Header files [Default: PREFIX/include]")
50 opt
.add_option('--datadir', type='string', help="Shared data [Default: PREFIX/share]")
51 if g_features
['docs']:
52 opt
.add_option('--mandir', type='string', help="Manual pages [Default: DATADIR/man]")
53 opt
.add_option('--htmldir', type='string', help="HTML documentation [Default: DATADIR/doc/PACKAGE]")
55 if sys
.platform
== "darwin":
56 opt
.add_option('--lv2dir', type='string', help="LV2 bundles [Default: /Library/Audio/Plug-Ins/LV2]")
58 opt
.add_option('--lv2dir', type='string', help="LV2 bundles [Default: LIBDIR/lv2]")
59 opt
.add_option('--lv2-user', action
='store_true', default
=False, dest
='lv2_user',
60 help="Install LV2 bundles to user-local location [Default: False]")
63 def check_header(conf
, name
, define
='', **args
):
64 "Check for a header iff it hasn't been checked for yet"
65 if type(conf
.env
['AUTOWAF_HEADERS']) != dict:
66 conf
.env
['AUTOWAF_HEADERS'] = {}
68 checked
= conf
.env
['AUTOWAF_HEADERS']
69 if not name
in checked
:
70 conf
.check_header(name
, define
, **args
)
73 def check_tool(conf
, name
):
74 "Check for a tool iff it hasn't been checked for yet"
75 if type(conf
.env
['AUTOWAF_TOOLS']) != dict:
76 conf
.env
['AUTOWAF_TOOLS'] = {}
78 checked
= conf
.env
['AUTOWAF_TOOLS']
79 if not name
in checked
:
83 def check_pkg(conf
, name
, **args
):
84 "Check for a package iff it hasn't been checked for yet"
85 if not 'HAVE_' + args
['destvar'] in conf
.env
:
86 if not conf
.check_pkg(name
, **args
):
87 conf
.env
['HAVE_' + args
['destvar']] = False
89 conf
.env
['HAVE_' + args
['destvar']] = 1
91 def chop_prefix(conf
, var
):
92 name
= conf
.env
[var
][len(conf
.env
['PREFIX']):]
93 if len(name
) > 0 and name
[0] == '/':
104 def append_cxx_flags(val
):
105 conf
.env
.append_value('CCFLAGS', val
)
106 conf
.env
.append_value('CXXFLAGS', val
)
107 check_tool(conf
, 'misc')
108 if g_features
['docs']:
109 conf
.env
['BUILD_DOCS'] = Params
.g_options
.build_docs
111 conf
.env
['BUILD_DOCS'] = False
112 conf
.env
['DEBUG'] = Params
.g_options
.debug
113 conf
.env
['PREFIX'] = os
.path
.abspath(os
.path
.expanduser(os
.path
.normpath(conf
.env
['PREFIX'])))
114 if Params
.g_options
.bundle
:
115 conf
.env
['BUNDLE'] = True
116 conf
.define('BUNDLE', 1)
117 conf
.env
['BINDIR'] = conf
.env
['PREFIX']
118 if g_features
['dev']:
119 conf
.env
['INCLUDEDIR'] = conf
.env
['PREFIX'] + '/Headers/'
120 conf
.env
['LIBDIR'] = conf
.env
['PREFIX'] + '/Libraries/'
121 conf
.env
['DATADIR'] = conf
.env
['PREFIX'] + '/Resources/'
122 if g_features
['docs']:
123 conf
.env
['HTMLDIR'] = conf
.env
['PREFIX'] + '/Resources/Documenation/'
124 conf
.env
['MANDIR'] = conf
.env
['PREFIX'] + '/Resources/Man/'
125 if g_features
['lv2']:
126 conf
.env
['LV2DIR'] = conf
.env
['PREFIX'] + '/PlugIns/'
128 conf
.env
['BUNDLE'] = False
129 if Params
.g_options
.bindir
:
130 conf
.env
['BINDIR'] = Params
.g_options
.bindir
132 conf
.env
['BINDIR'] = conf
.env
['PREFIX'] + '/bin/'
133 if g_features
['dev']:
134 if Params
.g_options
.includedir
:
135 conf
.env
['INCLUDEDIR'] = Params
.g_options
.includedir
137 conf
.env
['INCLUDEDIR'] = conf
.env
['PREFIX'] + '/include/'
138 if Params
.g_options
.libdir
:
139 conf
.env
['LIBDIR'] = Params
.g_options
.libdir
141 conf
.env
['LIBDIR'] = conf
.env
['PREFIX'] + '/lib/'
143 conf
.env
['LIBDIR'] = conf
.env
['PREFIX'] + '/lib/'
144 if Params
.g_options
.datadir
:
145 conf
.env
['DATADIR'] = Params
.g_options
.datadir
147 conf
.env
['DATADIR'] = conf
.env
['PREFIX'] + '/share/'
148 if g_features
['docs']:
149 if Params
.g_options
.htmldir
:
150 conf
.env
['HTMLDIR'] = Params
.g_options
.htmldir
152 conf
.env
['HTMLDIR'] = conf
.env
['DATADIR'] + 'doc/' + Utils
.g_module
.APPNAME
+ '/'
153 if Params
.g_options
.mandir
:
154 conf
.env
['MANDIR'] = Params
.g_options
.mandir
156 conf
.env
['MANDIR'] = conf
.env
['DATADIR'] + 'man/'
157 if g_features
['lv2']:
158 if Params
.g_options
.lv2dir
:
159 conf
.env
['LV2DIR'] = Params
.g_options
.lv2dir
161 if Params
.g_options
.lv2_user
:
162 if sys
.platform
== "darwin":
163 conf
.env
['LV2DIR'] = os
.getenv('HOME') + '/Library/Audio/Plug-Ins/LV2'
165 conf
.env
['LV2DIR'] = os
.getenv('HOME') + '/.lv2'
167 if sys
.platform
== "darwin":
168 conf
.env
['LV2DIR'] = '/Library/Audio/Plug-Ins/LV2'
170 conf
.env
['LV2DIR'] = conf
.env
['LIBDIR'] + 'lv2/'
172 conf
.env
['BINDIRNAME'] = chop_prefix(conf
, 'BINDIR')
173 conf
.env
['LIBDIRNAME'] = chop_prefix(conf
, 'LIBDIR')
174 conf
.env
['DATADIRNAME'] = chop_prefix(conf
, 'DATADIR')
175 if g_features
['lv2']:
176 conf
.env
['LV2DIRNAME'] = chop_prefix(conf
, 'LV2DIR')
178 if Params
.g_options
.debug
:
179 conf
.env
['CCFLAGS'] = '-O0 -g -std=c99'
180 conf
.env
['CXXFLAGS'] = '-O0 -g -ansi'
181 if Params
.g_options
.strict
:
182 conf
.env
['CCFLAGS'] = '-O0 -g -std=c99 -pedantic'
183 append_cxx_flags('-Wall -Wextra -Wno-unused-parameter')
184 append_cxx_flags('-fPIC -DPIC')
187 def set_local_lib(conf
, name
, has_objects
):
188 conf
.define('HAVE_' + name
.upper(), True)
190 if type(conf
.env
['AUTOWAF_LOCAL_LIBS']) != dict:
191 conf
.env
['AUTOWAF_LOCAL_LIBS'] = {}
192 conf
.env
['AUTOWAF_LOCAL_LIBS'][name
.lower()] = True
194 if type(conf
.env
['AUTOWAF_LOCAL_HEADERS']) != dict:
195 conf
.env
['AUTOWAF_LOCAL_HEADERS'] = {}
196 conf
.env
['AUTOWAF_LOCAL_HEADERS'][name
.lower()] = True
198 def use_lib(bld
, obj
, libs
):
199 abssrcdir
= os
.path
.abspath('.')
200 libs_list
= libs
.split()
202 in_headers
= l
.lower() in bld
.env()['AUTOWAF_LOCAL_HEADERS']
203 in_libs
= l
.lower() in bld
.env()['AUTOWAF_LOCAL_LIBS']
205 obj
.uselib_local
+= ' lib' + l
.lower() + ' '
207 if in_headers
or in_libs
:
208 inc_flag
= '-iquote ' + abssrcdir
+ '/' + l
.lower()
209 for f
in ['CCFLAGS', 'CXXFLAGS']:
210 if not inc_flag
in bld
.env()[f
]:
211 bld
.env().prepend_value(f
, inc_flag
)
213 obj
.uselib
+= ' ' + l
216 def display_header(title
):
217 Params
.pprint('BOLD', title
)
219 def display_msg(msg
, status
= None, color
= None):
220 Configure
.g_maxlen
= max(Configure
.g_maxlen
, len(msg
))
222 print "%s :" % msg
.ljust(Configure
.g_maxlen
),
223 Params
.pprint(color
, status
)
225 print "%s" % msg
.ljust(Configure
.g_maxlen
)
227 def display_feature(msg
, build
):
229 display_msg(msg
, "yes", 'GREEN')
231 display_msg(msg
, "no", 'YELLOW')
233 def print_summary(conf
):
241 display_header('Global configuration')
242 display_msg("Install prefix", conf
.env
['PREFIX'], 'CYAN')
243 display_msg("Debuggable build", str(conf
.env
['DEBUG']), 'YELLOW')
244 if g_features
['docs']:
245 display_msg("Build documentation", str(conf
.env
['BUILD_DOCS']), 'YELLOW')
249 def link_flags(env
, lib
):
250 return ' '.join(map(lambda x
: env
['LIB_ST'] % x
, env
['LIB_' + lib
]))
252 def compile_flags(env
, lib
):
253 return ' '.join(map(lambda x
: env
['CPPPATH_ST'] % x
, env
['CPPPATH_' + lib
]))
264 def build_pc(bld
, name
, version
, libs
):
265 '''Build a pkg-config file for a library.
266 name -- uppercase variable name (e.g. 'SOMENAME')
267 version -- version string (e.g. '1.2.3')
268 libs -- string/list of dependencies (e.g. 'LIBFOO GLIB')
271 obj
= bld
.create_obj('subst')
272 obj
.source
= name
.lower() + '.pc.in'
273 obj
.target
= name
.lower() + '.pc'
274 obj
.inst_var
= 'PREFIX'
275 obj
.inst_dir
= bld
.env()['LIBDIRNAME'] + 'pkgconfig'
276 pkg_prefix
= bld
.env()['PREFIX']
277 if pkg_prefix
[-1] == '/':
278 pkg_prefix
= pkg_prefix
[:-1]
280 'prefix' : pkg_prefix
,
281 'exec_prefix' : '${prefix}',
282 'libdir' : '${exec_prefix}/lib',
283 'includedir' : '${prefix}/include',
284 name
+ '_VERSION' : version
,
286 if type(libs
) != list:
289 obj
.dict[i
+ '_LIBS'] = link_flags(bld
.env(), i
)
290 obj
.dict[i
+ '_CFLAGS'] = compile_flags(bld
.env(), i
)
292 # Wrapper script (for bundle)
293 def build_wrapper(bld
, template
, prog
):
294 if not bld
.env()['BUNDLE']:
296 obj
= bld
.create_obj('subst')
298 obj
.source
= template
299 obj
.inst_var
= 'PREFIX'
302 'EXECUTABLE' : prog
.target
+ ".bin",
303 'LIB_DIR_NAME' : bld
.env()['LIBDIRNAME']
305 prog
.target
= prog
.target
+ '.bin'
307 # Doxygen API documentation
308 def build_dox(bld
, name
, version
, srcdir
, blddir
):
309 if not bld
.env()['BUILD_DOCS']:
311 obj
= bld
.create_obj('subst')
312 obj
.source
= 'doc/reference.doxygen.in'
313 obj
.target
= 'doc/reference.doxygen'
315 src_dir
= srcdir
+ '/' + name
.lower()
316 doc_dir
= blddir
+ '/default/' + name
.lower() + '/doc'
319 doc_dir
= blddir
+ '/default/doc'
321 name
+ '_VERSION' : version
,
322 name
+ '_SRCDIR' : os
.path
.abspath(src_dir
),
323 name
+ '_DOC_DIR' : os
.path
.abspath(doc_dir
)
326 out1
= bld
.create_obj('command-output')
327 out1
.stdout
= '/doc/doxygen.out'
328 out1
.stdin
= '/doc/reference.doxygen' # whatever..
329 out1
.command
= 'doxygen'
330 out1
.argv
= [os
.path
.abspath(doc_dir
) + '/reference.doxygen']
331 out1
.command_is_external
= True
334 # This isn't really correct (for packaging), but people asking is annoying
335 if Params
.g_commands
['install']:
336 try: os
.popen("/sbin/ldconfig")