# -*- 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.append_unique('DEFINES', ['_WEBSOCKETPP_CPP11_STL_'])
        self.env.INCLUDES_WEBSOCKET = websocketDir.parent.abspath()
        self.env.HAVE_WEBSOCKET = True
        self.define('HAVE_WEBSOCKET', 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/cawka/websocketpp/archive/0.8.1-hotfix.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))
