summarylogtreecommitdiffstats
path: root/Makefile
blob: 6227f10d6c2a1c3a6ace781be3c81b6a68dca93e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
MAKEFLAGS += --warn-undefined-variables
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := push
.ONESHELL:

# Simple ANSI colours
CC_YELLOW=\033[0;33m
CC_WHITE=\033[1;37m
CC_END=\033[0m

# Get the version information
current_pkgname=$(shell cat PKGBUILD | awk -F = '/^pkgname/ { print $$2 }')
use_pkgname=$(current_pkgname)
current_binaryname=$(shell cat PKGBUILD | awk -F = '/^_binaryname/ { print $$2 }')
use_binaryname=$(current_binaryname)
current_pkgver=$(shell cat PKGBUILD | awk -F = '/^pkgver/ { print $$2 }')
use_pkgver=$(current_pkgver)
current_pkgrel=$(shell cat PKGBUILD | awk -F = '/^pkgrel/ { print $$2 }')
use_pkgrel=$(current_pkgrel)

ifneq ($(strip $(pkgname)),)
	use_pkgname=$(pkgname)
endif
ifneq ($(strip $(pkgver)),)
	use_pkgver=$(pkgver)
endif
ifneq ($(strip $(pkgrel)),)
	use_pkgrel=$(pkgrel)
endif
ifneq ($(strip $(binaryname)),)
	use_binaryname=$(binaryname)
endif

.PHONY: help
help: ## Show this help message
	@grep '.*:.*##' Makefile | grep -v grep | sort | sed 's/:.* ##/:/g' | column -t -s :

.PHONY: clean
clean: ## Clean the current workspace
	@echo -e "${CC_YELLOW}==>${CC_WHITE} Cleaning up old package files${CC_END}"
	rm -rf *.pkg.tar.{xz,zst} *.zip ${use_pkgname}-*
	@echo -e "${CC_YELLOW}==>${CC_WHITE} Cleaning up old working directories${CC_END}"
	rm -rf ./pkg ./src

.PHONY: pull
pull: clean ## Pull changes from the AUR
	@echo -e "${CC_YELLOW}==>${CC_WHITE} Check for, and pull, changes from AUR${CC_END}"
	git pull --ff-only

.PHONY: update-version
update-version: pull ## Update the package version in PKGBUILD (use pkgver and pkgrel)
	@echo -e "${CC_YELLOW}==>${CC_WHITE} Update the package to $(use_pkgver)-$(use_pkgrel)"
	sed -i -e 's/^pkgver=.*$$/pkgver=$(use_pkgver)/' -e 's/^pkgrel=.*$$/pkgrel=$(use_pkgrel)/' PKGBUILD

.PHONY: update-pkgbuild
update-pkgbuild: update-version ## Update the checksums in the PKGBUILD
	@echo -e "${CC_YELLOW}==>${CC_WHITE} Update the checksums in PKGBUILD${CC_END}"
	updpkgsums

.PHONY: build
build: update-pkgbuild ## Build the package (as a test)
	@echo -e "${CC_YELLOW}==>${CC_WHITE} Build the package${CC_END}"
	makepkg -s

.PHONY: install
install: update-pkgbuild ## Install the package (as a test)
	@echo -e "${CC_YELLOW}==>${CC_WHITE} Install the package${CC_END}"
	makepkg -si

.PHONY: test-install-and-remove
test-install-and-remove: install ## Using the package (as a test)
	@echo -e "${CC_YELLOW}==>${CC_WHITE} Using the binary ${CC_END}"
	${use_binaryname} --version
	${use_binaryname} --help
	yay -R grafana-alloy-bin

.PHONY: update-srcinfo
update-srcinfo: build ## Update the .SRCINFO file
	@echo -e "${CC_YELLOW}==>${CC_WHITE} Update the .SRCINFO file${CC_END}"
	makepkg --printsrcinfo > .SRCINFO

.PHONY: commit
commit: update-pkgbuild update-srcinfo ## Commit the changes to the repository
	@echo -e "${CC_YELLOW}==>${CC_WHITE} Commit the PKGBUILD and .SRCINFO files${CC_END}"
	git add PKGBUILD .SRCINFO
	git commit -m "Bump package to $$(
		cat .SRCINFO \
			| awk -F ' = ' \
					' /\s+pkgver/ { version=$$2 }
					  /\s+pkgrel/ { release=$$2 }
						END 				{ printf "%s-%s", version, release }'
	)"

.PHONY: push
push: commit ## Push the changes back to up the AUR
	@echo -e "${CC_YELLOW}==>${CC_WHITE} Push the changes up to the AUR${CC_END}"
	git push