This repository was archived by the owner on Oct 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
60 lines (47 loc) · 1.95 KB
/
Copy pathMakefile
File metadata and controls
60 lines (47 loc) · 1.95 KB
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
APP := fancylock
ARCHES := amd64
BIN := bin
DIST := dist
INSTALL_PATH := /usr/local/bin
# Git version metadata
GIT_COMMIT := $(shell git rev-parse --short HEAD)
BUILD_DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
VERSION := $(shell git describe --tags --always --dirty)
TAG_VERSION := $(shell git describe --tags --abbrev=0 | sed 's/^v//')
# ldflags for embedding version info
LDFLAGS := -ldflags="-s -w \
-X github.com/tuxx/fancylock/internal.Version=$(VERSION) \
-X github.com/tuxx/fancylock/internal.Commit=$(GIT_COMMIT) \
-X github.com/tuxx/fancylock/internal.BuildDate=$(BUILD_DATE)"
.PHONY: all clean native install check-go $(ARCHES) package aur
all: check-go $(ARCHES)
$(BIN):
mkdir -p $(BIN)
$(DIST):
mkdir -p $(DIST)
check-go:
@command -v go >/dev/null 2>&1 || { echo >&2 "Go is not installed."; exit 1; }
$(ARCHES): | $(BIN)
GOOS=linux GOARCH=$@ CGO_ENABLED=1 go build $(LDFLAGS) -o "$(BIN)/$(APP)-linux-$@" main.go
native: check-go | $(BIN)
CGO_ENABLED=1 go build $(LDFLAGS) -o "$(BIN)/$(APP)-native" main.go
package: all | $(DIST)
@for arch in $(ARCHES); do \
[ -f "$(BIN)/$(APP)-linux-$$arch" ] && \
tar -czvf "$(DIST)/$(APP)-linux-$$arch.tar.gz" -C "$(BIN)" "$(APP)-linux-$$arch"; \
done
@if [ -f "$(BIN)/$(APP)-native" ]; then \
tar -czvf "$(DIST)/$(APP)-native.tar.gz" -C "$(BIN)" "$(APP)-native"; \
fi
cp "$(BIN)/$(APP)-linux-amd64" "$(DIST)/"
tar -C "$(DIST)" -czf "$(DIST)/$(APP)-linux-amd64.tar.gz" "$(APP)-linux-amd64"
install: native
@install -Dm755 "$(BIN)/$(APP)-native" "$(INSTALL_PATH)/$(APP)"
@echo "Installed $(APP)-native to $(INSTALL_PATH)/$(APP)"
@install -Dm644 "pam.d/fancylock" "/etc/pam.d/fancylock"
aur: package
mkdir -p packages/aur/fancylock-bin
sed "s/@VERSION@/$(TAG_VERSION)/g" packages/aur/fancylock-bin/PKGBUILD.template > packages/aur/fancylock-bin/PKGBUILD
sed "s/@VERSION@/$(TAG_VERSION)/g" packages/aur/fancylock-bin/.SRCINFO.template > packages/aur/fancylock-bin/.SRCINFO
clean:
rm -rf $(BIN) $(DIST)