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 b4787415 authored by Stefan Göbel's avatar Stefan Göbel
Browse files

Build binary as PIE by default

parent d730c3c3
......@@ -27,28 +27,32 @@
# arguments for run, for example (note the dashes):
#
# make run -- create --description something…
#
# The binary will be built as dynamically linked PIE by default. To change this, override GOFLAGS and
# GO_LDFLAGS, e.g.:
#
# GOFLAGS='-trimpath' GO_LDFLAGS='-w -s' make
## Variables: ###############################################################################################
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))
LDFLAGS = -s -w -extldflags=-zrelro -extldflags=-znow
GO_LDFLAGS ?= -linkmode=external -w -s
ifndef SOURCE_DATE_EPOCH
BLDTIME = $(shell date +'%Y/%m/%d %H:%M:%S')
LDFLAGS += -X "snot/cmd/snot/common.BuildTime=$(BLDTIME)"
bldtime = $(shell date +'%Y/%m/%d %H:%M:%S')
GO_LDFLAGS += -X "snot/cmd/snot/common.BuildTime=$(bldtime)"
endif
export GOFLAGS = $(GO_TRIM)
export GOPATH = $(GO_PATH)
export TMPDIR = $(TMP_DIR)
export GOFLAGS ?= -buildmode=pie -trimpath
export GOPATH = $(GO_PATH)
export TMPDIR = $(TMP_DIR)
## Installation paths: ######################################################################################
......@@ -57,6 +61,7 @@ SHARED ?= $(PREFIX)/share
BINDIR ?= $(DESTDIR)$(PREFIX)/bin
LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
MANDIR ?= $(DESTDIR)$(SHARED)/man
SHRDIR ?= $(DESTDIR)$(SHARED)/snot
DOCDIR ?= $(DESTDIR)$(SHARED)/doc/snot
......@@ -79,7 +84,7 @@ $(TMP_DIR):
bin/snot: $(ALL_GOS) | $(TMP_DIR)
go install -v -ldflags '$(LDFLAGS)' snot/cmd/snot
go install -v -ldflags '$(GO_LDFLAGS)' snot/cmd/snot
# Install and uninstall the snot executable: ----------------------------------------------------------------
......
......@@ -8,7 +8,7 @@ pkgdesc='Basic Btrfs snapshot tool.'
url='https://gitlab.com/goeb/snot'
license=('GPL3')
depends=('btrfs-progs')
makedepends=('go-pie' 'python-docutils')
makedepends=('go' 'python-docutils')
backup=(
'etc/pacman.d/hooks/snot.hook'
'etc/snot/create.conf'
......@@ -54,6 +54,11 @@ build() {
cd "$srcdir/$pkgname"
export CGO_CPPFLAGS="${CPPFLAGS}"
export CGO_CFLAGS="${CFLAGS}"
export CGO_CXXFLAGS="${CXXFLAGS}"
export CGO_LDFLAGS="${LDFLAGS}"
make
make docs
......
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