From a7d83ee4169a1d1d7b01793b4719f49eb0b911a1 Mon Sep 17 00:00:00 2001 From: Norwin Date: Fri, 3 Dec 2021 04:01:10 +0800 Subject: [PATCH] Simplify build & update installation instructions (#437) - "revert" the work done in #349. It turns out that this elaborate workaround to get statically built PIEs was only needed due to a bug in go, which got fixed in go 1.16. - Add an exception to the `-buildmode=pie` flag for OpenBSD, as discovered in #436 - Simplify & update README installation instructions (the Arch AUR package got deleted as it wasn't maintained, so we link to `gitea-tea-git` now.) Co-authored-by: Norwin Reviewed-on: https://gitea.com/gitea/tea/pulls/437 Reviewed-by: Lunny Xiao Reviewed-by: 6543 <6543@obermui.de> Co-authored-by: Norwin Co-committed-by: Norwin --- Makefile | 19 ++++++------------- README.md | 29 ++++++++++++++++------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 5a1c971..3b2c956 100644 --- a/Makefile +++ b/Makefile @@ -26,24 +26,20 @@ TEA_VERSION_TAG ?= $(shell sed 's/+/_/' <<< $(TEA_VERSION)) TAGS ?= LDFLAGS := -X "main.Version=$(TEA_VERSION)" -X "main.Tags=$(TAGS)" -s -w -ifeq ($(STATIC),true) - # NOTE: clean up this mess, when https://github.com/golang/go/issues/26492 is resolved - # static_build is a defacto standard tag used in go packages - TAGS := osusergo,netgo,static_build,$(TAGS) - LDFLAGS := $(LDFLAGS) -linkmode=external -extldflags "-static-pie" -X "main.Tags=$(TAGS)" - export CGO_ENABLED=1 # needed for linkmode=external -endif - # override to allow passing additional goflags via make CLI override GOFLAGS := $(GOFLAGS) -mod=vendor -tags '$(TAGS)' -ldflags '$(LDFLAGS)' PACKAGES ?= $(shell $(GO) list ./... | grep -v /vendor/) SOURCES ?= $(shell find . -name "*.go" -type f) +# OS specific vars. ifeq ($(OS), Windows_NT) EXECUTABLE := tea.exe else EXECUTABLE := tea + ifneq ($(shell uname -s), OpenBSD) + override BUILDMODE := -buildmode=pie + endif endif .PHONY: all @@ -124,16 +120,13 @@ check: test .PHONY: install install: $(SOURCES) @echo "installing to $(GOPATH)/bin/$(EXECUTABLE)" - $(GO) install -v -buildmode=pie $(GOFLAGS) + $(GO) install -v $(BUILDMODE) $(GOFLAGS) .PHONY: build build: $(EXECUTABLE) $(EXECUTABLE): $(SOURCES) -ifeq ($(STATIC),true) - @echo "enabling static build, make sure you have glibc-static (or equivalent) installed" -endif - $(GO) build -buildmode=pie $(GOFLAGS) -o $@ + $(GO) build $(BUILDMODE) $(GOFLAGS) -o $@ .PHONY: build-image build-image: diff --git a/README.md b/README.md index 0a9ce22..052f49d 100644 --- a/README.md +++ b/README.md @@ -85,29 +85,32 @@ There are different ways to get `tea`: brew tap gitea/tap https://gitea.com/gitea/homebrew-gitea brew install tea ``` - - arch linux ([gitea-tea](https://aur.archlinux.org/packages/gitea-tea), thirdparty) + - arch linux ([gitea-tea-git](https://aur.archlinux.org/packages/gitea-tea-git), thirdparty) - alpine linux ([tea](https://pkgs.alpinelinux.org/packages?name=tea&branch=edge), thirdparty) 2. Use the prebuilt binaries from [dl.gitea.io](https://dl.gitea.io/tea/) -3. Install from source (go 1.13 or newer is required): - ```sh - go get code.gitea.io/tea - go install code.gitea.io/tea - ``` +3. Install from source: [see *Compilation*](#compilation) 4. Docker (thirdparty): [tgerczei/tea](https://hub.docker.com/r/tgerczei/tea) ## Compilation -Make sure you have installed a current go version. -To compile the sources yourself run the following: +Make sure you have a current go version installed (1.13 or newer). -```sh -git clone https://gitea.com/gitea/tea.git -cd tea -make STATIC=true -``` +- To compile the source yourself with the recommended flags & tags: + ```sh + git clone https://gitea.com/gitea/tea.git # or: tea clone gitea.com/gitea/tea ;) + cd tea + make + ``` + Note that GNU Make (gmake on OpenBSD) is required. + +- For a quick installation without `git` & `make`: + ```sh + go get code.gitea.io/tea + go install code.gitea.io/tea + ``` ## Contributing