Qtopia Home · Home · Reference · User Guide · Internals

Add a custom compiler

Compilers operate on a number of files one by one or all at once.

Here's an example to compile some flex (lex) and bison (yacc) files. These examples are useful because qmake's builtin support for these compilers is limited. Note that this solution can only support 1 flex and 1 bison source file per project.

    FLEX_SOURCES=lexer.l
    BISON_SOURCES=parser.y

    flex.commands=flex -o${QMAKE_FILE_OUT} ${QMAKE_FILE_IN}
    flex.output=$$OUT_PWD/${QMAKE_FILE_BASE}.c
    flex.input=FLEX_SOURCES
    flex.variable_out=SOURCES
    flex.name=flex ${QMAKE_FILE_IN}
    # qmake can't parse lexer.l to see this dependency
    flex.depends=parser.h
    QMAKE_EXTRA_COMPILERS+=flex

    bisonsource.commands=bison -d -o${QMAKE_FILE_OUT} ${QMAKE_FILE_IN}
    bisonsource.output=$$OUT_PWD/${QMAKE_FILE_BASE}.c
    bisonsource.input=BISON_SOURCES
    bisonsource.variable_out=SOURCES
    bisonsource.name=bisonsource ${QMAKE_FILE_IN}
    QMAKE_EXTRA_COMPILERS+=bisonsource

    # This dummy entry is required so that qmake handles the header correctly
    bisonheader.commands=@true
    bisonheader.output=$$OUT_PWD/${QMAKE_FILE_BASE}.h
    bisonheader.input=BISON_SOURCES
    bisonheader.variable_out=HEADERS
    bisonheader.name=bisonheader ${QMAKE_FILE_IN}
    # this dependency is needed so that files that depend on parser.h are processed after bison is run
    bisonheader.depends=parser.c
    QMAKE_EXTRA_COMPILERS+=bisonheader

See also Advanced Tasks.


Copyright © 2008 Nokia Qtopia Build System Documentation