| 1 | SHELL := /bin/bash |
| 2 | GO ?= go |
| 3 | GO_CMD := CGO_ENABLED=0 $(GO) |
| 4 | GIT_VERSION := $(shell git describe --tags --dirty) |
| 5 | VERSION := $(GIT_VERSION:v%=%) |
| 6 | GIT_COMMIT := $(shell git rev-parse HEAD) |
| 7 | DOCKER_REPO ?= xperimental/nextcloud-exporter |
| 8 | DOCKER_TAG ?= dev |
| 9 | |
| 10 | .PHONY: all |
| 11 | all: test build-binary |
| 12 | |
| 13 | include .bingo/Variables.mk |
| 14 | |
| 15 | .PHONY: test |
| 16 | test: |
| 17 | $(GO_CMD) test -cover ./... |
| 18 | |
| 19 | .PHONY: lint |
| 20 | lint: $(GOLANGCI_LINT) |
| 21 | $(GOLANGCI_LINT) run |
| 22 | |
| 23 | .PHONY: lint-fix |
| 24 | lint-fix: $(GOLANGCI_LINT) |
| 25 | $(GOLANGCI_LINT) run --fix |
| 26 | |
| 27 | .PHONY: build-binary |
| 28 | build-binary: |
| 29 | $(GO_CMD) build -tags netgo -ldflags "-w -X main.Version=$(VERSION) -X main.GitCommit=$(GIT_COMMIT)" -o nextcloud-exporter . |
| 30 | |
| 31 | .PHONY: deb |
| 32 | deb: build-binary |
| 33 | mkdir -p dist/deb/DEBIAN dist/deb/usr/bin |
| 34 | sed 's/%VERSION%/$(VERSION)/' contrib/debian/control > dist/deb/DEBIAN/control |
| 35 | cp nextcloud-exporter dist/deb/usr/bin/ |
| 36 | fakeroot dpkg-deb --build dist/deb dist |
| 37 | |
| 38 | .PHONY: install |
| 39 | install: |
| 40 | install -D -t $(DESTDIR)/usr/bin/ nextcloud-exporter |
| 41 | install -D -m 0644 -t $(DESTDIR)/lib/systemd/system/ contrib/nextcloud-exporter.service |
| 42 | |
| 43 | .PHONY: image |
| 44 | image: |
| 45 | docker buildx build -t "ghcr.io/$(DOCKER_REPO):$(DOCKER_TAG)" --load . |
| 46 | |
| 47 | .PHONY: all-images |
| 48 | all-images: |
| 49 | docker buildx build -t "ghcr.io/$(DOCKER_REPO):$(DOCKER_TAG)" -t "docker.io/$(DOCKER_REPO):$(DOCKER_TAG)" --platform linux/amd64,linux/arm64 --push . |
| 50 | |
| 51 | .PHONY: tools |
| 52 | tools: $(BINGO) $(GOLANGCI_LINT) |
| 53 | @echo Tools built. |
| 54 | |
| 55 | .PHONY: clean |
| 56 | clean: |
| 57 | rm -f nextcloud-exporter |
| 58 | rm -r dist |