1 |
commit: 502631b86d63c4604b0ed78ad86a054e9726e897 |
2 |
Author: Sam James <sam <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Nov 2 00:37:57 2022 +0000 |
4 |
Commit: Sam James <sam <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Nov 2 00:38:55 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=502631b8 |
7 |
|
8 |
meson: include generated man pages in dist tarballs |
9 |
|
10 |
Meson doesn't have an idiomatic way of doing this (for once!) |
11 |
so we have to (per Eli Schwartz, thanks!) have: |
12 |
1. a dist script which duplicates the build rule; |
13 |
2. some meson.build if/else logic with fs.exists() to prefer the built manpage when using tarballs |
14 |
|
15 |
Sadly, still can't easily regenerate man pages if |
16 |
you apply a patch downstream though. |
17 |
|
18 |
We use Michael Stapelberg's example from the linked bug as inspiration. |
19 |
|
20 |
Bug: https://github.com/mesonbuild/meson/issues/2166 |
21 |
Reported-by: psykose <alice <AT> ayaya.dev> |
22 |
Thanks-to: Eli Schwartz <eschwartz <AT> archlinux.org> |
23 |
Signed-off-by: Sam James <sam <AT> gentoo.org> |
24 |
|
25 |
man/meson.build | 37 ++++++++++++++++++++++++------------- |
26 |
meson-build-dist-man.sh | 12 ++++++++++++ |
27 |
meson.build | 2 ++ |
28 |
3 files changed, 38 insertions(+), 13 deletions(-) |
29 |
|
30 |
diff --git a/man/meson.build b/man/meson.build |
31 |
index 2e346ec..130c8ec 100644 |
32 |
--- a/man/meson.build |
33 |
+++ b/man/meson.build |
34 |
@@ -18,20 +18,31 @@ pages = [ |
35 |
'dumpelf.docbook', 'pspax.docbook', 'scanelf.docbook', 'scanmacho.docbook' |
36 |
] |
37 |
|
38 |
+fs = import('fs') |
39 |
+ |
40 |
out_pages = [] |
41 |
+generated_man_pages_exist = true |
42 |
foreach page : pages |
43 |
- out_pages += page.replace('.docbook', '.1') |
44 |
+ man_page_name = page.replace('.docbook', '.1') |
45 |
+ out_pages += man_page_name |
46 |
+ if not fs.exists(man_page_name) |
47 |
+ generated_man_pages_exist = false |
48 |
+ endif |
49 |
endforeach |
50 |
|
51 |
-custom_target('docbook_to_man', |
52 |
- command : [ |
53 |
- xmlto, '-x', files('custom.xsl'), '--skip-validation', |
54 |
- '-o', meson.current_build_dir(), 'man', book |
55 |
- ], |
56 |
- input : [ |
57 |
- 'pax-utils.docbook.in', 'custom.xsl', 'fragment/reftail', |
58 |
- ] + pages, |
59 |
- output : out_pages, |
60 |
- install : true, |
61 |
- install_dir : get_option('mandir') / 'man1' |
62 |
-) |
63 |
+if generated_man_pages_exist |
64 |
+ install_man(out_pages) |
65 |
+else |
66 |
+ custom_target('docbook_to_man', |
67 |
+ command : [ |
68 |
+ xmlto, '-x', files('custom.xsl'), '--skip-validation', |
69 |
+ '-o', meson.current_build_dir(), 'man', book |
70 |
+ ], |
71 |
+ input : [ |
72 |
+ 'pax-utils.docbook.in', 'custom.xsl', 'fragment/reftail', |
73 |
+ ] + pages, |
74 |
+ output : out_pages, |
75 |
+ install : true, |
76 |
+ install_dir : get_option('mandir') / 'man1' |
77 |
+ ) |
78 |
+endif |
79 |
|
80 |
diff --git a/meson-build-dist-man.sh b/meson-build-dist-man.sh |
81 |
new file mode 100755 |
82 |
index 0000000..699a380 |
83 |
--- /dev/null |
84 |
+++ b/meson-build-dist-man.sh |
85 |
@@ -0,0 +1,12 @@ |
86 |
+#!/bin/sh |
87 |
+# This script should be invoked by meson itself (via 'meson dist') |
88 |
+# See https://github.com/mesonbuild/meson/issues/2166 and more specifically, |
89 |
+# https://github.com/mesonbuild/meson/issues/2166#issuecomment-629696911. |
90 |
+set -eu |
91 |
+ |
92 |
+cd "${MESON_DIST_ROOT}" |
93 |
+mkdir build |
94 |
+meson setup build -Dbuild_manpages=enabled |
95 |
+meson compile -C build |
96 |
+cp build/man/* man/ |
97 |
+rm -rf build |
98 |
|
99 |
diff --git a/meson.build b/meson.build |
100 |
index 0ee2630..0054ba4 100644 |
101 |
--- a/meson.build |
102 |
+++ b/meson.build |
103 |
@@ -138,6 +138,8 @@ install_data('symtree.sh', |
104 |
|
105 |
subdir('man') |
106 |
|
107 |
+meson.add_dist_script('meson-build-dist-man.sh') |
108 |
+ |
109 |
do_tests = get_option('tests') |
110 |
if do_tests |
111 |
subdir('tests/lddtree') |