-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
55 lines (44 loc) · 1.56 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Make settings
# Mostly copied from: https://tech.davis-hansson.com/p/make/
# Use Bash
SHELL := bash
# If one of the commands fails just fail properly and don't run the other commands.
.SHELLFLAGS := -eu -o pipefail -c
# Allows me to use a single shell session so you can do things like 'cd' without doing hacks.
.ONESHELL:
# Tells make not to do crazy shit.
MAKEFLAGS += --no-builtin-rules
# Allows me to replace tabs with > characters. This makes the things a bit easier to use things like forloops in bash.
ifeq ($(origin .RECIPEPREFIX), undefined)
$(error This Make does not support .RECIPEPREFIX. Please use GNU Make 4.0 or later)
endif
.RECIPEPREFIX = >
# App Vars
APP_NAME = release
GIT_COMMIT = $(shell git rev-parse --short HEAD)
# Although go 1.18 has the git info baked into the binary now it still seems like there is no support
# For including outside variables except this. So keep it for now.
GO_LDFLAGS = '-X "main.appVersion=$(VERSION)"'
SHELL = /bin/bash
SEMVER = 0.0.0
VERSION = ${SEMVER}_${GIT_COMMIT}
## build: run tests and compile application
build: check-path-included check-semver-included
> go test ./... -race
> go mod tidy
> export CGO_ENABLED=0
> go build -ldflags $(GO_LDFLAGS) -o $(OUTPUT)
.PHONY: build
## help: prints this help message
help:
> @echo "Usage: "
> @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
.PHONY: help
check-path-included:
ifndef OUTPUT
> $(error OUTPUT is undefined; ex. OUTPUT=/tmp/${APP_NAME})
endif
check-semver-included:
ifeq ($(SEMVER), 0.0.0)
> $(error SEMVER is undefined; ex. SEMVER=0.0.1)
endif