Skip to content

Commit b956c50

Browse files
committed
Add libtommath 1.3.0
1 parent 1be3202 commit b956c50

File tree

7 files changed

+540
-0
lines changed

7 files changed

+540
-0
lines changed

ci_config.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,16 @@
778778
"windows": false
779779
}
780780
},
781+
"libtommath": {
782+
"_comment": "MSVC build fails because it doesn't optimize away unreachable code leaving undefined symbols.",
783+
"build_options": [
784+
"libtommath:tests=true",
785+
"libtommath:buildtype=release"
786+
],
787+
"build_on": {
788+
"windows": false
789+
}
790+
},
781791
"libupnp": {
782792
"_comment": "Requires some special pthread library",
783793
"build_on": {

releases.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,6 +2459,14 @@
24592459
"1.17-1"
24602460
]
24612461
},
2462+
"libtommath": {
2463+
"dependency_names": [
2464+
"libtommath"
2465+
],
2466+
"versions": [
2467+
"1.3.0-1"
2468+
]
2469+
},
24622470
"libunibreak": {
24632471
"dependency_names": [
24642472
"libunibreak"

subprojects/libtommath.wrap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[wrap-file]
2+
directory = libtommath-1.3.0
3+
source_url = https://github.com/libtom/libtommath/releases/download/v1.3.0/ltm-1.3.0.tar.xz
4+
source_filename = libtommath-1.3.0.tar.xz
5+
source_hash = 296272d93435991308eb73607600c034b558807a07e829e751142e65ccfa9d08
6+
patch_directory = libtommath
7+
8+
[provide]
9+
dependency_names = libtommath
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env python3
2+
"""Build the libtommath PDF manual from LaTeX sources
3+
4+
This script is called by meson with the following environment variables set:
5+
LATEX, PDFLATEX, MAKEINDEX
6+
7+
Only requires standard Python library - no external tools beyond LaTeX itself.
8+
"""
9+
10+
import os
11+
import sys
12+
import shutil
13+
import subprocess
14+
import re
15+
from datetime import datetime, timezone
16+
17+
18+
def main():
19+
if len(sys.argv) != 4:
20+
print("Usage: build-manual.py INPUT OUTDIR OUTPUT", file=sys.stderr)
21+
sys.exit(1)
22+
23+
input_file = sys.argv[1]
24+
outdir = sys.argv[2]
25+
output_file = sys.argv[3]
26+
27+
# Get tools from environment
28+
latex = os.environ.get('LATEX', 'latex')
29+
pdflatex = os.environ.get('PDFLATEX', 'pdflatex')
30+
makeindex = os.environ.get('MAKEINDEX', 'makeindex')
31+
32+
# Convert paths to absolute before changing directories
33+
input_file = os.path.abspath(input_file)
34+
output_file = os.path.abspath(output_file)
35+
36+
# Change to output directory
37+
os.chdir(outdir)
38+
39+
# Copy input to bn.tex
40+
shutil.copy2(input_file, 'bn.tex')
41+
42+
# Create backup with same timestamp
43+
shutil.copy2('bn.tex', 'bn.bak')
44+
45+
# Get modification time of bn.tex and format for PDF
46+
mtime = os.stat('bn.tex').st_mtime
47+
dt = datetime.fromtimestamp(mtime, tz=timezone.utc)
48+
49+
# Format as PDF date string: D:YYYYMMDDHHmmSS+HH'mm'
50+
# For UTC, timezone offset is +00'00'
51+
date_str = dt.strftime("D:%Y%m%d%H%M%S+00'00'")
52+
53+
# Write deterministic PDF header
54+
with open('bn-deterministic.tex', 'w') as f:
55+
f.write(f"\\def\\fixedpdfdate{{{date_str}}}\n")
56+
f.write("\\pdfinfo{\n")
57+
f.write(" /CreationDate (\\fixedpdfdate)\n")
58+
f.write(" /ModDate (\\fixedpdfdate)\n")
59+
f.write("}\n")
60+
61+
# Append original content
62+
with open('bn.tex', 'r') as orig:
63+
f.write(orig.read())
64+
65+
# Replace bn.tex with deterministic version
66+
shutil.move('bn-deterministic.tex', 'bn.tex')
67+
68+
# Restore original timestamp
69+
shutil.copystat('bn.bak', 'bn.tex')
70+
71+
# Build the manual
72+
with open('bn.ind', 'w') as f:
73+
f.write('hello\n')
74+
75+
subprocess.run([latex, 'bn'], stdout=subprocess.DEVNULL, check=True)
76+
subprocess.run([latex, 'bn'], stdout=subprocess.DEVNULL, check=True)
77+
subprocess.run([makeindex, 'bn'], check=True)
78+
subprocess.run([latex, 'bn'], stdout=subprocess.DEVNULL, check=True)
79+
subprocess.run([pdflatex, 'bn'], stdout=subprocess.DEVNULL, check=True)
80+
81+
# Make PDF ID deterministic using Python
82+
with open('bn.pdf', 'rb') as f:
83+
pdf_data = f.read()
84+
85+
# Replace /ID [<...> <...>] with /ID [<0> <0>]
86+
pdf_data = re.sub(rb'^/ID \[.*\]$', rb'/ID [<0> <0>]', pdf_data, flags=re.MULTILINE)
87+
88+
with open('bn.pdf', 'wb') as f:
89+
f.write(pdf_data)
90+
91+
# Rename to desired output name
92+
shutil.move('bn.pdf', output_file)
93+
94+
# Cleanup
95+
shutil.move('bn.bak', 'bn.tex')
96+
97+
cleanup_files = [
98+
'bn.aux', 'bn.dvi', 'bn.log', 'bn.idx',
99+
'bn.lof', 'bn.out', 'bn.toc', 'bn.ilg',
100+
'bn.ind', 'bn.tex'
101+
]
102+
for f in cleanup_files:
103+
try:
104+
os.remove(f)
105+
except FileNotFoundError:
106+
pass
107+
108+
109+
if __name__ == '__main__':
110+
main()

0 commit comments

Comments
 (0)