First go at a makefile, woo-hoo!

This commit is contained in:
Brian Evans 2019-10-14 16:29:40 -07:00
parent 74ada2b8ed
commit 7ed2b46b32
3 changed files with 63 additions and 3 deletions

51
Makefile Normal file
View File

@ -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}

1
VERSION Normal file
View File

@ -0,0 +1 @@
v2.0.0

14
main.go
View File

@ -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