build: upgrade makefile/dockerfile for miqt and win64 support

This commit is contained in:
mappu 2024-10-05 16:37:23 +13:00
parent f9b4cb71a5
commit e43b261752
3 changed files with 56 additions and 78 deletions

View File

@ -1,72 +1,51 @@
export PATH := /usr/lib/mxe/usr/bin:$(PATH)
GOFLAGS := -ldflags='-s -w' -gcflags='-trimpath=$(CURDIR)' -asmflags='-trimpath=$(CURDIR)'
VERSION := 1.0.2
VERSION := 1.0.3
GOFLAGS := -ldflags='-s -w -X main.Version=v$(VERSION)' -buildvcs=false -gcflags='-trimpath=$(CURDIR)' -asmflags='-trimpath=$(CURDIR)'
SHELL := /bin/bash
# Allow overriding DOCKER with e.g. sudo docker
DOCKER := docker
MIQT_UIC := miqt-uic
MIQT_RCC := miqt-rcc
SOURCES := $(wildcard *.go *.ui *.qrc)
GENERATED_SOURCES := resources.go mainwindow_ui.go itemwindow_ui.go
.PHONY: all libs dist clean
.PHONY: all
all: build/qbolt build/qbolt.exe
all: \
build/linux/qbolt \
build/win32/release/qbolt.exe
libs: \
build/linux/qbolt.a \
build/win32/qbolt.a
dist: \
build/dist/qbolt-${VERSION}-win32.zip \
build/dist/qbolt-${VERSION}-linux_amd64.tar.xz
.PHONY: dist
dist: build/qbolt-${VERSION}-windows-x86_64.zip build/qbolt-${VERSION}-debian12-x86_64.tar.xz
.PHONY: clean
clean:
if [ -f qbolt/qbolt.a ] ; then rm qbolt/qbolt.a ; fi
if [ -f qbolt ] ; then rm qbolt ; fi
if [ -d build ] ; then rm -r build ; fi
# Build core golang shared library (linux)
build/linux/qbolt.a: *.go
mkdir -p build/linux
go build ${GOFLAGS} -buildmode=c-archive -o build/linux/qbolt.a
# Build core golang shared library (win32)
build/win32/qbolt.a: *.go
mkdir -p build/win32
CC=/usr/lib/mxe/usr/bin/i686-w64-mingw32.static-gcc CGO_ENABLED=1 GOARCH=386 GOOS=windows \
go build ${GOFLAGS} -buildmode=c-archive -o build/win32/qbolt.a
rm qbolt || true
rm -r build || true
# Linux binaries
build/linux/qbolt: build/linux/qbolt.a qbolt/*
cd build/linux && qmake ../../qbolt/qbolt.pro && make
resources.rcc resources.go: resources.qrc
$(MIQT_RCC) resources.qrc
mainwindow_ui.go: mainwindow.ui
$(MIQT_UIC) -InFile mainwindow.ui -OutFile mainwindow_ui.go
itemwindow_ui.go: itemwindow.ui
$(MIQT_UIC) -InFile itemwindow.ui -OutFile itemwindow_ui.go
build/qbolt: $(SOURCES) $(GENERATED_SOURCES)
go build $(GOFLAGS) -o build/qbolt
upx build/qbolt
# Linux distribution
build/dist/qbolt-${VERSION}-linux_amd64.tar.xz: build/linux/qbolt
XZ_OPTS=-9 tar caf build/dist/qbolt-${VERSION}-linux_amd64.tar.xz -C build/linux qbolt --owner=0 --group=0
# Windows binaries
build/win32/release/qbolt.exe: build/win32/qbolt.a qbolt/*
cd build/win32 && i686-w64-mingw32.static-qmake-qt5 ../../qbolt/qbolt.pro && make
build/qbolt-${VERSION}-debian12-x86_64.tar.xz: build/qbolt
XZ_OPTS=-9 tar caf build/qbolt-${VERSION}-debian12-x86_64.tar.xz -C build qbolt --owner=0 --group=0
# Dockerized Windows build
.PHONY: build-docker-build-environment
build-docker-build-environment:
cd docker && docker build -t win32-cross-qt-mxe:latest -f win32-cross-qt-mxe.Dockerfile
build/qbolt.exe: $(SOURCES) $(GENERATED_SOURCES)
( $(DOCKER) image ls | fgrep qbolt-win64-cross ) || ( cd docker && $(DOCKER) build -t qbolt-win64-cross:latest -f win64-cross.Dockerfile . )
$(DOCKER) run --rm -v $(CURDIR):/qbolt -w /qbolt qbolt-win64-cross:latest /bin/sh -c "go build $(GOFLAGS) -o build/qbolt.exe"
upx build/qbolt.exe
.PHONY: build-windows-in-docker
build-windows-in-docker:
docker run --rm -v $(CURDIR):/qbolt win32-cross-qt-mxe:latest /bin/sh -c 'cd /qbolt && make build/win32/release/qbolt.exe'
# Windows distribution
build/win32/dist/qbolt.exe: build/win32/release/qbolt.exe
mkdir -p build/win32/dist
cp build/win32/release/qbolt.exe build/win32/dist/qbolt.exe
# upx --lzma build/win32/dist/qbolt.exe
build/dist/qbolt-${VERSION}-win32.zip: build/win32/dist/qbolt.exe
mkdir -p build/dist
zip -0 -j build/dist/qbolt-${VERSION}-win32.zip build/win32/dist/qbolt.exe
build/qbolt-${VERSION}-windows-x86_64.zip: build/qbolt.exe
zip -0 -j build/dist/qbolt-${VERSION}-windows-x86_64.zip build/qbolt.exe

View File

@ -1,21 +0,0 @@
#!/bin/bash
set -eu
MIQT_UIC=${MIQT_UIC:-miqt-uic}
MIQT_RCC=${MIQT_RCC:-miqt-rcc}
main() {
$MIQT_RCC resources.qrc
$MIQT_UIC -InFile mainwindow.ui -OutFile mainwindow_ui.go
$MIQT_UIC -InFile itemwindow.ui -OutFile itemwindow_ui.go
go build -ldflags "-s -w" -gcflags='-trimpath=$(pwd)' -asmflags='-trimpath=$(pwd)'
echo "Build OK"
}
main "$@"

View File

@ -0,0 +1,20 @@
FROM golang:1.23-bookworm
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
apt-get install -qyy gnupg2 ca-certificates
RUN DEBIAN_FRONTEND=noninteractive \
echo "deb https://pkg.mxe.cc/repos/apt buster main" >/etc/apt/sources.list.d/mxeapt.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 86B72ED9 && \
apt-get update && \
apt-get install -qyy mxe-x86-64-w64-mingw32.static-qt5 && \
apt-get clean
ENV PATH=/usr/lib/mxe/usr/bin:$PATH
ENV CXX=x86_64-w64-mingw32.static-g++
ENV CC=x86_64-w64-mingw32.static-gcc
ENV PKG_CONFIG=x86_64-w64-mingw32.static-pkg-config
ENV GOOS=windows
ENV CGO_ENABLED=1