File: Makefile

package info (click to toggle)
gdu 5.34.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,288 kB
  • sloc: makefile: 145
file content (164 lines) | stat: -rw-r--r-- 5,488 bytes parent folder | download | duplicates (5)
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
NAME := gdu
MAJOR_VER := v5
PACKAGE := github.com/dundee/$(NAME)/$(MAJOR_VER)
CMD_GDU := cmd/gdu
VERSION := $(shell git describe --tags 2>/dev/null)
NAMEVER := $(NAME)-$(subst v,,$(VERSION))
DATE := $(shell date +'%Y-%m-%d')
GOBIN := go
GOFLAGS ?= -buildmode=pie -trimpath -mod=readonly -modcacherw -pgo=default.pgo
GOFLAGS_STATIC ?= -trimpath -mod=readonly -modcacherw -pgo=default.pgo
LDFLAGS := -s -w -extldflags '-static' \
	-X '$(PACKAGE)/build.Version=$(VERSION)' \
	-X '$(PACKAGE)/build.User=$(shell id -u -n)' \
	-X '$(PACKAGE)/build.Time=$(shell LC_ALL=en_US.UTF-8 date)'
TAR := tar
ifeq ($(shell uname -s),Darwin)
	TAR := gtar # brew install gnu-tar
endif

all: clean tarball build-all build-docker man clean-uncompressed-dist shasums

run:
	go run $(PACKAGE)/$(CMD_GDU)

vendor: go.mod go.sum
	go mod vendor

tarball: vendor
	-mkdir dist
	$(TAR) czf dist/$(NAMEVER).tgz --transform "s,^,$(NAMEVER)/," --exclude dist --exclude test_dir --exclude coverage.txt *

build:
	@echo "Version: " $(VERSION)
	mkdir -p dist
	GOFLAGS="$(GOFLAGS)" CGO_ENABLED=0 $(GOBIN) build -ldflags="$(LDFLAGS)" -o dist/$(NAME) $(PACKAGE)/$(CMD_GDU)

build-static:
	@echo "Version: " $(VERSION)
	mkdir -p dist
	GOFLAGS="$(GOFLAGS_STATIC)" CGO_ENABLED=0 $(GOBIN) build -ldflags="$(LDFLAGS)" -o dist/$(NAME) $(PACKAGE)/$(CMD_GDU)

build-docker:
	@echo "Version: " $(VERSION)
	docker build . --tag ghcr.io/dundee/gdu:$(VERSION)

build-all:
	@echo "Version: " $(VERSION)
	-mkdir dist
	-CGO_ENABLED=0 gox \
		-os="darwin" \
		-arch="amd64 arm64" \
		-output="dist/gdu_{{.OS}}_{{.Arch}}" \
		-ldflags="$(LDFLAGS)" \
		$(PACKAGE)/$(CMD_GDU)

	-CGO_ENABLED=0 gox \
		-os="windows" \
		-arch="amd64" \
		-output="dist/gdu_{{.OS}}_{{.Arch}}" \
		-ldflags="$(LDFLAGS)" \
		$(PACKAGE)/$(CMD_GDU)

	-CGO_ENABLED=0 gox \
		-os="linux freebsd netbsd openbsd" \
		-output="dist/gdu_{{.OS}}_{{.Arch}}" \
		-ldflags="$(LDFLAGS)" \
		$(PACKAGE)/$(CMD_GDU)

	GOFLAGS="$(GOFLAGS)" CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBIN) build -ldflags="$(LDFLAGS)" -o dist/gdu_linux_amd64 $(PACKAGE)/$(CMD_GDU)
	GOFLAGS="$(GOFLAGS_STATIC)" CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBIN) build -ldflags="$(LDFLAGS)" -o dist/gdu_linux_amd64_static $(PACKAGE)/$(CMD_GDU)

	CGO_ENABLED=0 GOOS=linux GOARM=5 GOARCH=arm $(GOBIN) build -ldflags="$(LDFLAGS)" -o dist/gdu_linux_armv5l $(PACKAGE)/$(CMD_GDU)
	CGO_ENABLED=0 GOOS=linux GOARM=6 GOARCH=arm $(GOBIN) build -ldflags="$(LDFLAGS)" -o dist/gdu_linux_armv6l $(PACKAGE)/$(CMD_GDU)
	CGO_ENABLED=0 GOOS=linux GOARM=7 GOARCH=arm $(GOBIN) build -ldflags="$(LDFLAGS)" -o dist/gdu_linux_armv7l $(PACKAGE)/$(CMD_GDU)
	CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GOBIN) build -ldflags="$(LDFLAGS)" -o dist/gdu_linux_arm64 $(PACKAGE)/$(CMD_GDU)
	CGO_ENABLED=0 GOOS=android GOARCH=arm64 $(GOBIN) build -ldflags="$(LDFLAGS)" -o dist/gdu_android_arm64 $(PACKAGE)/$(CMD_GDU)

	cd dist; for file in gdu_linux_* gdu_darwin_* gdu_netbsd_* gdu_openbsd_* gdu_freebsd_* gdu_android_*; do tar czf $$file.tgz $$file; done
	cd dist; for file in gdu_windows_*; do zip $$file.zip $$file; done

