From 7ed2b46b326976268ff7eb27161c17824254aefc Mon Sep 17 00:00:00 2001 From: Brian Evans Date: Mon, 14 Oct 2019 16:29:40 -0700 Subject: [PATCH] First go at a makefile, woo-hoo! --- Makefile | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ VERSION | 1 + main.go | 14 +++++++++++--- 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 Makefile create mode 100644 VERSION diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..99ba95a --- /dev/null +++ b/Makefile @@ -0,0 +1,51 @@ +BINARY := bombadillo +man1dir := /usr/local/share/man/man1 +#PKGS := $(shell go list ./... |grep -v /vendor) +VERSION := $(shell git describe --tags 2> /dev/null) +BUILD := $(shell date) +GOPATH ?= $(HOME)/go +GOBIN ?= ${GOPATH}/bin +BUILD_PATH ?= ${GOBIN} + +# If VERSION is empty or not deffined use the contents of the VERSION file +ifndef VERSION + VERSION := $(shell cat ./VERSION) +endif + +LDFLAGS := +ifdef CONF_PATH + LDFLAGS := -ldflags "-s -X main.version=${VERSION} -X main.build=${BUILD} -X main.conf_path${conf_path}" +else + LDFLAGS := -ldflags "-s -X main.version=${VERSION} -X main.build=${BUILD}" +endif + +.PHONY: test +test: + @echo ${LDFLAGS} + @echo ${VERSION} + @echo ${BUILD_PATH} + +.PHONY: build +build: + @go build ${LDFLAGS} -o ${BINARY} + +.PHONY: install +install: install-man + @go build ${LDFLAGS} -o ${BUILD_PATH}/${BINARY} + +.PHONY: install-man +install-man: bombadillo.1 + @gzip -k ./bombadillo.1 + @install -d ${man1dir} + @install -m 0644 ./bombadillo.1.gz ${man1dir} + +.PHONY: clean +clean: + @go clean -i + @rm ./bombadillo.1.gz 2> /dev/null + +.PHONY: uninstall +uninstall: clean + @rm -f ${man1dir}/bombadillo.1.gz + @echo Removing ${BINARY} + @rm -f ${BUILD_PATH}/${BINARY} diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..46b105a --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +v2.0.0 diff --git a/main.go b/main.go index 249139d..ded782d 100644 --- a/main.go +++ b/main.go @@ -32,7 +32,9 @@ import ( "tildegit.org/sloum/mailcap" ) -const version = "2.0.0" +var version string +var build string +var conf_path string var bombadillo *client var helplocation string = "gopher://colorfield.space:70/1/bombadillo-info" @@ -95,6 +97,11 @@ func lowerCaseOpt(opt, val string) string { } func loadConfig() error { + // If a compile time override exists for configlocation + // set it before loading the config. + if conf_path != "" { + bombadillo.Options["configlocation"] = conf_path + } file, err := os.Open(bombadillo.Options["configlocation"] + "/.bombadillo.ini") if err != nil { err = saveConfig() @@ -109,8 +116,9 @@ func loadConfig() error { for _, v := range settings.Settings { lowerkey := strings.ToLower(v.Key) if lowerkey == "configlocation" { - // The config should always be stored in home - // folder. Users cannot really edit this value. + // The config defaults to the home folder. + // Users cannot really edit this value. But + // a compile time override is available. // It is still stored in the ini and as a part // of the options map. continue