build fake c and pthread libraries
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 19 Apr 2011 23:13:50 +0200
changeset 65227f6347e4e1
parent 64 015a353a487b
child 66 2fe1f3e576c9
build fake c and pthread libraries
wscript
     1.1 --- a/wscript	Tue Apr 19 14:49:49 2011 +0200
     1.2 +++ b/wscript	Tue Apr 19 23:13:50 2011 +0200
     1.3 @@ -8,6 +8,16 @@
     1.4  def options(opt):
     1.5      opt.tool_options('compiler_cc') 
     1.6      ns3waf.options(opt)
     1.7 +    opt.add_option('--enable-kernel-stack',
     1.8 +                   help=('Path to the prefix where the kernel wrapper headers are installed'),
     1.9 +                   default=None,
    1.10 +                   dest='kernel_stack', type="string")
    1.11 +
    1.12 +def search_file(files):
    1.13 +    for f in files:
    1.14 +        if os.path.isfile (f):
    1.15 +            return f
    1.16 +    return None
    1.17  
    1.18  def configure(conf):
    1.19      ns3waf.check_modules(conf, ['core', 'network', 'internet'], mandatory = True)
    1.20 @@ -22,7 +32,47 @@
    1.21      if vg_h and vg_memcheck_h:
    1.22          conf.env.append_value('CXXDEFINES', 'HAVE_VALGRIND_H')
    1.23  
    1.24 +    conf.start_msg('Searching C library')
    1.25 +    libc = search_file ([
    1.26 +            '/lib64/libc.so.6',
    1.27 +            '/lib/libc.so.6',
    1.28 +            ])
    1.29 +    if libc is None:
    1.30 +        conf.fatal('not found')
    1.31 +    else:
    1.32 +        conf.end_msg(libc, True)
    1.33 +    conf.env['LIBC_FILE'] = libc
    1.34 +
    1.35 +    conf.start_msg('Searching pthread library')
    1.36 +    libpthread = search_file ([
    1.37 +            '/lib64/libpthread.so.0',
    1.38 +            '/lib/libpthread.so.0',
    1.39 +            ])
    1.40 +    if libpthread is None:
    1.41 +        conf.fatal('not found')
    1.42 +    else:
    1.43 +        conf.end_msg(libpthread, True)
    1.44 +    conf.env['LIBPTHREAD_FILE'] = libpthread
    1.45 +
    1.46 +    if Options.options.kernel_stack is not None and os.path.isdir(Options.options.kernel_stack):
    1.47 +        conf.check(header_name='sim/sim.h',
    1.48 +                   includes=os.path.join(Options.options.kernel_stack, 'include'))
    1.49 +        conf.check()
    1.50 +        conf.env['KERNEL_STACK'] = Options.options.kernel_stack
    1.51 +
    1.52  def build(bld):
    1.53 +    if bld.env['KERNEL_STACK']:
    1.54 +        kernel_source = [
    1.55 +            'linux-socket-fd-factory.cc',
    1.56 +            'linux-socket-fd.cc',
    1.57 +            ]
    1.58 +        kernel_headers = [ 'linux-socket-fd-factory.h']
    1.59 +        kernel_includes = [os.path.join(bld.env['KERNEL_STACK'], 'include')]
    1.60 +    else:
    1.61 +        kernel_source = []
    1.62 +        kernel_headers = []
    1.63 +        kernel_includes = []
    1.64 +
    1.65      module_source = [
    1.66          'model/dce-manager.cc',
    1.67  	'model/dce-application.cc',
    1.68 @@ -95,12 +145,47 @@
    1.69          'model/netlink-attribute.h',
    1.70          'model/netlink-socket-address.h',
    1.71          ]
    1.72 +    module_source = module_source + kernel_source
    1.73 +    module_headers = module_headers + kernel_headers
    1.74      module_test = [
    1.75          'test/dce-manager-test.cc',
    1.76          'test/netlink-socket-test.cc',
    1.77          ]
    1.78      uselib = ns3waf.modules_uselib(bld, ['core', 'network', 'internet'])
    1.79 -    ns3waf.build_module(bld, 'dce',
    1.80 +    ns3waf.build_module(bld, name='dce',
    1.81                          source=module_source,
    1.82                          headers=module_headers,
    1.83 -                        use=uselib)
    1.84 +                        use=uselib,
    1.85 +                        includes=kernel_includes)
    1.86 +
    1.87 +    bld.add_group('dce_version_files')
    1.88 +
    1.89 +    bld(source=['model/libc-ns3.version'],
    1.90 +            target='model/libc.version',
    1.91 +            rule='readversiondef ' + bld.env['LIBC_FILE'] + ' |' \
    1.92 +                'cat ${SRC[0].abspath()} - > ${TGT}')
    1.93 +
    1.94 +    bld(source=['model/libpthread-ns3.version'],
    1.95 +            target='model/libpthread.version',
    1.96 +            rule='readversiondef ' + bld.env['LIBPTHREAD_FILE'] + ' |' \
    1.97 +                'cat ${SRC[0].abspath()} - > ${TGT}')
    1.98 +
    1.99 +    bld.add_group('dce_use_version_files')
   1.100 +
   1.101 +    # The very small libc used to replace the glibc
   1.102 +    # and forward to the dce_* code
   1.103 +    bld.shlib(source = ['model/libc.c', 'model/libc-global-variables.c'],
   1.104 +              target='c-ns3', cflags=['-g'],
   1.105 +              defines=['LIBSETUP=libc_setup'],
   1.106 +              linkflags=['-nostdlib', 
   1.107 +                         '-Wl,--version-script=' + os.path.join('model', 'libc.version'),
   1.108 +                         '-Wl,-soname=libc.so.6'])
   1.109 +
   1.110 +    # The very small libpthread used to replace the glibc
   1.111 +    # and forward to the dce_* code
   1.112 +    bld.shlib(source = ['model/libc.c'],
   1.113 +              target='pthread-ns3', cflags=['-g'],
   1.114 +              defines=['LIBSETUP=libpthread_setup'],
   1.115 +              linkflags=['-nostdlib', '-lc',
   1.116 +                         '-Wl,--version-script=' + os.path.join('model', 'libpthread.version'),
   1.117 +                         '-Wl,-soname=libpthread.so.0'])