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
|
# Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
#
# SPDX-License-Identifier: GPL-2.0-or-later
.DEFAULT_GOAL = all
.SECONDARY:
.DELETE_ON_ERROR:
btrfsitem/items.txt: btrfsitem $(wildcard btrfsitem/item_*.go) $(MAKEFILE_LIST)
{ \
sed -En 's,^type (\S+) .* // (.*=.*),\1 \2,p' $(filter btrfsitem/item_%.go,$^) | while read -r typ keys; do \
for key in $$keys; do \
echo "$$key" "$$typ"; \
done; \
done; \
} | LC_COLLATE=C sort >$@
files += btrfsitem/items.txt
btrfsitem/items_gen.go: btrfsitem/items.txt $(MAKEFILE_LIST)
{ \
echo '// Code generated by Make. DO NOT EDIT.'; \
echo; \
echo '// SPDX-License-Identifier: GPL-2.0-or-later'; \
echo; \
echo 'package $(@D)'; \
echo 'import ('; \
echo '"reflect"'; \
echo; \
echo '"git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsprim"'; \
echo ')'; \
echo 'const ('; \
sed -E 's,(.*)=(.*) (.*),\1_KEY=btrfsprim.\1_KEY,' $<; \
echo ')'; \
echo 'var keytype2gotype = map[Type]reflect.Type{'; \
sed -En 's|(.*)=([^:]*) (.*)|\1_KEY: reflect.TypeOf(\3{}),|p' $<; \
echo '}'; \
echo 'var untypedObjID2gotype = map[btrfsprim.ObjID]reflect.Type{'; \
sed -En 's|UNTYPED=0:(.*) (.*)|btrfsprim.\1: reflect.TypeOf(\2{}),|p' $<; \
echo '}'; \
sed -En 's,(.*)=(.*) (.+),\3,p' $< | LC_COLLATE=C sort -u | sed 's,.*,func (&) isItem() {},'; \
} | gofmt >$@
files += btrfsitem/items_gen.go
btrfsprim/itemtype.go: btrfsitem/items.txt $(MAKEFILE_LIST)
{ \
echo '// Code generated by Make. DO NOT EDIT.'; \
echo; \
echo '// SPDX-License-Identifier: GPL-2.0-or-later'; \
echo; \
echo 'package $(@D)'; \
echo 'import "fmt"'; \
echo 'type ItemType uint8'; \
echo 'const ('; \
sed -E 's,(.*)=([^:]*)(:.*)? (.*),\1_KEY=ItemType(\2),' $< | uniq; \
echo ')'; \
echo 'func (t ItemType) String() string {'; \
echo ' names := map[ItemType]string{'; \
sed -E 's@(.*)=(.*) (.*)@\1_KEY: "\1",@' $< | sed 's/"UUID_/&KEY_/'; \
echo ' }'; \
echo ' if name, ok := names[t]; ok {'; \
echo ' return name'; \
echo ' }'; \
echo ' return fmt.Sprintf("%d", t)'; \
echo '}'; \
} | gofmt >$@
files += btrfsprim/itemtype.go
all: $(files)
.PHONY: all
clean:
rm -f -- $(files)
.PHONY: all
|