A Lisp implemented in AWK
# SPDX-License-Identifier: BSD-2-Clause

BEGIN {
    if(!AWK)
        AWK = "awk"
}

/^@shebang/ {}

/^@target/ {
    TARGET = $2
    # FILENAME is a builtin variable containing the name of awk's
    # current input file
    print TARGET " : tmpl.awk " FILENAME
}

/^@include/ {
    fn = $2
    print TARGET " : " fn
    # When we are trying to find dependencies, image.awk may well not
    # exist, and in any case it will never @include anything; so avoid
    # a fatal error by ignoring it.
    if(fn != "image.awk")
        while((AWK " -f tmpl-depends.awk -v TARGET=\"" TARGET "\" " fn | getline) > 0)
            print
    next
}