# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-

from waflib import Options, Logs, Errors, Configure
import re

def addWebsocketOptions(self, opt):
    opt.add_option('--without-websocket', action='store_false', default=True,
                   dest='with_websocket', help='Disable WebSocket face support')

setattr(Options.OptionsContext, 'addWebsocketOptions', addWebsocketOptions)

@Configure.conf
def checkWebsocket(self, **kw):
    if not self.options.with_websocket:
        return

    isMandatory = kw.get('mandatory', True)

    self.start_msg('Checking for WebSocket++ includes')

    try:
        websocketDir = self.path.find_dir('websocketpp/websocketpp')
        if not websocketDir:
            raise Errors.WafError('Not found')

        versionFile = websocketDir.find_node('version.hpp')
        if not websocketDir:
            raise Errors.WafError('WebSocket++ version file not found')

        try:
            txt = versionFile.read()
        except (OSError, IOError):
            raise Errors.WafError('Cannot read WebSocket++ version file')

        version = [None, None, None]
        # Looking for the following:
        # static int const major_version = 0;
        # static int const minor_version = 7;
        # static int const patch_version = 0;
        majorVersion = re.compile('^static int const major_version = (\\d+);$', re.M)
        version[0] = majorVersion.search(txt)
        minorVersion = re.compile('^static int const minor_version = (\\d+);$', re.M)
        version[1] = minorVersion.search(txt)
        patchVersion = re.compile('^static int const patch_version = (\\d+);$', re.M)
        version[2] = patchVersion.search(txt)

        if not version[0] or not version[1] or not version[2]:
            raise Errors.WafError('Cannot detect WebSocket++ version')

        self.env.WEBSOCKET_VERSION = [i.group(1) for i in version]

        # todo: version checking, if necessary

        self.end_msg('.'.join(self.env.WEBSOCKET_VERSION))

        self.env.INCLUDES_WEBSOCKET = websocketDir.parent.abspath()
        self.env.HAVE_WEBSOCKET = True
        self.define('HAVE_WEBSOCKET', 1)
        self.define('_WEBSOCKETPP_CPP11_STL_', 1)

    except Errors.WafError as error:
        if isMandatory:
            self.end_msg(str(error), color='RED')
            Logs.warn('If you are using NFD from the git repository, checkout the websocketpp submodule: ')
            Logs.warn('    git submodule update --init')
            Logs.warn('Otherwise, manually download and extract the websocketpp library:')
            Logs.warn('    mkdir -p websocketpp')
            Logs.warn('    curl -L https://github.com/zaphoyd/websocketpp/archive/0.8.1.tar.gz > websocketpp.tar.gz')
            Logs.warn('    tar xf websocketpp.tar.gz -C websocketpp/ --strip 1')
            Logs.warn('Alternatively, WebSocket support can be disabled with --without-websocket')
            self.fatal('WebSocket++ not found')
        else:
            self.end_msg(str(error))
