1:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2::
3:: Copyright (C) 2016 The Qt Company Ltd.
4:: Copyright (C) 2016 Intel Corporation.
5:: Contact: https://www.qt.io/licensing/
6::
7:: This file is part of the tools applications of the Qt Toolkit.
8::
9:: $QT_BEGIN_LICENSE:GPL-EXCEPT$
10:: Commercial License Usage
11:: Licensees holding valid commercial Qt licenses may use this file in
12:: accordance with the commercial license agreement provided with the
13:: Software or, alternatively, in accordance with the terms contained in
14:: a written agreement between you and The Qt Company. For licensing terms
15:: and conditions see https://www.qt.io/terms-conditions. For further
16:: information use the contact form at https://www.qt.io/contact-us.
17::
18:: GNU General Public License Usage
19:: Alternatively, this file may be used under the terms of the GNU
20:: General Public License version 3 as published by the Free Software
21:: Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
22:: included in the packaging of this file. Please review the following
23:: information to ensure the GNU General Public License requirements will
24:: be met: https://www.gnu.org/licenses/gpl-3.0.html.
25::
26:: $QT_END_LICENSE$
27::
28:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
29
30@echo off
31setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
32set ARGS=%*
33set QTSRC=%~dp0
34set QTSRC=%QTSRC:~0,-1%
35set QTDIR=%CD%
36
37rem Make sure qmake is not confused by these. Recursion via Makefiles would
38rem be still affected, so just unsetting them here is not an option.
39if not "%QMAKESPEC%" == "" goto envfail
40if not "%XQMAKESPEC%" == "" goto envfail
41if not "%QMAKEPATH%" == "" goto envfail
42if not "%QMAKEFEATURES%" == "" goto envfail
43goto envok
44:envfail
45echo >&2 Please make sure to unset the QMAKESPEC, XQMAKESPEC, QMAKEPATH,
46echo >&2 and QMAKEFEATURES environment variables prior to building Qt.
47exit /b 1
48:envok
49
50rem Parse command line
51
52set TOPLEVEL=false
53set TOPQTSRC=%QTSRC%
54set TOPQTDIR=%QTDIR%
55if /i not "%~1" == "-top-level" goto notoplevel
56set ARGS=%ARGS:~10%
57set TOPLEVEL=true
58for %%P in ("%TOPQTSRC%") do set TOPQTSRC=%%~dpP
59set TOPQTSRC=%TOPQTSRC:~0,-1%
60for %%P in ("%QTDIR%") do set TOPQTDIR=%%~dpP
61set TOPQTDIR=%TOPQTDIR:~0,-1%
62goto wastoplevel
63:notoplevel
64if not exist ..\.qmake.super goto wastoplevel
65echo ERROR: You cannot configure qtbase separately within a top-level build. >&2
66exit /b 1
67:wastoplevel
68
69set SYNCQT=
70set PLATFORM=
71set MAKE=
72call :doargs %ARGS%
73if errorlevel 1 exit /b
74goto doneargs
75
76:doargs
77    if "%~1" == "" exit /b
78
79    if "%~1" == "/?" goto help
80    if "%~1" == "-?" goto help
81    if /i "%~1" == "/h" goto help
82    if /i "%~1" == "-h" goto help
83    if /i "%~1" == "/help" goto help
84    if /i "%~1" == "-help" goto help
85    if /i "%~1" == "--help" goto help
86
87    if /i "%~1" == "-redo" goto redo
88    if /i "%~1" == "--redo" goto redo
89
90    if /i "%~1" == "-platform" goto platform
91    if /i "%~1" == "--platform" goto platform
92
93    if /i "%~1" == "-no-syncqt" goto nosyncqt
94    if /i "%~1" == "--no-syncqt" goto nosyncqt
95
96    if /i "%~1" == "-make-tool" goto maketool
97    if /i "%~1" == "--make-tool" goto maketool
98
99:nextarg
100    shift
101    goto doargs
102
103:help
104    type %QTSRC%\config_help.txt
105    if %TOPLEVEL% == false exit /b 1
106    for /d %%p in ("%TOPQTSRC%"\qt*) do (
107        if not "%%p" == "%QTSRC%" (
108            if exist "%%p\config_help.txt" (
109                echo.
110                type "%%p\config_help.txt"
111            )
112        )
113    )
114    exit /b 1
115
116:redo
117    if not exist "%TOPQTDIR%\config.opt" goto redoerr
118    set rargs=
119    for /f "usebackq delims=" %%i in ("%TOPQTDIR%\config.opt") do set rargs=!rargs! "%%i"
120    call :doargs %rargs%
121    goto nextarg
122:redoerr
123    echo No config.opt present - cannot redo configuration. >&2
124    exit /b 1
125
126:platform
127    shift
128    set PLATFORM=%~1
129    if "%PLATFORM:~0,10%" == "win32-msvc" goto msvc
130    goto nextarg
131:msvc
132    echo. >&2
133    echo Notice: re-mapping requested qmake spec to unified 'win32-msvc'. >&2
134    echo. >&2
135    set PLATFORM=win32-msvc
136    goto nextarg
137
138:nosyncqt
139    set SYNCQT=false
140    goto nextarg
141
142:maketool
143    shift
144    set MAKE=%~1
145    goto nextarg
146
147:doneargs
148
149rem Find various executables
150for %%C in (clang-cl.exe clang.exe cl.exe icl.exe g++.exe perl.exe jom.exe) do set %%C=%%~$PATH:C
151
152rem Determine host spec
153
154if "%PLATFORM%" == "" (
155    if not "%icl.exe%" == "" (
156        set PLATFORM=win32-icc
157    ) else if not "%cl.exe%" == "" (
158        set PLATFORM=win32-msvc
159    ) else if not "%clang-cl.exe%" == "" (
160        set PLATFORM=win32-clang-msvc
161    ) else if not "%clang.exe%" == "" (
162        set PLATFORM=win32-clang-g++
163    ) else if not "%g++.exe%" == "" (
164        set PLATFORM=win32-g++
165    ) else (
166        echo Cannot detect host toolchain. Please use -platform. Aborting. >&2
167        exit /b 1
168    )
169)
170if not exist "%QTSRC%\mkspecs\%PLATFORM%\qmake.conf" (
171    echo Host platform '%PLATFORM%' is invalid. Aborting. >&2
172    exit /b 1
173)
174if "%PLATFORM:g++=%" == "%PLATFORM%" (
175    if "%MAKE%" == "" (
176        if not "%jom.exe%" == "" (
177            set MAKE=jom
178        ) else (
179            set MAKE=nmake
180        )
181    )
182    set tmpl=win32
183) else (
184    if "%MAKE%" == "" (
185        set MAKE=mingw32-make
186    )
187    set tmpl=unix
188)
189
190rem Prepare build dir
191
192if not exist mkspecs (
193    md mkspecs
194    if errorlevel 1 exit /b
195)
196if not exist bin (
197    md bin
198    if errorlevel 1 exit /b
199)
200if not exist qmake (
201    md qmake
202    if errorlevel 1 exit /b
203)
204
205rem Extract Qt's version from .qmake.conf
206for /f "eol=# tokens=1,2,3,4 delims=.= " %%i in (%QTSRC%\.qmake.conf) do (
207    if %%i == MODULE_VERSION (
208        set QTVERMAJ=%%j
209        set QTVERMIN=%%k
210        set QTVERPAT=%%l
211    )
212)
213set QTVERSION=%QTVERMAJ%.%QTVERMIN%.%QTVERPAT%
214
215rem Create forwarding headers
216
217if "%SYNCQT%" == "" (
218    if exist "%QTSRC%\.git" (
219        set SYNCQT=true
220    ) else (
221        set SYNCQT=false
222    )
223)
224if "%SYNCQT%" == "true" (
225    if not "%perl.exe%" == "" (
226        echo Running syncqt ...
227        "%perl.exe%" -w "%QTSRC%\bin\syncqt.pl" -minimal -version %QTVERSION% -module QtCore -outdir "%QTDIR%" %QTSRC%
228        if errorlevel 1 exit /b
229    ) else (
230        echo Perl not found in PATH. Aborting. >&2
231        exit /b 1
232    )
233)
234
235rem Build qmake
236
237echo Bootstrapping qmake ...
238
239cd qmake
240if errorlevel 1 exit /b
241
242echo #### Generated by configure.bat - DO NOT EDIT! ####> Makefile
243echo/>> Makefile
244echo BUILD_PATH = ..>> Makefile
245if "%tmpl%" == "win32" (
246    echo SOURCE_PATH = %QTSRC%>> Makefile
247) else (
248    echo SOURCE_PATH = %QTSRC:\=/%>> Makefile
249)
250if exist "%QTSRC%\.git" (
251    echo INC_PATH = ../include>> Makefile
252) else (
253    echo INC_PATH = $^(SOURCE_PATH^)/include>> Makefile
254)
255echo QT_VERSION = %QTVERSION%>> Makefile
256rem These must have trailing spaces to avoid misinterpretation as 5>>, etc.
257echo QT_MAJOR_VERSION = %QTVERMAJ% >> Makefile
258echo QT_MINOR_VERSION = %QTVERMIN% >> Makefile
259echo QT_PATCH_VERSION = %QTVERPAT% >> Makefile
260if "%tmpl%" == "win32" (
261    echo QMAKESPEC = %PLATFORM%>> Makefile
262) else (
263    echo QMAKESPEC = $^(SOURCE_PATH^)/mkspecs/%PLATFORM%>> Makefile
264    echo CONFIG_CXXFLAGS = -std=c++11 -ffunction-sections>> Makefile
265    echo CONFIG_LFLAGS = -Wl,--gc-sections>> Makefile
266    type "%QTSRC%\qmake\Makefile.unix.win32" >> Makefile
267    type "%QTSRC%\qmake\Makefile.unix.mingw" >> Makefile
268)
269echo/>> Makefile
270type "%QTSRC%\qmake\Makefile.%tmpl%" >> Makefile
271
272%MAKE%
273if errorlevel 1 (cd .. & exit /b 1)
274
275cd ..
276
277rem Generate qt.conf
278
279> "%QTDIR%\bin\qt.conf" (
280    @echo [EffectivePaths]
281    @echo Prefix=..
282    @echo [Paths]
283    @echo TargetSpec=dummy
284    @echo HostSpec=%PLATFORM%
285)
286if not "%QTDIR%" == "%QTSRC%" (
287    >> "%QTDIR%\bin\qt.conf" (
288        @echo [EffectiveSourcePaths]
289        @echo Prefix=%QTSRC:\=/%
290    )
291)
292
293rem Launch qmake-based configure
294
295cd "%TOPQTDIR%"
296"%QTDIR%\bin\qmake.exe" "%TOPQTSRC%" -- %ARGS%
297