From c446763a0526cdad54da683bac68bfc68f4751e5 Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Thu, 22 Feb 2024 07:54:45 -0500 Subject: [PATCH] Improve makefile --- .gitignore | 3 ++- Makefile | 64 ++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 3b587c7..24dcee8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /target .pnpm-store .env -vendor +.vendor +*.tar.xz .cargo diff --git a/Makefile b/Makefile index 42c2b00..cfbf157 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,63 @@ -VERSION=$(shell cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version') -PKG_NAME=globalprotect-openconnect-$(VERSION) +OFFLINE ?= 0 +CARGO ?= cargo +VERSION = $(shell $(CARGO) metadata --no-deps --format-version 1 | jq -r '.packages[0].version') +PKG_NAME = globalprotect-openconnect-$(VERSION) -build: build-fe build-rs gpgui-helper +CARGO_BUILD_ARGS = --release +ifeq ($(OFFLINE), 1) + CARGO_BUILD_ARGS += --frozen +endif + +default: build + +version: + @echo $(VERSION) + +# Generate a vendor tarball and a .cargo/config.toml file +cargo-vendor: + mkdir -p .cargo + + $(CARGO) vendor .vendor > .cargo/config.toml + tar -cJf vendor.tar.xz .vendor + +tarball: clean clean-tarball build-fe cargo-vendor + rm -rf apps/gpgui-helper/node_modules + + tar --transform 's,^,${PKG_NAME}/,' -czf ../${PKG_NAME}.tar.gz * .cargo + +# 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 + +build: extract-vendor build-fe build-rs gpgui-helper + +# Install and build the frontend +# If OFFLINE is set to 1, skip it build-fe: - cd apps/gpgui-helper && pnpm install && pnpm build + if [ $(OFFLINE) -eq 0 ]; then \ + cd apps/gpgui-helper && pnpm install && pnpm build; \ + fi + + if [ ! -d apps/gpgui-helper/dist ]; then \ + echo "Error: frontend build failed"; \ + exit 1; \ + fi build-rs: - cargo build --release --frozen -p gpclient -p gpauth -p gpservice + $(CARGO) build $(CARGO_BUILD_ARGS) -p gpclient -p gpauth -p gpservice gpgui-helper: - cargo build --release --frozen -p gpgui-helper --features "tauri/custom-protocol" + $(CARGO) build $(CARGO_BUILD_ARGS) -p gpgui-helper --features "tauri/custom-protocol" -tarball: build-fe +clean: + $(CARGO) clean + rm -rf .vendor rm -rf apps/gpgui-helper/node_modules - mkdir -p .cargo - cargo vendor > .cargo/config.toml - - tar --transform 's,^,${PKG_NAME}/,' -cJf ../${PKG_NAME}.tar.xz * .cargo +clean-tarball: + rm -rf vendor.tar.xz + rm -rf ../$(PKG_NAME).tar.gz install: install -Dm755 target/release/gpclient $(DESTDIR)/usr/bin/gpclient @@ -45,3 +84,6 @@ uninstall: 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 + +deb: + debmake -e "k3vinyue@gmail.com" -f "Kevin Yue"