| 1 |
#!/usr/bin/env texlua |
| 2 |
|
| 3 |
-- Build script for "StrukTeX" files |
| 4 |
|
| 5 |
-- Identify the bundle and module: the module may be empty in the case where |
| 6 |
-- there is no subdivision |
| 7 |
bundle = "" |
| 8 |
module = "struktex" |
| 9 |
|
| 10 |
-- Location of main directory: use Unix-style path separators |
| 11 |
-- Should match that defined by the bundle. |
| 12 |
maindir = "." |
| 13 |
|
| 14 |
-- the files to be installed |
| 15 |
installfiles = {"*.sty"} |
| 16 |
|
| 17 |
-- the files which should not be installed |
| 18 |
excludefiles = {"*/TODO.md"} |
| 19 |
|
| 20 |
-- these files are to copy for unpackaging |
| 21 |
sourcefiles = {"*.dtx", "*.ins", "build.lua", "build-config.lua"} |
| 22 |
|
| 23 |
-- these files are part of the documentation |
| 24 |
docfiles = {"struktex.drv", "struktex.sty"} |
| 25 |
|
| 26 |
-- these files get tags |
| 27 |
tagfiles = {"*.sty"} |
| 28 |
|
| 29 |
-- this file must be TeXed to unpack all |
| 30 |
unpackfiles = {"struktex.dtx"} |
| 31 |
-- unpackopts = "-interaction=batchmode" |
| 32 |
|
| 33 |
-- create a TDS-suited .zip-file |
| 34 |
packtdszip = true |
| 35 |
|
| 36 |
-- Files to copy to unpacking when typesetting |
| 37 |
typesetsourcefiles = {"struktex.sty"} |
| 38 |
|
| 39 |
-- Files needed to support typesetting when "sandboxed"? |
| 40 |
typesetsuppfiles = {"tex-bib.bib"} |
| 41 |
|
| 42 |
-- only using the following engines for testing the code |
| 43 |
checkengines = checkengines or {"latex", "pdftex"} |
| 44 |
|
| 45 |
-- install also documentation (doesn't work, because |
| 46 |
-- there are no *.pdf-files in the unpacked directory |
| 47 |
installfiles = installfiles or {"*.pdf", "*.sty"} |
| 48 |
|
| 49 |
-- Load the common build code |
| 50 |
dofile(maindir .. "/build-config.lua") |
| 51 |
|
| 52 |
-- specific settings for the StrukTeX development repo, used by l3build script |
| 53 |
|
| 54 |
function prepare_contents(file) |
| 55 |
-- can't be set locally, so: set it back later on! |
| 56 |
typesetopts = "--output-format=dvi" |
| 57 |
tex(file) |
| 58 |
|
| 59 |
-- create .pdf-file from .dvi-source |
| 60 |
name = stripext(file) |
| 61 |
dvitopdf(name, typesetdir, typesetexe, true) |
| 62 |
run(typesetdir, "pdfcrop " .. name .. pdfext) |
| 63 |
ren(typesetdir, name .. "-crop" .. pdfext, name .. pdfext) |
| 64 |
end |
| 65 |
|
| 66 |
function print_log(log_message) |
| 67 |
print(log_message) |
| 68 |
return 0 |
| 69 |
end |
| 70 |
|
| 71 |
function typeset(file) |
| 72 |
local name = jobname(file) |
| 73 |
|
| 74 |
typesetopts = "--output-format=pdf" |
| 75 |
local errorlevel = tex(file, typesetdir) |
| 76 |
|
| 77 |
print("\ntypeset.errorlevel:", errorlevel, "\n") |
| 78 |
|
| 79 |
if errorlevel == 0 then |
| 80 |
-- Return a non-zero errorlevel if anything goes wrong |
| 81 |
print("prepare additional information") |
| 82 |
errorlevel = ( |
| 83 |
print_log("file: " .. file .. ", name: " .. name) + |
| 84 |
print_log("going to bibtex with >" .. name .. "<") + |
| 85 |
bibtex(name, typesetdir) + |
| 86 |
print_log("\nbibtex done\n") + |
| 87 |
tex(file, typesetdir) + |
| 88 |
print_log("going to makeindex with", name) + |
| 89 |
makeindex(name, typesetdir, ".idx", ".ind", ".ilg", "gind.ist") + |
| 90 |
makeindex(name, typesetdir, ".glo", ".gls", ".glg", "gglo.ist") + |
| 91 |
print_log("\nmakeindex done\n") + |
| 92 |
tex(file, typesetdir) |
| 93 |
) |
| 94 |
print_log("\ntypesetting done\n") |
| 95 |
ren(typesetdir, "struktex.pdf", "struktex." .. targetlanguage .. ".pdf") |
| 96 |
print_log("\nrenaming to struktex." .. targetlanguage .. ".pdf done\n") |
| 97 |
end |
| 98 |
|
| 99 |
return errorlevel |
| 100 |
end |
| 101 |
|
| 102 |
function setversion_update_line(line, date, release) |
| 103 |
local function get_date_release() |
| 104 |
-- get version information from git |
| 105 |
local f = io.popen("git describe", "r") |
| 106 |
local release = {} |
| 107 |
for entry in f:lines() do |
| 108 |
release[#release + 1] = entry |
| 109 |
end |
| 110 |
return os.date("%Y/%m/%d", os.time()), release[1]:sub(2, -1) |
| 111 |
end |
| 112 |
|
| 113 |
date, release = get_date_release() |
| 114 |
|
| 115 |
for _,i in pairs({"Class", "File", "Package"}) do |
| 116 |
if string.match( |
| 117 |
line, |
| 118 |
"^\\ProvidesExpl" .. i .. " *{[a-zA-Z0-9%-%.]+}" |
| 119 |
) then |
| 120 |
line = string.gsub( |
| 121 |
line, |
| 122 |
"{%d%d%d%d/%d%d/%d%d}( *){[^}]*}", |
| 123 |
"{" .. string.gsub(date, "%-", "/") .. "}%1{" .. release .. "}" |
| 124 |
) |
| 125 |
break |
| 126 |
end |
| 127 |
end |
| 128 |
return line |
| 129 |
end |
| 130 |
|
| 131 |
--### doc_init_hook begin ############################################ |
| 132 |
--[[ |
| 133 |
The git informations (commit name, commit date, commit author) |
| 134 |
must be included in the .sty files. This is done here. |
| 135 |
1. git describe --long HEAD: returns the most recent tag (HEAD |
| 136 |
can be omitted, it's the default), that's the commit name |
| 137 |
2. git --no-pager show -s --format=format:"<format>": returns |
| 138 |
the needed commit date and commit author. <format> is set |
| 139 |
up so that the three lines below are generated |
| 140 |
|
| 141 |
These informations replace the line |
| 142 |
%% git revision information |
| 143 |
by someting like |
| 144 |
\@git@ $Date: <commit date> $% |
| 145 |
$Revision: <commit name> $ |
| 146 |
%% $Author: <commit author> $ |
| 147 |
|
| 148 |
<commit date> has the format "yyyy-mm-dd hh:mm:ss +nnnn" |
| 149 |
<commit name> has the format as described in the git describe |
| 150 |
man page |
| 151 |
--]] |
| 152 |
function docinit_hook() |
| 153 |
print("now set git data") |
| 154 |
local f = io.popen('git describe --long HEAD', 'r') |
| 155 |
local commit_name = f:read "*all" |
| 156 |
commit_name = string.sub(commit_name, 1, #commit_name - 1) |
| 157 |
|
| 158 |
f = io.popen('git --no-pager show -s --format=format:"%n ' .. |
| 159 |
'\\@git@ \\$Date: %ci \\$%%%%%n \\$Revision: ' .. |
| 160 |
'<commit name> \\$%n %%%%%%%% \\$Author: %cn \\$%n"') |
| 161 |
local revision_information = f:read "*all" |
| 162 |
revision_information = string.sub(revision_information, 1, |
| 163 |
#revision_information - 1) |
| 164 |
|
| 165 |
print("commit_name: >>" .. commit_name .. "<<, Länge: " .. |
| 166 |
tostring(string.len(commit_name))) |
| 167 |
print("revision_information: " .. revision_information) |
| 168 |
|
| 169 |
revision_information = revision_information:gsub("<commit name>", commit_name) |
| 170 |
print("revision_information: " .. revision_information) |
| 171 |
|
| 172 |
filenames = {"strukdoc.sty", "struktex.sty", "struktxf.sty", "struktxp.sty"} |
| 173 |
|
| 174 |
for _, file in ipairs(filenames) do |
| 175 |
file = unpackdir .. "/" .. file |
| 176 |
print(file) |
| 177 |
|
| 178 |
local f = assert(io.open(file,"rb")) |
| 179 |
local content = f:read("*all") |
| 180 |
f:close() |
| 181 |
|
| 182 |
content = content:gsub("%%%% git revision information", |
| 183 |
revision_information) |
| 184 |
print(content) |
| 185 |
|
| 186 |
f = assert(io.open(file,"w")) |
| 187 |
f:write(content) |
| 188 |
f:close() |
| 189 |
|
| 190 |
if file == unpackdir .."/" .. "struktex.sty" then |
| 191 |
file = file:gsub(unpackdir, typesetdir) |
| 192 |
f = assert(io.open(file,"w")) |
| 193 |
f:write(content) |
| 194 |
f:close() |
| 195 |
end |
| 196 |
end |
| 197 |
|
| 198 |
-- this file is needed for the documentation but isn't automatically |
| 199 |
-- copied |
| 200 |
cp("struktex-tst-00.nss", unpackdir, typesetdir) |
| 201 |
|
| 202 |
return 0 |
| 203 |
end |
| 204 |
--### doc_init_hook end ############################################## |
| 205 |
|
| 206 |
-- Find and run the build system |
| 207 |
kpse.set_program_name("kpsewhich") |
| 208 |
if not release_date then |
| 209 |
dofile(kpse.lookup("l3build.lua")) |
| 210 |
end |
| 211 |
|
| 212 |
|