@echo off
SetLocal EnableDelayedExpansion

if "%1" == "-query" (
    echo QT_SYSROOT:
    echo QT_INSTALL_PREFIX:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr
    echo QT_INSTALL_ARCHDATA:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr/share/qt5
    echo QT_INSTALL_DATA:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr/share/qt5
    echo QT_INSTALL_DOCS:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr/share/doc/qt5
    echo QT_INSTALL_HEADERS:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr/include/qt5
    echo QT_INSTALL_LIBS:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr/lib
    echo QT_INSTALL_LIBEXECS:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr/lib/qt5/libexec
    echo QT_INSTALL_BINS:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr/lib/qt5/bin
    echo QT_INSTALL_TESTS:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr/lib/qt5/tests
    echo QT_INSTALL_PLUGINS:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr/lib/qt5/plugins
    echo QT_INSTALL_IMPORTS:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr/lib/qt5/imports
    echo QT_INSTALL_QML:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr/lib/qt5/qml
    echo QT_INSTALL_TRANSLATIONS:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr/share/qt5/translations
    echo QT_INSTALL_CONFIGURATION:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/etc/xdg
    echo QT_INSTALL_EXAMPLES:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr/lib/qt5/examples
    echo QT_INSTALL_DEMOS:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr/lib/qt5/examples
    echo QT_HOST_PREFIX:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr
    echo QT_HOST_DATA:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr/share/qt5
    echo QT_HOST_BINS:@install_dir@/bin
    echo QT_HOST_LIBS:@install_dir@/sdk/@release@/targets/armv7hl-meego-linux-gnueabi/usr/lib
    echo QMAKE_SPEC:linux-g++
    echo QMAKE_XSPEC:linux-armv7hl-meego-gnueabi-g++
    echo QMAKE_VERSION:3.0
    echo QT_VERSION:5.6.3
    goto :EOF
)
set SRC_DIR=%~dp1
set BUILD_DIR=%cd%

set argCount=0

for %%x in (%*) do (
    set /A argCount+=1
    set "argVec[!argCount!]=%%~x"
)
if %argCount% GTR 3 (
    set OPT_ARGS= --extra-options="
    for /L %%i in (4,1,%argCount%) do (
        set OPT_ARGS=!OPT_ARGS! !argVec[%%i]!
    )
    set OPT_ARGS=!OPT_ARGS!"
)
set BUILD_DIR=%BUILD_DIR:\=/%
SET BUILD_DIR=!BUILD_DIR:%WORKSPACE_DIR%=/workspace!
echo builddir=%BUILD_DIR%

set SRC_DIR=%SRC_DIR:\=/%
SET SRC_DIR=!SRC_DIR:%WORKSPACE_DIR%=/workspace!
echo srcdir=%SRC_DIR%

if not "%VAR_SPECFILE%" == "" (
    SET VAR_SPECFILE=--specfile "%VAR_SPECFILE%"
    SET VAR_SPECFILE=!VAR_SPECFILE:%WORKSPACE_DIR%=/workspace!
) else (
    SET VAR_SPECFILE=
)

docker run -i --rm --cap-add=SYS_ADMIN --security-opt apparmor:unconfined -v %WORKSPACE_DIR%:/workspace -w %BUILD_DIR% @docker_image_tag@ apptool build --arm32 --srcdir=%SRC_DIR% --dstdir=%BUILD_DIR% %VAR_SPECFILE% --configure%OPT_ARGS%