gdu.1: gdu.1.md
	sed 's/{{date}}/$(DATE)/g' gdu.1.md > gdu.1.date.md
	pandoc gdu.1.date.md -s -t man > gdu.1
	rm -f gdu.1.date.md

man: gdu.1
	cp gdu.1 dist
	cd dist; tar czf gdu.1.tgz gdu.1

show-man:
	sed 's/{{date}}/$(DATE)/g' gdu.1.md > gdu.1.date.md
	pandoc gdu.1.date.md -s -t man | man -l -

test:
	gotestsum

coverage:
	gotestsum -- -race -coverprofile=coverage.txt -covermode=atomic ./...

coverage-html: coverage
	$(GOBIN) tool cover -html=coverage.txt

gobench:
	$(GOBIN) test -bench=. $(PACKAGE)/pkg/analyze

heap-profile:
	$(GOBIN) tool pprof -web http://localhost:6060/debug/pprof/heap

pgo:
	wget -O cpu.pprof http://localhost:6060/debug/pprof/profile?seconds=30
	$(GOBIN) tool pprof -proto cpu.pprof default.pgo > merged.pprof
	mv merged.pprof default.pgo

trace:
	wget -O trace.out http://localhost:6060/debug/pprof/trace?seconds=30
	gotraceui ./trace.out

profile:
	wget -O cpu.pprof http://localhost:6060/debug/pprof/profile?seconds=30
	$(GOBIN) tool pprof -web cpu.pprof

benchmark:
	sudo cpupower frequency-set -g performance
	hyperfine --export-markdown=bench-cold.md \
		--prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' \
		--ignore-failure \
		'dua ~' 'duc index ~' 'ncdu -0 -o /dev/null ~' \
		'diskus ~' 'du -hs ~' 'dust -d0 ~' 'pdu ~' \
		'gdu -npc ~' 'gdu -gnpc ~' 'gdu -npc --use-storage ~'
	hyperfine --export-markdown=bench-warm.md \
		--warmup 5 \
		--ignore-failure \
		'dua ~' 'duc index ~' 'ncdu -0 -o /dev/null ~' \
		'diskus ~' 'du -hs ~' 'dust -d0 ~' 'pdu ~' \
		'gdu -npc ~' 'gdu -gnpc ~' 'gdu -npc --use-storage ~'
	sudo cpupower frequency-set -g schedutil

lint:
	golangci-lint run -c .golangci.yml

clean:
	$(GOBIN) mod tidy
	-rm coverage.txt
	-rm -r test_dir
	-rm -r vendor
	-rm -r dist

clean-uncompressed-dist:
	find dist -type f -not -name '*.tgz' -not -name '*.zip' -delete

shasums:
	cd dist; sha256sum * > sha256sums.txt
	cd dist; gpg --sign --armor --detach-sign sha256sums.txt

release:
	gh release create -t "gdu $(VERSION)" $(VERSION) ./dist/*

install-dev-dependencies:
	$(GOBIN) install gotest.tools/gotestsum@latest
	$(GOBIN) install github.com/mitchellh/gox@latest
	$(GOBIN) install honnef.co/go/gotraceui/cmd/gotraceui@latest
	$(GOBIN) install github.com/golangci/golangci-lint/cmd/golangci-lint@2.8.0

.PHONY: run build build-static build-all test gobench benchmark coverage coverage-html clean clean-uncompressed-dist man show-man release dev-build