# encoding: utf-8
#
# WAF build scripts for XMMS2
# Copyright (C) 2006-2009 XMMS2 Team

source = """
main.y
lexer.l
config.c
print.c
""".split()

## Code fragments for configuration.
bison_fragment = """
%{
#define YYSTYPE int
YYSTYPE yylex() {return 0;}
int yyerror(const char *s) {return 0;}
%}
%token	<int>	INTEGER_LITERAL
%destructor {} <*>
%%
input:;
%%
int main() {return 0;}
"""

def build(bld):
    bld(features='c cprogram',
        target = 's4',
        name = 's4-tool',
        source = source,
        includes = '.',
        use = "s4",
        uselib = "glib2 gthread2 readline"
        )

def configure (conf):
    conf.load("flex")
    conf.load("bison")
    conf.env.append_value('BISONFLAGS', '--verbose')

    fragment="""
    #include <stdio.h>
    #include <readline/readline.h>
    int main(void) {
        return readline("prompt") != 0;
    }
    """
    rl_headers=["stdio.h", "readline/readline.h"]
    conf.check_cc(header_name=rl_headers)
    conf.check_cc(lib="readline", header_name=rl_headers, fragment=fragment,
            uselib_store="readline")
    # Check support for %destructor in bison (bug 2594)
    conf.check_cc(fragment=bison_fragment, compile_filename="fragment.y")

def options (opt):
    pass
