-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Rakefile
285 lines (254 loc) · 8.36 KB
/
Rakefile
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
require "pathname"
require 'rake/clean'
CLEAN.include("publisher.pdf","publisher.log","publisher.protocol","publisher.vars")
CLOBBER.include("build/sourcedoc","src/go/sp/sp","src/go/sp/docgo", "src/go/sp/bin","src/go/sp/pkg")
installdir = Pathname.new(__FILE__).join("..")
srcdir = installdir.join("src")
builddir = installdir.join("build")
ENV['GOBIN'] = installdir.join("bin").to_s
@versions = {}
File.read("version").each_line do |line|
product,versionnumber = line.chomp.split(/=/) # / <-- ignore this slash
@versions[product]=versionnumber
end
desc "Show rake description"
task :default do
puts
puts "Run 'rake -T' for a list of tasks."
puts
puts "1: Use 'rake build' to build the 'sp' binary. That should be\n the starting point."
puts "2: Then try to build the documentation by running 'rake doc'\n followed by 'sp doc' to read the documentation."
puts
end
desc "Build sphelper program"
task :sphelper do
Dir.chdir(srcdir.join("go")) do
sh "go install -ldflags \"-X main.basedir=#{installdir} -s\" speedatapublisher/sphelper/sphelper"
end
end
desc "Compile and install necessary software"
task :build => [:sphelper] do
sh "#{installdir}/bin/sphelper build"
end
desc "Compile and install helper library"
task :buildlib => [:sphelper] do
sh "#{installdir}/bin/sphelper buildlib"
FileUtils.cp_r("#{builddir}/dylib/.","#{installdir}/lib/")
end
desc "Generate EPUB only"
task :epub => [:sphelper] do
sh "#{installdir}/bin/sphelper epub"
puts "done"
end
desc "Generate documentation"
task :doc => [:sphelper] do
sh "#{installdir}/bin/sphelper doc"
puts "done"
end
# without ugly urls
desc "Generate site documentation"
task :sitedoc => [:sphelper] do
sh "#{installdir}/bin/sphelper sitedoc"
puts "done"
end
desc "Generate schema from master"
task :schema => [:sphelper] do
# generate the lua translation + schema
sh "#{installdir}/bin/sphelper genschema"
end
desc "Source documentation"
task :sourcedoc => [:sphelper] do
sh "#{installdir}/bin/sphelper sourcedoc"
if RUBY_PLATFORM =~ /darwin/
sh "open #{builddir}/sourcedoc/publisher.html"
else
puts "Generated source documentation in \n#{builddir}/sourcedoc/publisher.html"
end
end
# For now: only a small test
desc "Test source code"
task :test do
ENV["LUA_PATH"] = "#{srcdir}/lua/?.lua;#{installdir}/lib/?.lua;#{installdir}/test/?.lua"
ENV["PUBLISHER_BASE_PATH"] = installdir.to_s
ENV["LD_LIBRARY_PATH"] = "#{installdir}/lib"
inifile = srcdir.join("lua/sdini.lua")
sh "bin/sdluatex --luaonly --lua=#{inifile} --ini --shell-escape #{installdir}/bin/luatest tc_xpath.lua"
end
desc "Run quality assurance"
task :qa do
sh "#{installdir}/bin/sp compare #{installdir}/qa"
end
desc "Clean QA intermediate files"
task :cleanqa do
FileUtils.rm Dir.glob("qa/**/pagediff-*.png")
FileUtils.rm Dir.glob("qa/**/reference-*.png")
FileUtils.rm Dir.glob("qa/**/source-*.png")
FileUtils.rm Dir.glob("qa/**/publisher.vars")
FileUtils.rm Dir.glob("qa/**/publisher.status")
FileUtils.rm Dir.glob("qa/**/publisher.finished")
FileUtils.rm Dir.glob("qa/**/publisher-protocol.xml")
FileUtils.rm Dir.glob("qa/**/publisher-aux.xml")
FileUtils.rm Dir.glob("qa/**/publisher.protocol")
FileUtils.rm Dir.glob("qa/**/publisher.pdf")
FileUtils.rm Dir.glob("qa/**/compare-report.html")
end
desc "Regenerate reference.pdf for qa"
task :regenerateqa do
Dir.glob("qa/**/") do |d|
Dir.chdir(d) do
if test(?f,"layout.xml") then
sh "sp -s --jobname reference"
sh "sp --jobname reference clean"
end
end
end
end
# The environment variable LUATEX_BIN must point to a directory with the following structure
# ├── darwin
# │ ├── amd64
# │ └── 386
# ├── linux
# │ ├── amd64
# │ └── 386
# └── windows
# ├── amd64
# └── 386
#
# and each of these amd64/386 directories look like this:
# ├── 0_79_1
# │ ├── kpathsea620w64.dll
# │ ├── lua52w64.dll
# │ ├── luatex.dll
# │ ├── luatex.exe
# │ └── msvcr100.dll
# └── default -> 0_79_1/
#
# The task looks for a directory named "default" and uses the binary files in that directory
desc "Make ZIP files for all platforms and installer for windows"
task :dist => [:sphelper] do
sh "#{installdir}/bin/sphelper dist windows/amd64 linux/amd64 linux/arm64"
end
desc "Create a customized directory strcuture for distribution"
task :distcustom => [:sphelper] do
# This should be taken as a blueprint for creating your own directory
# structure. Instructions: build the sphelper binary,
# then set the environment variables, and run
# sphelper distcutom linux/amd64
# (replace the target of course)
# for building the source tree
ENV['SP_BUILDDIR_SW'] = "/tmp/build/sw"
ENV['SP_BUILDDIR_SHARE'] = "/tmp/build/share"
ENV['SP_BUILDDIR_BIN'] = "/tmp/build/bin"
# lookup paths for the executable
ENV['SP_DESTDIR_SW'] = "/usr/src/speedata-publisher"
ENV['SP_DESTDIR_SHARE'] = "/usr/share"
ENV['SP_DESTDIR_BIN'] = "/usr/bin"
sh "#{installdir}/bin/sphelper distcustom linux/amd64"
end
desc "Prepare a .deb directory"
task :deb => [:sphelper] do
srcbindir = ENV["LUATEX_BIN"] || ""
if ! test(?d,srcbindir) then
puts "Environment variable LUATEX_BIN does not exist.\nMake sure it points to a path which contains `sdluatex'.\nUse like this: rake deb LUATEX_BIN=/path/to/bin\nAborting"
next
end
publisher_version = @versions['publisher_version']
destdir = builddir.join("deb")
targetbin = destdir.join("usr","bin")
targetshare = destdir.join("usr","share")
targetfonts = targetshare.join("speedata-publisher", "fonts")
targetimg = targetshare.join("speedata-publisher", "img")
targetlib = targetshare.join("speedata-publisher", "lib")
targetschema = targetshare.join("speedata-publisher", "schema")
targetsw = targetshare.join("speedata-publisher", "sw")
rm_rf destdir
mkdir_p targetbin
mkdir_p targetfonts
mkdir_p targetimg
mkdir_p targetlib
mkdir_p targetschema
mkdir_p targetsw
platform = nil
arch = nil
execfilename = "sdluatex"
if test(?f, srcbindir +"/sdluatex") then
cp_r(srcbindir +"/sdluatex",targetbin)
else
puts "copying failed, #{srcbindir}"
next
end
cmd = "file #{targetbin}/#{execfilename}"
res = `#{cmd}`.gsub(/^.*luatex.*:/,'')
case res
when /Linux/
platform = "linux"
end
case res
when /x86-64/,/x86_64/,/64-bit/
arch = "amd64"
debarch = arch
when /32-bit/,/80386/,/i386/
arch = "386"
debarch = "i386"
end
if platform != "linux" then
puts "platform is not linux"
next
end
if !arch then
puts "Could not determine architecture (amd64/386)"
puts "This is the output of 'file':"
puts res
next
end
sh "#{installdir}/bin/sphelper builddeb #{platform} #{arch} #{targetbin}/sp"
sh "#{installdir}/bin/sphelper buildlib"
cp_r("fonts/.",targetfonts)
cp_r(Dir.glob("img/*"),targetimg)
Dir.chdir("lib") do
Dir.glob("*").reject { |x|
x =~ /libsplib|imageedit|lib/
}.each { |x|
mkdir_p(targetlib.join(File.dirname(x)))
cp(x,targetlib.join(File.dirname(x)))
}
cp_r("lib" ,targetlib)
end
cp_r(Dir.glob("#{builddir}/dylib/libsplib.so"),targetlib)
cp_r(Dir.glob("#{builddir}/dylib/luaglue.so"),targetlib)
cp_r(File.join("schema","layoutschema-en.rng"),targetschema)
cp_r(File.join("schema","layoutschema-de.rng"),targetschema)
cp_r(File.join("schema","catalog-schema-en.xml"),targetschema)
cp_r(File.join("schema","catalog-schema-de.xml"),targetschema)
cp_r(File.join("schema","layoutschema-en.xsd"),targetschema)
cp_r(File.join("schema","layoutschema-de.xsd"),targetschema)
Dir.chdir("src") do
cp_r(["tex","hyphenation","metapost"],targetsw)
# do not copy every Lua file to the dest
# and leave out .gitignore and others
Dir.glob("lua/**/*.lua").reject { |x|
x =~ /viznode|fileutils|Shopify/
}.each { |x|
mkdir_p(targetsw.join(File.dirname(x)))
cp(x,targetsw.join(File.dirname(x)))
}
end
# control-file
mkdir_p destdir.join("DEBIAN")
size = `du -ks #{destdir}/usr | cut -f 1`.chomp
File.open(destdir.join("DEBIAN","control"), "w") do |f|
f << %Q{Package: speedata-publisher
Version: #{publisher_version}
Section: text
Priority: optional
Architecture: #{debarch}
Installed-Size: #{size}
Maintainer: speedata <info@speedata.de>
Description: speedata publisher
}.gsub(/^ /,"")
end # file.open
end
desc "Show the version number"
task :publisherversion do
puts @versions['publisher_version']
end