aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-03-14 00:45:41 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2020-03-15 14:49:27 -0600
commitf1effa21439bd211aab5b7411a3da79484716a19 (patch)
tree286b9400bc0f1f1b53cbbceee4029ac1dbd5d9f7
parentl18n: add go 1.14 generated output (diff)
downloadwireguard-windows-f1effa21439bd211aab5b7411a3da79484716a19.tar.xz
wireguard-windows-f1effa21439bd211aab5b7411a3da79484716a19.zip
l18n: add stub for cross platform
-rw-r--r--Makefile6
-rw-r--r--README.md2
-rw-r--r--build.bat11
-rw-r--r--gotext.go40
-rw-r--r--main.go2
5 files changed, 50 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index b8308ebe..446ddd34 100644
--- a/Makefile
+++ b/Makefile
@@ -46,8 +46,8 @@ fmt: export GOARCH := amd64
fmt:
go fmt ./...
-generate: export CC := x86_64-w64-mingw32-gcc
-generate: export GOARCH := amd64
+generate: export GOOS :=
+generate: export CGO_ENABLED := 0
generate:
go generate ./...
@@ -58,4 +58,4 @@ deploy: amd64/wireguard.exe
clean:
rm -rf *.syso ui/icon/*.ico x86/ amd64/
-.PHONY: deploy clean fmt remaster all
+.PHONY: deploy clean fmt remaster generate all
diff --git a/README.md b/README.md
index 793eec4b..6bda7f1e 100644
--- a/README.md
+++ b/README.md
@@ -30,7 +30,7 @@ To translate WireGuard UI to your language:
1. Upgrade `resources.rc` accordingly. Follow the pattern.
-2. Add your language ID to the `//go:generate go run golang.org/x/text/cmd/gotext ... -lang=en,<langID>...` line in `main.go`.
+2. Add your language ID to the `//go:generate ... -lang=en,<langID>...` line in `gotext.go`.
3. Configure and run `build` to prepare initial `locales\<langID>\messages.gotext.json` file:
diff --git a/build.bat b/build.bat
index 12c9da27..a118c3d4 100644
--- a/build.bat
+++ b/build.bat
@@ -2,7 +2,7 @@
rem SPDX-License-Identifier: MIT
rem Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
-setlocal
+setlocal enabledelayedexpansion
set BUILDDIR=%~dp0
set PATH=%BUILDDIR%.deps\go\bin;%BUILDDIR%.deps;%PATH%
set PATHEXT=.exe
@@ -34,6 +34,11 @@ if exist .deps\prepared goto :render
set GOOS=windows
set GOPATH=%BUILDDIR%.deps\gopath
set GOROOT=%BUILDDIR%.deps\go
+ if "%GoGenerate%"=="yes" (
+ echo [+] Regenerating files
+ set PATH=!BUILDDIR!.deps\x86_64-w64-mingw32-native\bin;!PATH!
+ go generate ./... || exit /b 1
+ )
set CGO_ENABLED=1
set CGO_CFLAGS=-O3 -Wall -Wno-unused-function -Wno-switch -std=gnu11 -DWINVER=0x0601
set CGO_LDFLAGS=-Wl,--dynamicbase -Wl,--nxcompat -Wl,--export-all-symbols
@@ -70,10 +75,6 @@ if exist .deps\prepared goto :render
mkdir %1 >NUL 2>&1
echo [+] Assembling resources %1
windres -i resources.rc -o resources.syso -O coff || exit /b %errorlevel%
- if "%GoGenerate%|%1"=="yes|x86" (
- echo [+] Regenerating files
- go generate ./... || exit /b 1
- )
echo [+] Building program %1
go build -ldflags="-H windowsgui -s -w" -tags walk_use_cgo -trimpath -v -o "%~1\wireguard.exe" || exit /b 1
if not exist "%~1\wg.exe" (
diff --git a/gotext.go b/gotext.go
new file mode 100644
index 00000000..1e83a1a1
--- /dev/null
+++ b/gotext.go
@@ -0,0 +1,40 @@
+// +build generate
+//go:generate go run gotext.go -srclang=en update -out=zgotext.go -lang=en,fr,ja,sl
+
+/* SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2020 WireGuard LLC. All Rights Reserved.
+ */
+
+package main
+
+import (
+ "io/ioutil"
+ "os"
+ "os/exec"
+)
+
+func main() {
+ gotext, err := ioutil.TempFile("", "gotext*.exe")
+ if err != nil {
+ panic(err)
+ }
+ gotextFilename := gotext.Name()
+ gotext.Close()
+ defer os.Remove(gotextFilename)
+ cmd := exec.Command("go", "build", "-o", gotextFilename, "golang.org/x/text/cmd/gotext")
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ err = cmd.Run()
+ if err != nil {
+ panic(err)
+ }
+ cmd = exec.Command(gotextFilename, os.Args[1:]...)
+ cmd.Env = append(os.Environ(), "GOOS=windows", "GOARCH=amd64", "CGO_ENABLED=1", "CC=x86_64-w64-mingw32-gcc")
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ err = cmd.Run()
+ if err != nil {
+ panic(err)
+ }
+}
diff --git a/main.go b/main.go
index 2de02160..132753cd 100644
--- a/main.go
+++ b/main.go
@@ -5,8 +5,6 @@
package main
-//go:generate go run golang.org/x/text/cmd/gotext -srclang=en update -out=zgotext.go -lang=en,fr,ja,sl
-
import (
"fmt"
"os"