Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 1 | #!/usr/bin/perl |
Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0-or-later |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 3 | use strict; |
| 4 | |
Mauro Carvalho Chehab | 2f9c502 | 2020-04-14 18:56:13 +0200 | [diff] [blame] | 5 | # Copyright (c) 2017-2020 Mauro Carvalho Chehab <mchehab@kernel.org> |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 6 | # |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 7 | |
Mike Rapoport | 8c69b77 | 2019-06-24 08:25:07 +0300 | [diff] [blame] | 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"; |
Mauro Carvalho Chehab | 44f4216 | 2019-05-29 20:09:24 -0300 | [diff] [blame] | 13 | my $virtenv_prefix = "sphinx_"; |
Mauro Carvalho Chehab | 5be3318 | 2017-07-17 18:46:37 -0300 | [diff] [blame] | 14 | |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 15 | # |
| 16 | # Static vars |
| 17 | # |
| 18 | |
| 19 | my %missing; |
| 20 | my $system_release; |
| 21 | my $need = 0; |
| 22 | my $optional = 0; |
| 23 | my $need_symlink = 0; |
| 24 | my $need_sphinx = 0; |
Mauro Carvalho Chehab | 2f9c502 | 2020-04-14 18:56:13 +0200 | [diff] [blame] | 25 | my $need_venv = 0; |
| 26 | my $need_virtualenv = 0; |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 27 | my $rec_sphinx_upgrade = 0; |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 28 | my $install = ""; |
Mauro Carvalho Chehab | 44f4216 | 2019-05-29 20:09:24 -0300 | [diff] [blame] | 29 | my $virtenv_dir = ""; |
Mauro Carvalho Chehab | 2f9c502 | 2020-04-14 18:56:13 +0200 | [diff] [blame] | 30 | my $python_cmd = ""; |
Mauro Carvalho Chehab | 44f4216 | 2019-05-29 20:09:24 -0300 | [diff] [blame] | 31 | my $min_version; |
Mauro Carvalho Chehab | 2834a74 | 2020-04-21 16:31:07 +0200 | [diff] [blame^] | 32 | my $cur_version; |
Mauro Carvalho Chehab | 1ef70ce | 2020-04-21 16:31:06 +0200 | [diff] [blame] | 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 |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 35 | |
| 36 | # |
| 37 | # Command line arguments |
| 38 | # |
| 39 | |
| 40 | my $pdf = 1; |
| 41 | my $virtualenv = 1; |
Mauro Carvalho Chehab | 9b88ad5 | 2019-05-29 20:09:26 -0300 | [diff] [blame] | 42 | my $version_check = 0; |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 43 | |
| 44 | # |
| 45 | # List of required texlive packages on Fedora and OpenSuse |
| 46 | # |
| 47 | |
| 48 | my %texlive = ( |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 49 | 'amsfonts.sty' => 'texlive-amsfonts', |
| 50 | 'amsmath.sty' => 'texlive-amsmath', |
| 51 | 'amssymb.sty' => 'texlive-amsfonts', |
| 52 | 'amsthm.sty' => 'texlive-amscls', |
| 53 | 'anyfontsize.sty' => 'texlive-anyfontsize', |
| 54 | 'atbegshi.sty' => 'texlive-oberdiek', |
| 55 | 'bm.sty' => 'texlive-tools', |
| 56 | 'capt-of.sty' => 'texlive-capt-of', |
| 57 | 'cmap.sty' => 'texlive-cmap', |
| 58 | 'ecrm1000.tfm' => 'texlive-ec', |
| 59 | 'eqparbox.sty' => 'texlive-eqparbox', |
| 60 | 'eu1enc.def' => 'texlive-euenc', |
| 61 | 'fancybox.sty' => 'texlive-fancybox', |
| 62 | 'fancyvrb.sty' => 'texlive-fancyvrb', |
| 63 | 'float.sty' => 'texlive-float', |
| 64 | 'fncychap.sty' => 'texlive-fncychap', |
| 65 | 'footnote.sty' => 'texlive-mdwtools', |
| 66 | 'framed.sty' => 'texlive-framed', |
| 67 | 'luatex85.sty' => 'texlive-luatex85', |
| 68 | 'multirow.sty' => 'texlive-multirow', |
| 69 | 'needspace.sty' => 'texlive-needspace', |
| 70 | 'palatino.sty' => 'texlive-psnfss', |
| 71 | 'parskip.sty' => 'texlive-parskip', |
| 72 | 'polyglossia.sty' => 'texlive-polyglossia', |
| 73 | 'tabulary.sty' => 'texlive-tabulary', |
| 74 | 'threeparttable.sty' => 'texlive-threeparttable', |
| 75 | 'titlesec.sty' => 'texlive-titlesec', |
| 76 | 'ucs.sty' => 'texlive-ucs', |
| 77 | 'upquote.sty' => 'texlive-upquote', |
| 78 | 'wrapfig.sty' => 'texlive-wrapfig', |
| 79 | ); |
| 80 | |
| 81 | # |
| 82 | # Subroutines that checks if a feature exists |
| 83 | # |
| 84 | |
| 85 | sub check_missing(%) |
| 86 | { |
| 87 | my %map = %{$_[0]}; |
| 88 | |
| 89 | foreach my $prog (sort keys %missing) { |
| 90 | my $is_optional = $missing{$prog}; |
| 91 | |
Mauro Carvalho Chehab | 56e5a63 | 2019-07-13 09:37:16 -0300 | [diff] [blame] | 92 | # At least on some LTS distros like CentOS 7, texlive doesn't |
| 93 | # provide all packages we need. When such distros are |
| 94 | # detected, we have to disable PDF output. |
| 95 | # |
| 96 | # So, we need to ignore the packages that distros would |
| 97 | # need for LaTeX to work |
| 98 | if ($is_optional == 2 && !$pdf) { |
| 99 | $optional--; |
| 100 | next; |
| 101 | } |
| 102 | |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 103 | if ($is_optional) { |
| 104 | print "Warning: better to also install \"$prog\".\n"; |
| 105 | } else { |
| 106 | print "ERROR: please install \"$prog\", otherwise, build won't work.\n"; |
| 107 | } |
| 108 | if (defined($map{$prog})) { |
| 109 | $install .= " " . $map{$prog}; |
| 110 | } else { |
| 111 | $install .= " " . $prog; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | $install =~ s/^\s//; |
| 116 | } |
| 117 | |
| 118 | sub add_package($$) |
| 119 | { |
| 120 | my $package = shift; |
| 121 | my $is_optional = shift; |
| 122 | |
| 123 | $missing{$package} = $is_optional; |
| 124 | if ($is_optional) { |
| 125 | $optional++; |
| 126 | } else { |
| 127 | $need++; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | sub check_missing_file($$$) |
| 132 | { |
Jeremy MAURO | ff8fdb3 | 2019-10-02 15:33:39 +0200 | [diff] [blame] | 133 | my $files = shift; |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 134 | my $package = shift; |
| 135 | my $is_optional = shift; |
| 136 | |
Jeremy MAURO | ff8fdb3 | 2019-10-02 15:33:39 +0200 | [diff] [blame] | 137 | for (@$files) { |
| 138 | return if(-e $_); |
| 139 | } |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 140 | |
| 141 | add_package($package, $is_optional); |
| 142 | } |
| 143 | |
| 144 | sub findprog($) |
| 145 | { |
| 146 | foreach(split(/:/, $ENV{PATH})) { |
| 147 | return "$_/$_[0]" if(-x "$_/$_[0]"); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | sub check_program($$) |
| 152 | { |
| 153 | my $prog = shift; |
| 154 | my $is_optional = shift; |
| 155 | |
Mauro Carvalho Chehab | 2f9c502 | 2020-04-14 18:56:13 +0200 | [diff] [blame] | 156 | return $prog if findprog($prog); |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 157 | |
| 158 | add_package($prog, $is_optional); |
| 159 | } |
| 160 | |
| 161 | sub check_perl_module($$) |
| 162 | { |
| 163 | my $prog = shift; |
| 164 | my $is_optional = shift; |
| 165 | |
| 166 | my $err = system("perl -M$prog -e 1 2>/dev/null /dev/null"); |
| 167 | return if ($err == 0); |
| 168 | |
| 169 | add_package($prog, $is_optional); |
| 170 | } |
| 171 | |
| 172 | sub check_python_module($$) |
| 173 | { |
| 174 | my $prog = shift; |
| 175 | my $is_optional = shift; |
| 176 | |
Mauro Carvalho Chehab | 2f9c502 | 2020-04-14 18:56:13 +0200 | [diff] [blame] | 177 | return if (!$python_cmd); |
| 178 | |
| 179 | my $err = system("$python_cmd -c 'import $prog' 2>/dev/null /dev/null"); |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 180 | return if ($err == 0); |
| 181 | |
| 182 | add_package($prog, $is_optional); |
| 183 | } |
| 184 | |
| 185 | sub check_rpm_missing($$) |
| 186 | { |
| 187 | my @pkgs = @{$_[0]}; |
| 188 | my $is_optional = $_[1]; |
| 189 | |
| 190 | foreach my $prog(@pkgs) { |
| 191 | my $err = system("rpm -q '$prog' 2>/dev/null >/dev/null"); |
| 192 | add_package($prog, $is_optional) if ($err); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | sub check_pacman_missing($$) |
| 197 | { |
| 198 | my @pkgs = @{$_[0]}; |
| 199 | my $is_optional = $_[1]; |
| 200 | |
| 201 | foreach my $prog(@pkgs) { |
| 202 | my $err = system("pacman -Q '$prog' 2>/dev/null >/dev/null"); |
| 203 | add_package($prog, $is_optional) if ($err); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | sub check_missing_tex($) |
| 208 | { |
| 209 | my $is_optional = shift; |
| 210 | my $kpsewhich = findprog("kpsewhich"); |
| 211 | |
| 212 | foreach my $prog(keys %texlive) { |
| 213 | my $package = $texlive{$prog}; |
| 214 | if (!$kpsewhich) { |
| 215 | add_package($package, $is_optional); |
| 216 | next; |
| 217 | } |
| 218 | my $file = qx($kpsewhich $prog); |
| 219 | add_package($package, $is_optional) if ($file =~ /^\s*$/); |
| 220 | } |
| 221 | } |
| 222 | |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 223 | sub get_sphinx_fname() |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 224 | { |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 225 | my $fname = "sphinx-build"; |
| 226 | return $fname if findprog($fname); |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 227 | |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 228 | $fname = "sphinx-build-3"; |
| 229 | if (findprog($fname)) { |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 230 | $need_symlink = 1; |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 231 | return $fname; |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 232 | } |
| 233 | |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 234 | return ""; |
| 235 | } |
| 236 | |
Mauro Carvalho Chehab | a8b380c | 2020-04-21 16:31:05 +0200 | [diff] [blame] | 237 | sub get_sphinx_version($) |
| 238 | { |
| 239 | my $cmd = shift; |
| 240 | my $ver; |
| 241 | |
| 242 | open IN, "$cmd --version 2>&1 |"; |
| 243 | while (<IN>) { |
| 244 | if (m/^\s*sphinx-build\s+([\d\.]+)(\+\/[\da-f]+)?$/) { |
| 245 | $ver=$1; |
| 246 | last; |
| 247 | } |
| 248 | # Sphinx 1.2.x uses a different format |
| 249 | if (m/^\s*Sphinx.*\s+([\d\.]+)$/) { |
| 250 | $ver=$1; |
| 251 | last; |
| 252 | } |
| 253 | } |
| 254 | close IN; |
| 255 | return $ver; |
| 256 | } |
| 257 | |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 258 | sub check_sphinx() |
| 259 | { |
Mauro Carvalho Chehab | 1ef70ce | 2020-04-21 16:31:06 +0200 | [diff] [blame] | 260 | my $default_version; |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 261 | |
| 262 | open IN, $conf or die "Can't open $conf"; |
| 263 | while (<IN>) { |
| 264 | if (m/^\s*needs_sphinx\s*=\s*[\'\"]([\d\.]+)[\'\"]/) { |
| 265 | $min_version=$1; |
| 266 | last; |
| 267 | } |
| 268 | } |
| 269 | close IN; |
| 270 | |
| 271 | die "Can't get needs_sphinx version from $conf" if (!$min_version); |
| 272 | |
| 273 | open IN, $requirement_file or die "Can't open $requirement_file"; |
| 274 | while (<IN>) { |
| 275 | if (m/^\s*Sphinx\s*==\s*([\d\.]+)$/) { |
Mauro Carvalho Chehab | 1ef70ce | 2020-04-21 16:31:06 +0200 | [diff] [blame] | 276 | $default_version=$1; |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 277 | last; |
| 278 | } |
| 279 | } |
| 280 | close IN; |
| 281 | |
Mauro Carvalho Chehab | 1ef70ce | 2020-04-21 16:31:06 +0200 | [diff] [blame] | 282 | die "Can't get default sphinx version from $requirement_file" if (!$default_version); |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 283 | |
Mauro Carvalho Chehab | 1ef70ce | 2020-04-21 16:31:06 +0200 | [diff] [blame] | 284 | $virtenv_dir = $virtenv_prefix . $default_version; |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 285 | |
| 286 | my $sphinx = get_sphinx_fname(); |
Mauro Carvalho Chehab | 2f9c502 | 2020-04-14 18:56:13 +0200 | [diff] [blame] | 287 | if ($sphinx eq "") { |
| 288 | $need_sphinx = 1; |
| 289 | return; |
| 290 | } |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 291 | |
Mauro Carvalho Chehab | a8b380c | 2020-04-21 16:31:05 +0200 | [diff] [blame] | 292 | $cur_version = get_sphinx_version($sphinx); |
| 293 | die ("$sphinx returned an error") if (!$cur_version); |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 294 | |
| 295 | die "$sphinx didn't return its version" if (!$cur_version); |
| 296 | |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 297 | if ($cur_version lt $min_version) { |
Mauro Carvalho Chehab | 9b88ad5 | 2019-05-29 20:09:26 -0300 | [diff] [blame] | 298 | printf "ERROR: Sphinx version is %s. It should be >= %s (recommended >= %s)\n", |
Mauro Carvalho Chehab | 1ef70ce | 2020-04-21 16:31:06 +0200 | [diff] [blame] | 299 | $cur_version, $min_version, $default_version; |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 300 | $need_sphinx = 1; |
| 301 | return; |
| 302 | } |
| 303 | |
| 304 | if ($cur_version lt $rec_version) { |
Mauro Carvalho Chehab | 9b88ad5 | 2019-05-29 20:09:26 -0300 | [diff] [blame] | 305 | printf "Sphinx version %s\n", $cur_version; |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 306 | print "Warning: It is recommended at least Sphinx version $rec_version.\n"; |
Mauro Carvalho Chehab | 1ef70ce | 2020-04-21 16:31:06 +0200 | [diff] [blame] | 307 | print " If you want pdf, you need at least $min_pdf_version.\n"; |
| 308 | $rec_sphinx_upgrade = 1; |
| 309 | return; |
| 310 | } |
| 311 | if ($cur_version lt $min_pdf_version) { |
| 312 | printf "Sphinx version %s\n", $cur_version; |
| 313 | print "Note: It is recommended at least Sphinx version $min_pdf_version if you need PDF support.\n"; |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 314 | $rec_sphinx_upgrade = 1; |
Mauro Carvalho Chehab | 9b88ad5 | 2019-05-29 20:09:26 -0300 | [diff] [blame] | 315 | return; |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 316 | } |
Mauro Carvalho Chehab | 9b88ad5 | 2019-05-29 20:09:26 -0300 | [diff] [blame] | 317 | |
| 318 | # On version check mode, just assume Sphinx has all mandatory deps |
| 319 | exit (0) if ($version_check); |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | # |
| 323 | # Ancillary subroutines |
| 324 | # |
| 325 | |
| 326 | sub catcheck($) |
| 327 | { |
| 328 | my $res = ""; |
| 329 | $res = qx(cat $_[0]) if (-r $_[0]); |
| 330 | return $res; |
| 331 | } |
| 332 | |
| 333 | sub which($) |
| 334 | { |
| 335 | my $file = shift; |
| 336 | my @path = split ":", $ENV{PATH}; |
| 337 | |
| 338 | foreach my $dir(@path) { |
| 339 | my $name = $dir.'/'.$file; |
| 340 | return $name if (-x $name ); |
| 341 | } |
| 342 | return undef; |
| 343 | } |
| 344 | |
| 345 | # |
| 346 | # Subroutines that check distro-specific hints |
| 347 | # |
| 348 | |
| 349 | sub give_debian_hints() |
| 350 | { |
| 351 | my %map = ( |
| 352 | "python-sphinx" => "python3-sphinx", |
| 353 | "sphinx_rtd_theme" => "python3-sphinx-rtd-theme", |
Mauro Carvalho Chehab | 2f9c502 | 2020-04-14 18:56:13 +0200 | [diff] [blame] | 354 | "ensurepip" => "python3-venv", |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 355 | "virtualenv" => "virtualenv", |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 356 | "dot" => "graphviz", |
| 357 | "convert" => "imagemagick", |
| 358 | "Pod::Usage" => "perl-modules", |
| 359 | "xelatex" => "texlive-xetex", |
Mauro Carvalho Chehab | 8e7d5d1 | 2017-07-17 18:46:40 -0300 | [diff] [blame] | 360 | "rsvg-convert" => "librsvg2-bin", |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 361 | ); |
| 362 | |
| 363 | if ($pdf) { |
Jeremy MAURO | ff8fdb3 | 2019-10-02 15:33:39 +0200 | [diff] [blame] | 364 | check_missing_file(["/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"], |
Mauro Carvalho Chehab | 56e5a63 | 2019-07-13 09:37:16 -0300 | [diff] [blame] | 365 | "fonts-dejavu", 2); |
Mauro Carvalho Chehab | 27eed92 | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 366 | |
Jeremy MAURO | 9692f2f | 2019-10-02 15:35:42 +0200 | [diff] [blame] | 367 | check_missing_file(["/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc", |
Mauro Carvalho Chehab | bfc7f42 | 2020-04-14 18:56:10 +0200 | [diff] [blame] | 368 | "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", |
| 369 | "/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc"], |
Mauro Carvalho Chehab | 27eed92 | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 370 | "fonts-noto-cjk", 2); |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 371 | } |
| 372 | |
Mauro Carvalho Chehab | 56e5a63 | 2019-07-13 09:37:16 -0300 | [diff] [blame] | 373 | check_program("dvipng", 2) if ($pdf); |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 374 | check_missing(\%map); |
| 375 | |
| 376 | return if (!$need && !$optional); |
| 377 | printf("You should run:\n\n\tsudo apt-get install $install\n"); |
| 378 | } |
| 379 | |
| 380 | sub give_redhat_hints() |
| 381 | { |
| 382 | my %map = ( |
| 383 | "python-sphinx" => "python3-sphinx", |
| 384 | "sphinx_rtd_theme" => "python3-sphinx_rtd_theme", |
| 385 | "virtualenv" => "python3-virtualenv", |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 386 | "dot" => "graphviz", |
| 387 | "convert" => "ImageMagick", |
| 388 | "Pod::Usage" => "perl-Pod-Usage", |
| 389 | "xelatex" => "texlive-xetex-bin", |
Mauro Carvalho Chehab | 8e7d5d1 | 2017-07-17 18:46:40 -0300 | [diff] [blame] | 390 | "rsvg-convert" => "librsvg2-tools", |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 391 | ); |
| 392 | |
Mauro Carvalho Chehab | 5d88953 | 2017-07-17 18:46:39 -0300 | [diff] [blame] | 393 | my @fedora26_opt_pkgs = ( |
| 394 | "graphviz-gd", # Fedora 26: needed for PDF support |
| 395 | ); |
| 396 | |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 397 | my @fedora_tex_pkgs = ( |
| 398 | "texlive-collection-fontsrecommended", |
| 399 | "texlive-collection-latex", |
Mauro Carvalho Chehab | 27eed92 | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 400 | "texlive-xecjk", |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 401 | "dejavu-sans-fonts", |
| 402 | "dejavu-serif-fonts", |
| 403 | "dejavu-sans-mono-fonts", |
| 404 | ); |
| 405 | |
Mauro Carvalho Chehab | 9b756a9 | 2017-07-24 09:09:24 -0300 | [diff] [blame] | 406 | # |
| 407 | # Checks valid for RHEL/CentOS version 7.x. |
| 408 | # |
Mauro Carvalho Chehab | 56e5a63 | 2019-07-13 09:37:16 -0300 | [diff] [blame] | 409 | my $old = 0; |
| 410 | my $rel; |
| 411 | $rel = $1 if ($system_release =~ /release\s+(\d+)/); |
| 412 | |
Mauro Carvalho Chehab | b308467 | 2019-07-13 08:50:24 -0300 | [diff] [blame] | 413 | if (!($system_release =~ /Fedora/)) { |
Mauro Carvalho Chehab | 9b756a9 | 2017-07-24 09:09:24 -0300 | [diff] [blame] | 414 | $map{"virtualenv"} = "python-virtualenv"; |
Mauro Carvalho Chehab | 56e5a63 | 2019-07-13 09:37:16 -0300 | [diff] [blame] | 415 | |
| 416 | if ($rel && $rel < 8) { |
| 417 | $old = 1; |
| 418 | $pdf = 0; |
| 419 | |
| 420 | printf("Note: texlive packages on RHEL/CENTOS <= 7 are incomplete. Can't support PDF output\n"); |
| 421 | printf("If you want to build PDF, please read:\n"); |
| 422 | printf("\thttps://www.systutorials.com/241660/how-to-install-tex-live-on-centos-7-linux/\n"); |
| 423 | } |
| 424 | } else { |
| 425 | if ($rel && $rel < 26) { |
| 426 | $old = 1; |
| 427 | } |
| 428 | } |
| 429 | if (!$rel) { |
| 430 | printf("Couldn't identify release number\n"); |
| 431 | $old = 1; |
| 432 | $pdf = 0; |
Mauro Carvalho Chehab | 9b756a9 | 2017-07-24 09:09:24 -0300 | [diff] [blame] | 433 | } |
| 434 | |
Mauro Carvalho Chehab | 27eed92 | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 435 | if ($pdf) { |
Jeremy MAURO | ff8fdb3 | 2019-10-02 15:33:39 +0200 | [diff] [blame] | 436 | check_missing_file(["/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc"], |
Mauro Carvalho Chehab | 27eed92 | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 437 | "google-noto-sans-cjk-ttc-fonts", 2); |
| 438 | } |
| 439 | |
Mauro Carvalho Chehab | 56e5a63 | 2019-07-13 09:37:16 -0300 | [diff] [blame] | 440 | check_rpm_missing(\@fedora26_opt_pkgs, 2) if ($pdf && !$old); |
| 441 | check_rpm_missing(\@fedora_tex_pkgs, 2) if ($pdf); |
| 442 | check_missing_tex(2) if ($pdf); |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 443 | check_missing(\%map); |
| 444 | |
| 445 | return if (!$need && !$optional); |
Mauro Carvalho Chehab | 9b756a9 | 2017-07-24 09:09:24 -0300 | [diff] [blame] | 446 | |
Mauro Carvalho Chehab | 56e5a63 | 2019-07-13 09:37:16 -0300 | [diff] [blame] | 447 | if (!$old) { |
Mauro Carvalho Chehab | 9b756a9 | 2017-07-24 09:09:24 -0300 | [diff] [blame] | 448 | # dnf, for Fedora 18+ |
| 449 | printf("You should run:\n\n\tsudo dnf install -y $install\n"); |
| 450 | } else { |
| 451 | # yum, for RHEL (and clones) or Fedora version < 18 |
| 452 | printf("You should run:\n\n\tsudo yum install -y $install\n"); |
| 453 | } |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | sub give_opensuse_hints() |
| 457 | { |
| 458 | my %map = ( |
| 459 | "python-sphinx" => "python3-sphinx", |
| 460 | "sphinx_rtd_theme" => "python3-sphinx_rtd_theme", |
| 461 | "virtualenv" => "python3-virtualenv", |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 462 | "dot" => "graphviz", |
| 463 | "convert" => "ImageMagick", |
| 464 | "Pod::Usage" => "perl-Pod-Usage", |
| 465 | "xelatex" => "texlive-xetex-bin", |
| 466 | ); |
| 467 | |
Mauro Carvalho Chehab | b3df622 | 2020-04-14 18:56:09 +0200 | [diff] [blame] | 468 | # On Tumbleweed, this package is also named rsvg-convert |
| 469 | $map{"rsvg-convert"} = "rsvg-view" if (!($system_release =~ /Tumbleweed/)); |
| 470 | |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 471 | my @suse_tex_pkgs = ( |
| 472 | "texlive-babel-english", |
| 473 | "texlive-caption", |
| 474 | "texlive-colortbl", |
| 475 | "texlive-courier", |
| 476 | "texlive-dvips", |
| 477 | "texlive-helvetic", |
| 478 | "texlive-makeindex", |
| 479 | "texlive-metafont", |
| 480 | "texlive-metapost", |
| 481 | "texlive-palatino", |
| 482 | "texlive-preview", |
| 483 | "texlive-times", |
| 484 | "texlive-zapfchan", |
| 485 | "texlive-zapfding", |
| 486 | ); |
| 487 | |
Mauro Carvalho Chehab | 353290a | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 488 | $map{"latexmk"} = "texlive-latexmk-bin"; |
| 489 | |
Mauro Carvalho Chehab | 27eed92 | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 490 | # FIXME: add support for installing CJK fonts |
| 491 | # |
| 492 | # I tried hard, but was unable to find a way to install |
| 493 | # "Noto Sans CJK SC" on openSUSE |
| 494 | |
Mauro Carvalho Chehab | 56e5a63 | 2019-07-13 09:37:16 -0300 | [diff] [blame] | 495 | check_rpm_missing(\@suse_tex_pkgs, 2) if ($pdf); |
| 496 | check_missing_tex(2) if ($pdf); |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 497 | check_missing(\%map); |
| 498 | |
| 499 | return if (!$need && !$optional); |
| 500 | printf("You should run:\n\n\tsudo zypper install --no-recommends $install\n"); |
| 501 | } |
| 502 | |
Mauro Carvalho Chehab | 800d408 | 2017-07-21 13:20:41 -0300 | [diff] [blame] | 503 | sub give_mageia_hints() |
| 504 | { |
| 505 | my %map = ( |
| 506 | "python-sphinx" => "python3-sphinx", |
| 507 | "sphinx_rtd_theme" => "python3-sphinx_rtd_theme", |
| 508 | "virtualenv" => "python3-virtualenv", |
Mauro Carvalho Chehab | 800d408 | 2017-07-21 13:20:41 -0300 | [diff] [blame] | 509 | "dot" => "graphviz", |
| 510 | "convert" => "ImageMagick", |
| 511 | "Pod::Usage" => "perl-Pod-Usage", |
| 512 | "xelatex" => "texlive", |
Mauro Carvalho Chehab | d6ebf18 | 2020-04-14 18:56:12 +0200 | [diff] [blame] | 513 | "rsvg-convert" => "librsvg2", |
Mauro Carvalho Chehab | 800d408 | 2017-07-21 13:20:41 -0300 | [diff] [blame] | 514 | ); |
| 515 | |
| 516 | my @tex_pkgs = ( |
| 517 | "texlive-fontsextra", |
| 518 | ); |
| 519 | |
Mauro Carvalho Chehab | 353290a | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 520 | $map{"latexmk"} = "texlive-collection-basic"; |
| 521 | |
Mauro Carvalho Chehab | d6ebf18 | 2020-04-14 18:56:12 +0200 | [diff] [blame] | 522 | my $packager_cmd; |
| 523 | my $noto_sans; |
| 524 | if ($system_release =~ /OpenMandriva/) { |
| 525 | $packager_cmd = "dnf install"; |
| 526 | $noto_sans = "noto-sans-cjk-fonts"; |
| 527 | @tex_pkgs = ( "texlive-collection-fontsextra" ); |
| 528 | } else { |
| 529 | $packager_cmd = "urpmi"; |
| 530 | $noto_sans = "google-noto-sans-cjk-ttc-fonts"; |
| 531 | } |
| 532 | |
| 533 | |
Mauro Carvalho Chehab | 27eed92 | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 534 | if ($pdf) { |
Mauro Carvalho Chehab | d6ebf18 | 2020-04-14 18:56:12 +0200 | [diff] [blame] | 535 | check_missing_file(["/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc", |
| 536 | "/usr/share/fonts/TTF/NotoSans-Regular.ttf"], |
| 537 | $noto_sans, 2); |
Mauro Carvalho Chehab | 27eed92 | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 538 | } |
| 539 | |
Mauro Carvalho Chehab | 56e5a63 | 2019-07-13 09:37:16 -0300 | [diff] [blame] | 540 | check_rpm_missing(\@tex_pkgs, 2) if ($pdf); |
Mauro Carvalho Chehab | 800d408 | 2017-07-21 13:20:41 -0300 | [diff] [blame] | 541 | check_missing(\%map); |
| 542 | |
| 543 | return if (!$need && !$optional); |
Mauro Carvalho Chehab | d6ebf18 | 2020-04-14 18:56:12 +0200 | [diff] [blame] | 544 | printf("You should run:\n\n\tsudo $packager_cmd $install\n"); |
Mauro Carvalho Chehab | 800d408 | 2017-07-21 13:20:41 -0300 | [diff] [blame] | 545 | } |
| 546 | |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 547 | sub give_arch_linux_hints() |
| 548 | { |
| 549 | my %map = ( |
| 550 | "sphinx_rtd_theme" => "python-sphinx_rtd_theme", |
| 551 | "virtualenv" => "python-virtualenv", |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 552 | "dot" => "graphviz", |
| 553 | "convert" => "imagemagick", |
| 554 | "xelatex" => "texlive-bin", |
Louis Taylor | 0d0da9a | 2019-11-02 18:45:11 +0000 | [diff] [blame] | 555 | "latexmk" => "texlive-core", |
Mauro Carvalho Chehab | 8e7d5d1 | 2017-07-17 18:46:40 -0300 | [diff] [blame] | 556 | "rsvg-convert" => "extra/librsvg", |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 557 | ); |
| 558 | |
| 559 | my @archlinux_tex_pkgs = ( |
| 560 | "texlive-core", |
| 561 | "texlive-latexextra", |
| 562 | "ttf-dejavu", |
| 563 | ); |
Mauro Carvalho Chehab | 56e5a63 | 2019-07-13 09:37:16 -0300 | [diff] [blame] | 564 | check_pacman_missing(\@archlinux_tex_pkgs, 2) if ($pdf); |
| 565 | |
Mauro Carvalho Chehab | 27eed92 | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 566 | if ($pdf) { |
Jeremy MAURO | ff8fdb3 | 2019-10-02 15:33:39 +0200 | [diff] [blame] | 567 | check_missing_file(["/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc"], |
Mauro Carvalho Chehab | 27eed92 | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 568 | "noto-fonts-cjk", 2); |
| 569 | } |
| 570 | |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 571 | check_missing(\%map); |
| 572 | |
| 573 | return if (!$need && !$optional); |
| 574 | printf("You should run:\n\n\tsudo pacman -S $install\n"); |
| 575 | } |
| 576 | |
| 577 | sub give_gentoo_hints() |
| 578 | { |
| 579 | my %map = ( |
| 580 | "sphinx_rtd_theme" => "dev-python/sphinx_rtd_theme", |
| 581 | "virtualenv" => "dev-python/virtualenv", |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 582 | "dot" => "media-gfx/graphviz", |
| 583 | "convert" => "media-gfx/imagemagick", |
| 584 | "xelatex" => "dev-texlive/texlive-xetex media-fonts/dejavu", |
Mauro Carvalho Chehab | 8e7d5d1 | 2017-07-17 18:46:40 -0300 | [diff] [blame] | 585 | "rsvg-convert" => "gnome-base/librsvg", |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 586 | ); |
| 587 | |
Jeremy MAURO | ff8fdb3 | 2019-10-02 15:33:39 +0200 | [diff] [blame] | 588 | check_missing_file(["/usr/share/fonts/dejavu/DejaVuSans.ttf"], |
Mauro Carvalho Chehab | 56e5a63 | 2019-07-13 09:37:16 -0300 | [diff] [blame] | 589 | "media-fonts/dejavu", 2) if ($pdf); |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 590 | |
Mauro Carvalho Chehab | 27eed92 | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 591 | if ($pdf) { |
Mauro Carvalho Chehab | e45a631 | 2020-04-14 18:56:11 +0200 | [diff] [blame] | 592 | check_missing_file(["/usr/share/fonts/noto-cjk/NotoSansCJKsc-Regular.otf", |
| 593 | "/usr/share/fonts/noto-cjk/NotoSerifCJK-Regular.ttc"], |
Mauro Carvalho Chehab | 27eed92 | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 594 | "media-fonts/noto-cjk", 2); |
| 595 | } |
| 596 | |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 597 | check_missing(\%map); |
| 598 | |
| 599 | return if (!$need && !$optional); |
Mauro Carvalho Chehab | bba1e4c | 2017-07-17 18:46:41 -0300 | [diff] [blame] | 600 | |
| 601 | printf("You should run:\n\n"); |
Mauro Carvalho Chehab | 4ea96d5 | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 602 | |
| 603 | my $imagemagick = "media-gfx/imagemagick svg png"; |
| 604 | my $cairo = "media-gfx/graphviz cairo pdf"; |
| 605 | my $portage_imagemagick = "/etc/portage/package.use/imagemagick"; |
| 606 | my $portage_cairo = "/etc/portage/package.use/graphviz"; |
| 607 | |
Mauro Carvalho Chehab | e45a631 | 2020-04-14 18:56:11 +0200 | [diff] [blame] | 608 | if (qx(grep imagemagick $portage_imagemagick 2>/dev/null) eq "") { |
Mauro Carvalho Chehab | 4ea96d5 | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 609 | printf("\tsudo su -c 'echo \"$imagemagick\" > $portage_imagemagick'\n") |
| 610 | } |
Mauro Carvalho Chehab | e45a631 | 2020-04-14 18:56:11 +0200 | [diff] [blame] | 611 | if (qx(grep graphviz $portage_cairo 2>/dev/null) eq "") { |
Mauro Carvalho Chehab | 4ea96d5 | 2019-07-13 08:19:44 -0300 | [diff] [blame] | 612 | printf("\tsudo su -c 'echo \"$cairo\" > $portage_cairo'\n"); |
| 613 | } |
| 614 | |
Mauro Carvalho Chehab | bba1e4c | 2017-07-17 18:46:41 -0300 | [diff] [blame] | 615 | printf("\tsudo emerge --ask $install\n"); |
| 616 | |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | sub check_distros() |
| 620 | { |
| 621 | # Distro-specific hints |
| 622 | if ($system_release =~ /Red Hat Enterprise Linux/) { |
| 623 | give_redhat_hints; |
| 624 | return; |
| 625 | } |
Mauro Carvalho Chehab | 9b756a9 | 2017-07-24 09:09:24 -0300 | [diff] [blame] | 626 | if ($system_release =~ /CentOS/) { |
| 627 | give_redhat_hints; |
| 628 | return; |
| 629 | } |
| 630 | if ($system_release =~ /Scientific Linux/) { |
| 631 | give_redhat_hints; |
| 632 | return; |
| 633 | } |
| 634 | if ($system_release =~ /Oracle Linux Server/) { |
| 635 | give_redhat_hints; |
| 636 | return; |
| 637 | } |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 638 | if ($system_release =~ /Fedora/) { |
| 639 | give_redhat_hints; |
| 640 | return; |
| 641 | } |
| 642 | if ($system_release =~ /Ubuntu/) { |
| 643 | give_debian_hints; |
| 644 | return; |
| 645 | } |
| 646 | if ($system_release =~ /Debian/) { |
| 647 | give_debian_hints; |
| 648 | return; |
| 649 | } |
| 650 | if ($system_release =~ /openSUSE/) { |
| 651 | give_opensuse_hints; |
| 652 | return; |
| 653 | } |
Mauro Carvalho Chehab | 800d408 | 2017-07-21 13:20:41 -0300 | [diff] [blame] | 654 | if ($system_release =~ /Mageia/) { |
| 655 | give_mageia_hints; |
| 656 | return; |
| 657 | } |
Mauro Carvalho Chehab | d6ebf18 | 2020-04-14 18:56:12 +0200 | [diff] [blame] | 658 | if ($system_release =~ /OpenMandriva/) { |
| 659 | give_mageia_hints; |
| 660 | return; |
| 661 | } |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 662 | if ($system_release =~ /Arch Linux/) { |
| 663 | give_arch_linux_hints; |
| 664 | return; |
| 665 | } |
| 666 | if ($system_release =~ /Gentoo/) { |
| 667 | give_gentoo_hints; |
| 668 | return; |
| 669 | } |
| 670 | |
| 671 | # |
| 672 | # Fall-back to generic hint code for other distros |
| 673 | # That's far from ideal, specially for LaTeX dependencies. |
| 674 | # |
| 675 | my %map = ( |
| 676 | "sphinx-build" => "sphinx" |
| 677 | ); |
Mauro Carvalho Chehab | 56e5a63 | 2019-07-13 09:37:16 -0300 | [diff] [blame] | 678 | check_missing_tex(2) if ($pdf); |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 679 | check_missing(\%map); |
| 680 | print "I don't know distro $system_release.\n"; |
| 681 | print "So, I can't provide you a hint with the install procedure.\n"; |
| 682 | print "There are likely missing dependencies.\n"; |
| 683 | } |
| 684 | |
| 685 | # |
| 686 | # Common dependencies |
| 687 | # |
| 688 | |
Shuah Khan | 2730ce0 | 2019-09-18 18:37:54 -0600 | [diff] [blame] | 689 | sub deactivate_help() |
| 690 | { |
Mauro Carvalho Chehab | 2f9c502 | 2020-04-14 18:56:13 +0200 | [diff] [blame] | 691 | printf "\nIf you want to exit the virtualenv, you can use:\n"; |
Shuah Khan | 2730ce0 | 2019-09-18 18:37:54 -0600 | [diff] [blame] | 692 | printf "\tdeactivate\n"; |
| 693 | } |
| 694 | |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 695 | sub check_needs() |
| 696 | { |
Mauro Carvalho Chehab | 2f9c502 | 2020-04-14 18:56:13 +0200 | [diff] [blame] | 697 | # Check if Sphinx is already accessible from current environment |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 698 | check_sphinx(); |
Mauro Carvalho Chehab | 9b88ad5 | 2019-05-29 20:09:26 -0300 | [diff] [blame] | 699 | |
| 700 | if ($system_release) { |
| 701 | print "Detected OS: $system_release.\n\n"; |
| 702 | } else { |
| 703 | print "Unknown OS\n\n"; |
| 704 | } |
| 705 | |
Mauro Carvalho Chehab | 2f9c502 | 2020-04-14 18:56:13 +0200 | [diff] [blame] | 706 | # Check python command line, trying first python3 |
| 707 | $python_cmd = findprog("python3"); |
| 708 | $python_cmd = check_program("python", 0) if (!$python_cmd); |
| 709 | |
| 710 | # Check the type of virtual env, depending on Python version |
| 711 | if ($python_cmd) { |
| 712 | if ($virtualenv) { |
| 713 | my $tmp = qx($python_cmd --version 2>&1); |
| 714 | if ($tmp =~ m/(\d+\.)(\d+\.)/) { |
| 715 | if ($1 >= 3 && $2 >= 3) { |
| 716 | $need_venv = 1; # python 3.3 or upper |
| 717 | } else { |
| 718 | $need_virtualenv = 1; |
| 719 | } |
| 720 | if ($1 < 3) { |
| 721 | # Complain if it finds python2 (or worse) |
| 722 | printf "Warning: python$1 support is deprecated. Use it with caution!\n"; |
| 723 | } |
| 724 | } else { |
| 725 | die "Warning: couldn't identify $python_cmd version!"; |
| 726 | } |
| 727 | } else { |
| 728 | add_package("python-sphinx", 0); |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | # Set virtualenv command line, if python < 3.3 |
| 733 | my $virtualenv_cmd; |
| 734 | if ($need_virtualenv) { |
| 735 | $virtualenv_cmd = findprog("virtualenv-3"); |
| 736 | $virtualenv_cmd = findprog("virtualenv-3.5") if (!$virtualenv_cmd); |
| 737 | if (!$virtualenv_cmd) { |
| 738 | check_program("virtualenv", 0); |
| 739 | $virtualenv_cmd = "virtualenv"; |
| 740 | } |
| 741 | } |
| 742 | |
Mauro Carvalho Chehab | 9b88ad5 | 2019-05-29 20:09:26 -0300 | [diff] [blame] | 743 | # Check for needed programs/tools |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 744 | check_perl_module("Pod::Usage", 0); |
| 745 | check_program("make", 0); |
| 746 | check_program("gcc", 0); |
| 747 | check_python_module("sphinx_rtd_theme", 1) if (!$virtualenv); |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 748 | check_program("dot", 1); |
| 749 | check_program("convert", 1); |
Mauro Carvalho Chehab | 56e5a63 | 2019-07-13 09:37:16 -0300 | [diff] [blame] | 750 | |
| 751 | # Extra PDF files - should use 2 for is_optional |
| 752 | check_program("xelatex", 2) if ($pdf); |
| 753 | check_program("rsvg-convert", 2) if ($pdf); |
| 754 | check_program("latexmk", 2) if ($pdf); |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 755 | |
Mauro Carvalho Chehab | 2f9c502 | 2020-04-14 18:56:13 +0200 | [diff] [blame] | 756 | if ($need_sphinx || $rec_sphinx_upgrade) { |
| 757 | check_python_module("ensurepip", 0) if ($need_venv); |
| 758 | } |
| 759 | |
| 760 | # Do distro-specific checks and output distro-install commands |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 761 | check_distros(); |
| 762 | |
Mauro Carvalho Chehab | 2f9c502 | 2020-04-14 18:56:13 +0200 | [diff] [blame] | 763 | if (!$python_cmd) { |
| 764 | if ($need == 1) { |
| 765 | die "Can't build as $need mandatory dependency is missing"; |
| 766 | } elsif ($need) { |
| 767 | die "Can't build as $need mandatory dependencies are missing"; |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | # Check if sphinx-build is called sphinx-build-3 |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 772 | if ($need_symlink) { |
| 773 | printf "\tsudo ln -sf %s /usr/bin/sphinx-build\n\n", |
| 774 | which("sphinx-build-3"); |
| 775 | } |
Mauro Carvalho Chehab | 2f9c502 | 2020-04-14 18:56:13 +0200 | [diff] [blame] | 776 | |
| 777 | # NOTE: if the system has a too old Sphinx version installed, |
| 778 | # it will recommend installing a newer version using virtualenv |
| 779 | |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 780 | if ($need_sphinx || $rec_sphinx_upgrade) { |
Mauro Carvalho Chehab | 44f4216 | 2019-05-29 20:09:24 -0300 | [diff] [blame] | 781 | my $min_activate = "$ENV{'PWD'}/${virtenv_prefix}${min_version}/bin/activate"; |
Mauro Carvalho Chehab | 9b88ad5 | 2019-05-29 20:09:26 -0300 | [diff] [blame] | 782 | my @activates = glob "$ENV{'PWD'}/${virtenv_prefix}*/bin/activate"; |
Mauro Carvalho Chehab | 44f4216 | 2019-05-29 20:09:24 -0300 | [diff] [blame] | 783 | |
Mauro Carvalho Chehab | 9b88ad5 | 2019-05-29 20:09:26 -0300 | [diff] [blame] | 784 | @activates = sort {$b cmp $a} @activates; |
Mauro Carvalho Chehab | a8b380c | 2020-04-21 16:31:05 +0200 | [diff] [blame] | 785 | my ($activate, $ver); |
| 786 | foreach my $f (@activates) { |
Mauro Carvalho Chehab | 2834a74 | 2020-04-21 16:31:07 +0200 | [diff] [blame^] | 787 | next if ($f lt $min_activate); |
Mauro Carvalho Chehab | 44f4216 | 2019-05-29 20:09:24 -0300 | [diff] [blame] | 788 | |
Mauro Carvalho Chehab | 2834a74 | 2020-04-21 16:31:07 +0200 | [diff] [blame^] | 789 | my $sphinx_cmd = $f; |
Mauro Carvalho Chehab | a8b380c | 2020-04-21 16:31:05 +0200 | [diff] [blame] | 790 | $sphinx_cmd =~ s/activate/sphinx-build/; |
| 791 | next if (! -f $sphinx_cmd); |
| 792 | |
| 793 | $ver = get_sphinx_version($sphinx_cmd); |
Mauro Carvalho Chehab | 2834a74 | 2020-04-21 16:31:07 +0200 | [diff] [blame^] | 794 | if ($need_sphinx && ($ver ge $min_version)) { |
| 795 | $activate = $f; |
| 796 | last; |
| 797 | } elsif ($ver gt $cur_version) { |
| 798 | $activate = $f; |
| 799 | last; |
| 800 | } |
Mauro Carvalho Chehab | a8b380c | 2020-04-21 16:31:05 +0200 | [diff] [blame] | 801 | } |
Mauro Carvalho Chehab | 2834a74 | 2020-04-21 16:31:07 +0200 | [diff] [blame^] | 802 | if ($activate ne "") { |
| 803 | if ($need_sphinx) { |
| 804 | printf "\nNeed to activate Sphinx (version $ver) on virtualenv with:\n"; |
| 805 | printf "\t. $activate\n"; |
| 806 | deactivate_help(); |
| 807 | exit (1); |
| 808 | } else { |
| 809 | printf "\nYou may also use a newer Sphinx (version $ver) with:\n"; |
| 810 | printf "\tdeactivate && . $activate\n"; |
| 811 | } |
Mauro Carvalho Chehab | 5be3318 | 2017-07-17 18:46:37 -0300 | [diff] [blame] | 812 | } else { |
Mauro Carvalho Chehab | 44f4216 | 2019-05-29 20:09:24 -0300 | [diff] [blame] | 813 | my $rec_activate = "$virtenv_dir/bin/activate"; |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 814 | |
Mauro Carvalho Chehab | 2834a74 | 2020-04-21 16:31:07 +0200 | [diff] [blame^] | 815 | print "To upgrade Sphinx, use:\n\n" if ($rec_sphinx_upgrade); |
| 816 | |
Mauro Carvalho Chehab | 2f9c502 | 2020-04-14 18:56:13 +0200 | [diff] [blame] | 817 | if ($need_venv) { |
| 818 | printf "\t$python_cmd -m venv $virtenv_dir\n"; |
| 819 | } else { |
| 820 | printf "\t$virtualenv_cmd $virtenv_dir\n"; |
Tim Bird | c428cd5 | 2020-02-24 18:34:41 -0700 | [diff] [blame] | 821 | } |
Mauro Carvalho Chehab | 44f4216 | 2019-05-29 20:09:24 -0300 | [diff] [blame] | 822 | printf "\t. $rec_activate\n"; |
Mauro Carvalho Chehab | fb947f3 | 2017-07-17 18:46:38 -0300 | [diff] [blame] | 823 | printf "\tpip install -r $requirement_file\n"; |
Shuah Khan | 2730ce0 | 2019-09-18 18:37:54 -0600 | [diff] [blame] | 824 | deactivate_help(); |
Mauro Carvalho Chehab | 77d09ad | 2019-05-22 18:43:46 -0300 | [diff] [blame] | 825 | |
| 826 | $need++ if (!$rec_sphinx_upgrade); |
Mauro Carvalho Chehab | 5be3318 | 2017-07-17 18:46:37 -0300 | [diff] [blame] | 827 | } |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 828 | } |
| 829 | printf "\n"; |
| 830 | |
Bjorn Helgaas | 54002b5 | 2019-05-30 16:59:14 -0500 | [diff] [blame] | 831 | print "All optional dependencies are met.\n" if (!$optional); |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 832 | |
| 833 | if ($need == 1) { |
| 834 | die "Can't build as $need mandatory dependency is missing"; |
| 835 | } elsif ($need) { |
| 836 | die "Can't build as $need mandatory dependencies are missing"; |
| 837 | } |
| 838 | |
| 839 | print "Needed package dependencies are met.\n"; |
| 840 | } |
| 841 | |
| 842 | # |
| 843 | # Main |
| 844 | # |
| 845 | |
| 846 | while (@ARGV) { |
| 847 | my $arg = shift(@ARGV); |
| 848 | |
| 849 | if ($arg eq "--no-virtualenv") { |
| 850 | $virtualenv = 0; |
| 851 | } elsif ($arg eq "--no-pdf"){ |
| 852 | $pdf = 0; |
Mauro Carvalho Chehab | 9b88ad5 | 2019-05-29 20:09:26 -0300 | [diff] [blame] | 853 | } elsif ($arg eq "--version-check"){ |
| 854 | $version_check = 1; |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 855 | } else { |
Mauro Carvalho Chehab | 9b88ad5 | 2019-05-29 20:09:26 -0300 | [diff] [blame] | 856 | print "Usage:\n\t$0 <--no-virtualenv> <--no-pdf> <--version-check>\n\n"; |
| 857 | print "Where:\n"; |
| 858 | print "\t--no-virtualenv\t- Recommend installing Sphinx instead of using a virtualenv\n"; |
| 859 | print "\t--version-check\t- if version is compatible, don't check for missing dependencies\n"; |
| 860 | print "\t--no-pdf\t- don't check for dependencies required to build PDF docs\n\n"; |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 861 | exit -1; |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | # |
| 866 | # Determine the system type. There's no standard unique way that would |
| 867 | # work with all distros with a minimal package install. So, several |
| 868 | # methods are used here. |
| 869 | # |
| 870 | # By default, it will use lsb_release function. If not available, it will |
| 871 | # fail back to reading the known different places where the distro name |
| 872 | # is stored |
| 873 | # |
| 874 | |
| 875 | $system_release = qx(lsb_release -d) if which("lsb_release"); |
| 876 | $system_release =~ s/Description:\s*// if ($system_release); |
| 877 | $system_release = catcheck("/etc/system-release") if !$system_release; |
| 878 | $system_release = catcheck("/etc/redhat-release") if !$system_release; |
| 879 | $system_release = catcheck("/etc/lsb-release") if !$system_release; |
| 880 | $system_release = catcheck("/etc/gentoo-release") if !$system_release; |
Mauro Carvalho Chehab | d14d0c1 | 2020-04-14 18:56:08 +0200 | [diff] [blame] | 881 | |
| 882 | # This seems more common than LSB these days |
| 883 | if (!$system_release) { |
| 884 | my %os_var; |
| 885 | if (open IN, "cat /etc/os-release|") { |
| 886 | while (<IN>) { |
| 887 | if (m/^([\w\d\_]+)=\"?([^\"]*)\"?\n/) { |
| 888 | $os_var{$1}=$2; |
| 889 | } |
| 890 | } |
| 891 | $system_release = $os_var{"NAME"}; |
| 892 | if (defined($os_var{"VERSION_ID"})) { |
| 893 | $system_release .= " " . $os_var{"VERSION_ID"} if (defined($os_var{"VERSION_ID"})); |
| 894 | } else { |
| 895 | $system_release .= " " . $os_var{"VERSION"}; |
| 896 | } |
| 897 | } |
| 898 | } |
Mauro Carvalho Chehab | 24071ac | 2017-07-17 18:46:36 -0300 | [diff] [blame] | 899 | $system_release = catcheck("/etc/issue") if !$system_release; |
| 900 | $system_release =~ s/\s+$//; |
| 901 | |
| 902 | check_needs; |