IntroductionTo reduce script maintenance, parameters or flags such as -O2 or -DDEBUG must be kept within the configuration section as much as possible. The problem is to use the flags in the program. For example, a pair of link flags and library names need to be added at the same time to the flags of a program. The uselib systemLet us consider a task generator instance (obj): def build(bld):
obj = bld.new_task_gen(features='cpp program', source='doh.cpp', target='thisprogram')To link against libpng.so, it can be tempting to add several lines of this form: obj.cxxflags = '-O3'
obj.libpath = '/usr/local/lib'
obj.lib = 'png'Problems arise as soon as a new variable such as LINKFLAGS or FRAMEWORK are needed. Worse, all flags will need to be duplicated for other objects. Instead, we will write this: def build(bld):
obj = bld.new_task_gen(features='cpp program', source='doh.cpp', target='aprogram', uselib='PNG')The configuration section will contain the following code instead: def configure(conf):
conf.env['CXXFLAGS_PNG'] = '-O3'
conf.env['LIBPATH_PNG'] = '/usr/local/lib'
conf.env['LIB_PNG'] = 'png'
Linking against local libraries : uselib_localTo link a program against a library created in your own build, for example: def build(bld):
obj = bld.new_task_gen(features='cpp shlib', source='d1.cpp', target='mylib', vnum='1.2.3')The following code is necessary: obj = bld.new_task_gen(features='cpp program', source='e.cpp', target='program_dyn_linked', uselib_local = 'mylib')
|