comparison mupdf-source/thirdparty/zint/tools/update_version.php @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 <?php
2 /* Update Zint version number in various files */
3 /*
4 libzint - the open source barcode library
5 Copyright (C) 2020-2024 Robin Stuart <rstuart114@gmail.com>
6 */
7 /* SPDX-License-Identifier: BSD-3-Clause */
8
9 /* Run from project directory
10 *
11 * php tools/update_version.php ZINT_VERSION_MAJOR ZINT_VERSION_MINOR ZINT_VERSION_RELEASE [ZINT_VERSION_BUILD]
12 *
13 * e.g. before release
14 * php tools/update_version.php 3 4 5
15 * cd docs; make
16 * after release
17 * php tools/update_version.php 3 4 5 9
18 * cd docs; make
19 */
20
21 $basename = basename(__FILE__);
22 $dirname = dirname(__FILE__);
23
24 $data_dirname = $dirname . '/../';
25
26 if ($argc < 4) {
27 exit("$basename: ZINT_VERSION_MAJOR ZINT_VERSION_MINOR ZINT_VERSION_RELEASE [ZINT_VERSION_BUILD]" . PHP_EOL);
28 }
29
30 $major = $argv[1];
31 $minor = $argv[2];
32 $release = $argv[3];
33 $build = $argc > 4 ? $argv[4] : "0";
34 if (!ctype_digit($major) || !ctype_digit($minor) || !ctype_digit($release) || !ctype_digit($build)) {
35 exit("$basename: ZINT_VERSION_MAJOR ZINT_VERSION_MINOR ZINT_VERSION_RELEASE [ZINT_VERSION_BUILD] must be numeric" . PHP_EOL);
36 }
37 $major = (int) $major;
38 $minor = (int) $minor;
39 $release = (int) $release;
40 $build = (int) $build;
41 if ($major === 0) {
42 exit("$basename: ZINT_VERSION_MAJOR zero" . PHP_EOL);
43 }
44 if ($build && $build !== 9) {
45 exit("$basename: ZINT_VERSION_BUILD not 9" . PHP_EOL);
46 }
47
48 $v_base_str = $v_str = "$major.$minor.$release";
49 if ($build) {
50 $v_str .= ".$build";
51 }
52 $v_str_dev = $build ? $v_str . ' (dev)' : $v_str;
53
54 $rc_str1 = "$major,$minor,$release,$build";
55 $rc_str2 = "$major.$minor.$release.$build";
56
57 $year = date("Y");
58
59 /* `$to_do` is no. of lines that should get replaced/changed, not no. of replacements */
60 function version_replace($to_do, $file, $match_pattern, $replace_pattern, $replace_str) {
61 global $basename;
62
63 if (($get = file_get_contents($file)) === false) {
64 exit("$basename: ERROR: Could not read file \"$file\"" . PHP_EOL);
65 }
66
67 $lines = explode("\n", $get);
68 $done = 0;
69 foreach ($lines as $li => $line) {
70 if (preg_match($match_pattern, $line)) {
71 $cnt = 0;
72 $lines[$li] = preg_replace($replace_pattern, $replace_str, $line, -1, $cnt);
73 if ($cnt === 0 || $lines[$li] === NULL) {
74 exit("$basename: ERROR: Could not replace \"$match_pattern\" in file \"$file\"" . PHP_EOL);
75 }
76 $done++;
77 }
78 if ($done === $to_do) {
79 break;
80 }
81 }
82 if ($done !== $to_do) {
83 exit("$basename: ERROR: Only did $done replacements of $to_do in file \"$file\"" . PHP_EOL);
84 }
85 if (!file_put_contents($file, implode("\n", $lines))) {
86 exit("$basename: ERROR: Could not write file \"$file\"" . PHP_EOL);
87 }
88 }
89
90 function rc_replace($file, $rc_str1, $rc_str2, $year = '') {
91 global $basename;
92
93 if (($get = file_get_contents($file)) === false) {
94 exit("$basename: ERROR: Could not read file \"$file\"" . PHP_EOL);
95 }
96
97 $match_pattern1 = '/#define[ \t]+VER_FILEVERSION[ \t]+/';
98 $match_pattern2 = '/#define[ \t]+VER_FILEVERSION_STR[ \t]+/';
99 $lines = explode("\n", $get);
100 $done = 0;
101 foreach ($lines as $li => $line) {
102 if (preg_match($match_pattern1, $line)) {
103 $cnt = 0;
104 $lines[$li] = preg_replace('/[0-9,]+/', $rc_str1, $line, 1, $cnt);
105 if ($cnt === 0 || $lines[$li] === NULL) {
106 exit("$basename: ERROR: Could not replace \"$match_pattern1\" in file \"$file\"" . PHP_EOL);
107 }
108 $done++;
109 } else if (preg_match($match_pattern2, $line)) {
110 $cnt = 0;
111 $lines[$li] = preg_replace('/[0-9.]+/', $rc_str2, $line, 1, $cnt);
112 if ($cnt === 0 || $lines[$li] === NULL) {
113 exit("$basename: ERROR: Could not replace \"$match_pattern2\" in file \"$file\"" . PHP_EOL);
114 }
115 $done++;
116 }
117 if ($done === 2) {
118 break;
119 }
120 }
121 if ($done !== 2) {
122 exit("$basename: ERROR: Only did $done replacements of 2 in file \"$file\"" . PHP_EOL);
123 }
124 if ($year !== '') {
125 $match_pattern = '/VALUE[ \t]+"LegalCopyright",[ \t]+"Copyright /';
126 $done = 0;
127 foreach ($lines as $li => $line) {
128 if (preg_match($match_pattern, $line)) {
129 $cnt = 0;
130 $lines[$li] = preg_replace('/[0-9]+/', $year, $line, 1, $cnt);
131 if ($cnt === 0 || $lines[$li] === NULL) {
132 exit("$basename: ERROR: Could not replace \"$match_pattern\" in file \"$file\"" . PHP_EOL);
133 }
134 $done++;
135 break;
136 }
137 }
138 if ($done !== 1) {
139 exit("$basename: ERROR: Failed to replace Copyright year in file \"$file\"" . PHP_EOL);
140 }
141 }
142 if (!file_put_contents($file, implode("\n", $lines))) {
143 exit("$basename: ERROR: Could not write file \"$file\"" . PHP_EOL);
144 }
145 }
146
147 function year_replace($file, $year) {
148 global $basename;
149
150 if (($get = file_get_contents($file)) === false) {
151 exit("$basename: ERROR: Could not read file \"$file\"" . PHP_EOL);
152 }
153
154 $match_pattern = '/Copyright /';
155 $lines = explode("\n", $get);
156 $done = 0;
157 foreach ($lines as $li => $line) {
158 if (preg_match($match_pattern, $line)) {
159 $cnt = 0;
160 $lines[$li] = preg_replace('/[0-9]+/', $year, $line, 1, $cnt);
161 if ($cnt === 0 || $lines[$li] === NULL) {
162 exit("$basename: ERROR: Could not replace \"$match_pattern\" in file \"$file\"" . PHP_EOL);
163 }
164 $done++;
165 break;
166 }
167 }
168 if ($done !== 1) {
169 exit("$basename: ERROR: Failed to replace Copyright year in file \"$file\"" . PHP_EOL);
170 }
171 if (!file_put_contents($file, implode("\n", $lines))) {
172 exit("$basename: ERROR: Could not write file \"$file\"" . PHP_EOL);
173 }
174 }
175
176 // CMakeLists.txt
177
178 $file = $data_dirname . 'CMakeLists.txt';
179
180 if (($get = file_get_contents($file)) === false) {
181 exit("$basename: ERROR: Could not read file \"$file\"" . PHP_EOL);
182 }
183
184 $lines = explode("\n", $get);
185 $done = 0;
186 foreach ($lines as $li => $line) {
187 if (preg_match('/\(ZINT_VERSION_(MAJOR|MINOR|RELEASE|BUILD)/', $line, $matches)) {
188 $cnt = 0;
189 $mmr = $matches[1] === "MAJOR" ? $major : ($matches[1] === "MINOR" ? $minor : ($matches[1] === "RELEASE" ? $release : $build));
190 $lines[$li] = preg_replace('/[0-9]+\)/', $mmr . ')', $line, 1, $cnt);
191 if ($cnt === 0 || $lines[$li] === NULL) {
192 exit("$basename: ERROR: Could not replace ZINT_VERSION_{$matches[1]} in file \"$file\"" . PHP_EOL);
193 }
194 $done++;
195 }
196 if ($done === 4) {
197 break;
198 }
199 }
200 if ($done !== 4) {
201 exit("$basename: ERROR: Only did $done replacements of 4 in file \"$file\"" . PHP_EOL);
202 }
203 if (!file_put_contents($file, implode("\n", $lines))) {
204 exit("$basename: ERROR: Could not write file \"$file\"" . PHP_EOL);
205 }
206
207 // README
208
209 year_replace($data_dirname . 'README', $year);
210
211 // README.linux
212
213 version_replace(4, $data_dirname . 'README.linux', '/zint-[0-9]/', '/[0-9][0-9.]+/', $v_base_str);
214
215 // zint.spec
216
217 version_replace(1, $data_dirname . 'zint.spec', '/^Version:/', '/[0-9.]+/', $v_base_str);
218
219 // zint.nsi
220
221 version_replace(1, $data_dirname . 'zint.nsi', '/^!define +PRODUCT_VERSION/', '/"[0-9.]+"/', '"' . $v_str . '"');
222
223 // backend/libzint.rc
224
225 rc_replace($data_dirname . 'backend/libzint.rc', $rc_str1, $rc_str2, $year);
226
227 // backend/zint.h
228
229 version_replace(1, $data_dirname . 'backend/zint.h', '/^ \* Version: /', '/[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?( \(dev\))?/', $v_str_dev);
230
231 // backend/zintconfig.h
232
233 $file = $data_dirname . 'backend/zintconfig.h';
234
235 if (($get = file_get_contents($file)) === false) {
236 exit("$basename: ERROR: Could not read file \"$file\"" . PHP_EOL);
237 }
238
239 $lines = explode("\n", $get);
240 $done = 0;
241 foreach ($lines as $li => $line) {
242 if (preg_match('/define[ \t]+ZINT_VERSION_(MAJOR|MINOR|RELEASE)[ \t]+/', $line, $matches)) {
243 $cnt = 0;
244 $mmr = $matches[1] === "MAJOR" ? $major : ($matches[1] === "MINOR" ? $minor : $release);
245 $lines[$li] = preg_replace('/[0-9]+/', $mmr, $line, 1, $cnt);
246 if ($cnt === 0 || $lines[$li] === NULL) {
247 exit("$basename: ERROR: Could not replace ZINT_VERSION_{$matches[1]} in file \"$file\"" . PHP_EOL);
248 }
249 $done++;
250 } elseif (preg_match('/define[ \t]+ZINT_VERSION_BUILD[ \t]+/', $line)) {
251 $cnt = 0;
252 $lines[$li] = preg_replace('/(BUILD[ \t]+)[0-9]+/', '${1}' . $build, $line, 1, $cnt);
253 if ($cnt === 0 || $lines[$li] === NULL) {
254 exit("$basename: ERROR: Could not replace ZINT_VERSION_BUILD in file \"$file\"" . PHP_EOL);
255 }
256 $done++;
257 }
258 if ($done === 4) {
259 break;
260 }
261 }
262 if ($done !== 4) {
263 exit("$basename: ERROR: Only did $done replacements of 4 in file \"$file\"" . PHP_EOL);
264 }
265 if (!file_put_contents($file, implode("\n", $lines))) {
266 exit("$basename: ERROR: Could not write file \"$file\"" . PHP_EOL);
267 }
268
269 // backend/Makefile.mingw
270
271 version_replace(1, $data_dirname . 'backend/Makefile.mingw', '/^ZINT_VERSION:=-DZINT_VERSION=/', '/[0-9.]+/', $v_str);
272
273 // backend_tcl/configure.ac
274
275 version_replace(1, $data_dirname . 'backend_tcl/configure.ac', '/^AC_INIT\(\[zint\],[ \t]*\[/', '/[0-9.]+/', $v_base_str);
276
277 // backend_tcl/zint_tcl.dsp
278
279 version_replace(2, $data_dirname . 'backend_tcl/zint_tcl.dsp', '/ZINT_VERSION="\\\\"/', '/ZINT_VERSION="\\\\"[0-9.]+\\\\""/', 'ZINT_VERSION="\\"' . $v_str . '\\""');
280
281 // backend_tcl/lib/zint/pkgIndex.tcl
282
283 version_replace(1, $data_dirname . 'backend_tcl/lib/zint/pkgIndex.tcl', '/zint /', '/zint [0-9.]+/', 'zint ' . $v_base_str . '');
284
285 // backend_tcl/licence.txt
286
287 year_replace($data_dirname . 'backend_tcl/licence.txt', $year);
288
289 // frontend/zint.rc
290
291 rc_replace($data_dirname . 'frontend/zint.rc', $rc_str1, $rc_str2, $year);
292
293 // frontend/Makefile.mingw
294
295 version_replace(1, $data_dirname . 'frontend/Makefile.mingw', '/^ZINT_VERSION:=-DZINT_VERSION=/', '/[0-9.]+/', $v_str);
296
297 // backend_qt/backend_vc8.pro
298
299 version_replace(1, $data_dirname . 'backend_qt/backend_vc8.pro', '/^VERSION[ \t]*=/', '/[0-9.]+/', $v_str);
300 -
301 // backend_qt/backend_qt.pro
302
303 version_replace(1, $data_dirname . 'backend_qt/backend_qt.pro', '/ZINT_VERSION="/', '/[0-9.]+/', $v_str);
304 version_replace(1, $data_dirname . 'backend_qt/backend_qt.pro', '/^VERSION[ \t]*=/', '/[0-9.]+/', $v_str);
305
306 // docs/manual.pmd
307
308 version_replace(1, $data_dirname . 'docs/manual.pmd', '/^% Version /', '/[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?( \(dev\))?/', $v_str);
309 version_replace(1, $data_dirname . 'docs/manual.pmd', '/^The current stable version of Zint/', '/[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?/', $v_base_str);
310
311 // docs/zint.1.pmd
312
313 version_replace(1, $data_dirname . 'docs/zint.1.pmd', '/^% ZINT\(1\) Version /', '/[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?( \(dev\))?/', $v_str);
314
315 // frontend_qt/res/qtZint.rc
316
317 rc_replace($data_dirname . 'frontend_qt/res/qtZint.rc', $rc_str1, $rc_str2, $year);
318
319 // win32/libzint.vcxproj
320
321 version_replace(2, $data_dirname . 'win32/libzint.vcxproj', '/ZINT_VERSION="/', '/ZINT_VERSION="[0-9.]+"/', 'ZINT_VERSION="' . $v_str . '"');
322
323 // win32/zint.vcxproj
324
325 version_replace(2, $data_dirname . 'win32/zint.vcxproj', '/ZINT_VERSION="/', '/ZINT_VERSION="[0-9.]+"/', 'ZINT_VERSION="' . $v_str . '"');
326
327 // win32/zint_cmdline_vc6/zint.rc
328
329 rc_replace($data_dirname . 'win32/zint_cmdline_vc6/zint.rc', $rc_str1, $rc_str2, $year);
330
331 // win32/zint_cmdline_vc6/zint_cmdline_vc6.dsp
332
333 version_replace(2, $data_dirname . 'win32/zint_cmdline_vc6/zint_cmdline_vc6.dsp', '/ZINT_VERSION="/', '/ZINT_VERSION="\\\\"[0-9.]+\\\\""/', 'ZINT_VERSION="\\"' . $v_str . '\\""');
334
335 // win32/vs2008/libzint.vcproj
336
337 version_replace(2, $data_dirname . 'win32/vs2008/libzint.vcproj', '/ZINT_VERSION=&quot;/', '/&quot;[0-9.]+/', '&quot;' . $v_str);
338
339 // win32/vs2008/zint.vcproj
340
341 version_replace(2, $data_dirname . 'win32/vs2008/zint.vcproj', '/ZINT_VERSION=&quot;/', '/&quot;[0-9.]+/', '&quot;' . $v_str);
342
343 // win32/vs2015/libzint.vcxproj
344
345 version_replace(6, $data_dirname . 'win32/vs2015/libzint.vcxproj', '/ZINT_VERSION="/', '/ZINT_VERSION="[0-9.]+"/', 'ZINT_VERSION="' . $v_str . '"');
346
347 // win32/vs2015/zint.vcxproj
348
349 version_replace(6, $data_dirname . 'win32/vs2015/zint.vcxproj', '/ZINT_VERSION="/', '/ZINT_VERSION="[0-9.]+"/', 'ZINT_VERSION="' . $v_str . '"');
350
351 // win32/vs2017/libzint.vcxproj
352
353 version_replace(2, $data_dirname . 'win32/vs2017/libzint.vcxproj', '/ZINT_VERSION="/', '/ZINT_VERSION="[0-9.]+"/', 'ZINT_VERSION="' . $v_str . '"');
354
355 // win32/vs2017/zint.vcxproj
356
357 version_replace(2, $data_dirname . 'win32/vs2017/zint.vcxproj', '/ZINT_VERSION="/', '/ZINT_VERSION="[0-9.]+"/', 'ZINT_VERSION="' . $v_str . '"');
358
359 // win32/vs2019/libzint.vcxproj
360
361 version_replace(2, $data_dirname . 'win32/vs2019/libzint.vcxproj', '/ZINT_VERSION="/', '/ZINT_VERSION="[0-9.]+"/', 'ZINT_VERSION="' . $v_str . '"');
362
363 // win32/vs2019/zint.vcxproj
364
365 version_replace(2, $data_dirname . 'win32/vs2019/zint.vcxproj', '/ZINT_VERSION="/', '/ZINT_VERSION="[0-9.]+"/', 'ZINT_VERSION="' . $v_str . '"');
366
367 // Leaving auto-generated files:
368 // backend_tcl/configure (PACKAGE_VERSION and PACKAGE_STRING) - generated by autoconf from configure.ac
369 // frontend_qt/Inno_Setup_qtzint.iss (MyAppVersion)
370
371 print PHP_EOL;
372 print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' . PHP_EOL;
373 print '!!! REMEMBER: update release date in manual and man page !!!' . PHP_EOL;
374 print '!!! REMEMBER: cd docs; make !!!' . PHP_EOL;
375 print '!!! REMEMBER: run "autoconf" and "./configure" in "backend_tcl/" !!!' . PHP_EOL;
376 print '!!! REMEMBER: update version and date in "ChangeLog" !!!' . PHP_EOL;
377 print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' . PHP_EOL;
378 print PHP_EOL;
379
380 /* vim: set ts=4 sw=4 et : */