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