-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.ninja
213 lines (161 loc) · 7.61 KB
/
build.ninja
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# Ninja file generated by bang (https://cdelord.fr/bang)
# bang build.lua -o build.ninja
# Panda
#
# Targets:
# help show this help message
# compile Bundle Panda into a single Lua script
# all Compile, test and generate documentation
# test Run Panda tests
# doc Generate Panda documentation
# install install Panda in PREFIX or ~/.local
# clean clean generated files
# mrproper clean generated files and more
# Files installed in bin
# .build/bin/panda.lua
# .build/bin/panda
ninja_required_version = 1.11.1
######################################################################
# This file is part of Panda.
#
# Panda is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Panda is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Panda. If not, see <https://www.gnu.org/licenses/>.
#
# For further information about Panda you can visit
# http://cdelord.fr/panda
######################################################################
builddir = .build
plantuml_version = 1.2024.6
plantuml_url = https://github.com/plantuml/plantuml/releases/download/v$plantuml_version/plantuml-$plantuml_version.jar
ditaa_version = 0.11.0
ditaa_url = https://github.com/stathissideris/ditaa/releases/download/v$ditaa_version/ditaa-${ditaa_version}-standalone.jar
######################################################################
# Compilation
######################################################################
rule _builddir_src__PANDA_VERSION.lua
description = VERSION $out
command = echo "return [[$$(git describe --tags)]] --@LOAD" > $out
build $builddir/src/_PANDA_VERSION.lua: _builddir_src__PANDA_VERSION.lua | .git/refs/tags .git/index
rule luax-lua
description = luax-lua $out
command = luax compile -t lua $in -o $out -q
build $builddir/bin/panda.lua: luax-lua src/panda.lua $builddir/src/_PANDA_VERSION.lua
rule cp
description = cp $out
command = cp -d --preserve=mode $in $out
build $builddir/bin/panda: cp src/panda
######################################################################
# Tests
######################################################################
rule diff
description = DIFF $in
command = diff $in > $out || (cat $out && false)
build $builddir/test/test.md.diff: diff $builddir/test/test.md test/test_result.md
build $builddir/test/test.md.d.diff: diff $builddir/test/test.md.d test/test.md.d
rule _builddir_test_test.md
description = PANDOC $in
command = export PLANTUML=$builddir/plantuml.jar; export DITAA=$builddir/ditaa.jar; export LUA_PATH=test/?.lua; export PANDA_IMG=$builddir/img; pandoc -L $builddir/bin/panda.lua -Vpanda_target=$out -Vbuild=$builddir --standalone $in -o $out
build $builddir/test/test.md | $builddir/test/test.md.d: _builddir_test_test.md test/test.md | $builddir/plantuml.jar $builddir/ditaa.jar $builddir/bin/panda.lua |@ $builddir/test/test.md.diff $builddir/test/test.md.d.diff
######################################################################
# PlantUML
######################################################################
rule _builddir_plantuml.jar
description = WGET $out
command = wget $plantuml_url -O $out
build $builddir/plantuml.jar: _builddir_plantuml.jar
######################################################################
# Ditaa
######################################################################
rule _builddir_ditaa.jar
description = WGET $out
command = wget $ditaa_url -O $out
build $builddir/ditaa.jar: _builddir_ditaa.jar
######################################################################
# Documentation
######################################################################
css = $builddir/doc/cdelord.css
rule README.md
description = PANDOC $out
command = export PLANTUML=$builddir/plantuml.jar; export DITAA=$builddir/ditaa.jar; pandoc -L $builddir/bin/panda.lua -Vpanda_target=$out -Vpanda_dep_file=$depfile -Vdoc=doc --to=gfm $in -o $out
depfile = $builddir/doc/$out.d
build README.md: README.md doc/panda.md | $builddir/bin/panda.lua $builddir/plantuml.jar $builddir/ditaa.jar
rule _builddir_doc_panda.html
description = PANDOC $out
command = export PLANTUML=$builddir/plantuml.jar; export DITAA=$builddir/ditaa.jar; pandoc -L $builddir/bin/panda.lua -Vpanda_target=$out -Vpanda_dep_file=$depfile -Vdoc=doc --to=html5 --standalone --embed-resources --css=$css $in -o $out
depfile = $out.d
build $builddir/doc/panda.html: _builddir_doc_panda.html doc/panda.md | $builddir/bin/panda.lua $builddir/plantuml.jar $builddir/ditaa.jar $css
rule _css
description = WGET $out
command = wget http://cdelord.fr/cdelord.css -O $out
build $css: _css
######################################################################
# Shortcuts
######################################################################
build compile: phony $builddir/bin/panda.lua $builddir/bin/panda
build all: phony compile test doc
build test: phony $builddir/test/test.md
build doc: phony README.md $builddir/doc/panda.html
default compile
######################################################################
# Installation
######################################################################
prefix = ~/.local
rule install-bin
description = INSTALL $in to bin
command = install -v -D -t $${PREFIX:-$prefix}/bin $in
build install-bin: install-bin $builddir/bin/panda.lua $builddir/bin/panda
build install: phony install-bin
######################################################################
# Clean
######################################################################
rule clean-_builddir_src
description = CLEAN $builddir/src
command = rm -rf $builddir/src
build clean-_builddir_src: clean-_builddir_src
rule clean-_builddir_bin
description = CLEAN $builddir/bin
command = rm -rf $builddir/bin
build clean-_builddir_bin: clean-_builddir_bin
build clean: phony clean-_builddir_src clean-_builddir_bin
######################################################################
# Clean (mrproper)
######################################################################
rule mrproper-_builddir
description = CLEAN $builddir
command = rm -rf $builddir/*
build mrproper-_builddir: mrproper-_builddir
build mrproper: phony clean mrproper-_builddir
######################################################################
# Help
######################################################################
rule help
description = help
command = echo "Panda"; $
echo ""; $
echo "Targets:"; $
echo " help show this help message"; $
echo " compile Bundle Panda into a single Lua script"; $
echo " all Compile, test and generate documentation"; $
echo " test Run Panda tests"; $
echo " doc Generate Panda documentation"; $
echo " install install Panda in PREFIX or ~/.local"; $
echo " clean clean generated files"; $
echo " mrproper clean generated files and more"
build help: help
######################################################################
# Regenerate build.ninja when build.lua changes
######################################################################
rule bang
command = bang $in -o $out
generator = true
build build.ninja: bang build.lua