summary refs log tree commit diff
path: root/.config/yamlfs/go.yaml
blob: 96f659913509014c1a8d493edebce98a193b7a7a (plain) (blame)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
{% $man := .man %}
cmd:
  {% .name %}:
    main.go: |
      package main

      func main() {
      	println("hello world")
      }

version:
  version.go: |
    package version

    var (
    	Package = "{% .pkg %}"
    	Revision = "-"
    	Version = "0.0.0+unknown"
    )

go.mod: |
{% exec "sh" "-c" (printf "cd /tmp/;go mod init %s;cat go.mod;rm go.mod;" .pkg) | indent 4 %}

Makefile: |
  .POSIX:

  DESTDIR      ?= .
  BINDIR       ?= $(PREFIX)/bin
  MANDIR       ?= $(PREFIX)/share/man
  VERSION      ?= $(shell git describe --match 'v[0-9]*' --dirty='+dev' --always --tags || printf "0.0.0+unknown")
  REVISION     ?= $(shell git rev-parse HEAD || printf "-")
  
  GO           ?= go
  GOLINT       ?= $(GO) vet # golangci-lint run --build-tags "$(GO_BUILDTAGS)"
  GOTEST       ?= $(GO) test # gotestsum --format=testname --
  {% if $man -%}
  SCDOC        ?= scdoc
  {%- end %}
  
  GO_BUILDTAGS ?= netgo osusergo static_build
  GO_LDFLAGS   ?= -s -w -extldflags -static
  GOTEST_FLAGS ?=
  GOLINT_FLAGS ?=

  all: lint test build {% if $man %}man{% end %}

  .PHONY: build
  build: {% .name %}

  {% .name %}: GO_PKG = {% .pkg %}
  {% .name %}: GO_VERSIONFLAGS += -X $(GO_PKG)/version.Version=$(VERSION)
  {% .name %}: GO_VERSIONFLAGS += -X $(GO_PKG)/version.Revision=$(REVISION)
  {% .name %}: GO_VERSIONFLAGS += -X $(GO_PKG)/version.Package=$(GO_PKG)
  {% .name %}: $(shell find . -name '*.go')
  	$(GO) build -o $(DESTDIR)$(PREFIX)/$@ -tags '$(GO_BUILDTAGS)' -ldflags '$(GO_LDFLAGS) $(GO_VERSIONFLAGS)' ./cmd/$@

  .PHONY: lint
  lint:
  	$(GOLINT) $(GOLINT_FLAGS) ./...
  .PHONY: validate
  validate: lint

  .PHONY: test
  test:
  	$(GOTEST) $(GOTEST_FLAGS) -tags '$(GO_BUILDTAGS)' -cover -covermode=atomic ./...
  .PHONY: check
  check: test

  {% if $man %}
  manpages = doc/{% .name %}.1
  $(manpages): %: %.scd
  $(manpages):
  	$(SCDOC) <$^ >$@
  .PHONY:
  man: $(manpages)

  {% end %}
  .PHONY: clean
  clean: RM ?= rm -f
  clean:
  	$(RM) {% .name %}

  .PHONY: install
  install:
  	mkdir -p $(DESTDIR)$(BINDIR)
	{% if $man -%}
  	mkdir -p $(DESTDIR)$(MANDIR)/man1
  	{%- end %}
  	cp -f {% .name %} $(DESTDIR)$(BINDIR)
	{% if $man -%}
  	cp -f doc/{% .name %}.1 $(DESTDIR)$(MANDIR)/man1
  	{%- end %}

  .PHONY: uninstall
  uninstall:
  	rm -v $(DESTDIR)$(BINDIR)/{% .name %}
	{% if $man -%}
  	rm -v $(DESTDIR)$(MANDIR)/man1/{% .name %}.1
  	{%- end %}

  .PHONY: help
  help:
  	@printf "Usage:\n"
  	@printf "  build             build\n"
  	@printf "  validate          linter\n"
  	@printf "  test              tests\n"
  	@printf "  (un)install       install into system directories\n"
  	@printf "\n"
  	@printf "  DESTDIR, PREFIX   install location\n"
  	@printf "\n"

.editorconfig: |
  ; http://editorconfig.org/

  root = true

  [*]
  insert_final_newline = true
  charset = utf-8
  trim_trailing_whitespace = true
  indent_style = space
  indent_size = 2

  [{Makefile,go.mod,go.sum,*go}]
  indent_style = tab
  indent_size = 4

  [*.md]
  trim_trailing_whitespace = false

  [Dockerfile]
  indent_size = 4

README.md: |
  # {% .name %}

  TODO

{% if $man %}
doc:
  {% .name %}.1.scd: |
    {% .name %}(1)

    # NAME

    {% .name %} - TODO

    # SYNOPSIS

    *{% .name %}* [options...]

    # DESCRIPTION

    TODO

    # OPTIONS

    *-h, -help*
    	Show help message and quit.

    # SEE ALSO

    	*{% .name %}*(5)

    # AUTHORS

    Maintained by TODO author <mail>.
    For more information, see {% .pkg %}.
{% end %}