meson
meson copied to clipboard
[feature request] add bison/flex support
Like autotools does. This could simplify the tacks for users using bison/flex
How about use find_program and custom_target?
For libpcap:
lex = find_program('flex', 'lex')
yacc = find_program('bison', 'yacc', 'byacc')
scanner_c = custom_target('scanner.c',
output: [ 'scanner.c', 'scanner.h' ],
input: 'scanner.l',
command: [lex, '-P', 'pcap_', '-o@OUTPUT0@', '--nounput',
'--header-file=@OUTPUT1@', '@INPUT@', ],
)
I would be open to discussing a module for common code generators (protoc anyone?), but only if part of the plan was to ease the differences between flex vs lex, and yacc vs byacc vs bison, and handling host machine specific flags automatically (ie, does flex need --wincompat).
Mesa has a pile of code for dealing with all of those differences
+1 for adding flex/bison modules or special casing find_program, currently i have this chunk of config to get them both reliably working on windows and unix
lexargs = []
parseargs = []
host = host_machine.system()
# setup required flex/bison args
if host == 'windows'
lexargs += [ '--wincompat' ]
else
parseargs += [ '-Wdeprecated' ]
endif
flex = find_program('flex', 'win_flex', version : '>=2.6')
bison = find_program('bison', 'win_bison', version : host == 'windows' ? '>=2.6' : '>=3.5')
lex = generator(flex,
output : [ '@BASENAME@_flex.c', '@BASENAME@_flex.h' ],
arguments : lexargs + [
'--outfile=@OUTPUT0@',
'--header-file=@OUTPUT1@',
'@INPUT@'
]
)
parse = generator(bison,
output : [ '@BASENAME@_bison.c', '@BASENAME@_bison.h' ],
arguments : parseargs + [
'-d', '@INPUT@', '-v',
'--output=@OUTPUT0@',
'--defines=@OUTPUT1@'
]
)
Hello there, I am new to meson but if I am not mistaken, the flex/bison files (e.g. scanner.c) generated by the above solutions are placed in the build directory.
However, when distributing the sources to another user, in our autotools-based project (which I am trying to convert to meson) the generated flex/bison files were included in the source tree so as not to obligate the user to have flex/bison installed. How would this be possible with meson?
Ideally, scanner.c should be generated only if a) there is no scanner.c in the source tree or b) the relevant source files (scanner.l) were modified so a new scanner.c should be generated. Is there any way to have such a behavior?
@vvdimako there isn't a good way to do (b), ninja either needs to own the files as generated or be able to assume they're not generated. (a) is not too hard to do, there's a function in the fs module for that. Something like:
fs = import('fs)
if fs.is_file(meson.current_source_dir() / 'scanner.c')
'<do path for tarball>'
else
'<do path for git>'
endif`
I concede I haven't yet had the chance to research how the current pull request handles this, but it's possible that a cross variant of lex or yacc would need to be used for cross building. Per POSIX's specification for lex and likewise for yacc it is implementation-defined what assumptions these tools make about the host system. If Meson will be identifying the different implementations, it seems just as sensible for Meson to bear responsibility for deciding if some implementation is appropriate for cross-building.