1#
2# Yacc extra-compiler for handling files specified in the YACCSOURCES variable
3#
4
5isEmpty(YACC_DIR): YACC_DIR = .
6
7defineReplace(yaccCommands) {
8    input = $$relative_path($$absolute_path($$1, $$OUT_PWD), $$OUT_PWD/$$YACC_DIR)
9    input_base = $$basename(1)
10    input_base ~= s/\.[^.]*$//
11    hpp_output = $$2
12    cpp_output = $$hpp_output
13    cpp_output ~= s/$$re_escape($$first(QMAKE_EXT_H))$/$$first(QMAKE_EXT_CPP)/
14
15    isEmpty(QMAKE_YACCFLAGS_MANGLE) {
16        QMAKE_YACCFLAGS_MANGLE = -p $${input_base} -b $${input_base}
17        QMAKE_YACC_HEADER      = $${input_base}.tab.h
18        QMAKE_YACC_SOURCE      = $${input_base}.tab.c
19    } else {
20        QMAKE_YACCFLAGS_MANGLE ~= s/\\$base/$${input_base}/g #backwards compat
21        QMAKE_YACC_HEADER      ~= s/\\$base/$${input_base}/g
22        QMAKE_YACC_SOURCE      ~= s/\\$base/$${input_base}/g
23    }
24    QMAKE_YACCDECLFLAGS = $$QMAKE_YACCFLAGS
25    !yacc_no_name_mangle: QMAKE_YACCDECLFLAGS += $$QMAKE_YACCFLAGS_MANGLE
26
27    !equals(YACC_DIR, .): yacc_call = cd $$YACC_DIR &&
28    yacc_call += $$QMAKE_YACC $$QMAKE_YACCDECLFLAGS $${input}
29
30    commands = \
31        -$(DEL_FILE) $${hpp_output} $${cpp_output}$$escape_expand(\\n\\t) \
32        $${yacc_call}$$escape_expand(\\n\\t) \
33        $(MOVE) $$shell_path($${YACC_DIR}/$${QMAKE_YACC_HEADER}) $${hpp_output}$$escape_expand(\\n\\t) \
34        $(MOVE) $$shell_path($${YACC_DIR}/$${QMAKE_YACC_SOURCE}) $${cpp_output}$$escape_expand(\\n\\t)
35
36    silent: commands = @echo Yacc $$1 && $$commands
37    return($$commands)
38}
39
40yacc_output_base = $${YACC_DIR}/$${QMAKE_CPP_MOD_MOC}${QMAKE_FILE_BASE}$${QMAKE_MOD_YACC}
41
42{
43    yacc_decl.name = Yacc header
44    yacc_decl.input = YACCSOURCES
45    yacc_decl.variable_out = GENERATED_FILES
46    yacc_decl.commands = ${QMAKE_FUNC_yaccCommands}
47    yacc_decl.output = $${yacc_output_base}$$first(QMAKE_EXT_H)
48    QMAKE_EXTRA_COMPILERS += yacc_decl
49}
50
51{
52    yacc_impl.name = source for ${QMAKE_FILE_IN}
53    yacc_impl.input = YACCSOURCES
54    yacc_impl.variable_out = GENERATED_SOURCES
55    yacc_impl.dependency_type = TYPE_C
56    yacc_impl.commands = $$escape_expand(\\n)        # We don't want any commands where, but if command is empty no rules are created
57    yacc_impl.depends += $${yacc_output_base}$$first(QMAKE_EXT_H)    # Make sure we depend on the step above
58    yacc_impl.output = $${yacc_output_base}$$first(QMAKE_EXT_CPP)    # Faked output from this step, output really created in step above
59    QMAKE_EXTRA_COMPILERS += yacc_impl
60}
61
62unset(yacc_output_base)
63