golang.zx2c4.com/wireguard/windows@v0.5.4-0.20230123132234-dcc0eb72a04b/embeddable-dll-service/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
     6  set BUILDDIR=%~dp0
     7  set PATH=%BUILDDIR%..\.deps\llvm-mingw\bin;%BUILDDIR%..\.deps\go\bin;%PATH%
     8  set PATHEXT=.exe
     9  cd /d %BUILDDIR% || exit /b 1
    10  
    11  if exist ..\.deps\prepared goto :build
    12  :installdeps
    13  	call ..\build.bat || goto :error
    14  
    15  :build
    16  	set GOOS=windows
    17  	set GOARM=7
    18  	set GOPATH=%BUILDDIR%..\.deps\gopath
    19  	set GOROOT=%BUILDDIR%..\.deps\go
    20  	set CGO_ENABLED=1
    21  	set CGO_CFLAGS=-O3 -Wall -Wno-unused-function -Wno-switch -std=gnu11 -DWINVER=0x0601
    22  	call :build_plat x86 i686 386 || goto :error
    23  	call :build_plat amd64 x86_64 amd64 || goto :error
    24  	call :build_plat arm64 aarch64 arm64 || goto :error
    25  
    26  :sign
    27  	if exist ..\sign.bat call ..\sign.bat
    28  	if "%SigningCertificate%"=="" goto :success
    29  	if "%TimestampServer%"=="" goto :success
    30  	echo [+] Signing
    31  	signtool sign /sha1 "%SigningCertificate%" /fd sha256 /tr "%TimestampServer%" /td sha256 /d "WireGuard Tunnel" x86\tunnel.dll amd64\tunnel.dll arm64\tunnel.dll || goto :error
    32  
    33  :success
    34  	echo [+] Success
    35  	exit /b 0
    36  
    37  :build_plat
    38  	set CC=%~2-w64-mingw32-gcc
    39  	set GOARCH=%~3
    40  	mkdir %1 >NUL 2>&1
    41  	echo [+] Building library %1
    42  	go build -buildmode c-shared -ldflags="-w -s" -trimpath -v -o "%~1/tunnel.dll" || exit /b 1
    43  	del "%~1\tunnel.h"
    44  	goto :eof
    45  
    46  :error
    47  	echo [-] Failed with error #%errorlevel%.
    48  	cmd /c exit %errorlevel%