2 # SPDX-License-Identifier: GPL-2.0-or-later
5 # Copyright (c) 2017-2020 Mauro Carvalho Chehab <mchehab@kernel.org>
9 $prefix = "$ENV{'srctree'}/" if ($ENV{'srctree'});
11 my $conf = $prefix . "Documentation/conf.py";
12 my $requirement_file = $prefix . "Documentation/sphinx/requirements.txt";
13 my $virtenv_prefix = "sphinx_";
26 my $need_virtualenv = 0;
27 my $rec_sphinx_upgrade = 0;
28 my $verbose_warn_install = 1;
35 my $rec_version = "1.7.9"; # PDF won't build here
36 my $min_pdf_version = "2.4.4"; # Min version where pdf builds
40 # Command line arguments
45 my $version_check = 0;
48 # List of required texlive packages on Fedora and OpenSuse
52 'amsfonts.sty' => 'texlive-amsfonts',
53 'amsmath.sty' => 'texlive-amsmath',
54 'amssymb.sty' => 'texlive-amsfonts',
55 'amsthm.sty' => 'texlive-amscls',
56 'anyfontsize.sty' => 'texlive-anyfontsize',
57 'atbegshi.sty' => 'texlive-oberdiek',
58 'bm.sty' => 'texlive-tools',
59 'capt-of.sty' => 'texlive-capt-of',
60 'cmap.sty' => 'texlive-cmap',
61 'ecrm1000.tfm' => 'texlive-ec',
62 'eqparbox.sty' => 'texlive-eqparbox',
63 'eu1enc.def' => 'texlive-euenc',
64 'fancybox.sty' => 'texlive-fancybox',
65 'fancyvrb.sty' => 'texlive-fancyvrb',
66 'float.sty' => 'texlive-float',
67 'fncychap.sty' => 'texlive-fncychap',
68 'footnote.sty' => 'texlive-mdwtools',
69 'framed.sty' => 'texlive-framed',
70 'luatex85.sty' => 'texlive-luatex85',
71 'multirow.sty' => 'texlive-multirow',
72 'needspace.sty' => 'texlive-needspace',
73 'palatino.sty' => 'texlive-psnfss',
74 'parskip.sty' => 'texlive-parskip',
75 'polyglossia.sty' => 'texlive-polyglossia',
76 'tabulary.sty' => 'texlive-tabulary',
77 'threeparttable.sty' => 'texlive-threeparttable',
78 'titlesec.sty' => 'texlive-titlesec',
79 'ucs.sty' => 'texlive-ucs',
80 'upquote.sty' => 'texlive-upquote',
81 'wrapfig.sty' => 'texlive-wrapfig',
82 'ctexhook.sty' => 'texlive-ctex',
86 # Subroutines that checks if a feature exists
93 foreach my $prog (sort keys %missing) {
94 my $is_optional = $missing{$prog};
96 # At least on some LTS distros like CentOS 7, texlive doesn't
97 # provide all packages we need. When such distros are
98 # detected, we have to disable PDF output.
100 # So, we need to ignore the packages that distros would
101 # need for LaTeX to work
102 if ($is_optional == 2 && !$pdf) {
107 if ($verbose_warn_install) {
109 print "Warning: better to also install \"$prog\".\n";
111 print "ERROR: please install \"$prog\", otherwise, build won't work.\n";
114 if (defined($map{$prog})) {
115 $install .= " " . $map{$prog};
117 $install .= " " . $prog;
127 my $is_optional = shift;
129 $missing{$package} = $is_optional;
137 sub check_missing_file($$$)
141 my $is_optional = shift;
147 add_package($package, $is_optional);
152 foreach(split(/:/, $ENV{PATH})) {
153 return "$_/$_[0]" if(-x "$_/$_[0]");
157 sub find_python_no_venv()
161 my $cur_dir = qx(pwd);
162 $cur_dir =~ s/\s+$//;
164 foreach my $dir (split(/:/, $ENV{PATH})) {
165 next if ($dir =~ m,($cur_dir)/sphinx,);
166 return "$dir/python3" if(-x "$dir/python3");
168 foreach my $dir (split(/:/, $ENV{PATH})) {
169 next if ($dir =~ m,($cur_dir)/sphinx,);
170 return "$dir/python" if(-x "$dir/python");
175 sub check_program($$)
178 my $is_optional = shift;
180 return $prog if findprog($prog);
182 add_package($prog, $is_optional);
185 sub check_perl_module($$)
188 my $is_optional = shift;
190 my $err = system("perl -M$prog -e 1 2>/dev/null /dev/null");
191 return if ($err == 0);
193 add_package($prog, $is_optional);
196 sub check_python_module($$)
199 my $is_optional = shift;
201 return if (!$python_cmd);
203 my $err = system("$python_cmd -c 'import $prog' 2>/dev/null /dev/null");
204 return if ($err == 0);
206 add_package($prog, $is_optional);
209 sub check_rpm_missing($$)
212 my $is_optional = $_[1];
214 foreach my $prog(@pkgs) {
215 my $err = system("rpm -q '$prog' 2>/dev/null >/dev/null");
216 add_package($prog, $is_optional) if ($err);
220 sub check_pacman_missing($$)
223 my $is_optional = $_[1];
225 foreach my $prog(@pkgs) {
226 my $err = system("pacman -Q '$prog' 2>/dev/null >/dev/null");
227 add_package($prog, $is_optional) if ($err);
231 sub check_missing_tex($)
233 my $is_optional = shift;
234 my $kpsewhich = findprog("kpsewhich");
236 foreach my $prog(keys %texlive) {
237 my $package = $texlive{$prog};
239 add_package($package, $is_optional);
242 my $file = qx($kpsewhich $prog);
243 add_package($package, $is_optional) if ($file =~ /^\s*$/);
247 sub get_sphinx_fname()
249 my $fname = "sphinx-build";
250 return $fname if findprog($fname);
252 $fname = "sphinx-build-3";
253 if (findprog($fname)) {
261 sub get_sphinx_version($)
266 open IN, "$cmd --version 2>&1 |";
268 if (m/^\s*sphinx-build\s+([\d\.]+)((\+\/[\da-f]+)|(b\d+))?$/) {
272 # Sphinx 1.2.x uses a different format
273 if (m/^\s*Sphinx.*\s+([\d\.]+)$/) {
286 open IN, $conf or die "Can't open $conf";
288 if (m/^\s*needs_sphinx\s*=\s*[\'\"]([\d\.]+)[\'\"]/) {
295 die "Can't get needs_sphinx version from $conf" if (!$min_version);
297 open IN, $requirement_file or die "Can't open $requirement_file";
299 if (m/^\s*Sphinx\s*==\s*([\d\.]+)$/) {
306 die "Can't get default sphinx version from $requirement_file" if (!$default_version);
308 $virtenv_dir = $virtenv_prefix . $default_version;
310 my $sphinx = get_sphinx_fname();
316 $cur_version = get_sphinx_version($sphinx);
317 die ("$sphinx returned an error") if (!$cur_version);
319 die "$sphinx didn't return its version" if (!$cur_version);
321 if ($cur_version lt $min_version) {
322 printf "ERROR: Sphinx version is %s. It should be >= %s (recommended >= %s)\n",
323 $cur_version, $min_version, $default_version;
328 return if ($cur_version lt $rec_version);
330 # On version check mode, just assume Sphinx has all mandatory deps
331 exit (0) if ($version_check);
335 # Ancillary subroutines
341 $res = qx(cat $_[0]) if (-r $_[0]);
348 my @path = split ":", $ENV{PATH};
350 foreach my $dir(@path) {
351 my $name = $dir.'/'.$file;
352 return $name if (-x $name );
358 # Subroutines that check distro-specific hints
361 sub give_debian_hints()
364 "python-sphinx" => "python3-sphinx",
365 "sphinx_rtd_theme" => "python3-sphinx-rtd-theme",
366 "ensurepip" => "python3-venv",
367 "virtualenv" => "virtualenv",
369 "convert" => "imagemagick",
370 "Pod::Usage" => "perl-modules",
371 "xelatex" => "texlive-xetex",
372 "rsvg-convert" => "librsvg2-bin",
376 check_missing_file(["/usr/share/texlive/texmf-dist/tex/latex/ctex/ctexhook.sty"],
377 "texlive-lang-chinese", 2);
379 check_missing_file(["/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"],
382 check_missing_file(["/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc",
383 "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
384 "/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc"],
385 "fonts-noto-cjk", 2);
388 check_program("dvipng", 2) if ($pdf);
389 check_missing(\%map);
391 return if (!$need && !$optional);
392 printf("You should run:\n") if ($verbose_warn_install);
393 printf("\n\tsudo apt-get install $install\n");
396 sub give_redhat_hints()
399 "python-sphinx" => "python3-sphinx",
400 "sphinx_rtd_theme" => "python3-sphinx_rtd_theme",
401 "virtualenv" => "python3-virtualenv",
403 "convert" => "ImageMagick",
404 "Pod::Usage" => "perl-Pod-Usage",
405 "xelatex" => "texlive-xetex-bin",
406 "rsvg-convert" => "librsvg2-tools",
409 my @fedora26_opt_pkgs = (
410 "graphviz-gd", # Fedora 26: needed for PDF support
413 my @fedora_tex_pkgs = (
414 "texlive-collection-fontsrecommended",
415 "texlive-collection-latex",
418 "dejavu-serif-fonts",
419 "dejavu-sans-mono-fonts",
423 # Checks valid for RHEL/CentOS version 7.x.
427 $rel = $1 if ($system_release =~ /release\s+(\d+)/);
429 if (!($system_release =~ /Fedora/)) {
430 $map{"virtualenv"} = "python-virtualenv";
432 if ($rel && $rel < 8) {
436 printf("Note: texlive packages on RHEL/CENTOS <= 7 are incomplete. Can't support PDF output\n");
437 printf("If you want to build PDF, please read:\n");
438 printf("\thttps://www.systutorials.com/241660/how-to-install-tex-live-on-centos-7-linux/\n");
441 if ($rel && $rel < 26) {
446 printf("Couldn't identify release number\n");
452 check_missing_file(["/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc"],
453 "google-noto-sans-cjk-ttc-fonts", 2);
456 check_rpm_missing(\@fedora26_opt_pkgs, 2) if ($pdf && !$old);
457 check_rpm_missing(\@fedora_tex_pkgs, 2) if ($pdf);
458 check_missing_tex(2) if ($pdf);
459 check_missing(\%map);
461 return if (!$need && !$optional);
464 # dnf, for Fedora 18+
465 printf("You should run:\n") if ($verbose_warn_install);
466 printf("\n\tsudo dnf install -y $install\n");
468 # yum, for RHEL (and clones) or Fedora version < 18
469 printf("You should run:\n") if ($verbose_warn_install);
470 printf("\n\tsudo yum install -y $install\n");
474 sub give_opensuse_hints()
477 "python-sphinx" => "python3-sphinx",
478 "sphinx_rtd_theme" => "python3-sphinx_rtd_theme",
479 "virtualenv" => "python3-virtualenv",
481 "convert" => "ImageMagick",
482 "Pod::Usage" => "perl-Pod-Usage",
483 "xelatex" => "texlive-xetex-bin",
486 # On Tumbleweed, this package is also named rsvg-convert
487 $map{"rsvg-convert"} = "rsvg-view" if (!($system_release =~ /Tumbleweed/));
489 my @suse_tex_pkgs = (
490 "texlive-babel-english",
506 $map{"latexmk"} = "texlive-latexmk-bin";
508 # FIXME: add support for installing CJK fonts
510 # I tried hard, but was unable to find a way to install
511 # "Noto Sans CJK SC" on openSUSE
513 check_rpm_missing(\@suse_tex_pkgs, 2) if ($pdf);
514 check_missing_tex(2) if ($pdf);
515 check_missing(\%map);
517 return if (!$need && !$optional);
518 printf("You should run:\n") if ($verbose_warn_install);
519 printf("\n\tsudo zypper install --no-recommends $install\n");
522 sub give_mageia_hints()
525 "python-sphinx" => "python3-sphinx",
526 "sphinx_rtd_theme" => "python3-sphinx_rtd_theme",
527 "virtualenv" => "python3-virtualenv",
529 "convert" => "ImageMagick",
530 "Pod::Usage" => "perl-Pod-Usage",
531 "xelatex" => "texlive",
532 "rsvg-convert" => "librsvg2",
536 "texlive-fontsextra",
539 $map{"latexmk"} = "texlive-collection-basic";
543 if ($system_release =~ /OpenMandriva/) {
544 $packager_cmd = "dnf install";
545 $noto_sans = "noto-sans-cjk-fonts";
546 @tex_pkgs = ( "texlive-collection-fontsextra" );
548 $packager_cmd = "urpmi";
549 $noto_sans = "google-noto-sans-cjk-ttc-fonts";
554 check_missing_file(["/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc",
555 "/usr/share/fonts/TTF/NotoSans-Regular.ttf"],
559 check_rpm_missing(\@tex_pkgs, 2) if ($pdf);
560 check_missing(\%map);
562 return if (!$need && !$optional);
563 printf("You should run:\n") if ($verbose_warn_install);
564 printf("\n\tsudo $packager_cmd $install\n");
567 sub give_arch_linux_hints()
570 "sphinx_rtd_theme" => "python-sphinx_rtd_theme",
571 "virtualenv" => "python-virtualenv",
573 "convert" => "imagemagick",
574 "xelatex" => "texlive-bin",
575 "latexmk" => "texlive-core",
576 "rsvg-convert" => "extra/librsvg",
579 my @archlinux_tex_pkgs = (
581 "texlive-latexextra",
584 check_pacman_missing(\@archlinux_tex_pkgs, 2) if ($pdf);
587 check_missing_file(["/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc"],
588 "noto-fonts-cjk", 2);
591 check_missing(\%map);
593 return if (!$need && !$optional);
594 printf("You should run:\n") if ($verbose_warn_install);
595 printf("\n\tsudo pacman -S $install\n");
598 sub give_gentoo_hints()
601 "sphinx_rtd_theme" => "dev-python/sphinx_rtd_theme",
602 "virtualenv" => "dev-python/virtualenv",
603 "dot" => "media-gfx/graphviz",
604 "convert" => "media-gfx/imagemagick",
605 "xelatex" => "dev-texlive/texlive-xetex media-fonts/dejavu",
606 "rsvg-convert" => "gnome-base/librsvg",
609 check_missing_file(["/usr/share/fonts/dejavu/DejaVuSans.ttf"],
610 "media-fonts/dejavu", 2) if ($pdf);
613 check_missing_file(["/usr/share/fonts/noto-cjk/NotoSansCJKsc-Regular.otf",
614 "/usr/share/fonts/noto-cjk/NotoSerifCJK-Regular.ttc"],
615 "media-fonts/noto-cjk", 2);
618 check_missing(\%map);
620 return if (!$need && !$optional);
622 printf("You should run:\n") if ($verbose_warn_install);
625 my $imagemagick = "media-gfx/imagemagick svg png";
626 my $cairo = "media-gfx/graphviz cairo pdf";
627 my $portage_imagemagick = "/etc/portage/package.use/imagemagick";
628 my $portage_cairo = "/etc/portage/package.use/graphviz";
630 if (qx(grep imagemagick $portage_imagemagick 2>/dev/null) eq "") {
631 printf("\tsudo su -c 'echo \"$imagemagick\" > $portage_imagemagick'\n")
633 if (qx(grep graphviz $portage_cairo 2>/dev/null) eq "") {
634 printf("\tsudo su -c 'echo \"$cairo\" > $portage_cairo'\n");
637 printf("\tsudo emerge --ask $install\n");
643 # Distro-specific hints
644 if ($system_release =~ /Red Hat Enterprise Linux/) {
648 if ($system_release =~ /CentOS/) {
652 if ($system_release =~ /Scientific Linux/) {
656 if ($system_release =~ /Oracle Linux Server/) {
660 if ($system_release =~ /Fedora/) {
664 if ($system_release =~ /Ubuntu/) {
668 if ($system_release =~ /Debian/) {
672 if ($system_release =~ /openSUSE/) {
676 if ($system_release =~ /Mageia/) {
680 if ($system_release =~ /OpenMandriva/) {
684 if ($system_release =~ /Arch Linux/) {
685 give_arch_linux_hints;
688 if ($system_release =~ /Gentoo/) {
694 # Fall-back to generic hint code for other distros
695 # That's far from ideal, specially for LaTeX dependencies.
698 "sphinx-build" => "sphinx"
700 check_missing_tex(2) if ($pdf);
701 check_missing(\%map);
702 print "I don't know distro $system_release.\n";
703 print "So, I can't provide you a hint with the install procedure.\n";
704 print "There are likely missing dependencies.\n";
708 # Common dependencies
711 sub deactivate_help()
713 printf "\n If you want to exit the virtualenv, you can use:\n";
714 printf "\tdeactivate\n";
720 my $min_activate = "$ENV{'PWD'}/${virtenv_prefix}${min_version}/bin/activate";
721 my @activates = glob "$ENV{'PWD'}/${virtenv_prefix}*/bin/activate";
723 @activates = sort {$b cmp $a} @activates;
725 foreach my $f (@activates) {
726 next if ($f lt $min_activate);
729 $sphinx_cmd =~ s/activate/sphinx-build/;
730 next if (! -f $sphinx_cmd);
732 my $ver = get_sphinx_version($sphinx_cmd);
735 $f =~ s#/bin/activate##;
736 print("Warning: virtual environment $f is not working.\nPython version upgrade? Remove it with:\n\n\trm -rf $f\n\n");
739 if ($need_sphinx && ($ver ge $min_version)) {
741 } elsif ($ver gt $cur_version) {
748 sub recommend_sphinx_upgrade()
752 # Avoid running sphinx-builds from venv if $cur_version is good
753 if ($cur_version && ($cur_version ge $rec_version)) {
754 $latest_avail_ver = $cur_version;
758 # Get the highest version from sphinx_*/bin/sphinx-build and the
759 # corresponding command to activate the venv/virtenv
760 ($activate_cmd, $venv_ver) = get_virtenv();
762 # Store the highest version from Sphinx existing virtualenvs
763 if (($activate_cmd ne "") && ($venv_ver gt $cur_version)) {
764 $latest_avail_ver = $venv_ver;
766 $latest_avail_ver = $cur_version if ($cur_version);
769 # As we don't know package version of Sphinx, and there's no
770 # virtual environments, don't check if upgrades are needed
772 return if (!$latest_avail_ver);
775 # Either there are already a virtual env or a new one should be created
778 return if (!$latest_avail_ver);
780 # Return if the reason is due to an upgrade or not
781 if ($latest_avail_ver lt $rec_version) {
782 $rec_sphinx_upgrade = 1;
785 return $latest_avail_ver;
789 # The logic here is complex, as it have to deal with different versions:
790 # - minimal supported version;
791 # - minimal PDF version;
792 # - recommended version.
793 # It also needs to work fine with both distro's package and venv/virtualenv
794 sub recommend_sphinx_version($)
796 my $virtualenv_cmd = shift;
798 # Version is OK. Nothing to do.
799 if ($cur_version && ($cur_version ge $rec_version)) {
800 if ($cur_version lt $min_pdf_version) {
801 print "note: If you want pdf, you need at least Sphinx $min_pdf_version.\n";
807 # sphinx-build is present and its version is >= $min_version
809 #only recommend enabling a newer virtenv version if makes sense.
810 if ($latest_avail_ver gt $cur_version) {
811 printf "\nYou may also use the newer Sphinx version $latest_avail_ver with:\n";
812 printf "\tdeactivate\n" if ($ENV{'PWD'} =~ /${virtenv_prefix}/);
813 printf "\t. $activate_cmd\n";
818 return if ($latest_avail_ver ge $rec_version);
822 # No sphinx either via package or via virtenv. As we can't
823 # Compare the versions here, just return, recommending the
824 # user to install it from the package distro.
825 return if (!$latest_avail_ver);
827 # User doesn't want a virtenv recommendation, but he already
828 # installed one via virtenv with a newer version.
829 # So, print commands to enable it
830 if ($latest_avail_ver gt $cur_version) {
831 printf "\nYou may also use the Sphinx virtualenv version $latest_avail_ver with:\n";
832 printf "\tdeactivate\n" if ($ENV{'PWD'} =~ /${virtenv_prefix}/);
833 printf "\t. $activate_cmd\n";
840 $need++ if ($need_sphinx);
843 # Suggest newer versions if current ones are too old
844 if ($latest_avail_ver && $latest_avail_ver ge $min_version) {
845 # If there's a good enough version, ask the user to enable it
846 if ($latest_avail_ver ge $rec_version) {
847 printf "\nNeed to activate Sphinx (version $latest_avail_ver) on virtualenv with:\n";
848 printf "\t. $activate_cmd\n";
851 if ($latest_avail_ver lt $min_pdf_version) {
852 print "note: If you want pdf, you need at least Sphinx $min_pdf_version.\n";
858 # Version is above the minimal required one, but may be
859 # below the recommended one. So, print warnings/notes
861 if ($latest_avail_ver lt $rec_version) {
862 print "Warning: It is recommended at least Sphinx version $rec_version.\n";
866 # At this point, either it needs Sphinx or upgrade is recommended,
869 if ($rec_sphinx_upgrade) {
871 print "Instead of install/upgrade Python Sphinx pkg, you could use pip/pypi with:\n\n";
873 print "To upgrade Sphinx, use:\n\n";
876 print "\nSphinx needs to be installed either:\n1) via pip/pypi with:\n\n";
879 $python_cmd = find_python_no_venv();
881 printf "\t$virtualenv_cmd $virtenv_dir\n";
883 printf "\t. $virtenv_dir/bin/activate\n";
884 printf "\tpip install -r $requirement_file\n";
887 printf "\n2) As a package with:\n";
889 my $old_need = $need;
890 my $old_optional = $optional;
895 $verbose_warn_install = 0;
897 add_package("python-sphinx", 0);
898 check_python_module("sphinx_rtd_theme", 1);
903 $optional = $old_optional;
905 printf "\n Please note that Sphinx >= 3.0 will currently produce false-positive\n";
906 printf " warning when the same name is used for more than one type (functions,\n";
907 printf " structs, enums,...). This is known Sphinx bug. For more details, see:\n";
908 printf "\thttps://github.com/sphinx-doc/sphinx/pull/8313\n";
913 # Check if Sphinx is already accessible from current environment
916 if ($system_release) {
917 print "Detected OS: $system_release.\n";
919 print "Unknown OS\n";
921 printf "Sphinx version: %s\n\n", $cur_version if ($cur_version);
923 # Check python command line, trying first python3
924 $python_cmd = findprog("python3");
925 $python_cmd = check_program("python", 0) if (!$python_cmd);
927 # Check the type of virtual env, depending on Python version
930 my $tmp = qx($python_cmd --version 2>&1);
931 if ($tmp =~ m/(\d+\.)(\d+\.)/) {
933 # Fail if it finds python2 (or worse)
934 die "Python 3 is required to build the kernel docs\n";
936 if ($1 == 3 && $2 < 3) {
937 # Need Python 3.3 or upper for venv
938 $need_virtualenv = 1;
941 die "Warning: couldn't identify $python_cmd version!";
944 add_package("python-sphinx", 0);
948 my $venv_ver = recommend_sphinx_upgrade();
953 # Set virtualenv command line, if python < 3.3
954 if ($need_virtualenv) {
955 $virtualenv_cmd = findprog("virtualenv-3");
956 $virtualenv_cmd = findprog("virtualenv-3.5") if (!$virtualenv_cmd);
957 if (!$virtualenv_cmd) {
958 check_program("virtualenv", 0);
959 $virtualenv_cmd = "virtualenv";
962 $virtualenv_cmd = "$python_cmd -m venv";
963 check_python_module("ensurepip", 0);
967 # Check for needed programs/tools
968 check_perl_module("Pod::Usage", 0);
969 check_program("make", 0);
970 check_program("gcc", 0);
971 check_python_module("sphinx_rtd_theme", 1) if (!$virtualenv);
972 check_program("dot", 1);
973 check_program("convert", 1);
975 # Extra PDF files - should use 2 for is_optional
976 check_program("xelatex", 2) if ($pdf);
977 check_program("rsvg-convert", 2) if ($pdf);
978 check_program("latexmk", 2) if ($pdf);
980 # Do distro-specific checks and output distro-install commands
985 die "Can't build as $need mandatory dependency is missing";
987 die "Can't build as $need mandatory dependencies are missing";
991 # Check if sphinx-build is called sphinx-build-3
993 printf "\tsudo ln -sf %s /usr/bin/sphinx-build\n\n",
994 which("sphinx-build-3");
997 recommend_sphinx_version($virtualenv_cmd);
1000 print "All optional dependencies are met.\n" if (!$optional);
1003 die "Can't build as $need mandatory dependency is missing";
1005 die "Can't build as $need mandatory dependencies are missing";
1008 print "Needed package dependencies are met.\n";
1016 my $arg = shift(@ARGV);
1018 if ($arg eq "--no-virtualenv") {
1020 } elsif ($arg eq "--no-pdf"){
1022 } elsif ($arg eq "--version-check"){
1025 print "Usage:\n\t$0 <--no-virtualenv> <--no-pdf> <--version-check>\n\n";
1027 print "\t--no-virtualenv\t- Recommend installing Sphinx instead of using a virtualenv\n";
1028 print "\t--version-check\t- if version is compatible, don't check for missing dependencies\n";
1029 print "\t--no-pdf\t- don't check for dependencies required to build PDF docs\n\n";
1035 # Determine the system type. There's no standard unique way that would
1036 # work with all distros with a minimal package install. So, several
1037 # methods are used here.
1039 # By default, it will use lsb_release function. If not available, it will
1040 # fail back to reading the known different places where the distro name
1044 $system_release = qx(lsb_release -d) if which("lsb_release");
1045 $system_release =~ s/Description:\s*// if ($system_release);
1046 $system_release = catcheck("/etc/system-release") if !$system_release;
1047 $system_release = catcheck("/etc/redhat-release") if !$system_release;
1048 $system_release = catcheck("/etc/lsb-release") if !$system_release;
1049 $system_release = catcheck("/etc/gentoo-release") if !$system_release;
1051 # This seems more common than LSB these days
1052 if (!$system_release) {
1054 if (open IN, "cat /etc/os-release|") {
1056 if (m/^([\w\d\_]+)=\"?([^\"]*)\"?\n/) {
1060 $system_release = $os_var{"NAME"};
1061 if (defined($os_var{"VERSION_ID"})) {
1062 $system_release .= " " . $os_var{"VERSION_ID"} if (defined($os_var{"VERSION_ID"}));
1064 $system_release .= " " . $os_var{"VERSION"};
1068 $system_release = catcheck("/etc/issue") if !$system_release;
1069 $system_release =~ s/\s+$//;