.. | .. |
---|
1 | | -#!/usr/bin/perl |
---|
| 1 | +#!/usr/bin/env perl |
---|
| 2 | +# SPDX-License-Identifier: GPL-2.0-or-later |
---|
2 | 3 | use strict; |
---|
3 | 4 | |
---|
4 | | -# Copyright (c) 2017 Mauro Carvalho Chehab <mchehab@kernel.org> |
---|
| 5 | +# Copyright (c) 2017-2020 Mauro Carvalho Chehab <mchehab@kernel.org> |
---|
5 | 6 | # |
---|
6 | | -# This program is free software; you can redistribute it and/or |
---|
7 | | -# modify it under the terms of the GNU General Public License |
---|
8 | | -# as published by the Free Software Foundation; either version 2 |
---|
9 | | -# of the License, or (at your option) any later version. |
---|
10 | | -# |
---|
11 | | -# This program is distributed in the hope that it will be useful, |
---|
12 | | -# but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | | -# GNU General Public License for more details. |
---|
15 | 7 | |
---|
16 | | -my $virtenv_dir = "sphinx_1.4"; |
---|
17 | | -my $requirement_file = "Documentation/sphinx/requirements.txt"; |
---|
| 8 | +my $prefix = "./"; |
---|
| 9 | +$prefix = "$ENV{'srctree'}/" if ($ENV{'srctree'}); |
---|
| 10 | + |
---|
| 11 | +my $conf = $prefix . "Documentation/conf.py"; |
---|
| 12 | +my $requirement_file = $prefix . "Documentation/sphinx/requirements.txt"; |
---|
| 13 | +my $virtenv_prefix = "sphinx_"; |
---|
18 | 14 | |
---|
19 | 15 | # |
---|
20 | 16 | # Static vars |
---|
.. | .. |
---|
26 | 22 | my $optional = 0; |
---|
27 | 23 | my $need_symlink = 0; |
---|
28 | 24 | my $need_sphinx = 0; |
---|
| 25 | +my $need_venv = 0; |
---|
| 26 | +my $need_virtualenv = 0; |
---|
| 27 | +my $rec_sphinx_upgrade = 0; |
---|
29 | 28 | my $install = ""; |
---|
| 29 | +my $virtenv_dir = ""; |
---|
| 30 | +my $python_cmd = ""; |
---|
| 31 | +my $min_version; |
---|
| 32 | +my $cur_version; |
---|
| 33 | +my $rec_version = "1.7.9"; # PDF won't build here |
---|
| 34 | +my $min_pdf_version = "2.4.4"; # Min version where pdf builds |
---|
30 | 35 | |
---|
31 | 36 | # |
---|
32 | 37 | # Command line arguments |
---|
.. | .. |
---|
34 | 39 | |
---|
35 | 40 | my $pdf = 1; |
---|
36 | 41 | my $virtualenv = 1; |
---|
| 42 | +my $version_check = 0; |
---|
37 | 43 | |
---|
38 | 44 | # |
---|
39 | 45 | # List of required texlive packages on Fedora and OpenSuse |
---|
.. | .. |
---|
70 | 76 | 'ucs.sty' => 'texlive-ucs', |
---|
71 | 77 | 'upquote.sty' => 'texlive-upquote', |
---|
72 | 78 | 'wrapfig.sty' => 'texlive-wrapfig', |
---|
| 79 | + 'ctexhook.sty' => 'texlive-ctex', |
---|
73 | 80 | ); |
---|
74 | 81 | |
---|
75 | 82 | # |
---|
.. | .. |
---|
82 | 89 | |
---|
83 | 90 | foreach my $prog (sort keys %missing) { |
---|
84 | 91 | my $is_optional = $missing{$prog}; |
---|
| 92 | + |
---|
| 93 | + # At least on some LTS distros like CentOS 7, texlive doesn't |
---|
| 94 | + # provide all packages we need. When such distros are |
---|
| 95 | + # detected, we have to disable PDF output. |
---|
| 96 | + # |
---|
| 97 | + # So, we need to ignore the packages that distros would |
---|
| 98 | + # need for LaTeX to work |
---|
| 99 | + if ($is_optional == 2 && !$pdf) { |
---|
| 100 | + $optional--; |
---|
| 101 | + next; |
---|
| 102 | + } |
---|
85 | 103 | |
---|
86 | 104 | if ($is_optional) { |
---|
87 | 105 | print "Warning: better to also install \"$prog\".\n"; |
---|
.. | .. |
---|
113 | 131 | |
---|
114 | 132 | sub check_missing_file($$$) |
---|
115 | 133 | { |
---|
116 | | - my $file = shift; |
---|
| 134 | + my $files = shift; |
---|
117 | 135 | my $package = shift; |
---|
118 | 136 | my $is_optional = shift; |
---|
119 | 137 | |
---|
120 | | - return if(-e $file); |
---|
| 138 | + for (@$files) { |
---|
| 139 | + return if(-e $_); |
---|
| 140 | + } |
---|
121 | 141 | |
---|
122 | 142 | add_package($package, $is_optional); |
---|
123 | 143 | } |
---|
.. | .. |
---|
129 | 149 | } |
---|
130 | 150 | } |
---|
131 | 151 | |
---|
| 152 | +sub find_python_no_venv() |
---|
| 153 | +{ |
---|
| 154 | + my $prog = shift; |
---|
| 155 | + |
---|
| 156 | + my $cur_dir = qx(pwd); |
---|
| 157 | + $cur_dir =~ s/\s+$//; |
---|
| 158 | + |
---|
| 159 | + foreach my $dir (split(/:/, $ENV{PATH})) { |
---|
| 160 | + next if ($dir =~ m,($cur_dir)/sphinx,); |
---|
| 161 | + return "$dir/python3" if(-x "$dir/python3"); |
---|
| 162 | + } |
---|
| 163 | + foreach my $dir (split(/:/, $ENV{PATH})) { |
---|
| 164 | + next if ($dir =~ m,($cur_dir)/sphinx,); |
---|
| 165 | + return "$dir/python" if(-x "$dir/python"); |
---|
| 166 | + } |
---|
| 167 | + return "python"; |
---|
| 168 | +} |
---|
| 169 | + |
---|
132 | 170 | sub check_program($$) |
---|
133 | 171 | { |
---|
134 | 172 | my $prog = shift; |
---|
135 | 173 | my $is_optional = shift; |
---|
136 | 174 | |
---|
137 | | - return if findprog($prog); |
---|
| 175 | + return $prog if findprog($prog); |
---|
138 | 176 | |
---|
139 | 177 | add_package($prog, $is_optional); |
---|
140 | 178 | } |
---|
.. | .. |
---|
155 | 193 | my $prog = shift; |
---|
156 | 194 | my $is_optional = shift; |
---|
157 | 195 | |
---|
158 | | - my $err = system("python3 -c 'import $prog' 2>/dev/null /dev/null"); |
---|
159 | | - return if ($err == 0); |
---|
160 | | - my $err = system("python -c 'import $prog' 2>/dev/null /dev/null"); |
---|
| 196 | + return if (!$python_cmd); |
---|
| 197 | + |
---|
| 198 | + my $err = system("$python_cmd -c 'import $prog' 2>/dev/null /dev/null"); |
---|
161 | 199 | return if ($err == 0); |
---|
162 | 200 | |
---|
163 | 201 | add_package($prog, $is_optional); |
---|
.. | .. |
---|
201 | 239 | } |
---|
202 | 240 | } |
---|
203 | 241 | |
---|
| 242 | +sub get_sphinx_fname() |
---|
| 243 | +{ |
---|
| 244 | + my $fname = "sphinx-build"; |
---|
| 245 | + return $fname if findprog($fname); |
---|
| 246 | + |
---|
| 247 | + $fname = "sphinx-build-3"; |
---|
| 248 | + if (findprog($fname)) { |
---|
| 249 | + $need_symlink = 1; |
---|
| 250 | + return $fname; |
---|
| 251 | + } |
---|
| 252 | + |
---|
| 253 | + return ""; |
---|
| 254 | +} |
---|
| 255 | + |
---|
| 256 | +sub get_sphinx_version($) |
---|
| 257 | +{ |
---|
| 258 | + my $cmd = shift; |
---|
| 259 | + my $ver; |
---|
| 260 | + |
---|
| 261 | + open IN, "$cmd --version 2>&1 |"; |
---|
| 262 | + while (<IN>) { |
---|
| 263 | + if (m/^\s*sphinx-build\s+([\d\.]+)(\+\/[\da-f]+)?$/) { |
---|
| 264 | + $ver=$1; |
---|
| 265 | + last; |
---|
| 266 | + } |
---|
| 267 | + # Sphinx 1.2.x uses a different format |
---|
| 268 | + if (m/^\s*Sphinx.*\s+([\d\.]+)$/) { |
---|
| 269 | + $ver=$1; |
---|
| 270 | + last; |
---|
| 271 | + } |
---|
| 272 | + } |
---|
| 273 | + close IN; |
---|
| 274 | + return $ver; |
---|
| 275 | +} |
---|
| 276 | + |
---|
204 | 277 | sub check_sphinx() |
---|
205 | 278 | { |
---|
206 | | - return if findprog("sphinx-build"); |
---|
| 279 | + my $default_version; |
---|
207 | 280 | |
---|
208 | | - if (findprog("sphinx-build-3")) { |
---|
209 | | - $need_symlink = 1; |
---|
| 281 | + open IN, $conf or die "Can't open $conf"; |
---|
| 282 | + while (<IN>) { |
---|
| 283 | + if (m/^\s*needs_sphinx\s*=\s*[\'\"]([\d\.]+)[\'\"]/) { |
---|
| 284 | + $min_version=$1; |
---|
| 285 | + last; |
---|
| 286 | + } |
---|
| 287 | + } |
---|
| 288 | + close IN; |
---|
| 289 | + |
---|
| 290 | + die "Can't get needs_sphinx version from $conf" if (!$min_version); |
---|
| 291 | + |
---|
| 292 | + open IN, $requirement_file or die "Can't open $requirement_file"; |
---|
| 293 | + while (<IN>) { |
---|
| 294 | + if (m/^\s*Sphinx\s*==\s*([\d\.]+)$/) { |
---|
| 295 | + $default_version=$1; |
---|
| 296 | + last; |
---|
| 297 | + } |
---|
| 298 | + } |
---|
| 299 | + close IN; |
---|
| 300 | + |
---|
| 301 | + die "Can't get default sphinx version from $requirement_file" if (!$default_version); |
---|
| 302 | + |
---|
| 303 | + $virtenv_dir = $virtenv_prefix . $default_version; |
---|
| 304 | + |
---|
| 305 | + my $sphinx = get_sphinx_fname(); |
---|
| 306 | + if ($sphinx eq "") { |
---|
| 307 | + $need_sphinx = 1; |
---|
210 | 308 | return; |
---|
211 | 309 | } |
---|
212 | 310 | |
---|
213 | | - if ($virtualenv) { |
---|
214 | | - my $prog = findprog("virtualenv-3"); |
---|
215 | | - $prog = findprog("virtualenv-3.5") if (!$prog); |
---|
| 311 | + $cur_version = get_sphinx_version($sphinx); |
---|
| 312 | + die ("$sphinx returned an error") if (!$cur_version); |
---|
216 | 313 | |
---|
217 | | - check_program("virtualenv", 0) if (!$prog); |
---|
| 314 | + die "$sphinx didn't return its version" if (!$cur_version); |
---|
| 315 | + |
---|
| 316 | + if ($cur_version lt $min_version) { |
---|
| 317 | + printf "ERROR: Sphinx version is %s. It should be >= %s (recommended >= %s)\n", |
---|
| 318 | + $cur_version, $min_version, $default_version; |
---|
218 | 319 | $need_sphinx = 1; |
---|
219 | | - } else { |
---|
220 | | - add_package("python-sphinx", 0); |
---|
| 320 | + return; |
---|
221 | 321 | } |
---|
| 322 | + |
---|
| 323 | + if ($cur_version lt $rec_version) { |
---|
| 324 | + $rec_sphinx_upgrade = 1; |
---|
| 325 | + return; |
---|
| 326 | + } |
---|
| 327 | + |
---|
| 328 | + # On version check mode, just assume Sphinx has all mandatory deps |
---|
| 329 | + exit (0) if ($version_check); |
---|
222 | 330 | } |
---|
223 | 331 | |
---|
224 | 332 | # |
---|
.. | .. |
---|
253 | 361 | my %map = ( |
---|
254 | 362 | "python-sphinx" => "python3-sphinx", |
---|
255 | 363 | "sphinx_rtd_theme" => "python3-sphinx-rtd-theme", |
---|
| 364 | + "ensurepip" => "python3-venv", |
---|
256 | 365 | "virtualenv" => "virtualenv", |
---|
257 | 366 | "dot" => "graphviz", |
---|
258 | 367 | "convert" => "imagemagick", |
---|
.. | .. |
---|
262 | 371 | ); |
---|
263 | 372 | |
---|
264 | 373 | if ($pdf) { |
---|
265 | | - check_missing_file("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", |
---|
266 | | - "fonts-dejavu", 1); |
---|
| 374 | + check_missing_file(["/usr/share/texlive/texmf-dist/tex/latex/ctex/ctexhook.sty"], |
---|
| 375 | + "texlive-lang-chinese", 2); |
---|
| 376 | + |
---|
| 377 | + check_missing_file(["/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"], |
---|
| 378 | + "fonts-dejavu", 2); |
---|
| 379 | + |
---|
| 380 | + check_missing_file(["/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc", |
---|
| 381 | + "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", |
---|
| 382 | + "/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc"], |
---|
| 383 | + "fonts-noto-cjk", 2); |
---|
267 | 384 | } |
---|
268 | 385 | |
---|
269 | | - check_program("dvipng", 1) if ($pdf); |
---|
| 386 | + check_program("dvipng", 2) if ($pdf); |
---|
270 | 387 | check_missing(\%map); |
---|
271 | 388 | |
---|
272 | 389 | return if (!$need && !$optional); |
---|
.. | .. |
---|
293 | 410 | my @fedora_tex_pkgs = ( |
---|
294 | 411 | "texlive-collection-fontsrecommended", |
---|
295 | 412 | "texlive-collection-latex", |
---|
| 413 | + "texlive-xecjk", |
---|
296 | 414 | "dejavu-sans-fonts", |
---|
297 | 415 | "dejavu-serif-fonts", |
---|
298 | 416 | "dejavu-sans-mono-fonts", |
---|
.. | .. |
---|
301 | 419 | # |
---|
302 | 420 | # Checks valid for RHEL/CentOS version 7.x. |
---|
303 | 421 | # |
---|
| 422 | + my $old = 0; |
---|
| 423 | + my $rel; |
---|
| 424 | + $rel = $1 if ($system_release =~ /release\s+(\d+)/); |
---|
| 425 | + |
---|
304 | 426 | if (!($system_release =~ /Fedora/)) { |
---|
305 | 427 | $map{"virtualenv"} = "python-virtualenv"; |
---|
| 428 | + |
---|
| 429 | + if ($rel && $rel < 8) { |
---|
| 430 | + $old = 1; |
---|
| 431 | + $pdf = 0; |
---|
| 432 | + |
---|
| 433 | + printf("Note: texlive packages on RHEL/CENTOS <= 7 are incomplete. Can't support PDF output\n"); |
---|
| 434 | + printf("If you want to build PDF, please read:\n"); |
---|
| 435 | + printf("\thttps://www.systutorials.com/241660/how-to-install-tex-live-on-centos-7-linux/\n"); |
---|
| 436 | + } |
---|
| 437 | + } else { |
---|
| 438 | + if ($rel && $rel < 26) { |
---|
| 439 | + $old = 1; |
---|
| 440 | + } |
---|
| 441 | + } |
---|
| 442 | + if (!$rel) { |
---|
| 443 | + printf("Couldn't identify release number\n"); |
---|
| 444 | + $old = 1; |
---|
| 445 | + $pdf = 0; |
---|
306 | 446 | } |
---|
307 | 447 | |
---|
308 | | - my $release; |
---|
| 448 | + if ($pdf) { |
---|
| 449 | + check_missing_file(["/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc"], |
---|
| 450 | + "google-noto-sans-cjk-ttc-fonts", 2); |
---|
| 451 | + } |
---|
309 | 452 | |
---|
310 | | - $release = $1 if ($system_release =~ /Fedora\s+release\s+(\d+)/); |
---|
311 | | - |
---|
312 | | - check_rpm_missing(\@fedora26_opt_pkgs, 1) if ($pdf && $release >= 26); |
---|
313 | | - check_rpm_missing(\@fedora_tex_pkgs, 1) if ($pdf); |
---|
314 | | - check_missing_tex(1) if ($pdf); |
---|
| 453 | + check_rpm_missing(\@fedora26_opt_pkgs, 2) if ($pdf && !$old); |
---|
| 454 | + check_rpm_missing(\@fedora_tex_pkgs, 2) if ($pdf); |
---|
| 455 | + check_missing_tex(2) if ($pdf); |
---|
315 | 456 | check_missing(\%map); |
---|
316 | 457 | |
---|
317 | 458 | return if (!$need && !$optional); |
---|
318 | 459 | |
---|
319 | | - if ($release >= 18) { |
---|
| 460 | + if (!$old) { |
---|
320 | 461 | # dnf, for Fedora 18+ |
---|
321 | 462 | printf("You should run:\n\n\tsudo dnf install -y $install\n"); |
---|
322 | 463 | } else { |
---|
.. | .. |
---|
335 | 476 | "convert" => "ImageMagick", |
---|
336 | 477 | "Pod::Usage" => "perl-Pod-Usage", |
---|
337 | 478 | "xelatex" => "texlive-xetex-bin", |
---|
338 | | - "rsvg-convert" => "rsvg-view", |
---|
339 | 479 | ); |
---|
| 480 | + |
---|
| 481 | + # On Tumbleweed, this package is also named rsvg-convert |
---|
| 482 | + $map{"rsvg-convert"} = "rsvg-view" if (!($system_release =~ /Tumbleweed/)); |
---|
340 | 483 | |
---|
341 | 484 | my @suse_tex_pkgs = ( |
---|
342 | 485 | "texlive-babel-english", |
---|
.. | .. |
---|
355 | 498 | "texlive-zapfding", |
---|
356 | 499 | ); |
---|
357 | 500 | |
---|
358 | | - check_rpm_missing(\@suse_tex_pkgs, 1) if ($pdf); |
---|
359 | | - check_missing_tex(1) if ($pdf); |
---|
| 501 | + $map{"latexmk"} = "texlive-latexmk-bin"; |
---|
| 502 | + |
---|
| 503 | + # FIXME: add support for installing CJK fonts |
---|
| 504 | + # |
---|
| 505 | + # I tried hard, but was unable to find a way to install |
---|
| 506 | + # "Noto Sans CJK SC" on openSUSE |
---|
| 507 | + |
---|
| 508 | + check_rpm_missing(\@suse_tex_pkgs, 2) if ($pdf); |
---|
| 509 | + check_missing_tex(2) if ($pdf); |
---|
360 | 510 | check_missing(\%map); |
---|
361 | 511 | |
---|
362 | 512 | return if (!$need && !$optional); |
---|
.. | .. |
---|
373 | 523 | "convert" => "ImageMagick", |
---|
374 | 524 | "Pod::Usage" => "perl-Pod-Usage", |
---|
375 | 525 | "xelatex" => "texlive", |
---|
376 | | - "rsvg-convert" => "librsvg2-tools", |
---|
| 526 | + "rsvg-convert" => "librsvg2", |
---|
377 | 527 | ); |
---|
378 | 528 | |
---|
379 | 529 | my @tex_pkgs = ( |
---|
380 | 530 | "texlive-fontsextra", |
---|
381 | 531 | ); |
---|
382 | 532 | |
---|
383 | | - check_rpm_missing(\@tex_pkgs, 1) if ($pdf); |
---|
| 533 | + $map{"latexmk"} = "texlive-collection-basic"; |
---|
| 534 | + |
---|
| 535 | + my $packager_cmd; |
---|
| 536 | + my $noto_sans; |
---|
| 537 | + if ($system_release =~ /OpenMandriva/) { |
---|
| 538 | + $packager_cmd = "dnf install"; |
---|
| 539 | + $noto_sans = "noto-sans-cjk-fonts"; |
---|
| 540 | + @tex_pkgs = ( "texlive-collection-fontsextra" ); |
---|
| 541 | + } else { |
---|
| 542 | + $packager_cmd = "urpmi"; |
---|
| 543 | + $noto_sans = "google-noto-sans-cjk-ttc-fonts"; |
---|
| 544 | + } |
---|
| 545 | + |
---|
| 546 | + |
---|
| 547 | + if ($pdf) { |
---|
| 548 | + check_missing_file(["/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc", |
---|
| 549 | + "/usr/share/fonts/TTF/NotoSans-Regular.ttf"], |
---|
| 550 | + $noto_sans, 2); |
---|
| 551 | + } |
---|
| 552 | + |
---|
| 553 | + check_rpm_missing(\@tex_pkgs, 2) if ($pdf); |
---|
384 | 554 | check_missing(\%map); |
---|
385 | 555 | |
---|
386 | 556 | return if (!$need && !$optional); |
---|
387 | | - printf("You should run:\n\n\tsudo urpmi $install\n"); |
---|
| 557 | + printf("You should run:\n\n\tsudo $packager_cmd $install\n"); |
---|
388 | 558 | } |
---|
389 | 559 | |
---|
390 | 560 | sub give_arch_linux_hints() |
---|
.. | .. |
---|
395 | 565 | "dot" => "graphviz", |
---|
396 | 566 | "convert" => "imagemagick", |
---|
397 | 567 | "xelatex" => "texlive-bin", |
---|
| 568 | + "latexmk" => "texlive-core", |
---|
398 | 569 | "rsvg-convert" => "extra/librsvg", |
---|
399 | 570 | ); |
---|
400 | 571 | |
---|
.. | .. |
---|
403 | 574 | "texlive-latexextra", |
---|
404 | 575 | "ttf-dejavu", |
---|
405 | 576 | ); |
---|
406 | | - check_pacman_missing(\@archlinux_tex_pkgs, 1) if ($pdf); |
---|
| 577 | + check_pacman_missing(\@archlinux_tex_pkgs, 2) if ($pdf); |
---|
| 578 | + |
---|
| 579 | + if ($pdf) { |
---|
| 580 | + check_missing_file(["/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc"], |
---|
| 581 | + "noto-fonts-cjk", 2); |
---|
| 582 | + } |
---|
| 583 | + |
---|
407 | 584 | check_missing(\%map); |
---|
408 | 585 | |
---|
409 | 586 | return if (!$need && !$optional); |
---|
.. | .. |
---|
421 | 598 | "rsvg-convert" => "gnome-base/librsvg", |
---|
422 | 599 | ); |
---|
423 | 600 | |
---|
424 | | - check_missing_file("/usr/share/fonts/dejavu/DejaVuSans.ttf", |
---|
425 | | - "media-fonts/dejavu", 1) if ($pdf); |
---|
| 601 | + check_missing_file(["/usr/share/fonts/dejavu/DejaVuSans.ttf"], |
---|
| 602 | + "media-fonts/dejavu", 2) if ($pdf); |
---|
| 603 | + |
---|
| 604 | + if ($pdf) { |
---|
| 605 | + check_missing_file(["/usr/share/fonts/noto-cjk/NotoSansCJKsc-Regular.otf", |
---|
| 606 | + "/usr/share/fonts/noto-cjk/NotoSerifCJK-Regular.ttc"], |
---|
| 607 | + "media-fonts/noto-cjk", 2); |
---|
| 608 | + } |
---|
426 | 609 | |
---|
427 | 610 | check_missing(\%map); |
---|
428 | 611 | |
---|
429 | 612 | return if (!$need && !$optional); |
---|
430 | 613 | |
---|
431 | 614 | printf("You should run:\n\n"); |
---|
432 | | - printf("\tsudo su -c 'echo \"media-gfx/imagemagick svg png\" > /etc/portage/package.use/imagemagick'\n"); |
---|
433 | | - printf("\tsudo su -c 'echo \"media-gfx/graphviz cairo pdf\" > /etc/portage/package.use/graphviz'\n"); |
---|
| 615 | + |
---|
| 616 | + my $imagemagick = "media-gfx/imagemagick svg png"; |
---|
| 617 | + my $cairo = "media-gfx/graphviz cairo pdf"; |
---|
| 618 | + my $portage_imagemagick = "/etc/portage/package.use/imagemagick"; |
---|
| 619 | + my $portage_cairo = "/etc/portage/package.use/graphviz"; |
---|
| 620 | + |
---|
| 621 | + if (qx(grep imagemagick $portage_imagemagick 2>/dev/null) eq "") { |
---|
| 622 | + printf("\tsudo su -c 'echo \"$imagemagick\" > $portage_imagemagick'\n") |
---|
| 623 | + } |
---|
| 624 | + if (qx(grep graphviz $portage_cairo 2>/dev/null) eq "") { |
---|
| 625 | + printf("\tsudo su -c 'echo \"$cairo\" > $portage_cairo'\n"); |
---|
| 626 | + } |
---|
| 627 | + |
---|
434 | 628 | printf("\tsudo emerge --ask $install\n"); |
---|
435 | 629 | |
---|
436 | 630 | } |
---|
.. | .. |
---|
474 | 668 | give_mageia_hints; |
---|
475 | 669 | return; |
---|
476 | 670 | } |
---|
| 671 | + if ($system_release =~ /OpenMandriva/) { |
---|
| 672 | + give_mageia_hints; |
---|
| 673 | + return; |
---|
| 674 | + } |
---|
477 | 675 | if ($system_release =~ /Arch Linux/) { |
---|
478 | 676 | give_arch_linux_hints; |
---|
479 | 677 | return; |
---|
.. | .. |
---|
490 | 688 | my %map = ( |
---|
491 | 689 | "sphinx-build" => "sphinx" |
---|
492 | 690 | ); |
---|
493 | | - check_missing_tex(1) if ($pdf); |
---|
| 691 | + check_missing_tex(2) if ($pdf); |
---|
494 | 692 | check_missing(\%map); |
---|
495 | 693 | print "I don't know distro $system_release.\n"; |
---|
496 | 694 | print "So, I can't provide you a hint with the install procedure.\n"; |
---|
.. | .. |
---|
501 | 699 | # Common dependencies |
---|
502 | 700 | # |
---|
503 | 701 | |
---|
| 702 | +sub deactivate_help() |
---|
| 703 | +{ |
---|
| 704 | + printf "\nIf you want to exit the virtualenv, you can use:\n"; |
---|
| 705 | + printf "\tdeactivate\n"; |
---|
| 706 | +} |
---|
| 707 | + |
---|
504 | 708 | sub check_needs() |
---|
505 | 709 | { |
---|
| 710 | + # Check if Sphinx is already accessible from current environment |
---|
| 711 | + check_sphinx(); |
---|
| 712 | + |
---|
506 | 713 | if ($system_release) { |
---|
507 | 714 | print "Detected OS: $system_release.\n"; |
---|
508 | 715 | } else { |
---|
509 | 716 | print "Unknown OS\n"; |
---|
510 | 717 | } |
---|
| 718 | + printf "Sphinx version: %s\n\n", $cur_version if ($cur_version); |
---|
511 | 719 | |
---|
512 | | - # RHEL 7.x and clones have Sphinx version 1.1.x and incomplete texlive |
---|
513 | | - if (($system_release =~ /Red Hat Enterprise Linux/) || |
---|
514 | | - ($system_release =~ /CentOS/) || |
---|
515 | | - ($system_release =~ /Scientific Linux/) || |
---|
516 | | - ($system_release =~ /Oracle Linux Server/)) { |
---|
517 | | - $virtualenv = 1; |
---|
518 | | - $pdf = 0; |
---|
| 720 | + # Check python command line, trying first python3 |
---|
| 721 | + $python_cmd = findprog("python3"); |
---|
| 722 | + $python_cmd = check_program("python", 0) if (!$python_cmd); |
---|
519 | 723 | |
---|
520 | | - printf("NOTE: On this distro, Sphinx and TexLive shipped versions are incompatible\n"); |
---|
521 | | - printf("with doc build. So, use Sphinx via a Python virtual environment.\n\n"); |
---|
522 | | - printf("This script can't install a TexLive version that would provide PDF.\n"); |
---|
| 724 | + # Check the type of virtual env, depending on Python version |
---|
| 725 | + if ($python_cmd) { |
---|
| 726 | + if ($virtualenv) { |
---|
| 727 | + my $tmp = qx($python_cmd --version 2>&1); |
---|
| 728 | + if ($tmp =~ m/(\d+\.)(\d+\.)/) { |
---|
| 729 | + if ($1 >= 3 && $2 >= 3) { |
---|
| 730 | + $need_venv = 1; # python 3.3 or upper |
---|
| 731 | + } else { |
---|
| 732 | + $need_virtualenv = 1; |
---|
| 733 | + } |
---|
| 734 | + if ($1 < 3) { |
---|
| 735 | + # Complain if it finds python2 (or worse) |
---|
| 736 | + printf "Warning: python$1 support is deprecated. Use it with caution!\n"; |
---|
| 737 | + } |
---|
| 738 | + } else { |
---|
| 739 | + die "Warning: couldn't identify $python_cmd version!"; |
---|
| 740 | + } |
---|
| 741 | + } else { |
---|
| 742 | + add_package("python-sphinx", 0); |
---|
| 743 | + } |
---|
| 744 | + } |
---|
| 745 | + |
---|
| 746 | + # Set virtualenv command line, if python < 3.3 |
---|
| 747 | + my $virtualenv_cmd; |
---|
| 748 | + if ($need_virtualenv) { |
---|
| 749 | + $virtualenv_cmd = findprog("virtualenv-3"); |
---|
| 750 | + $virtualenv_cmd = findprog("virtualenv-3.5") if (!$virtualenv_cmd); |
---|
| 751 | + if (!$virtualenv_cmd) { |
---|
| 752 | + check_program("virtualenv", 0); |
---|
| 753 | + $virtualenv_cmd = "virtualenv"; |
---|
| 754 | + } |
---|
523 | 755 | } |
---|
524 | 756 | |
---|
525 | 757 | # Check for needed programs/tools |
---|
526 | | - check_sphinx(); |
---|
527 | 758 | check_perl_module("Pod::Usage", 0); |
---|
528 | 759 | check_program("make", 0); |
---|
529 | 760 | check_program("gcc", 0); |
---|
530 | 761 | check_python_module("sphinx_rtd_theme", 1) if (!$virtualenv); |
---|
531 | | - check_program("xelatex", 1) if ($pdf); |
---|
532 | 762 | check_program("dot", 1); |
---|
533 | 763 | check_program("convert", 1); |
---|
534 | | - check_program("rsvg-convert", 1) if ($pdf); |
---|
535 | 764 | |
---|
| 765 | + # Extra PDF files - should use 2 for is_optional |
---|
| 766 | + check_program("xelatex", 2) if ($pdf); |
---|
| 767 | + check_program("rsvg-convert", 2) if ($pdf); |
---|
| 768 | + check_program("latexmk", 2) if ($pdf); |
---|
| 769 | + |
---|
| 770 | + if ($need_sphinx || $rec_sphinx_upgrade) { |
---|
| 771 | + check_python_module("ensurepip", 0) if ($need_venv); |
---|
| 772 | + } |
---|
| 773 | + |
---|
| 774 | + # Do distro-specific checks and output distro-install commands |
---|
536 | 775 | check_distros(); |
---|
537 | 776 | |
---|
| 777 | + if (!$python_cmd) { |
---|
| 778 | + if ($need == 1) { |
---|
| 779 | + die "Can't build as $need mandatory dependency is missing"; |
---|
| 780 | + } elsif ($need) { |
---|
| 781 | + die "Can't build as $need mandatory dependencies are missing"; |
---|
| 782 | + } |
---|
| 783 | + } |
---|
| 784 | + |
---|
| 785 | + # Check if sphinx-build is called sphinx-build-3 |
---|
538 | 786 | if ($need_symlink) { |
---|
539 | 787 | printf "\tsudo ln -sf %s /usr/bin/sphinx-build\n\n", |
---|
540 | 788 | which("sphinx-build-3"); |
---|
541 | 789 | } |
---|
542 | | - if ($need_sphinx) { |
---|
543 | | - my $activate = "$virtenv_dir/bin/activate"; |
---|
544 | | - if (-e "$ENV{'PWD'}/$activate") { |
---|
545 | | - printf "\nNeed to activate virtualenv with:\n"; |
---|
546 | | - printf "\t. $activate\n"; |
---|
547 | | - } else { |
---|
548 | | - my $virtualenv = findprog("virtualenv-3"); |
---|
549 | | - $virtualenv = findprog("virtualenv-3.5") if (!$virtualenv); |
---|
550 | | - $virtualenv = findprog("virtualenv") if (!$virtualenv); |
---|
551 | | - $virtualenv = "virtualenv" if (!$virtualenv); |
---|
552 | 790 | |
---|
553 | | - printf "\t$virtualenv $virtenv_dir\n"; |
---|
554 | | - printf "\t. $activate\n"; |
---|
| 791 | + # NOTE: if the system has a too old Sphinx version installed, |
---|
| 792 | + # it will recommend installing a newer version using virtualenv |
---|
| 793 | + |
---|
| 794 | + if ($need_sphinx || $rec_sphinx_upgrade) { |
---|
| 795 | + my $min_activate = "$ENV{'PWD'}/${virtenv_prefix}${min_version}/bin/activate"; |
---|
| 796 | + my @activates = glob "$ENV{'PWD'}/${virtenv_prefix}*/bin/activate"; |
---|
| 797 | + |
---|
| 798 | + if ($cur_version lt $rec_version) { |
---|
| 799 | + print "Warning: It is recommended at least Sphinx version $rec_version.\n"; |
---|
| 800 | + print " If you want pdf, you need at least $min_pdf_version.\n"; |
---|
| 801 | + } |
---|
| 802 | + if ($cur_version lt $min_pdf_version) { |
---|
| 803 | + print "Note: It is recommended at least Sphinx version $min_pdf_version if you need PDF support.\n"; |
---|
| 804 | + } |
---|
| 805 | + @activates = sort {$b cmp $a} @activates; |
---|
| 806 | + my ($activate, $ver); |
---|
| 807 | + foreach my $f (@activates) { |
---|
| 808 | + next if ($f lt $min_activate); |
---|
| 809 | + |
---|
| 810 | + my $sphinx_cmd = $f; |
---|
| 811 | + $sphinx_cmd =~ s/activate/sphinx-build/; |
---|
| 812 | + next if (! -f $sphinx_cmd); |
---|
| 813 | + |
---|
| 814 | + $ver = get_sphinx_version($sphinx_cmd); |
---|
| 815 | + if ($need_sphinx && ($ver ge $min_version)) { |
---|
| 816 | + $activate = $f; |
---|
| 817 | + last; |
---|
| 818 | + } elsif ($ver gt $cur_version) { |
---|
| 819 | + $activate = $f; |
---|
| 820 | + last; |
---|
| 821 | + } |
---|
| 822 | + } |
---|
| 823 | + if ($activate ne "") { |
---|
| 824 | + if ($need_sphinx) { |
---|
| 825 | + printf "\nNeed to activate Sphinx (version $ver) on virtualenv with:\n"; |
---|
| 826 | + printf "\t. $activate\n"; |
---|
| 827 | + deactivate_help(); |
---|
| 828 | + exit (1); |
---|
| 829 | + } else { |
---|
| 830 | + printf "\nYou may also use a newer Sphinx (version $ver) with:\n"; |
---|
| 831 | + printf "\tdeactivate && . $activate\n"; |
---|
| 832 | + } |
---|
| 833 | + } else { |
---|
| 834 | + my $rec_activate = "$virtenv_dir/bin/activate"; |
---|
| 835 | + |
---|
| 836 | + print "To upgrade Sphinx, use:\n\n" if ($rec_sphinx_upgrade); |
---|
| 837 | + |
---|
| 838 | + $python_cmd = find_python_no_venv(); |
---|
| 839 | + |
---|
| 840 | + if ($need_venv) { |
---|
| 841 | + printf "\t$python_cmd -m venv $virtenv_dir\n"; |
---|
| 842 | + } else { |
---|
| 843 | + printf "\t$virtualenv_cmd $virtenv_dir\n"; |
---|
| 844 | + } |
---|
| 845 | + printf "\t. $rec_activate\n"; |
---|
555 | 846 | printf "\tpip install -r $requirement_file\n"; |
---|
556 | | - $need++; |
---|
| 847 | + deactivate_help(); |
---|
| 848 | + |
---|
| 849 | + $need++ if (!$rec_sphinx_upgrade); |
---|
557 | 850 | } |
---|
558 | 851 | } |
---|
559 | 852 | printf "\n"; |
---|
560 | 853 | |
---|
561 | | - print "All optional dependenties are met.\n" if (!$optional); |
---|
| 854 | + print "All optional dependencies are met.\n" if (!$optional); |
---|
562 | 855 | |
---|
563 | 856 | if ($need == 1) { |
---|
564 | 857 | die "Can't build as $need mandatory dependency is missing"; |
---|
.. | .. |
---|
580 | 873 | $virtualenv = 0; |
---|
581 | 874 | } elsif ($arg eq "--no-pdf"){ |
---|
582 | 875 | $pdf = 0; |
---|
| 876 | + } elsif ($arg eq "--version-check"){ |
---|
| 877 | + $version_check = 1; |
---|
583 | 878 | } else { |
---|
584 | | - print "Usage:\n\t$0 <--no-virtualenv> <--no-pdf>\n\n"; |
---|
| 879 | + print "Usage:\n\t$0 <--no-virtualenv> <--no-pdf> <--version-check>\n\n"; |
---|
| 880 | + print "Where:\n"; |
---|
| 881 | + print "\t--no-virtualenv\t- Recommend installing Sphinx instead of using a virtualenv\n"; |
---|
| 882 | + print "\t--version-check\t- if version is compatible, don't check for missing dependencies\n"; |
---|
| 883 | + print "\t--no-pdf\t- don't check for dependencies required to build PDF docs\n\n"; |
---|
585 | 884 | exit -1; |
---|
586 | 885 | } |
---|
587 | 886 | } |
---|
.. | .. |
---|
602 | 901 | $system_release = catcheck("/etc/redhat-release") if !$system_release; |
---|
603 | 902 | $system_release = catcheck("/etc/lsb-release") if !$system_release; |
---|
604 | 903 | $system_release = catcheck("/etc/gentoo-release") if !$system_release; |
---|
| 904 | + |
---|
| 905 | +# This seems more common than LSB these days |
---|
| 906 | +if (!$system_release) { |
---|
| 907 | + my %os_var; |
---|
| 908 | + if (open IN, "cat /etc/os-release|") { |
---|
| 909 | + while (<IN>) { |
---|
| 910 | + if (m/^([\w\d\_]+)=\"?([^\"]*)\"?\n/) { |
---|
| 911 | + $os_var{$1}=$2; |
---|
| 912 | + } |
---|
| 913 | + } |
---|
| 914 | + $system_release = $os_var{"NAME"}; |
---|
| 915 | + if (defined($os_var{"VERSION_ID"})) { |
---|
| 916 | + $system_release .= " " . $os_var{"VERSION_ID"} if (defined($os_var{"VERSION_ID"})); |
---|
| 917 | + } else { |
---|
| 918 | + $system_release .= " " . $os_var{"VERSION"}; |
---|
| 919 | + } |
---|
| 920 | + } |
---|
| 921 | +} |
---|
605 | 922 | $system_release = catcheck("/etc/issue") if !$system_release; |
---|
606 | 923 | $system_release =~ s/\s+$//; |
---|
607 | 924 | |
---|