<commit_before># Monary - Copyright 2011-2014 <NAME>
# Please see the included LICENSE.TXT and NOTICE.TXT for licensing information.

import os
import platform
import re
import subprocess
from distutils.core import setup, Command
from distutils.command.build import build
from distutils.ccompiler import new_compiler

DEBUG = False

VERSION = "0.3.0"

# Hijack the build process by inserting specialized commands into
# the list of build sub commands
build.sub_commands = [ ("build_cmongo", None), ("build_cmonary", None) ] + build.sub_commands

# Platform specific stuff
if platform.system() == 'Windows':
    compiler_kw = {'compiler' : 'mingw32'}
    linker_kw = {'libraries' : ['ws2_32']}
    so_target = 'cmonary.dll'
else:
    compiler_kw = {}
    linker_kw = {'libraries' : ['ssl', 'crypto', 'pthread']}
    so_target = 'libcmonary.so' 

compiler = new_compiler(**compiler_kw)

MONARY_DIR = "monary"
CMONGO_SRC = "mongodb-mongo-c-driver-0.96.4"
CFLAGS = ["-fPIC", "-O2"]

if not DEBUG:
    CFLAGS.append("-DNDEBUG")

class BuildException(Exception):
    """Indicates an error occurred while compiling from source."""
    pass

# I suspect I could be using the build_clib command for this, but don't know how.
class BuildCMongoDriver(Command):
    """Custom command to build the C Mongo driver. Relies on autotools."""
    description = "builds the C Mongo driver"
    user_options = [ ]
    def initialize_options(self):
        pass
    def finalize_options(self):
        pass
    def run(self):
        try:
            os.chdir(CMONGO_SRC)
            status = subprocess.call(["./configure", "--enable-static",
                                      "--without-documentation",
                                      "--disable-maintainer-mode",
                                      "--disable-tests", "--disable-examples"])
            if status != 0:
                raise BuildException("configure script failed with exit status %d" % status)

            status = subprocess.call(["make"])
            if status != 0:
                raise BuildException("make failed with exit status %d" % status)
            # after configuring, add libs to linker_kw
            with open(os.path.join("src", "libmongoc-1.0.pc")) as f:
                libs = re.search(r"Libs:\s+(.+)$", f.read(), flags=re.MULTILINE).group(1)
                libs = [l[2:] for l in re.split(r"\s+", libs) if l.startswith("-l")]
                linker_kw["libraries"] += libs
        finally:
            os.chdir("..")

class BuildCMonary(Command):
    """Custom command to build the cmonary library, static linking to the cmongo drivers,
       a producing a .so library that can be loaded via ctypes.
    """<commit_msg>Update setup for linker flags<commit_after># Monary - Copyright 2011-2014 <NAME>
# Please see the included LICENSE.TXT and NOTICE.TXT for licensing information.

import os
import platform
import re
import subprocess
from distutils.core import setup, Command
from distutils.command.build import build
from distutils.ccompiler import new_compiler

DEBUG = False

VERSION = "0.3.0"

# Hijack the build process by inserting specialized commands into
# the list of build sub commands
build.sub_commands = [ ("build_cmongo", None), ("build_cmonary", None) ] + build.sub_commands

# Platform specific stuff
if platform.system() == 'Windows':
    compiler_kw = {'compiler' : 'mingw32'}
    linker_kw = {'libraries' : ['ws2_32']}
    so_target = 'cmonary.dll'
else:
    compiler_kw = {}
    linker_kw = {'libraries' : []}
    so_target = 'libcmonary.so' 

compiler = new_compiler(**compiler_kw)

MONARY_DIR = "monary"
CMONGO_SRC = "mongodb-mongo-c-driver-0.96.4"
CFLAGS = ["-fPIC", "-O2"]

if not DEBUG:
    CFLAGS.append("-DNDEBUG")

class BuildException(Exception):
    """Indicates an error occurred while compiling from source."""
    pass

# I suspect I could be using the build_clib command for this, but don't know how.
class BuildCMongoDriver(Command):
    """Custom command to build the C Mongo driver. Relies on autotools."""
    description = "builds the C Mongo driver"
    user_options = [ ]
    def initialize_options(self):
        pass
    def finalize_options(self):
        pass
    def run(self):
        try:
            os.chdir(CMONGO_SRC)
            status = subprocess.call(["./configure", "--enable-static",
                                      "--without-documentation",
                                      "--disable-maintainer-mode",
                                      "--disable-tests", "--disable-examples"])
            if status != 0:
                raise BuildException("configure script failed with exit status %d" % status)

            status = subprocess.call(["make"])
            if status != 0:
                raise BuildException("make failed with exit status %d" % status)
            # after configuring, add libs to linker_kw
            with open(os.path.join("src", "libmongoc-1.0.pc")) as f:
                libs = re.search(r"Libs:\s+(.+)$", f.read(), flags=re.MULTILINE).group(1)
                libs = [l[2:] for l in re.split(r"\s+", libs)[:-1] if l.startswith("-l")]
                linker_kw["libraries"] += libs
        finally:
            os.chdir("..")

class BuildCMonary(Command):
    """Custom command to build the cmonary library, static linking to the cmongo drivers,
       a producing a .so library that can be loaded via ctypes.
    """
{'fraction_non_alphanumeric': 0.12132420935823932, 'fraction_numerical': 0.010171999260218235, 'mean_word_length': 2.543905635648755, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1383803', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1552, 'n_words': 479}