Skip to content
This repository
tag: v1.0.0
Fetching contributors…

Cannot retrieve contributors at this time

file 99 lines (78 sloc) 3.298 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
import os, shutil, subprocess, Scripting, Options

out = 'build'
name = 'dns_sd_bindings'

def set_options(opt):
  opt.tool_options('compiler_cxx')
  opt.tool_options('node_addon')

def configure(conf):
  conf.check_tool('compiler_cxx')
  conf.check_tool('node_addon')

  # HACK: The current node master builds a i386 binary while older releases used
  # the compilers default x86_64. node-waf still targets x86_64 resulting in an
  # incompatible binary. Building the add-on as a universal binary for both
  # architectures solves this for now ...
  if conf.env.DEST_OS == 'darwin':
    universal_flags = ['-arch', 'i386', '-arch', 'x86_64']
    conf.env.append_value('CXXFLAGS', universal_flags)
    conf.env.append_value('LINKFLAGS_MACBUNDLE', universal_flags)

  includes = ['/usr/local/include'] # help freebsd
  libpath = ['/usr/local/lib'] # help freebsd
  if conf.check( header_name='dns_sd.h'
               , includes=includes
               , uselib_store='DNS_SD'
               , mandatory=True):
    conf.check(lib='dns_sd', libpath=libpath, uselib_store='DNS_SD')
 
    conf.check(function_name='DNSServiceGetAddrInfo',
               header_name="dns_sd.h",
               uselib='DNS_SD')


def build(bld):
  obj = bld.new_task_gen('cxx', 'shlib', 'node_addon')
  obj.target = name
  obj.uselib = 'DNS_SD'
  if bld.env.HAVE_DNSSERVICEGETADDRINFO:
    obj.defines = ['HAVE_DNSSERVICEGETADDRINFO']
  obj.includes = ['..']
  obj.cxxflags = ['-Wall']
  obj.source = [ 'src/dns_sd.cpp'
               , 'src/dns_service_browse.cpp'
               , 'src/dns_service_enumerate_domains.cpp'
               , 'src/dns_service_process_result.cpp'
               , 'src/dns_service_ref.cpp'
               , 'src/dns_service_ref_deallocate.cpp'
               , 'src/dns_service_ref_sock_fd.cpp'
               , 'src/dns_service_register.cpp'
               , 'src/dns_service_resolve.cpp'
               , 'src/dns_service_get_addr_info.cpp'
               , 'src/mdns_utils.cpp'
               , 'src/txt_record_ref.cpp'
               , 'src/txt_record_create.cpp'
               , 'src/txt_record_deallocate.cpp'
               , 'src/txt_record_set_value.cpp'
               , 'src/txt_record_get_length.cpp'
               , 'src/txt_record_buffer_to_object.cpp'
               ]

  obj = bld.new_task_gen('cxx', 'shlib', 'node_addon')
  obj.target = 'demangle'
  obj.cxxflags = ['-Wall']
  obj.source = [ 'src/demangle.cpp' ]

  #bld.add_post_fun(post_build)


def update_addon_symlink(ctx, directory, target):
  symlink_path = os.path.join(directory, target)
  remove_symlink(symlink_path)
  path_to_addon = os.path.join('..', 'out', ctx.path.bld_dir(ctx.env), target)
  os.symlink(path_to_addon, symlink_path)

def post_build(ctx):
  update_addon_symlink(ctx, 'lib', name + '.node')
  update_addon_symlink(ctx, 'utils/lib', 'demangle.node')


def remove_symlink(symlink):
  if os.path.lexists(symlink):
    os.unlink(symlink)

def distclean(ctx):
  Scripting.distclean(ctx)

  remove_symlink(os.path.join('lib', name + '.node'))
  remove_symlink(os.path.join('utils/lib', 'demangle.node'))

  if os.path.exists('node_modules'):
      shutil.rmtree('node_modules')

def test(ctx):
  subprocess.call(['utils/testrun'])


# vim: set filetype=python shiftwidth=2 softtabstop=2 :
Something went wrong with that request. Please try again.