From 28589d0d16cd91663f4ad1f6af3ed3409eb6f0fa Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 16 Dec 2023 00:03:54 +0000 Subject: [PATCH] chore(build): add Makefile --- .gitignore | 2 ++ Makefile | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d902d94 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bin/* +dist/* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..67940f3 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +NAME = macos-battery-exporter +BINARY = bin/${NAME} +VERSION ?= $(shell cat VERSION) +SOURCES = $(shell find . -name '*.go' -o -name 'Makefile') + +$(BINARY): $(SOURCES) + CGO_ENABLED=0 go build -o ${BINARY} -ldflags \ "\ + -s -w \ + -X main.version=${VERSION} \ + -X main.commit=$(shell git show --format="%h" --no-patch)" + +.PHONY: build +build: $(BINARY) + +.PHONY: run +run: $(BINARY) + $(BINARY) + +.PHONY: clean +clean: + $(eval BIN_DIR := $(shell dirname ${BINARY})) + if [ -f ${BINARY} ]; then rm ${BINARY}; fi + if [ -d ${BIN_DIR} ]; then rmdir ${BIN_DIR}; fi + +.PHONY: docker +docker: + docker build -t "$(shell whoami)/$(NAME)" .