Skip to content

Commit

Permalink
Improve makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
yuezk committed Feb 22, 2024
1 parent cfdba00 commit c446763
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/target
.pnpm-store
.env
vendor
.vendor
*.tar.xz

.cargo
64 changes: 53 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 "[email protected]" -f "Kevin Yue"

0 comments on commit c446763

Please sign in to comment.