QT += core gui
QT += widgets serialport network

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = ATBUpdateTool

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

# 1.3.6 :   Do not update device-controller/json files, but have the library
#           (in a later step) do that.
#           Fixed sending messages to ISMAS.
#           Always execute contents of opkg_commands-file (even if there are no
#           changes).
# 1.3.7 :   Wait forever for git-commands to finish in QProcess executing such
#           a command.
# 1.3.8 :   Remove accessing opkg_commands under file-system-path /etc/psa_update.
#           Activate download of json-configuration files.
# 1.3.9 :   Fix sendLastVersion: use configured branch and not master branch in
#               git show origin/master -s --format="c=%h m=%s d=%cI"    ==>
#               git show origin/zg1/zone1 -s --format="c=%h m=%s d=%cI"
#           Use dynamic values for os-release and apism-version when sending
#           last version info.
# 1.3.10:   Fix premature killing opkg-commands: detected timeout of 100s was
#           too small when updating apism.
#           Fix display of UPDATE_SUCCESS when opkg_command fails. Detected when
#           updating apsim failed.
# 1.3.11:   Integrate version of ATBUpdateTool in SendLastVersion-ISMAS-message.
# 1.3.12:   Add command parameters for output of yocto-infos about ATBUpdateTool.
#           Use 'git pull' instead of 'git fetch'.
#           Use 'git clone --filter=blob:none' instead of 'git clone' to speed
#           up cloning of customer repository.
# 1.3.13:   Fix: if the customer repository is corrupted, remove it and re-clone
#           the repository (without checking the ISMAS-trigger (WAIT-)button.
# 1.3.14:   Add additional check for sanity of customer repository using
#           "git fsck".
#           Stream-lined code of update process: massive refactoring.
#           Added functionality: If WAIT button is not active, then an existing
#           customer repository will be repaired, or a not existing repository
#           will be cloned. The process stops then.
#           However, if the WAIT button is active, the at least the commands in
#           opkg_commands will be executed. Changed files in the customer
#           repository will be worked on: tariff-files will be synced with the
#           local filesystem, json-files will be downloaded to firmware.
#           The device-controller firmware will be handled in a later version.
VERSION="1.3.15"
#           Bug fixes found during testing.

# PLANNED TODOS:
#   1:  Das Repository wird repariert bwz. neu geklont. Unabhaengig vom WAIT.
#   2:  Wenn der WAIT-Button aktiv ist, dann wird ein Repository repariert (neu
#       geklont), aber zusaetzlich werden alle verfuegbaren Dateien als neu
#       angesehen und die entsprechenden Aktionen durchgefuehrt: tariff-files
#       spiegeln, json-files laden und dc laden. Also VORSICHT: das repository
#       muss in diesem fall wirklich in ordnung sein.
#   3:  Wurde keine Datei geaendert, kein initiales Clone und der WAIT-button
#       nicht aktiv, so (passiert natuerlich nichts) kann man davon ausgehen,
#       dass es sich um ein automatisches Update handelt. Dann koennte man im
#       ISMAS eine entsprechende Meldung anzeigen als Teil von SEND-LAST-VERSION.
#       Wenn der WAIT-button aktiv ist, dann werden zumindest die opkg-commands
#       ausgefuehrt.
#   4:  rsync: immer alle Dateien soiegeln (bis auf opkg-commands)
#   5:  Falls das Tool mal abstuerzt, dann einen Signal-Handler (fuer TERM)
#       installieren, sodass zumnidest SEND-LASt-VERSION mit rausgeht.
#   6:  rsync: explizites Binary, nicht das in busybox enthaltene.

win32 {
    BUILD_DATE=$$system("date /t")
    BUILD_TIME=$$system("time /t")
} else {
    BUILD_DATE=$$system("date +%d-%m-%y")
    BUILD_TIME=$$system("date +%H:%M:%S")
}

GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")

EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"

INCLUDEPATH += plugins

CONFIG += c++17
# CONFIG -= app_bundle

DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"
DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\"
DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\"

# keep comments, as /* fall through */
QMAKE_CXXFLAGS += -C
QMAKE_CXXFLAGS += -g
QMAKE_CXXFLAGS += -Wno-deprecated-copy

contains( CONFIG, PTU5 ) {
    greaterThan(QT_MAJOR_VERSION, 4): QT += serialport
    CONFIG += link_pkgconfig
    lessThan(QT_MAJOR_VERSION, 5):   PKGCONFIG += qextserialport
    QMAKE_CXXFLAGS += -O2 -std=c++17   # for GCC >= 4.7
    # QMAKE_CXXFLAGS += -Wno-deprecated-copy
    ARCH = PTU5
    DEFINES+=PTU5
}
contains( CONFIG, PTU5_YOCTO ) {
    greaterThan(QT_MAJOR_VERSION, 4): QT += serialport
    QMAKE_CXXFLAGS += -std=c++17   # for GCC >= 4.7
    # QMAKE_CXXFLAGS += -Wno-deprecated-copy
    PTU5BASEPATH = /opt/devel/ptu5
    ARCH = PTU5
    DEFINES+=PTU5

    # add qmqtt lib
    #LIBS += -lQt5Qmqtt
}
contains( CONFIG, DesktopLinux ) {
    greaterThan(QT_MAJOR_VERSION, 4): QT += serialport
    lessThan(QT_MAJOR_VERSION, 5):    CONFIG += extserialport
    # QMAKE_CC = ccache $$QMAKE_CC
    # QMAKE_CXX = ccache $$QMAKE_CXX
    QMAKE_CXXFLAGS += -std=c++17
    # QMAKE_CXXFLAGS += -Wno-deprecated-copy
    linux-clang {  QMAKE_CXXFLAGS += -Qunused-arguments   }
    ARCH = DesktopLinux
    DEFINES+=DesktopLinux
}

SOURCES += \
        main.cpp \
        progress_event.cpp \
        update_dc_event.cpp \
        mainwindow.cpp \
        utils.cpp \
        update.cpp \
        git/git_client.cpp \
        ismas/ismas_client.cpp \
        process/command.cpp \
        message_handler.cpp \
        worker.cpp \
        worker_thread.cpp

HEADERS += \
        update.h \
        progress_event.h \
        update_dc_event.h \
        utils.h \
        mainwindow.h \
        git/git_client.h \
        apism/ismas_data.h \
        ismas/ismas_client.h \
        process/command.h \
        message_handler.h \
        worker.h \
        worker_thread.h \
        plugins/interfaces.h

FORMS += \
    mainwindow.ui


##########################################################################################
# for running program on target through QtCreator
contains( CONFIG, PTU5 ) {
   qnx: target.path = /tmp/$${TARGET}/bin
   else: unix:!android: target.path = /opt/app/tools/atbupdate/
   !isEmpty(target.path): INSTALLS += target
}
