forked from AllenDang/cimgui-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
158 lines (137 loc) · 5.89 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
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
NAME=cimgui-go Code Generator
.PHONY: all
## all: generates both bindings.
all: generate
## setup: prepare some dependencies
.PHONY: setup
setup:
go install mvdan.cc/gofumpt@latest
cd cmd/codegen; \
go build -o ../../codegen .
# Parameters:
# $1: prefix
# $2: go package name
# $3: include path (of header file)
# $4: definitions.json filepath
# $5: structs_and_enums.json filepath
# $6: typedefs_dict.json filepath
# $7: additional agruments to codegen call (e.g. -r option)
define generate
@echo "Generating for $(1)"
mkdir -p $(2)
cat templates/cflags.go |sed -e "s/^package.*/package $(2)/g" > $(2)/cflags.go
cd $(2); \
../codegen -preset ../cmd/codegen/cimgui-go-preset.json -p $(1) -pkg $(2) -i ../$(3) -d ../$(4) -e ../$(5) -t ../$(6) $(7)
go run mvdan.cc/gofumpt@latest -w $(2)/enums.go
go run mvdan.cc/gofumpt@latest -w $(2)/funcs.go
go run mvdan.cc/gofumpt@latest -w $(2)/typedefs.go
go run mvdan.cc/gofumpt@latest -w $(2)/callbacks.go
go run golang.org/x/tools/cmd/goimports@latest -w $(2)/funcs.go
go run golang.org/x/tools/cmd/goimports@latest -w $(2)/enums.go
go run golang.org/x/tools/cmd/goimports@latest -w $(2)/typedefs.go
go run golang.org/x/tools/cmd/goimports@latest -w $(2)/callbacks.go
endef
define imgui
$(call generate,cimgui,imgui,cwrappers/cimgui.h,cwrappers/cimgui_templates/definitions.json,cwrappers/cimgui_templates/structs_and_enums.json,cwrappers/cimgui_templates/typedefs_dict.json)
endef
## cimgui: generate imgui binding
.PHONY: imgui
imgui: setup
$(call imgui)
define implot
$(call generate,cimplot,implot,cwrappers/cimplot.h,cwrappers/cimplot_templates/definitions.json,cwrappers/cimplot_templates/structs_and_enums.json,cwrappers/cimplot_templates/typedefs_dict.json,-r ../cwrappers/cimgui_templates/structs_and_enums.json -rt ../cwrappers/cimgui_templates/typedefs_dict.json)
endef
## implot: generate implot binding
.PHONY: implot
implot: setup
$(call implot)
define imnodes
$(call generate,cimnodes,imnodes,cwrappers/cimnodes.h,cwrappers/cimnodes_templates/definitions.json,cwrappers/cimnodes_templates/structs_and_enums.json,cwrappers/cimnodes_templates/typedefs_dict.json,-r ../cwrappers/cimgui_templates/structs_and_enums.json -rt ../cwrappers/cimgui_templates/typedefs_dict.json)
endef
## imnodes: generate imnodes binding
.PHONY: imnodes
imnodes: setup
$(call imnodes)
define immarkdown
$(call generate,cimmarkdown,immarkdown,cwrappers/cimmarkdown.h,cwrappers/cimmarkdown_templates/definitions.json,cwrappers/cimmarkdown_templates/structs_and_enums.json,cwrappers/cimmarkdown_templates/typedefs_dict.json,-r ../cwrappers/cimgui_templates/structs_and_enums.json -rt ../cwrappers/cimgui_templates/typedefs_dict.json)
endef
## immarkdown: generate immarkdown binding
.PHONY: immarkdown
immarkdown: setup
$(call immarkdown)
define imguizmo
$(call generate,cimguizmo,imguizmo,cwrappers/cimguizmo.h,cwrappers/cimguizmo_templates/definitions.json,cwrappers/cimguizmo_templates/structs_and_enums.json,cwrappers/cimguizmo_templates/typedefs_dict.json,-r ../cwrappers/cimgui_templates/structs_and_enums.json -rt ../cwrappers/cimgui_templates/typedefs_dict.json)
endef
## imguizmo: generate imguizmo binding
.PHONY: imguizmo
imguizmo: setup
$(call imguizmo)
define imcte
$(call generate,cimcte,ImGuiColorTextEdit,cwrappers/cimCTE.h,cwrappers/cimCTE_templates/definitions.json,cwrappers/cimCTE_templates/structs_and_enums.json,cwrappers/cimCTE_templates/typedefs_dict.json,-r ../cwrappers/cimgui_templates/structs_and_enums.json -rt ../cwrappers/cimgui_templates/typedefs_dict.json)
endef
## imcte: generate ImGuiColorTextEdit binding
.PHONY: imcte
imcte: setup
$(call imcte)
## generate: generates both bindings (equal to `all`)
.PHONY: generate
generate: imgui implot imnodes immarkdown imguizmo imcte
# update updates sub-repos (like cimplot or cimgui)
# $1 - subrepo directory
# $2 - repository URL
# $3 - $1/<c++ repo>/
# $4 - branch in $3 (cd tmp/$1/$3 && git checkout $4)
# $5 - additional generator options
define update
@echo "updating $1 from $2"
mkdir -p tmp/
if test -e tmp/$1; then \
rm -rf tmp/*; \
fi
git clone --recurse-submodules $2 tmp/$1
cd tmp/$1/$3; \
git checkout $4
cd tmp/$1/generator; \
bash generator.sh --target "internal noimstrv comments" $5
cp -f tmp/$1/$1* cwrappers/
if test -e tmp/$1/generator/output/$1*; then \
cp -f tmp/$1/generator/output/$1* cwrappers/; \
fi
mkdir cwrappers/$1_templates
cp -f tmp/$1/generator/output/*json cwrappers/$1_templates
mkdir -p cwrappers/$3
cp -rf tmp/$1/$3/* cwrappers/$3
cd tmp/$1; \
echo "$1 ($2) HEAD is on: `git rev-parse HEAD`" >> ../../cwrappers/VERSION.txt
cd tmp/$1/$3; \
echo "$1/$3 HEAD is on: `git rev-parse HEAD`" >> ../../../cwrappers/VERSION.txt
endef
.PHONY: update
update: setup
rm -rf cwrappers/*
$(call update,cimgui,https://github.com/cimgui/cimgui,imgui,docking, --cflags "glfw opengl3 opengl2 sdl2 -DIMGUI_USE_WCHAR32")
cat templates/assert.h >> cwrappers/imgui/imconfig.h
$(call cimgui)
$(call update,cimplot,https://github.com/cimgui/cimplot,implot,master)
$(call cimplot)
$(call update,cimnodes,https://github.com/cimgui/cimnodes,imnodes,master)
$(call cimnodes)
$(call update,cimmarkdown,https://github.com/gucio321/cimmarkdown,imgui_markdown,main)
$(call cimmarkdown)
$(call update,cimguizmo,https://github.com/cimgui/cimguizmo,ImGuizmo,master)
$(call cimguizmo)
$(call update,cimCTE,https://github.com/cimgui/cimcte,ImGuiColorTextEdit,master)
$(call cimcte)
$(call dummy)
# dummy creates dummy.go files to baypass GO vendor policy that excludes everything that has no .go files (including our C source).
define dummy
echo -e "//go:build required\n// +build required\n\npackage imgui\n\nimport (\n" > dummy.go
for i in `find cwrappers -type f \( -name "*.h" -o -name "*.cpp" \) -exec dirname {} \; | sort -u`; do \
cp templates/dummy.go.template $$i/dummy.go; \
echo -e "\t_ \"github.com/AllenDang/cimgui-go/$$i\"" >> dummy.go; \
done
echo ")" >> dummy.go
endef
.PHONY: dummy
dummy:
$(call dummy)