From e8a64539aa3bbc0cb4cd48ae465e2429065a9709 Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Sun, 25 Feb 2024 17:30:41 +0800 Subject: [PATCH] Update build --- .github/workflows/build.yaml | 11 +- Makefile | 137 ++++++++++++------ packaging/binary/Makefile.in | 30 ++++ packaging/deb/rules | 2 +- packaging/pkgbuild/PKGBUILD.in | 7 +- .../rpm/globalprotect-openconnect.spec.in | 2 +- 6 files changed, 138 insertions(+), 51 deletions(-) create mode 100644 packaging/binary/Makefile.in diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 0ac7dc8..53a8dba 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -34,7 +34,8 @@ jobs: with: name: artifact-tarball path: | - globalprotect-openconnect-*.tar.gz + gp/.build/tarball/*.tar.gz + deb: runs-on: ubuntu-latest needs: [tarball] @@ -50,12 +51,13 @@ jobs: name: artifact-tarball - name: Build DEB package run: | - tar -xzf globalprotect-openconnect-*.tar.gz + tar -xzf *.tar.gz cd globalprotect-openconnect-* make deb - name: Install DEB package run: | - sudo dpkg -i globalprotect-openconnect_*.deb + cd globalprotect-openconnect-*/ + sudo dpkg -i .build/deb/*.deb gpclient --version gpservice --version @@ -66,7 +68,7 @@ jobs: with: name: artifact-deb path: | - globalprotect-openconnect_*.deb + globalprotect-openconnect-*/.build/deb/*.deb rpm: runs-on: ubuntu-latest @@ -104,6 +106,7 @@ jobs: path: | globalprotect-openconnect-*/.build/rpm/*.rpm + # Include arm64 if ref is a tag # setup-matrix: # runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index 51d5ad9..185b3f5 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ PPA_REVISION ?= 1 PKG_NAME = globalprotect-openconnect PKG = $(PKG_NAME)-$(VERSION) SERIES ?= $(shell lsb_release -cs) +PUBLISH ?= 0 export DEBEMAIL = k3vinyue@gmail.com export DEBFULLNAME = Kevin Yue @@ -22,21 +23,27 @@ default: build version: @echo $(VERSION) -# Generate a vendor tarball and a .cargo/config.toml file -cargo-vendor: - mkdir -p .cargo +clean-tarball: + rm -rf .build/tarball + rm -rf .vendor + rm -rf vendor.tar.xz + rm -rf .cargo - $(CARGO) vendor .vendor > .cargo/config.toml - tar -cJf vendor.tar.xz .vendor - -tarball: clean clean-tarball build-fe cargo-vendor +# Create a tarball, include the cargo dependencies if OFFLINE is set to 1 +tarball: clean-tarball build-fe + # Remove node_modules to reduce the tarball size rm -rf apps/gpgui-helper/node_modules - tar --transform 's,^,${PKG}/,' -czf ../${PKG}.tar.gz * .cargo + mkdir -p .cargo + mkdir -p .build/tarball -# Extract the vendor tarball to the .vendor directory if it exists -extract-vendor: - if [ -f vendor.tar.xz ]; then tar -xJf vendor.tar.xz; fi + # If OFFLINE is set to 1, vendor all cargo dependencies + if [ $(OFFLINE) -eq 1 ]; then \ + $(CARGO) vendor .vendor > .cargo/config.toml; \ + tar -cJf vendor.tar.xz .vendor; \ + fi + + tar --exclude .vendor --exclude target --transform 's,^,${PKG}/,' -czf .build/tarball/${PKG}.tar.gz * .cargo build: build-fe build-rs @@ -52,9 +59,13 @@ build-fe: exit 1; \ fi -build-rs: extract-vendor - $(CARGO) build $(CARGO_BUILD_ARGS) -p gpauth - # $(CARGO) build $(CARGO_BUILD_ARGS) -p gpgui-helper --features "tauri/custom-protocol" +build-rs: + if [ $(OFFLINE) -eq 1 ]; then \ + tar -xJf vendor.tar.xz; \ + fi + + $(CARGO) build $(CARGO_BUILD_ARGS) -p gpclient -p gpservice -p gpauth + $(CARGO) build $(CARGO_BUILD_ARGS) -p gpgui-helper --features "tauri/custom-protocol" clean: $(CARGO) clean @@ -62,11 +73,9 @@ clean: rm -rf .vendor rm -rf apps/gpgui-helper/node_modules -clean-tarball: - rm -rf vendor.tar.xz - rm -rf ../$(PKG).tar.gz - install: + @echo "Installing $(PKG_NAME) $(VERSION)" + install -Dm755 target/release/gpclient $(DESTDIR)/usr/bin/gpclient install -Dm755 target/release/gpauth $(DESTDIR)/usr/bin/gpauth install -Dm755 target/release/gpservice $(DESTDIR)/usr/bin/gpservice @@ -80,10 +89,13 @@ install: install -Dm644 packaging/files/usr/share/polkit-1/actions/com.yuezk.gpgui.policy $(DESTDIR)/usr/share/polkit-1/actions/com.yuezk.gpgui.policy uninstall: + @echo "Uninstalling $(PKG_NAME) $(VERSION)" + rm -f $(DESTDIR)/usr/bin/gpclient rm -f $(DESTDIR)/usr/bin/gpauth rm -f $(DESTDIR)/usr/bin/gpservice rm -f $(DESTDIR)/usr/bin/gpgui-helper + rm -f $(DESTDIR)/usr/bin/gpgui rm -f $(DESTDIR)/usr/share/applications/gpgui.desktop rm -f $(DESTDIR)/usr/share/icons/hicolor/scalable/apps/gpgui.svg @@ -92,25 +104,45 @@ uninstall: rm -f $(DESTDIR)/usr/share/icons/hicolor/256x256@2/apps/gpgui.png rm -f $(DESTDIR)/usr/share/polkit-1/actions/com.yuezk.gpgui.policy -init-debian: - rm -rf .vendor - rm -rf debian +clean-debian: + rm -rf .build/deb + +# Generate the debian package structure, without the changelog +init-debian: clean-debian tarball + mkdir -p .build/deb + cp .build/tarball/${PKG}.tar.gz .build/deb + + tar -xzf .build/deb/${PKG}.tar.gz + cd .build/deb/${PKG} debmake cp -f packaging/deb/control.in debian/control cp -f packaging/deb/rules debian/rules + + sed -i "s/@OFFLINE@/$(OFFLINE)/g" debian/rules + rm -f debian/changelog deb: init-debian + cd .build/deb/${PKG} + + # Remove the rust build depdency from the control file sed -i "s/@RUST@//g" debian/control dch --create --distribution unstable --package $(PKG_NAME) --newversion $(VERSION)-$(REVISION) "Bugfix and improvements." debuild --preserve-env -e PATH -us -uc -b -# Usage: make ppa SERIES=focal -ppa: init-debian +check-ppa: + if [ $(OFFLINE) -eq 0 ]; then \ + @echo "Error: ppa build requires offline mode (OFFLINE=1)"; \ + fi + +# Usage: make ppa SERIES=focal OFFLINE=1 PUBLISH=1 +ppa: check-ppa init-debian + cd .build/deb/${PKG} + sed -i "s/@RUST@/rust-all(>=1.70)/g" debian/control $(eval SERIES_VER = $(shell distro-info --series $(SERIES) -r | cut -d' ' -f1)) @@ -120,12 +152,17 @@ ppa: init-debian echo "y" | debuild -e PATH -S -sa -k"$(GPG_KEY_ID)" -p"gpg --batch --passphrase $(GPG_KEY_PASS) --pinentry-mode loopback" -publish-ppa: ppa - dput ppa:yuezk/globalprotect-openconnect ../*.changes + if [ $(PUBLISH) -eq 1 ]; then \ + dput ppa:yuezk/globalprotect-openconnect ../*.changes; \ + else + @echo "Skipping ppa publish (PUBLISH=0)" + fi + +clean-rpm: + rm -rf .build/rpm # Generate RPM sepc file -init-rpm: - rm -rf .build/rpm +init-rpm: clean-rpm mkdir -p .build/rpm cp packaging/rpm/globalprotect-openconnect.spec.in .build/rpm/globalprotect-openconnect.spec @@ -133,26 +170,20 @@ init-rpm: sed -i "s/@VERSION@/$(VERSION)/g" .build/rpm/globalprotect-openconnect.spec sed -i "s/@REVISION@/$(REVISION)/g" .build/rpm/globalprotect-openconnect.spec + sed -i "s/@OFFLINE@/$(OFFLINE)/g" .build/rpm/globalprotect-openconnect.spec sed -i "s/@DATE@/$(shell date "+%a %b %d %Y")/g" .build/rpm/globalprotect-openconnect.spec sed -i "s/@VERSION@/$(VERSION)/g" .build/rpm/globalprotect-openconnect.changes sed -i "s/@DATE@/$(shell LC_ALL=en.US date -u "+%a %b %e %T %Z %Y")/g" .build/rpm/globalprotect-openconnect.changes -# Ensure ../globalprotect-openconnect-*.tar.gz exists. -rpm: init-rpm - if [ ! -f ../$(PKG).tar.gz ]; then \ - echo "Missing ../$(PKG).tar.gz"; \ - exit 1; \ - fi - +rpm: init-rpm tarball rm -rf $(HOME)/rpmbuild rpmdev-setuptree - cp ../$(PKG).tar.gz $(HOME)/rpmbuild/SOURCES/$(PKG_NAME).tar.gz - + cp .build/tarball/${PKG}.tar.gz $(HOME)/rpmbuild/SOURCES rpmbuild -ba .build/rpm/globalprotect-openconnect.spec - # Copy RPM package + # Copy RPM package from build directory cp $(HOME)/rpmbuild/RPMS/$(shell uname -m)/$(PKG_NAME)*.rpm .build/rpm # Copy the SRPM only for x86_64. @@ -160,20 +191,38 @@ rpm: init-rpm cp $(HOME)/rpmbuild/SRPMS/$(PKG_NAME)*.rpm .build/rpm; \ fi -init-pkgbuild: +clean-pkgbuild: rm -rf .build/pkgbuild + +init-pkgbuild: clean-pkgbuild tarball mkdir -p .build/pkgbuild - if [ ! -f ../$(PKG).tar.gz ]; then \ - echo "Missing ../$(PKG).tar.gz"; \ - exit 1; \ - fi - cp ../$(PKG).tar.gz .build/pkgbuild - + cp .build/tarball/${PKG}.tar.gz .build/pkgbuild cp packaging/pkgbuild/PKGBUILD.in .build/pkgbuild/PKGBUILD + sed -i "s/@PKG_NAME@/$(PKG_NAME)/g" .build/pkgbuild/PKGBUILD sed -i "s/@VERSION@/$(VERSION)/g" .build/pkgbuild/PKGBUILD sed -i "s/@REVISION@/$(REVISION)/g" .build/pkgbuild/PKGBUILD + sed -i "s/@OFFLINE@/$(OFFLINE)/g" .build/pkgbuild/PKGBUILD pkgbuild: init-pkgbuild cd .build/pkgbuild && makepkg -s --noconfirm + +clean-binary: + rm -rf .build/binary + +binary: clean-binary tarball + mkdir -p .build/binary + + cp .build/tarball/${PKG}.tar.gz .build/binary + tar -xzf .build/binary/${PKG}.tar.gz -C .build/binary + + mkdir -p .build/binary/$(PKG_NAME)_$(VERSION)_$(shell uname -m)/artifacts + + make -C .build/binary/${PKG} build OFFLINE=$(OFFLINE) + make -C .build/binary/${PKG} install DESTDIR=$(PWD)/.build/binary/$(PKG_NAME)_$(VERSION)_$(shell uname -m)/artifacts + + cp packaging/binary/Makefile.in .build/binary/$(PKG_NAME)_$(VERSION)_$(shell uname -m)/Makefile + + # Create a tarball for the binary package + tar -czf .build/binary/$(PKG_NAME)_$(VERSION)_$(shell uname -m).bin.tar.gz -C .build/binary $(PKG_NAME)_$(VERSION)_$(shell uname -m) diff --git a/packaging/binary/Makefile.in b/packaging/binary/Makefile.in new file mode 100644 index 0000000..96b7faa --- /dev/null +++ b/packaging/binary/Makefile.in @@ -0,0 +1,30 @@ +install: + @echo "===> Installing..." + + install -Dm755 artifacts/usr/bin/gpclient $(DESTDIR)/usr/bin/gpclient + install -Dm755 artifacts/usr/bin/gpservice $(DESTDIR)/usr/bin/gpservice + install -Dm755 artifacts/usr/bin/gpauth $(DESTDIR)/usr/bin/gpauth + install -Dm755 artifacts/usr/bin/gpgui-helper $(DESTDIR)/usr/bin/gpgui-helper + + install -Dm644 artifacts/usr/share/applications/gpgui.desktop $(DESTDIR)/usr/share/applications/gpgui.desktop + install -Dm644 artifacts/usr/share/icons/hicolor/scalable/apps/gpgui.svg $(DESTDIR)/usr/share/icons/hicolor/scalable/apps/gpgui.svg + install -Dm644 artifacts/usr/share/icons/hicolor/32x32/apps/gpgui.png $(DESTDIR)/usr/share/icons/hicolor/32x32/apps/gpgui.png + install -Dm644 artifacts/usr/share/icons/hicolor/128x128/apps/gpgui.png $(DESTDIR)/usr/share/icons/hicolor/128x128/apps/gpgui.png + install -Dm644 artifacts/usr/share/icons/hicolor/256x256@2/apps/gpgui.png $(DESTDIR)/usr/share/icons/hicolor/256x256@2/apps/gpgui.png + install -Dm644 artifacts/usr/share/polkit-1/actions/com.yuezk.gpgui.policy $(DESTDIR)/usr/share/polkit-1/actions/com.yuezk.gpgui.policy + +uninstall: + @echo "===> Uninstalling from $(DESTDIR)..." + + rm -f $(DESTDIR)/usr/bin/gpclient + rm -f $(DESTDIR)/usr/bin/gpservice + rm -f $(DESTDIR)/usr/bin/gpauth + rm -f $(DESTDIR)/usr/bin/gpgui-helper + rm -f $(DESTDIR)/usr/bin/gpgui + + rm -f $(DESTDIR)/usr/share/applications/gpgui.desktop + rm -f $(DESTDIR)/usr/share/icons/hicolor/scalable/apps/gpgui.svg + rm -f $(DESTDIR)/usr/share/icons/hicolor/32x32/apps/gpgui.png + rm -f $(DESTDIR)/usr/share/icons/hicolor/128x128/apps/gpgui.png + rm -f $(DESTDIR)/usr/share/icons/hicolor/256x256@2/apps/gpgui.png + rm -f $(DESTDIR)/usr/share/polkit-1/actions/com.yuezk.gpgui.policy diff --git a/packaging/deb/rules b/packaging/deb/rules index 6c7b7f8..92e3fb9 100755 --- a/packaging/deb/rules +++ b/packaging/deb/rules @@ -1,6 +1,6 @@ #!/usr/bin/make -f -export OFFLINE = 1 +export OFFLINE = @OFFLINE@ %: dh $@ diff --git a/packaging/pkgbuild/PKGBUILD.in b/packaging/pkgbuild/PKGBUILD.in index 9ab0aaa..93634ef 100644 --- a/packaging/pkgbuild/PKGBUILD.in +++ b/packaging/pkgbuild/PKGBUILD.in @@ -21,10 +21,15 @@ options=('!strip') build() { cd "$pkgname-$pkgver" - make build OFFLINE=1 + + # Must unset the CFLAGS, otherwise the build fails + unset CFLAGS + + make build OFFLINE=@OFFLINE@ } package() { cd "$pkgname-$pkgver" + make install DESTDIR="$pkgdir" } diff --git a/packaging/rpm/globalprotect-openconnect.spec.in b/packaging/rpm/globalprotect-openconnect.spec.in index a0e6361..a7abd47 100644 --- a/packaging/rpm/globalprotect-openconnect.spec.in +++ b/packaging/rpm/globalprotect-openconnect.spec.in @@ -35,7 +35,7 @@ A GUI for GlobalProtect VPN, based on OpenConnect, supports the SSO authenticati %setup %build -make build OFFLINE=1 +make build OFFLINE=@OFFLINE@ %install %make_install