<commit_before>import gen.build.graph as graph
import gen.build.target as target
import gen.atom as atom
from gen.env import Environment, VarRef, flagstr
from gen.path import Path
import gen.build.graph
import gen.build.linux as linux
import platform

def add_sources(graph, proj, env, settings):
    pass

def get_example_source(proj):
    for group in proj.sourcelist.groups():
        if group.simple_name == 'sglib':
            srcs = []
            for source in group.sources():
                if source.atoms == ('SGLIB',):
                    srcs.append(source.relpath.posix)
            srcs.sort()
            if not srcs:
                raise Exception('cannot find source')
            return srcs[0]

class AutoConf(target.Commands):
    """Linux: Run autoconf etc."""
    __slots__ = ['_env']

    def input(self):
        yield Path('configure.ac')

    def output(self):
        yield Path('configure')
        yield Path('config.h.in')

    def name(self):
        return 'AUTOCONF'

    def commands(self):
        return [['aclocal'], ['autoheader'], ['autoconf']]

class Configure(target.Commands):
    """Linux: Run configure."""
    __slots__ = ['_env']

    def input(self):
        yield Path('configure')
        yield Path('config.mak.in')

    def output(self):
        yield Path('config.mak')
        yield Path('config.h')

    def name(self):
        return 'CONFIGURE'

    def commands(self):
        return [['./configure']]

class LookupAC(object):
    """Class for looking up autoconf template variables."""
    __slots__ = ['_proj']

    def __init__(self, proj):
        self._proj = proj

    def __call__(self, x):
        info = self._proj.info
        if info.haskey(x):
            return getattr(info, x)
        if x == 'SRCFILE':
            return get_example_source(self._proj)

def add_targets(graph, proj, env, settings):
    """Generate targets for autotools build on Linux."""
    mf = Path('Makefile')
    graph.add(Makefile(mf, proj))
    rs = Path('run.sh')
    graph.add(RunSh(rs, proj))
    cm = Path('config.mak.in')
    graph.add(ConfigMak(cm))
    ccin = Path('configure.ac')
    ccsrc = Path(proj.sgpath, 'scripts/configure.ac')
    lookup = LookupAC(proj)
    graph.add(target.Template(ccin, ccsrc, lookup, regex=r'@(\w+)@'))

    deps = [mf, cm, ccin, rs]
    if platform.system() in ('Linux', 'Darwin'):
        graph.add(AutoConf(env))
        deps.append(Path('configure'))

    deps.extend(graph.platform_built_sources(proj, 'LINUX'))
    graph.add(target.DepTarget('gmake', deps))

    if platform.system() == 'Linux':
        graph.add(Configure(env))
        cdep = [Path('config.mak'), 'gmake']
        graph.add(target.DepTarget('config', cdep))
        graph.add(target.DepTarget('default', ['config']))

LIBS = ['LIBJPEG', 'GTK', 'LIBPNG', 'PANGO']
FLAGS = ['CC', 'CXX',
         'CPPFLAGS', 'CFLAGS', 'CXXFLAGS', 'CWARN', 'CXXWARN',<commit_msg>build: add default configure flags<commit_after>import gen.build.graph as graph
import gen.build.target as target
import gen.atom as atom
from gen.env import Environment, VarRef, flagstr
from gen.path import Path
import gen.build.graph
import gen.build.linux as linux
import platform

def add_sources(graph, proj, env, settings):
    pass

def get_example_source(proj):
    for group in proj.sourcelist.groups():
        if group.simple_name == 'sglib':
            srcs = []
            for source in group.sources():
                if source.atoms == ('SGLIB',):
                    srcs.append(source.relpath.posix)
            srcs.sort()
            if not srcs:
                raise Exception('cannot find source')
            return srcs[0]

class AutoConf(target.Commands):
    """Linux: Run autoconf etc."""
    __slots__ = ['_env']

    def input(self):
        yield Path('configure.ac')

    def output(self):
        yield Path('configure')
        yield Path('config.h.in')

    def name(self):
        return 'AUTOCONF'

    def commands(self):
        return [['aclocal'], ['autoheader'], ['autoconf']]

class Configure(target.Commands):
    """Linux: Run configure."""
    __slots__ = ['_env', '_settings']

    def __init__(self, env, settings):
        self._env = env
        self._settings = settings

    def input(self):
        yield Path('configure')
        yield Path('config.mak.in')

    def output(self):
        yield Path('config.mak')
        yield Path('config.h')

    def commands(self):
        s = self._settings
        cflags = {
            'debug': '-O0 -g',
            'release': '-O2 -g',
        }
        try:
            cflags = cflags[s.CONFIG]
        except KeyError:
            raise ValueError('unknown configuration: %r' % (s.CONFIG,))
        return [['./configure', '--enable-warnings=error',
                 'CFLAGS=' + cflags, 'CXXFLAGS=' + cflags]]

class LookupAC(object):
    """Class for looking up autoconf template variables."""
    __slots__ = ['_proj']

    def __init__(self, proj):
        self._proj = proj

    def __call__(self, x):
        info = self._proj.info
        if info.haskey(x):
            return getattr(info, x)
        if x == 'SRCFILE':
            return get_example_source(self._proj)

def add_targets(graph, proj, env, settings):
    """Generate targets for autotools build on Linux."""
    mf = Path('Makefile')
    graph.add(Makefile(mf, proj))
    rs = Path('run.sh')
    graph.add(RunSh(rs, proj))
    cm = Path('config.mak.in')
    graph.add(ConfigMak(cm))
    ccin = Path('configure.ac')
    ccsrc = Path(proj.sgpath, 'scripts/configure.ac')
    lookup = LookupAC(proj)
    graph.add(target.Template(ccin, ccsrc, lookup, regex=r'@(\w+)@'))

    deps = [mf, cm, ccin, rs]
    if platform.system() in ('Linux', 'Darwin'):
        graph.add(AutoConf(env))
        deps.append(Path('configure'))

    deps.extend(graph.platform_built_sources(proj, 'LINUX'))
    graph.add(target.DepTarget('gmake', deps))

    if platform.system() == 'Linux':
        graph.add(Configure(env, settings))
        cdep = [Path('config.mak'), 'gmake']
        graph.add(target.DepTarget('config', cdep))
        graph.add(target.DepTarget('default', ['config']))

LIBS = ['LIBJPEG', 'GTK', 'LIBPNG', 'PANGO']
FLAGS = ['CC', 'CXX',
         'CPPFLAGS', 'CFLAGS', 'CXXFLAGS', 'CWARN', 'CXXWARN',
{'fraction_non_alphanumeric': 0.1515729265967588, 'fraction_numerical': 0.0006355258976803305, 'mean_word_length': 2.6053837342497137, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1652637', 'n_tokens_mistral': 2058, 'n_tokens_neox': 1982, 'n_words': 481}