# dipstick — plasmoid plus daemon. The two halves install together: a widget # without its daemon shows a dash, a daemon without its widget is invisible. # # Two ways to install: # make install into the user's home (default) # make install DESTDIR=... PREFIX=/usr SYSTEM=1 for a package # # With SYSTEM=1 neither systemd nor kpackagetool6 is touched: inside a # buildroot that would make no sense, and the package scriptlets handle it. PREFIX ?= $(HOME)/.local DESTDIR ?= SYSTEM ?= BINDIR ?= $(PREFIX)/bin DATADIR ?= $(PREFIX)/share LOCALEDIR ?= $(DATADIR)/locale ifeq ($(SYSTEM),) UNITDIR ?= $(HOME)/.config/systemd/user PLASMOIDIR ?= else UNITDIR ?= $(PREFIX)/lib/systemd/user PLASMOIDIR ?= $(DATADIR)/plasma/plasmoids/org.kde.plasma.dipstick endif NAME := dipstick VERSION ?= 0.1.0 APPLET_ID := org.kde.plasma.dipstick CATALOG := plasma_applet_$(APPLET_ID) # GO_LDFLAGS and not LDFLAGS: the latter is a standard environment variable # that rpmbuild fills with C linker flags, and with `?=` the environment wins. # Go was handed flags it does not understand, and the build failed only inside # rpmbuild. # Pass --nodeps here if Go is not installed as an RPM (via mise, say): the # BuildRequires stays correct for a real build. RPMBUILD_FLAGS ?= GOFLAGS ?= -trimpath GO_LDFLAGS ?= -s -w # Compiled catalogues live inside the plasmoid package: that is where Plasma # looks for them for a third-party applet. PO := $(wildcard translations/*.po) MO := $(patsubst translations/%.po,plasmoid/contents/locale/%/LC_MESSAGES/$(CATALOG).mo,$(PO)) .PHONY: all build test vet fmt extract translations dist rpm \ install install-daemon install-plasmoid install-icon uninstall \ enable disable clean all: build translations build: go build $(GOFLAGS) -ldflags '$(GO_LDFLAGS)' -o dipstick ./cmd/dipstick test: go test ./... # gofmt -l only lists; the test turns an unformatted file into a failure, so # `make vet` is usable as a gate rather than something to read by eye. vet: go vet ./... @unformatted=$$(gofmt -l cmd internal); \ if [ -n "$$unformatted" ]; then \ echo "not gofmt-ed:"; echo "$$unformatted"; exit 1; \ fi # Regenerate the .pot from the sources and re-align the catalogues. extract: ./translations/extract.sh translations: $(MO) plasmoid/contents/locale/%/LC_MESSAGES/$(CATALOG).mo: translations/%.po @mkdir -p $(dir $@) msgfmt --check -o $@ $< install: install-daemon install-plasmoid ifeq ($(SYSTEM),) @echo @echo "Installed. Two steps are left, and they are yours to take:" @echo @echo " 1. dipstick auth (OAuth login)" @echo " 2. systemctl --user enable --now dipstick" @echo @echo "Then add 'Dipstick' to the panel from the Add Widgets menu." endif install-daemon: build install -Dm755 dipstick $(DESTDIR)$(BINDIR)/dipstick @mkdir -p $(DESTDIR)$(UNITDIR) sed 's|@BINDIR@|$(BINDIR)|' packaging/dipstick.service.in \ > $(DESTDIR)$(UNITDIR)/dipstick.service chmod 644 $(DESTDIR)$(UNITDIR)/dipstick.service ifeq ($(SYSTEM),) systemctl --user daemon-reload endif # The icon goes into hicolor as well as into the package. KPackage does not # look inside contents/ for the applet icon: metadata.json's Icon is resolved # against the icon theme, so without this the widget shows a blank page in the # "Add Widgets" list. Same file in both places, one source. install-icon: install -Dm644 plasmoid/contents/icons/dipstick.svg \ $(DESTDIR)$(DATADIR)/icons/hicolor/scalable/apps/dipstick.svg install-plasmoid: translations install-icon ifeq ($(SYSTEM),) kpackagetool6 --type Plasma/Applet --install plasmoid \ || kpackagetool6 --type Plasma/Applet --upgrade plasmoid else @mkdir -p $(DESTDIR)$(PLASMOIDIR) cp -r plasmoid/metadata.json plasmoid/contents $(DESTDIR)$(PLASMOIDIR)/ find $(DESTDIR)$(PLASMOIDIR) -type f -exec chmod 644 {} + find $(DESTDIR)$(PLASMOIDIR) -type d -exec chmod 755 {} + endif # Touches neither the token nor the state: those are the user's data, and # uninstalling is not the moment to throw them away. Remove them by hand from # ~/.config/dipstick. uninstall: -systemctl --user disable --now dipstick -rm -f $(BINDIR)/dipstick $(UNITDIR)/dipstick.service \ $(DATADIR)/icons/hicolor/scalable/apps/dipstick.svg -systemctl --user daemon-reload -kpackagetool6 --type Plasma/Applet --remove $(APPLET_ID) enable: systemctl --user enable --now dipstick disable: systemctl --user disable --now dipstick # Source tarball, as the spec expects it. Taken from HEAD, not the working # tree: a package must come from something committed. dist: git archive --format=tar.gz --prefix=$(NAME)-$(VERSION)/ \ -o $(NAME)-$(VERSION).tar.gz HEAD # Build the RPM locally. Requires rpm-build, which is not a project # dependency: it only matters to whoever wants the package. rpm: dist rpmbuild -bb $(RPMBUILD_FLAGS) --define "_sourcedir $(CURDIR)" \ packaging/dipstick.spec clean: rm -f dipstick $(NAME)-$(VERSION).tar.gz rm -rf plasmoid/contents/locale