-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
103 lines (79 loc) · 2.12 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Copyright © 2018 ARClab, Lionel Riem - https://arclab.ch/
#
# Use of this source code is governed by the MIT license that can be found in
# the LICENSE file.
# Binary output and package
OUT := changelog
# Go package
PKG := github.com/arclabch/changelog
# Stop if Windows detected
ifeq ($(OS),Windows_NT)
$(error Windows is not supported.)
endif
# Get version from Git
VERSION := $(shell git describe --always --tags --long --dirty 2>/dev/null || echo undefined)
# Get the OS
KERNEL := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
# Get the machine platform
PLATFORM := $(shell sh -c 'uname -m 2>/dev/null || echo Unknown')
# Set the build timestamp
TIMESTAMP := $(shell sh -c 'date +"%Y-%m-%dT%H:%M%z"')
# If no prefix, set it
ifeq ($(PREFIX),)
# FreeBSD lands in /usr/local, /usr otherwise
ifeq ($(KERNEL),FreeBSD)
PREFIX := /usr/local
else
PREFIX := /usr
endif
endif
# For test/lint/vet/fmt
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)
GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/)
# Where to put the work we do
ifeq ($(WORKDIR),)
WORKDIR := work
endif
# Default target is build
all: build
# Normal build
build:
go build -i -v -o ${WORKDIR}/${OUT} -ldflags="-w -s \
-X main.version=${VERSION} -X main.kernel=${KERNEL} -X main.machine=${PLATFORM} \
-X main.built=${TIMESTAMP}" ${PKG}
# Run Go Test on the package(s)
test:
@go test -short ${PKG_LIST}
# Vet the package(s)
vet:
@go vet ${PKG_LIST}
# Lint the files
lint:
@for file in ${GO_FILES} ; do \
golint $$file ; \
done
# Clean, vet, lint and build
dev-build: clean vet lint build
# Install
install:
install -m 755 ${WORKDIR}/${OUT} ${DESTDIR}${PREFIX}/bin/
# Uninstall
uninstall:
@rm ${DESTDIR}${PREFIX}/bin/${OUT}
# Clean
clean:
@rm -rf ${WORKDIR}
# Format the files
fmt:
@for file in ${GO_FILES} ; do \
gofmt -w $$file ; \
done
# Check the files format and print a diff
fmt-diff:
@for file in ${GO_FILES} ; do \
gofmt -d $$file ; \
done
# Clean, vet, lint, build and run
run: dev-build
./${WORKDIR}/${OUT}
.PHONY: build dev-build test vet lint install uninstall clean fmt fmt-diff run