golang.zx2c4.com/wireguard/windows@v0.5.4-0.20230123132234-dcc0eb72a04b/build.bat (about)

     1  @echo off
     2  rem SPDX-License-Identifier: MIT
     3  rem Copyright (C) 2019-2022 WireGuard LLC. All Rights Reserved.
     4  
     5  setlocal enabledelayedexpansion
     6  set BUILDDIR=%~dp0
     7  set PATH=%BUILDDIR%.deps\llvm-mingw\bin;%BUILDDIR%.deps\go\bin;%BUILDDIR%.deps;%PATH%
     8  set PATHEXT=.exe
     9  cd /d %BUILDDIR% || exit /b 1
    10  
    11  if exist .deps\prepared goto :render
    12  :installdeps
    13  	rmdir /s /q .deps 2> NUL
    14  	mkdir .deps || goto :error
    15  	cd .deps || goto :error
    16  	call :download go.zip https://go.dev/dl/go1.18.windows-amd64.zip 65c5c0c709a7ca1b357091b10b795b439d8b50e579d3893edab4c7e9b384f435 || goto :error
    17  	rem Mirror of https://github.com/mstorsjo/llvm-mingw/releases/download/20201020/llvm-mingw-20201020-msvcrt-x86_64.zip
    18  	call :download llvm-mingw-msvcrt.zip https://download.wireguard.com/windows-toolchain/distfiles/llvm-mingw-20201020-msvcrt-x86_64.zip 2e46593245090df96d15e360e092f0b62b97e93866e0162dca7f93b16722b844 || goto :error
    19  	rem Mirror of https://imagemagick.org/download/binaries/ImageMagick-7.0.8-42-portable-Q16-x64.zip
    20  	call :download imagemagick.zip https://download.wireguard.com/windows-toolchain/distfiles/ImageMagick-7.0.8-42-portable-Q16-x64.zip 584e069f56456ce7dde40220948ff9568ac810688c892c5dfb7f6db902aa05aa "convert.exe colors.xml delegates.xml" || goto :error
    21  	rem Mirror of https://sourceforge.net/projects/ezwinports/files/make-4.2.1-without-guile-w32-bin.zip
    22  	call :download make.zip https://download.wireguard.com/windows-toolchain/distfiles/make-4.2.1-without-guile-w32-bin.zip 30641be9602712be76212b99df7209f4f8f518ba764cf564262bc9d6e4047cc7 "--strip-components 1 bin" || goto :error
    23  	call :download wireguard-tools.zip https://git.zx2c4.com/wireguard-tools/snapshot/wireguard-tools-1ee37b8e4833a25efe6f1fc0d5bdcb476148f4ba.zip ed0739bc3e5a7021a59d4cc4fc63e5fb60a0cb8628d30515a747bfbdcf1fdb0a "--exclude wg-quick --strip-components 1" || goto :error
    24  	call :download wireguard-nt.zip https://download.wireguard.com/wireguard-nt/wireguard-nt-0.10.1.zip 772c0b1463d8d2212716f43f06f4594d880dea4f735165bd68e388fc41b81605 || goto :error
    25  	copy /y NUL prepared > NUL || goto :error
    26  	cd .. || goto :error
    27  
    28  :render
    29  	echo [+] Rendering icons
    30  	for %%a in ("ui\icon\*.svg") do convert -background none "%%~fa" -define icon:auto-resize="256,192,128,96,64,48,40,32,24,20,16" -compress zip "%%~dpna.ico" || goto :error
    31  
    32  :build
    33  	for /f "tokens=3" %%a in ('findstr /r "Number.*=.*[0-9.]*" .\version\version.go') do set WIREGUARD_VERSION=%%a
    34  	set WIREGUARD_VERSION=%WIREGUARD_VERSION:"=%
    35  	for /f "tokens=1-4" %%a in ("%WIREGUARD_VERSION:.= % 0 0 0") do set WIREGUARD_VERSION_ARRAY=%%a,%%b,%%c,%%d
    36  	set GOOS=windows
    37  	set GOARM=7
    38  	set GOPATH=%BUILDDIR%.deps\gopath
    39  	set GOROOT=%BUILDDIR%.deps\go
    40  	if "%GoGenerate%"=="yes" (
    41  		echo [+] Regenerating files
    42  		go generate ./... || exit /b 1
    43  	)
    44  	call :build_plat x86 i686 386 || goto :error
    45  	call :build_plat amd64 x86_64 amd64 || goto :error
    46  	call :build_plat arm64 aarch64 arm64 || goto :error
    47  
    48  :sign
    49  	if exist .\sign.bat call .\sign.bat
    50  	if "%SigningCertificate%"=="" goto :success
    51  	if "%TimestampServer%"=="" goto :success
    52  	echo [+] Signing
    53  	signtool sign /sha1 "%SigningCertificate%" /fd sha256 /tr "%TimestampServer%" /td sha256 /d WireGuard x86\wireguard.exe x86\wg.exe amd64\wireguard.exe amd64\wg.exe arm64\wireguard.exe arm64\wg.exe || goto :error
    54  
    55  :success
    56  	echo [+] Success. Launch wireguard.exe.
    57  	exit /b 0
    58  
    59  :download
    60  	echo [+] Downloading %1
    61  	curl -#fLo %1 %2 || exit /b 1
    62  	echo [+] Verifying %1
    63  	for /f %%a in ('CertUtil -hashfile %1 SHA256 ^| findstr /r "^[0-9a-f]*$"') do if not "%%a"=="%~3" exit /b 1
    64  	echo [+] Extracting %1
    65  	tar -xf %1 %~4 || exit /b 1
    66  	echo [+] Cleaning up %1
    67  	del %1 || exit /b 1
    68  	goto :eof
    69  
    70  :build_plat
    71  	set GOARCH=%~3
    72  	mkdir %1 >NUL 2>&1
    73  	echo [+] Assembling resources %1
    74  	%~2-w64-mingw32-windres -I ".deps\wireguard-nt\bin\%~1" -DWIREGUARD_VERSION_ARRAY=%WIREGUARD_VERSION_ARRAY% -DWIREGUARD_VERSION_STR=%WIREGUARD_VERSION% -i resources.rc -o "resources_%~3.syso" -O coff -c 65001 || exit /b %errorlevel%
    75  	echo [+] Building program %1
    76  	go build -tags load_wgnt_from_rsrc -ldflags="-H windowsgui -s -w" -trimpath -buildvcs=false -v -o "%~1\wireguard.exe" || exit /b 1
    77  	if not exist "%~1\wg.exe" (
    78  		echo [+] Building command line tools %1
    79  		del .deps\src\*.exe .deps\src\*.o .deps\src\wincompat\*.o .deps\src\wincompat\*.lib 2> NUL
    80  		set LDFLAGS=-s
    81  		make --no-print-directory -C .deps\src PLATFORM=windows CC=%~2-w64-mingw32-gcc WINDRES=%~2-w64-mingw32-windres V=1 RUNSTATEDIR= SYSTEMDUNITDIR= -j%NUMBER_OF_PROCESSORS% || exit /b 1
    82  		move /Y .deps\src\wg.exe "%~1\wg.exe" > NUL || exit /b 1
    83  	)
    84  	goto :eof
    85  
    86  :error
    87  	echo [-] Failed with error #%errorlevel%.
    88  	cmd /c exit %errorlevel%