#  W A R N I N G
#  -------------
#
# This file is not part of the Qt API.  It exists purely as an
# implementation detail.  It may change from version to version
# without notice, or even be removed.
#
# We mean it.
#

qtPrepareLibExecTool(QMAKE_TRACEGEN, tracegen)

isEmpty(TRACEGEN_DIR): TRACEGEN_DIR = .

PROVIDER_NAME = qt$$lower($$MODULE)
INCLUDEPATH += $$absolute_path($$TRACEGEN_DIR, $$OUT_PWD)
HEADER_PATH = $$OUT_PWD/$$TRACEGEN_DIR/$${PROVIDER_NAME}_tracepoints_p$${first(QMAKE_EXT_H)}

if(qtConfig(lttng)|qtConfig(etw)) {
    SOURCE_PATH = $$OUT_PWD/$$TRACEGEN_DIR/$${PROVIDER_NAME}_tracepoints$${first(QMAKE_EXT_CPP)}

    isEmpty(BUILDS)|build_pass {
        impl_file_contents = \
            "$${LITERAL_HASH}define TRACEPOINT_CREATE_PROBES" \
            "$${LITERAL_HASH}define TRACEPOINT_DEFINE" \
            "$${LITERAL_HASH}include \"$${HEADER_PATH}\""

        write_file($$SOURCE_PATH, impl_file_contents)|error()
    }

    GENERATED_SOURCES += $$SOURCE_PATH

    tracegen.input = TRACEPOINT_PROVIDER
    tracegen.output = $$HEADER_PATH
    tracegen.variable_out = HEADERS
    tracegen.depends += $$QMAKE_TRACEGEN_EXE
    tracegen.CONFIG = target_predeps

    qtConfig(lttng) {
        tracegen.commands = $$QMAKE_TRACEGEN lttng ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT}
        QMAKE_USE_PRIVATE += lttng-ust
    } else {
        tracegen.commands = $$QMAKE_TRACEGEN etw ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT}
    }

    QMAKE_EXTRA_COMPILERS += tracegen

    DEFINES += Q_TRACEPOINT
} else {
    isEmpty(BUILDS)|build_pass {
        header_file_contents = "$${LITERAL_HASH}include <private/qtrace_p.h>"
        write_file($$HEADER_PATH, header_file_contents)|error()
    }
}
