GitLab Commit is coming up on August 3-4. Learn how to innovate together using GitLab, the DevOps platform. Register for free: gitlabcommitvirtual2021.com

Commit 93083ad6 authored by Stefan Göbel's avatar Stefan Göbel
Browse files

Makefile and PKGBUILD changes

parent 19a7632e
......@@ -32,14 +32,23 @@
GO_PATH = $(shell pwd)
TMP_DIR = $(GO_PATH)/tmp
GO_TRIM = -gcflags=all=-trimpath=$(GO_PATH) -asmflags=all=-trimpath=$(GO_PATH)
ALL_GOS = $(shell find . -type f -name '*.go')
pkglist = $(shell GOPATH=$(GO_PATH) go list snot/lib/... )
pkglist = $(shell GOPATH=$(GO_PATH) go list snot/lib/...)
nullvar =
a_space = $(nullvar) # <- Whitespace at the end (before this comment) won't be stripped.
a_comma = ,
ALL_PKG = $(subst $(a_space),$(a_comma),$(pkglist))
BLDTIME = $(shell date +'%Y/%m/%d %H:%M:%S' )
LDFLAGS = "-s -w -X 'snot/cmd/snot/common.BuildTime=$(BLDTIME)'"
LDFLAGS = -s -w -extldflags=-zrelro -extldflags=-znow
ifndef SOURCE_DATE_EPOCH
BLDTIME = $(shell date +'%Y/%m/%d %H:%M:%S')
LDFLAGS += -X "snot/cmd/snot/common.BuildTime=$(BLDTIME)"
endif
export GOFLAGS = $(GO_TRIM)
export GOPATH = $(GO_PATH)
export TMPDIR = $(TMP_DIR)
## Installation paths: ######################################################################################
......@@ -56,9 +65,6 @@ ETCDIR ?= $(DESTDIR)/etc
## Rules: ###################################################################################################
export GOPATH = $(GO_PATH)
export TMPDIR = $(TMP_DIR)
# Default target: -------------------------------------------------------------------------------------------
snot: bin/snot
......@@ -67,87 +73,87 @@ snot: bin/snot
$(TMP_DIR):
mkdir -p $(TMP_DIR)
mkdir -p '$(TMP_DIR)'
# Build snot (executable will be placed in the bin folder): -------------------------------------------------
bin/snot: $(ALL_GOS) | $(TMP_DIR)
go install -v -ldflags $(LDFLAGS) snot/cmd/snot
go install -v -ldflags '$(LDFLAGS)' snot/cmd/snot
# Install and uninstall the snot executable: ----------------------------------------------------------------
install: snot
install -m 755 -D -s $(GO_PATH)/bin/snot $(BINDIR)/snot
install -m 644 -D -t $(ETCDIR)/snot $(GO_PATH)/doc/conf/*.conf
install -m 755 -D -s '$(GO_PATH)'/bin/snot '$(BINDIR)'/snot
install -m 644 -D -t '$(ETCDIR)'/snot '$(GO_PATH)'/doc/conf/*.conf
uninstall: docs-uninstall arch-uninstall
rm -f $(BINDIR)/snot
rm -rf $(ETCDIR)/snot
rm -f '$(BINDIR)'/snot
rm -rf '$(ETCDIR)'/snot
# Generate the man page: ------------------------------------------------------------------------------------
docs: doc/snot.1.rst | $(TMP_DIR)
rst2man doc/man/snot.1.rst >$(TMP_DIR)/snot.1
rst2man doc/man/snot.1.rst >'$(TMP_DIR)'/snot.1
# Install and uninstall the man page, LICENSE and README files: ---------------------------------------------
docs-install: docs
install -m 644 -D $(TMP_DIR)/snot.1 $(MANDIR)/man1/snot.1
install -m 644 -D $(GO_PATH)/LICENSE $(DOCDIR)/LICENSE
install -m 644 -D $(GO_PATH)/README $(DOCDIR)/README
install -m 644 -D '$(TMP_DIR)'/snot.1 '$(MANDIR)'/man1/snot.1
install -m 644 -D '$(GO_PATH)'/LICENSE '$(DOCDIR)'/LICENSE
install -m 644 -D '$(GO_PATH)'/README '$(DOCDIR)'/README
docs-uninstall:
rm -f $(MANDIR)/man1/snot.1
rm -f $(DOCDIR)/LICENSE
rm -f $(DOCDIR)/README
rm -f '$(MANDIR)'/man1/snot.1
rm -f '$(DOCDIR)'/LICENSE
rm -f '$(DOCDIR)'/README
rmdir --ignore-fail-on-non-empty $(MANDIR)/man1 || true
rmdir --ignore-fail-on-non-empty $(DOCDIR) || true
rmdir --ignore-fail-on-non-empty '$(MANDIR)'/man1 || true
rmdir --ignore-fail-on-non-empty '$(DOCDIR)' || true
# Install and uninstall the pacman and mkinitcpio hooks: ----------------------------------------------------
arch-install:
install -m 644 -D $(GO_PATH)/arch/initcpio/snot.hook $(LIBDIR)/initcpio/hooks/snot
install -m 644 -D $(GO_PATH)/arch/initcpio/snot.install $(LIBDIR)/initcpio/install/snot
install -m 755 -D $(GO_PATH)/arch/pacman/snot-pacman $(SHRDIR)/snot-pacman
install -m 644 -D $(GO_PATH)/arch/pacman/snot.hook $(ETCDIR)/pacman.d/hooks/snot.hook
install -m 644 -D '$(GO_PATH)'/arch/initcpio/snot.hook '$(LIBDIR)'/initcpio/hooks/snot
install -m 644 -D '$(GO_PATH)'/arch/initcpio/snot.install '$(LIBDIR)'/initcpio/install/snot
install -m 755 -D '$(GO_PATH)'/arch/pacman/snot-pacman '$(SHRDIR)'/snot-pacman
install -m 644 -D '$(GO_PATH)'/arch/pacman/snot.hook '$(ETCDIR)'/pacman.d/hooks/snot.hook
install -m 644 -D $(GO_PATH)/doc/conf/create.conf $(ETCDIR)/snot/create.init
install -m 644 -D $(GO_PATH)/doc/conf/delete.conf $(ETCDIR)/snot/delete.init
install -m 644 -D $(GO_PATH)/doc/conf/list.conf $(ETCDIR)/snot/list.init
install -m 644 -D $(GO_PATH)/doc/conf/restore.conf $(ETCDIR)/snot/restore.init
install -m 644 -D '$(GO_PATH)'/doc/conf/create.conf '$(ETCDIR)'/snot/create.init
install -m 644 -D '$(GO_PATH)'/doc/conf/delete.conf '$(ETCDIR)'/snot/delete.init
install -m 644 -D '$(GO_PATH)'/doc/conf/list.conf '$(ETCDIR)'/snot/list.init
install -m 644 -D '$(GO_PATH)'/doc/conf/restore.conf '$(ETCDIR)'/snot/restore.init
sed \
-e "1i # This file is copied to the initramfs by snot's mkinitcpio hook." \
-e "1i # Delete it to use the default config file.\n" \
-i $(ETCDIR)/snot/*.init
-i '$(ETCDIR)'/snot/*.init
rm -f $(DOCDIR)/LICENSE
rm -f '$(DOCDIR)'/LICENSE
arch-uninstall:
rm -f $(LIBDIR)/initcpio/hooks/snot
rm -f $(LIBDIR)/initcpio/install/snot
rm -f $(SHRDIR)/snot-pacman
rm -f $(ETCDIR)/pacman.d/hooks/snot.hook
rm -f $(ETCDIR)/snot/*.init
rm -f '$(LIBDIR)'/initcpio/hooks/snot
rm -f '$(LIBDIR)'/initcpio/install/snot
rm -f '$(SHRDIR)'/snot-pacman
rm -f '$(ETCDIR)'/pacman.d/hooks/snot.hook
rm -f '$(ETCDIR)'/snot/*.init
rmdir --ignore-fail-on-non-empty $(LIBDIR)/initcpio/hooks || true
rmdir --ignore-fail-on-non-empty $(LIBDIR)/initcpio/install || true
rmdir --ignore-fail-on-non-empty $(LIBDIR)/initcpio || true
rmdir --ignore-fail-on-non-empty '$(LIBDIR)'/initcpio/hooks || true
rmdir --ignore-fail-on-non-empty '$(LIBDIR)'/initcpio/install || true
rmdir --ignore-fail-on-non-empty '$(LIBDIR)'/initcpio || true
rmdir --ignore-fail-on-non-empty $(ETCDIR)/pacman.d/hooks || true
rmdir --ignore-fail-on-non-empty $(ETCDIR)/pacman.d || true
rmdir --ignore-fail-on-non-empty $(ETCDIR)/snot || true
rmdir --ignore-fail-on-non-empty '$(ETCDIR)'/pacman.d/hooks || true
rmdir --ignore-fail-on-non-empty '$(ETCDIR)'/pacman.d || true
rmdir --ignore-fail-on-non-empty '$(ETCDIR)'/snot || true
rmdir --ignore-fail-on-non-empty $(SHRDIR) || true
rmdir --ignore-fail-on-non-empty '$(SHRDIR)' || true
# Remove all that is generated by build/run/etc.: -----------------------------------------------------------
......@@ -159,15 +165,15 @@ clean:
test: | $(TMP_DIR)
go test -tags test -v -cover -coverprofile $(TMP_DIR)/coverage.txt -coverpkg $(ALL_PKG) ./...
go tool cover -html=$(TMP_DIR)/coverage.txt -o=$(TMP_DIR)/coverage.html
go test -tags test -v -cover -coverprofile '$(TMP_DIR)'/coverage.txt -coverpkg $(ALL_PKG) ./...
go tool cover -html='$(TMP_DIR)'/coverage.txt -o='$(TMP_DIR)'/coverage.html
# Run more tests: -------------------------------------------------------------------------------------------
testall: | $(TMP_DIR)
go test -tags 'test testall' -v -cover -coverprofile $(TMP_DIR)/coverage.txt -coverpkg $(ALL_PKG) ./...
go tool cover -html=$(TMP_DIR)/coverage.txt -o=$(TMP_DIR)/coverage.html
go test -tags 'test testall' -v -cover -coverprofile '$(TMP_DIR)'/coverage.txt -coverpkg $(ALL_PKG) ./...
go tool cover -html='$(TMP_DIR)'/coverage.txt -o='$(TMP_DIR)'/coverage.html
# Run go vet for all files: ---------------------------------------------------------------------------------
......@@ -190,4 +196,4 @@ run: | $(TMP_DIR)
.PHONY: clean run snot test testall vet install docs docs-install arch-install
# :indentSize=3:tabSize=3:noTabs=false:mode=makefile:maxLineLen=109: ########################################
\ No newline at end of file
# :indentSize=3:tabSize=3:noTabs=false:mode=makefile:maxLineLen=109: ########################################
......@@ -8,7 +8,7 @@ pkgdesc='Basic Btrfs snapshot tool.'
url='https://gitlab.com/goeb/snot'
license=('GPL3')
depends=('btrfs-progs')
makedepends=('git' 'go' 'python-docutils')
makedepends=('go-pie' 'python-docutils')
backup=(
'etc/pacman.d/hooks/snot.hook'
'etc/snot/create.conf'
......@@ -32,7 +32,7 @@ _source_files=(
'README'
)
export GOCACHE="$_pkgbuild_dir/.cache/"
export GOCACHE="${TMPDIR:-/tmp}/gocache/"
prepare() {
......@@ -57,7 +57,13 @@ build() {
make
make docs
rm -rf "$_pkgbuild_dir/.cache/"
}
check() {
cd "$srcdir/$pkgname"
make testall
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment