xref: /openbmc/linux/scripts/sphinx-pre-install (revision 54002b56b04bc83f8961c8751f6bfef07461d587)
124071ac1SMauro Carvalho Chehab#!/usr/bin/perl
224071ac1SMauro Carvalho Chehabuse strict;
324071ac1SMauro Carvalho Chehab
444f42165SMauro Carvalho Chehab# Copyright (c) 2017-2019 Mauro Carvalho Chehab <mchehab@kernel.org>
524071ac1SMauro Carvalho Chehab#
624071ac1SMauro Carvalho Chehab# This program is free software; you can redistribute it and/or
724071ac1SMauro Carvalho Chehab# modify it under the terms of the GNU General Public License
824071ac1SMauro Carvalho Chehab# as published by the Free Software Foundation; either version 2
924071ac1SMauro Carvalho Chehab# of the License, or (at your option) any later version.
1024071ac1SMauro Carvalho Chehab#
1124071ac1SMauro Carvalho Chehab# This program is distributed in the hope that it will be useful,
1224071ac1SMauro Carvalho Chehab# but WITHOUT ANY WARRANTY; without even the implied warranty of
1324071ac1SMauro Carvalho Chehab# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1424071ac1SMauro Carvalho Chehab# GNU General Public License for more details.
1524071ac1SMauro Carvalho Chehab
1677d09ad9SMauro Carvalho Chehabmy $conf = "Documentation/conf.py";
17fb947f3fSMauro Carvalho Chehabmy $requirement_file = "Documentation/sphinx/requirements.txt";
1844f42165SMauro Carvalho Chehabmy $virtenv_prefix = "sphinx_";
195be33182SMauro Carvalho Chehab
2024071ac1SMauro Carvalho Chehab#
2124071ac1SMauro Carvalho Chehab# Static vars
2224071ac1SMauro Carvalho Chehab#
2324071ac1SMauro Carvalho Chehab
2424071ac1SMauro Carvalho Chehabmy %missing;
2524071ac1SMauro Carvalho Chehabmy $system_release;
2624071ac1SMauro Carvalho Chehabmy $need = 0;
2724071ac1SMauro Carvalho Chehabmy $optional = 0;
2824071ac1SMauro Carvalho Chehabmy $need_symlink = 0;
2924071ac1SMauro Carvalho Chehabmy $need_sphinx = 0;
3077d09ad9SMauro Carvalho Chehabmy $rec_sphinx_upgrade = 0;
3124071ac1SMauro Carvalho Chehabmy $install = "";
3244f42165SMauro Carvalho Chehabmy $virtenv_dir = "";
3344f42165SMauro Carvalho Chehabmy $min_version;
3424071ac1SMauro Carvalho Chehab
3524071ac1SMauro Carvalho Chehab#
3624071ac1SMauro Carvalho Chehab# Command line arguments
3724071ac1SMauro Carvalho Chehab#
3824071ac1SMauro Carvalho Chehab
3924071ac1SMauro Carvalho Chehabmy $pdf = 1;
4024071ac1SMauro Carvalho Chehabmy $virtualenv = 1;
419b88ad54SMauro Carvalho Chehabmy $version_check = 0;
4224071ac1SMauro Carvalho Chehab
4324071ac1SMauro Carvalho Chehab#
4424071ac1SMauro Carvalho Chehab# List of required texlive packages on Fedora and OpenSuse
4524071ac1SMauro Carvalho Chehab#
4624071ac1SMauro Carvalho Chehab
4724071ac1SMauro Carvalho Chehabmy %texlive = (
4824071ac1SMauro Carvalho Chehab	'amsfonts.sty'       => 'texlive-amsfonts',
4924071ac1SMauro Carvalho Chehab	'amsmath.sty'        => 'texlive-amsmath',
5024071ac1SMauro Carvalho Chehab	'amssymb.sty'        => 'texlive-amsfonts',
5124071ac1SMauro Carvalho Chehab	'amsthm.sty'         => 'texlive-amscls',
5224071ac1SMauro Carvalho Chehab	'anyfontsize.sty'    => 'texlive-anyfontsize',
5324071ac1SMauro Carvalho Chehab	'atbegshi.sty'       => 'texlive-oberdiek',
5424071ac1SMauro Carvalho Chehab	'bm.sty'             => 'texlive-tools',
5524071ac1SMauro Carvalho Chehab	'capt-of.sty'        => 'texlive-capt-of',
5624071ac1SMauro Carvalho Chehab	'cmap.sty'           => 'texlive-cmap',
5724071ac1SMauro Carvalho Chehab	'ecrm1000.tfm'       => 'texlive-ec',
5824071ac1SMauro Carvalho Chehab	'eqparbox.sty'       => 'texlive-eqparbox',
5924071ac1SMauro Carvalho Chehab	'eu1enc.def'         => 'texlive-euenc',
6024071ac1SMauro Carvalho Chehab	'fancybox.sty'       => 'texlive-fancybox',
6124071ac1SMauro Carvalho Chehab	'fancyvrb.sty'       => 'texlive-fancyvrb',
6224071ac1SMauro Carvalho Chehab	'float.sty'          => 'texlive-float',
6324071ac1SMauro Carvalho Chehab	'fncychap.sty'       => 'texlive-fncychap',
6424071ac1SMauro Carvalho Chehab	'footnote.sty'       => 'texlive-mdwtools',
6524071ac1SMauro Carvalho Chehab	'framed.sty'         => 'texlive-framed',
6624071ac1SMauro Carvalho Chehab	'luatex85.sty'       => 'texlive-luatex85',
6724071ac1SMauro Carvalho Chehab	'multirow.sty'       => 'texlive-multirow',
6824071ac1SMauro Carvalho Chehab	'needspace.sty'      => 'texlive-needspace',
6924071ac1SMauro Carvalho Chehab	'palatino.sty'       => 'texlive-psnfss',
7024071ac1SMauro Carvalho Chehab	'parskip.sty'        => 'texlive-parskip',
7124071ac1SMauro Carvalho Chehab	'polyglossia.sty'    => 'texlive-polyglossia',
7224071ac1SMauro Carvalho Chehab	'tabulary.sty'       => 'texlive-tabulary',
7324071ac1SMauro Carvalho Chehab	'threeparttable.sty' => 'texlive-threeparttable',
7424071ac1SMauro Carvalho Chehab	'titlesec.sty'       => 'texlive-titlesec',
7524071ac1SMauro Carvalho Chehab	'ucs.sty'            => 'texlive-ucs',
7624071ac1SMauro Carvalho Chehab	'upquote.sty'        => 'texlive-upquote',
7724071ac1SMauro Carvalho Chehab	'wrapfig.sty'        => 'texlive-wrapfig',
7824071ac1SMauro Carvalho Chehab);
7924071ac1SMauro Carvalho Chehab
8024071ac1SMauro Carvalho Chehab#
8124071ac1SMauro Carvalho Chehab# Subroutines that checks if a feature exists
8224071ac1SMauro Carvalho Chehab#
8324071ac1SMauro Carvalho Chehab
8424071ac1SMauro Carvalho Chehabsub check_missing(%)
8524071ac1SMauro Carvalho Chehab{
8624071ac1SMauro Carvalho Chehab	my %map = %{$_[0]};
8724071ac1SMauro Carvalho Chehab
8824071ac1SMauro Carvalho Chehab	foreach my $prog (sort keys %missing) {
8924071ac1SMauro Carvalho Chehab		my $is_optional = $missing{$prog};
9024071ac1SMauro Carvalho Chehab
9124071ac1SMauro Carvalho Chehab		if ($is_optional) {
9224071ac1SMauro Carvalho Chehab			print "Warning: better to also install \"$prog\".\n";
9324071ac1SMauro Carvalho Chehab		} else {
9424071ac1SMauro Carvalho Chehab			print "ERROR: please install \"$prog\", otherwise, build won't work.\n";
9524071ac1SMauro Carvalho Chehab		}
9624071ac1SMauro Carvalho Chehab		if (defined($map{$prog})) {
9724071ac1SMauro Carvalho Chehab			$install .= " " . $map{$prog};
9824071ac1SMauro Carvalho Chehab		} else {
9924071ac1SMauro Carvalho Chehab			$install .= " " . $prog;
10024071ac1SMauro Carvalho Chehab		}
10124071ac1SMauro Carvalho Chehab	}
10224071ac1SMauro Carvalho Chehab
10324071ac1SMauro Carvalho Chehab	$install =~ s/^\s//;
10424071ac1SMauro Carvalho Chehab}
10524071ac1SMauro Carvalho Chehab
10624071ac1SMauro Carvalho Chehabsub add_package($$)
10724071ac1SMauro Carvalho Chehab{
10824071ac1SMauro Carvalho Chehab	my $package = shift;
10924071ac1SMauro Carvalho Chehab	my $is_optional = shift;
11024071ac1SMauro Carvalho Chehab
11124071ac1SMauro Carvalho Chehab	$missing{$package} = $is_optional;
11224071ac1SMauro Carvalho Chehab	if ($is_optional) {
11324071ac1SMauro Carvalho Chehab		$optional++;
11424071ac1SMauro Carvalho Chehab	} else {
11524071ac1SMauro Carvalho Chehab		$need++;
11624071ac1SMauro Carvalho Chehab	}
11724071ac1SMauro Carvalho Chehab}
11824071ac1SMauro Carvalho Chehab
11924071ac1SMauro Carvalho Chehabsub check_missing_file($$$)
12024071ac1SMauro Carvalho Chehab{
12124071ac1SMauro Carvalho Chehab	my $file = shift;
12224071ac1SMauro Carvalho Chehab	my $package = shift;
12324071ac1SMauro Carvalho Chehab	my $is_optional = shift;
12424071ac1SMauro Carvalho Chehab
12524071ac1SMauro Carvalho Chehab	return if(-e $file);
12624071ac1SMauro Carvalho Chehab
12724071ac1SMauro Carvalho Chehab	add_package($package, $is_optional);
12824071ac1SMauro Carvalho Chehab}
12924071ac1SMauro Carvalho Chehab
13024071ac1SMauro Carvalho Chehabsub findprog($)
13124071ac1SMauro Carvalho Chehab{
13224071ac1SMauro Carvalho Chehab	foreach(split(/:/, $ENV{PATH})) {
13324071ac1SMauro Carvalho Chehab		return "$_/$_[0]" if(-x "$_/$_[0]");
13424071ac1SMauro Carvalho Chehab	}
13524071ac1SMauro Carvalho Chehab}
13624071ac1SMauro Carvalho Chehab
13724071ac1SMauro Carvalho Chehabsub check_program($$)
13824071ac1SMauro Carvalho Chehab{
13924071ac1SMauro Carvalho Chehab	my $prog = shift;
14024071ac1SMauro Carvalho Chehab	my $is_optional = shift;
14124071ac1SMauro Carvalho Chehab
14224071ac1SMauro Carvalho Chehab	return if findprog($prog);
14324071ac1SMauro Carvalho Chehab
14424071ac1SMauro Carvalho Chehab	add_package($prog, $is_optional);
14524071ac1SMauro Carvalho Chehab}
14624071ac1SMauro Carvalho Chehab
14724071ac1SMauro Carvalho Chehabsub check_perl_module($$)
14824071ac1SMauro Carvalho Chehab{
14924071ac1SMauro Carvalho Chehab	my $prog = shift;
15024071ac1SMauro Carvalho Chehab	my $is_optional = shift;
15124071ac1SMauro Carvalho Chehab
15224071ac1SMauro Carvalho Chehab	my $err = system("perl -M$prog -e 1 2>/dev/null /dev/null");
15324071ac1SMauro Carvalho Chehab	return if ($err == 0);
15424071ac1SMauro Carvalho Chehab
15524071ac1SMauro Carvalho Chehab	add_package($prog, $is_optional);
15624071ac1SMauro Carvalho Chehab}
15724071ac1SMauro Carvalho Chehab
15824071ac1SMauro Carvalho Chehabsub check_python_module($$)
15924071ac1SMauro Carvalho Chehab{
16024071ac1SMauro Carvalho Chehab	my $prog = shift;
16124071ac1SMauro Carvalho Chehab	my $is_optional = shift;
16224071ac1SMauro Carvalho Chehab
16324071ac1SMauro Carvalho Chehab	my $err = system("python3 -c 'import $prog' 2>/dev/null /dev/null");
16424071ac1SMauro Carvalho Chehab	return if ($err == 0);
16524071ac1SMauro Carvalho Chehab	my $err = system("python -c 'import $prog' 2>/dev/null /dev/null");
16624071ac1SMauro Carvalho Chehab	return if ($err == 0);
16724071ac1SMauro Carvalho Chehab
16824071ac1SMauro Carvalho Chehab	add_package($prog, $is_optional);
16924071ac1SMauro Carvalho Chehab}
17024071ac1SMauro Carvalho Chehab
17124071ac1SMauro Carvalho Chehabsub check_rpm_missing($$)
17224071ac1SMauro Carvalho Chehab{
17324071ac1SMauro Carvalho Chehab	my @pkgs = @{$_[0]};
17424071ac1SMauro Carvalho Chehab	my $is_optional = $_[1];
17524071ac1SMauro Carvalho Chehab
17624071ac1SMauro Carvalho Chehab	foreach my $prog(@pkgs) {
17724071ac1SMauro Carvalho Chehab		my $err = system("rpm -q '$prog' 2>/dev/null >/dev/null");
17824071ac1SMauro Carvalho Chehab		add_package($prog, $is_optional) if ($err);
17924071ac1SMauro Carvalho Chehab	}
18024071ac1SMauro Carvalho Chehab}
18124071ac1SMauro Carvalho Chehab
18224071ac1SMauro Carvalho Chehabsub check_pacman_missing($$)
18324071ac1SMauro Carvalho Chehab{
18424071ac1SMauro Carvalho Chehab	my @pkgs = @{$_[0]};
18524071ac1SMauro Carvalho Chehab	my $is_optional = $_[1];
18624071ac1SMauro Carvalho Chehab
18724071ac1SMauro Carvalho Chehab	foreach my $prog(@pkgs) {
18824071ac1SMauro Carvalho Chehab		my $err = system("pacman -Q '$prog' 2>/dev/null >/dev/null");
18924071ac1SMauro Carvalho Chehab		add_package($prog, $is_optional) if ($err);
19024071ac1SMauro Carvalho Chehab	}
19124071ac1SMauro Carvalho Chehab}
19224071ac1SMauro Carvalho Chehab
19324071ac1SMauro Carvalho Chehabsub check_missing_tex($)
19424071ac1SMauro Carvalho Chehab{
19524071ac1SMauro Carvalho Chehab	my $is_optional = shift;
19624071ac1SMauro Carvalho Chehab	my $kpsewhich = findprog("kpsewhich");
19724071ac1SMauro Carvalho Chehab
19824071ac1SMauro Carvalho Chehab	foreach my $prog(keys %texlive) {
19924071ac1SMauro Carvalho Chehab		my $package = $texlive{$prog};
20024071ac1SMauro Carvalho Chehab		if (!$kpsewhich) {
20124071ac1SMauro Carvalho Chehab			add_package($package, $is_optional);
20224071ac1SMauro Carvalho Chehab			next;
20324071ac1SMauro Carvalho Chehab		}
20424071ac1SMauro Carvalho Chehab		my $file = qx($kpsewhich $prog);
20524071ac1SMauro Carvalho Chehab		add_package($package, $is_optional) if ($file =~ /^\s*$/);
20624071ac1SMauro Carvalho Chehab	}
20724071ac1SMauro Carvalho Chehab}
20824071ac1SMauro Carvalho Chehab
20977d09ad9SMauro Carvalho Chehabsub get_sphinx_fname()
21024071ac1SMauro Carvalho Chehab{
21177d09ad9SMauro Carvalho Chehab	my $fname = "sphinx-build";
21277d09ad9SMauro Carvalho Chehab	return $fname if findprog($fname);
21324071ac1SMauro Carvalho Chehab
21477d09ad9SMauro Carvalho Chehab	$fname = "sphinx-build-3";
21577d09ad9SMauro Carvalho Chehab	if (findprog($fname)) {
21624071ac1SMauro Carvalho Chehab		$need_symlink = 1;
21777d09ad9SMauro Carvalho Chehab		return $fname;
21824071ac1SMauro Carvalho Chehab	}
21924071ac1SMauro Carvalho Chehab
22024071ac1SMauro Carvalho Chehab	if ($virtualenv) {
221800d408aSMauro Carvalho Chehab		my $prog = findprog("virtualenv-3");
222800d408aSMauro Carvalho Chehab		$prog = findprog("virtualenv-3.5") if (!$prog);
223800d408aSMauro Carvalho Chehab
224800d408aSMauro Carvalho Chehab		check_program("virtualenv", 0) if (!$prog);
22524071ac1SMauro Carvalho Chehab		$need_sphinx = 1;
22624071ac1SMauro Carvalho Chehab	} else {
22724071ac1SMauro Carvalho Chehab		add_package("python-sphinx", 0);
22824071ac1SMauro Carvalho Chehab	}
22977d09ad9SMauro Carvalho Chehab
23077d09ad9SMauro Carvalho Chehab	return "";
23177d09ad9SMauro Carvalho Chehab}
23277d09ad9SMauro Carvalho Chehab
23377d09ad9SMauro Carvalho Chehabsub check_sphinx()
23477d09ad9SMauro Carvalho Chehab{
23577d09ad9SMauro Carvalho Chehab	my $rec_version;
23677d09ad9SMauro Carvalho Chehab	my $cur_version;
23777d09ad9SMauro Carvalho Chehab
23877d09ad9SMauro Carvalho Chehab	open IN, $conf or die "Can't open $conf";
23977d09ad9SMauro Carvalho Chehab	while (<IN>) {
24077d09ad9SMauro Carvalho Chehab		if (m/^\s*needs_sphinx\s*=\s*[\'\"]([\d\.]+)[\'\"]/) {
24177d09ad9SMauro Carvalho Chehab			$min_version=$1;
24277d09ad9SMauro Carvalho Chehab			last;
24377d09ad9SMauro Carvalho Chehab		}
24477d09ad9SMauro Carvalho Chehab	}
24577d09ad9SMauro Carvalho Chehab	close IN;
24677d09ad9SMauro Carvalho Chehab
24777d09ad9SMauro Carvalho Chehab	die "Can't get needs_sphinx version from $conf" if (!$min_version);
24877d09ad9SMauro Carvalho Chehab
24977d09ad9SMauro Carvalho Chehab	open IN, $requirement_file or die "Can't open $requirement_file";
25077d09ad9SMauro Carvalho Chehab	while (<IN>) {
25177d09ad9SMauro Carvalho Chehab		if (m/^\s*Sphinx\s*==\s*([\d\.]+)$/) {
25277d09ad9SMauro Carvalho Chehab			$rec_version=$1;
25377d09ad9SMauro Carvalho Chehab			last;
25477d09ad9SMauro Carvalho Chehab		}
25577d09ad9SMauro Carvalho Chehab	}
25677d09ad9SMauro Carvalho Chehab	close IN;
25777d09ad9SMauro Carvalho Chehab
25877d09ad9SMauro Carvalho Chehab	die "Can't get recommended sphinx version from $requirement_file" if (!$min_version);
25977d09ad9SMauro Carvalho Chehab
26044f42165SMauro Carvalho Chehab	$virtenv_dir = $virtenv_prefix . $rec_version;
26177d09ad9SMauro Carvalho Chehab
26277d09ad9SMauro Carvalho Chehab	my $sphinx = get_sphinx_fname();
26377d09ad9SMauro Carvalho Chehab	return if ($sphinx eq "");
26477d09ad9SMauro Carvalho Chehab
26577d09ad9SMauro Carvalho Chehab	open IN, "$sphinx --version 2>&1 |" or die "$sphinx returned an error";
26677d09ad9SMauro Carvalho Chehab	while (<IN>) {
26777d09ad9SMauro Carvalho Chehab		if (m/^\s*sphinx-build\s+([\d\.]+)$/) {
26877d09ad9SMauro Carvalho Chehab			$cur_version=$1;
26977d09ad9SMauro Carvalho Chehab			last;
27077d09ad9SMauro Carvalho Chehab		}
27177d09ad9SMauro Carvalho Chehab		# Sphinx 1.2.x uses a different format
27277d09ad9SMauro Carvalho Chehab		if (m/^\s*Sphinx.*\s+([\d\.]+)$/) {
27377d09ad9SMauro Carvalho Chehab			$cur_version=$1;
27477d09ad9SMauro Carvalho Chehab			last;
27577d09ad9SMauro Carvalho Chehab		}
27677d09ad9SMauro Carvalho Chehab	}
27777d09ad9SMauro Carvalho Chehab	close IN;
27877d09ad9SMauro Carvalho Chehab
27977d09ad9SMauro Carvalho Chehab	die "$sphinx didn't return its version" if (!$cur_version);
28077d09ad9SMauro Carvalho Chehab
28177d09ad9SMauro Carvalho Chehab	if ($cur_version lt $min_version) {
2829b88ad54SMauro Carvalho Chehab		printf "ERROR: Sphinx version is %s. It should be >= %s (recommended >= %s)\n",
2839b88ad54SMauro Carvalho Chehab		       $cur_version, $min_version, $rec_version;;
28477d09ad9SMauro Carvalho Chehab		$need_sphinx = 1;
28577d09ad9SMauro Carvalho Chehab		return;
28677d09ad9SMauro Carvalho Chehab	}
28777d09ad9SMauro Carvalho Chehab
28877d09ad9SMauro Carvalho Chehab	if ($cur_version lt $rec_version) {
2899b88ad54SMauro Carvalho Chehab		printf "Sphinx version %s\n", $cur_version;
29077d09ad9SMauro Carvalho Chehab		print "Warning: It is recommended at least Sphinx version $rec_version.\n";
29177d09ad9SMauro Carvalho Chehab		$rec_sphinx_upgrade = 1;
2929b88ad54SMauro Carvalho Chehab		return;
29377d09ad9SMauro Carvalho Chehab	}
2949b88ad54SMauro Carvalho Chehab
2959b88ad54SMauro Carvalho Chehab	# On version check mode, just assume Sphinx has all mandatory deps
2969b88ad54SMauro Carvalho Chehab	exit (0) if ($version_check);
29724071ac1SMauro Carvalho Chehab}
29824071ac1SMauro Carvalho Chehab
29924071ac1SMauro Carvalho Chehab#
30024071ac1SMauro Carvalho Chehab# Ancillary subroutines
30124071ac1SMauro Carvalho Chehab#
30224071ac1SMauro Carvalho Chehab
30324071ac1SMauro Carvalho Chehabsub catcheck($)
30424071ac1SMauro Carvalho Chehab{
30524071ac1SMauro Carvalho Chehab  my $res = "";
30624071ac1SMauro Carvalho Chehab  $res = qx(cat $_[0]) if (-r $_[0]);
30724071ac1SMauro Carvalho Chehab  return $res;
30824071ac1SMauro Carvalho Chehab}
30924071ac1SMauro Carvalho Chehab
31024071ac1SMauro Carvalho Chehabsub which($)
31124071ac1SMauro Carvalho Chehab{
31224071ac1SMauro Carvalho Chehab	my $file = shift;
31324071ac1SMauro Carvalho Chehab	my @path = split ":", $ENV{PATH};
31424071ac1SMauro Carvalho Chehab
31524071ac1SMauro Carvalho Chehab	foreach my $dir(@path) {
31624071ac1SMauro Carvalho Chehab		my $name = $dir.'/'.$file;
31724071ac1SMauro Carvalho Chehab		return $name if (-x $name );
31824071ac1SMauro Carvalho Chehab	}
31924071ac1SMauro Carvalho Chehab	return undef;
32024071ac1SMauro Carvalho Chehab}
32124071ac1SMauro Carvalho Chehab
32224071ac1SMauro Carvalho Chehab#
32324071ac1SMauro Carvalho Chehab# Subroutines that check distro-specific hints
32424071ac1SMauro Carvalho Chehab#
32524071ac1SMauro Carvalho Chehab
32624071ac1SMauro Carvalho Chehabsub give_debian_hints()
32724071ac1SMauro Carvalho Chehab{
32824071ac1SMauro Carvalho Chehab	my %map = (
32924071ac1SMauro Carvalho Chehab		"python-sphinx"		=> "python3-sphinx",
33024071ac1SMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "python3-sphinx-rtd-theme",
33124071ac1SMauro Carvalho Chehab		"virtualenv"		=> "virtualenv",
33224071ac1SMauro Carvalho Chehab		"dot"			=> "graphviz",
33324071ac1SMauro Carvalho Chehab		"convert"		=> "imagemagick",
33424071ac1SMauro Carvalho Chehab		"Pod::Usage"		=> "perl-modules",
33524071ac1SMauro Carvalho Chehab		"xelatex"		=> "texlive-xetex",
3368e7d5d15SMauro Carvalho Chehab		"rsvg-convert"		=> "librsvg2-bin",
33724071ac1SMauro Carvalho Chehab	);
33824071ac1SMauro Carvalho Chehab
33924071ac1SMauro Carvalho Chehab	if ($pdf) {
34024071ac1SMauro Carvalho Chehab		check_missing_file("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
34124071ac1SMauro Carvalho Chehab				   "fonts-dejavu", 1);
34224071ac1SMauro Carvalho Chehab	}
34324071ac1SMauro Carvalho Chehab
34424071ac1SMauro Carvalho Chehab	check_program("dvipng", 1) if ($pdf);
34524071ac1SMauro Carvalho Chehab	check_missing(\%map);
34624071ac1SMauro Carvalho Chehab
34724071ac1SMauro Carvalho Chehab	return if (!$need && !$optional);
34824071ac1SMauro Carvalho Chehab	printf("You should run:\n\n\tsudo apt-get install $install\n");
34924071ac1SMauro Carvalho Chehab}
35024071ac1SMauro Carvalho Chehab
35124071ac1SMauro Carvalho Chehabsub give_redhat_hints()
35224071ac1SMauro Carvalho Chehab{
35324071ac1SMauro Carvalho Chehab	my %map = (
35424071ac1SMauro Carvalho Chehab		"python-sphinx"		=> "python3-sphinx",
35524071ac1SMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "python3-sphinx_rtd_theme",
35624071ac1SMauro Carvalho Chehab		"virtualenv"		=> "python3-virtualenv",
35724071ac1SMauro Carvalho Chehab		"dot"			=> "graphviz",
35824071ac1SMauro Carvalho Chehab		"convert"		=> "ImageMagick",
35924071ac1SMauro Carvalho Chehab		"Pod::Usage"		=> "perl-Pod-Usage",
36024071ac1SMauro Carvalho Chehab		"xelatex"		=> "texlive-xetex-bin",
3618e7d5d15SMauro Carvalho Chehab		"rsvg-convert"		=> "librsvg2-tools",
36224071ac1SMauro Carvalho Chehab	);
36324071ac1SMauro Carvalho Chehab
3645d88953cSMauro Carvalho Chehab	my @fedora26_opt_pkgs = (
3655d88953cSMauro Carvalho Chehab		"graphviz-gd",		# Fedora 26: needed for PDF support
3665d88953cSMauro Carvalho Chehab	);
3675d88953cSMauro Carvalho Chehab
36824071ac1SMauro Carvalho Chehab	my @fedora_tex_pkgs = (
36924071ac1SMauro Carvalho Chehab		"texlive-collection-fontsrecommended",
37024071ac1SMauro Carvalho Chehab		"texlive-collection-latex",
37124071ac1SMauro Carvalho Chehab		"dejavu-sans-fonts",
37224071ac1SMauro Carvalho Chehab		"dejavu-serif-fonts",
37324071ac1SMauro Carvalho Chehab		"dejavu-sans-mono-fonts",
37424071ac1SMauro Carvalho Chehab	);
37524071ac1SMauro Carvalho Chehab
3769b756a9dSMauro Carvalho Chehab	#
3779b756a9dSMauro Carvalho Chehab	# Checks valid for RHEL/CentOS version 7.x.
3789b756a9dSMauro Carvalho Chehab	#
3799b756a9dSMauro Carvalho Chehab	if (! $system_release =~ /Fedora/) {
3809b756a9dSMauro Carvalho Chehab		$map{"virtualenv"} = "python-virtualenv";
3819b756a9dSMauro Carvalho Chehab	}
3829b756a9dSMauro Carvalho Chehab
3835d88953cSMauro Carvalho Chehab	my $release;
3845d88953cSMauro Carvalho Chehab
3855d88953cSMauro Carvalho Chehab	$release = $1 if ($system_release =~ /Fedora\s+release\s+(\d+)/);
3865d88953cSMauro Carvalho Chehab
3875d88953cSMauro Carvalho Chehab	check_rpm_missing(\@fedora26_opt_pkgs, 1) if ($pdf && $release >= 26);
38824071ac1SMauro Carvalho Chehab	check_rpm_missing(\@fedora_tex_pkgs, 1) if ($pdf);
38924071ac1SMauro Carvalho Chehab	check_missing_tex(1) if ($pdf);
39024071ac1SMauro Carvalho Chehab	check_missing(\%map);
39124071ac1SMauro Carvalho Chehab
39224071ac1SMauro Carvalho Chehab	return if (!$need && !$optional);
3939b756a9dSMauro Carvalho Chehab
3949b756a9dSMauro Carvalho Chehab	if ($release >= 18) {
3959b756a9dSMauro Carvalho Chehab		# dnf, for Fedora 18+
39624071ac1SMauro Carvalho Chehab		printf("You should run:\n\n\tsudo dnf install -y $install\n");
3979b756a9dSMauro Carvalho Chehab	} else {
3989b756a9dSMauro Carvalho Chehab		# yum, for RHEL (and clones) or Fedora version < 18
3999b756a9dSMauro Carvalho Chehab		printf("You should run:\n\n\tsudo yum install -y $install\n");
4009b756a9dSMauro Carvalho Chehab	}
40124071ac1SMauro Carvalho Chehab}
40224071ac1SMauro Carvalho Chehab
40324071ac1SMauro Carvalho Chehabsub give_opensuse_hints()
40424071ac1SMauro Carvalho Chehab{
40524071ac1SMauro Carvalho Chehab	my %map = (
40624071ac1SMauro Carvalho Chehab		"python-sphinx"		=> "python3-sphinx",
40724071ac1SMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "python3-sphinx_rtd_theme",
40824071ac1SMauro Carvalho Chehab		"virtualenv"		=> "python3-virtualenv",
40924071ac1SMauro Carvalho Chehab		"dot"			=> "graphviz",
41024071ac1SMauro Carvalho Chehab		"convert"		=> "ImageMagick",
41124071ac1SMauro Carvalho Chehab		"Pod::Usage"		=> "perl-Pod-Usage",
41224071ac1SMauro Carvalho Chehab		"xelatex"		=> "texlive-xetex-bin",
4138e7d5d15SMauro Carvalho Chehab		"rsvg-convert"		=> "rsvg-view",
41424071ac1SMauro Carvalho Chehab	);
41524071ac1SMauro Carvalho Chehab
41624071ac1SMauro Carvalho Chehab	my @suse_tex_pkgs = (
41724071ac1SMauro Carvalho Chehab		"texlive-babel-english",
41824071ac1SMauro Carvalho Chehab		"texlive-caption",
41924071ac1SMauro Carvalho Chehab		"texlive-colortbl",
42024071ac1SMauro Carvalho Chehab		"texlive-courier",
42124071ac1SMauro Carvalho Chehab		"texlive-dvips",
42224071ac1SMauro Carvalho Chehab		"texlive-helvetic",
42324071ac1SMauro Carvalho Chehab		"texlive-makeindex",
42424071ac1SMauro Carvalho Chehab		"texlive-metafont",
42524071ac1SMauro Carvalho Chehab		"texlive-metapost",
42624071ac1SMauro Carvalho Chehab		"texlive-palatino",
42724071ac1SMauro Carvalho Chehab		"texlive-preview",
42824071ac1SMauro Carvalho Chehab		"texlive-times",
42924071ac1SMauro Carvalho Chehab		"texlive-zapfchan",
43024071ac1SMauro Carvalho Chehab		"texlive-zapfding",
43124071ac1SMauro Carvalho Chehab	);
43224071ac1SMauro Carvalho Chehab
43324071ac1SMauro Carvalho Chehab	check_rpm_missing(\@suse_tex_pkgs, 1) if ($pdf);
43424071ac1SMauro Carvalho Chehab	check_missing_tex(1) if ($pdf);
43524071ac1SMauro Carvalho Chehab	check_missing(\%map);
43624071ac1SMauro Carvalho Chehab
43724071ac1SMauro Carvalho Chehab	return if (!$need && !$optional);
43824071ac1SMauro Carvalho Chehab	printf("You should run:\n\n\tsudo zypper install --no-recommends $install\n");
43924071ac1SMauro Carvalho Chehab}
44024071ac1SMauro Carvalho Chehab
441800d408aSMauro Carvalho Chehabsub give_mageia_hints()
442800d408aSMauro Carvalho Chehab{
443800d408aSMauro Carvalho Chehab	my %map = (
444800d408aSMauro Carvalho Chehab		"python-sphinx"		=> "python3-sphinx",
445800d408aSMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "python3-sphinx_rtd_theme",
446800d408aSMauro Carvalho Chehab		"virtualenv"		=> "python3-virtualenv",
447800d408aSMauro Carvalho Chehab		"dot"			=> "graphviz",
448800d408aSMauro Carvalho Chehab		"convert"		=> "ImageMagick",
449800d408aSMauro Carvalho Chehab		"Pod::Usage"		=> "perl-Pod-Usage",
450800d408aSMauro Carvalho Chehab		"xelatex"		=> "texlive",
451800d408aSMauro Carvalho Chehab		"rsvg-convert"		=> "librsvg2-tools",
452800d408aSMauro Carvalho Chehab	);
453800d408aSMauro Carvalho Chehab
454800d408aSMauro Carvalho Chehab	my @tex_pkgs = (
455800d408aSMauro Carvalho Chehab		"texlive-fontsextra",
456800d408aSMauro Carvalho Chehab	);
457800d408aSMauro Carvalho Chehab
458800d408aSMauro Carvalho Chehab	check_rpm_missing(\@tex_pkgs, 1) if ($pdf);
459800d408aSMauro Carvalho Chehab	check_missing(\%map);
460800d408aSMauro Carvalho Chehab
461800d408aSMauro Carvalho Chehab	return if (!$need && !$optional);
462800d408aSMauro Carvalho Chehab	printf("You should run:\n\n\tsudo urpmi $install\n");
463800d408aSMauro Carvalho Chehab}
464800d408aSMauro Carvalho Chehab
46524071ac1SMauro Carvalho Chehabsub give_arch_linux_hints()
46624071ac1SMauro Carvalho Chehab{
46724071ac1SMauro Carvalho Chehab	my %map = (
46824071ac1SMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "python-sphinx_rtd_theme",
46924071ac1SMauro Carvalho Chehab		"virtualenv"		=> "python-virtualenv",
47024071ac1SMauro Carvalho Chehab		"dot"			=> "graphviz",
47124071ac1SMauro Carvalho Chehab		"convert"		=> "imagemagick",
47224071ac1SMauro Carvalho Chehab		"xelatex"		=> "texlive-bin",
4738e7d5d15SMauro Carvalho Chehab		"rsvg-convert"		=> "extra/librsvg",
47424071ac1SMauro Carvalho Chehab	);
47524071ac1SMauro Carvalho Chehab
47624071ac1SMauro Carvalho Chehab	my @archlinux_tex_pkgs = (
47724071ac1SMauro Carvalho Chehab		"texlive-core",
47824071ac1SMauro Carvalho Chehab		"texlive-latexextra",
47924071ac1SMauro Carvalho Chehab		"ttf-dejavu",
48024071ac1SMauro Carvalho Chehab	);
48124071ac1SMauro Carvalho Chehab	check_pacman_missing(\@archlinux_tex_pkgs, 1) if ($pdf);
48224071ac1SMauro Carvalho Chehab	check_missing(\%map);
48324071ac1SMauro Carvalho Chehab
48424071ac1SMauro Carvalho Chehab	return if (!$need && !$optional);
48524071ac1SMauro Carvalho Chehab	printf("You should run:\n\n\tsudo pacman -S $install\n");
48624071ac1SMauro Carvalho Chehab}
48724071ac1SMauro Carvalho Chehab
48824071ac1SMauro Carvalho Chehabsub give_gentoo_hints()
48924071ac1SMauro Carvalho Chehab{
49024071ac1SMauro Carvalho Chehab	my %map = (
49124071ac1SMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "dev-python/sphinx_rtd_theme",
49224071ac1SMauro Carvalho Chehab		"virtualenv"		=> "dev-python/virtualenv",
49324071ac1SMauro Carvalho Chehab		"dot"			=> "media-gfx/graphviz",
49424071ac1SMauro Carvalho Chehab		"convert"		=> "media-gfx/imagemagick",
49524071ac1SMauro Carvalho Chehab		"xelatex"		=> "dev-texlive/texlive-xetex media-fonts/dejavu",
4968e7d5d15SMauro Carvalho Chehab		"rsvg-convert"		=> "gnome-base/librsvg",
49724071ac1SMauro Carvalho Chehab	);
49824071ac1SMauro Carvalho Chehab
49924071ac1SMauro Carvalho Chehab	check_missing_file("/usr/share/fonts/dejavu/DejaVuSans.ttf",
50024071ac1SMauro Carvalho Chehab			   "media-fonts/dejavu", 1) if ($pdf);
50124071ac1SMauro Carvalho Chehab
50224071ac1SMauro Carvalho Chehab	check_missing(\%map);
50324071ac1SMauro Carvalho Chehab
50424071ac1SMauro Carvalho Chehab	return if (!$need && !$optional);
505bba1e4cbSMauro Carvalho Chehab
506bba1e4cbSMauro Carvalho Chehab	printf("You should run:\n\n");
507bba1e4cbSMauro Carvalho Chehab	printf("\tsudo su -c 'echo \"media-gfx/imagemagick svg png\" > /etc/portage/package.use/imagemagick'\n");
508bba1e4cbSMauro Carvalho Chehab	printf("\tsudo su -c 'echo \"media-gfx/graphviz cairo pdf\" > /etc/portage/package.use/graphviz'\n");
509bba1e4cbSMauro Carvalho Chehab	printf("\tsudo emerge --ask $install\n");
510bba1e4cbSMauro Carvalho Chehab
51124071ac1SMauro Carvalho Chehab}
51224071ac1SMauro Carvalho Chehab
51324071ac1SMauro Carvalho Chehabsub check_distros()
51424071ac1SMauro Carvalho Chehab{
51524071ac1SMauro Carvalho Chehab	# Distro-specific hints
51624071ac1SMauro Carvalho Chehab	if ($system_release =~ /Red Hat Enterprise Linux/) {
51724071ac1SMauro Carvalho Chehab		give_redhat_hints;
51824071ac1SMauro Carvalho Chehab		return;
51924071ac1SMauro Carvalho Chehab	}
5209b756a9dSMauro Carvalho Chehab	if ($system_release =~ /CentOS/) {
5219b756a9dSMauro Carvalho Chehab		give_redhat_hints;
5229b756a9dSMauro Carvalho Chehab		return;
5239b756a9dSMauro Carvalho Chehab	}
5249b756a9dSMauro Carvalho Chehab	if ($system_release =~ /Scientific Linux/) {
5259b756a9dSMauro Carvalho Chehab		give_redhat_hints;
5269b756a9dSMauro Carvalho Chehab		return;
5279b756a9dSMauro Carvalho Chehab	}
5289b756a9dSMauro Carvalho Chehab	if ($system_release =~ /Oracle Linux Server/) {
5299b756a9dSMauro Carvalho Chehab		give_redhat_hints;
5309b756a9dSMauro Carvalho Chehab		return;
5319b756a9dSMauro Carvalho Chehab	}
53224071ac1SMauro Carvalho Chehab	if ($system_release =~ /Fedora/) {
53324071ac1SMauro Carvalho Chehab		give_redhat_hints;
53424071ac1SMauro Carvalho Chehab		return;
53524071ac1SMauro Carvalho Chehab	}
53624071ac1SMauro Carvalho Chehab	if ($system_release =~ /Ubuntu/) {
53724071ac1SMauro Carvalho Chehab		give_debian_hints;
53824071ac1SMauro Carvalho Chehab		return;
53924071ac1SMauro Carvalho Chehab	}
54024071ac1SMauro Carvalho Chehab	if ($system_release =~ /Debian/) {
54124071ac1SMauro Carvalho Chehab		give_debian_hints;
54224071ac1SMauro Carvalho Chehab		return;
54324071ac1SMauro Carvalho Chehab	}
54424071ac1SMauro Carvalho Chehab	if ($system_release =~ /openSUSE/) {
54524071ac1SMauro Carvalho Chehab		give_opensuse_hints;
54624071ac1SMauro Carvalho Chehab		return;
54724071ac1SMauro Carvalho Chehab	}
548800d408aSMauro Carvalho Chehab	if ($system_release =~ /Mageia/) {
549800d408aSMauro Carvalho Chehab		give_mageia_hints;
550800d408aSMauro Carvalho Chehab		return;
551800d408aSMauro Carvalho Chehab	}
55224071ac1SMauro Carvalho Chehab	if ($system_release =~ /Arch Linux/) {
55324071ac1SMauro Carvalho Chehab		give_arch_linux_hints;
55424071ac1SMauro Carvalho Chehab		return;
55524071ac1SMauro Carvalho Chehab	}
55624071ac1SMauro Carvalho Chehab	if ($system_release =~ /Gentoo/) {
55724071ac1SMauro Carvalho Chehab		give_gentoo_hints;
55824071ac1SMauro Carvalho Chehab		return;
55924071ac1SMauro Carvalho Chehab	}
56024071ac1SMauro Carvalho Chehab
56124071ac1SMauro Carvalho Chehab	#
56224071ac1SMauro Carvalho Chehab	# Fall-back to generic hint code for other distros
56324071ac1SMauro Carvalho Chehab	# That's far from ideal, specially for LaTeX dependencies.
56424071ac1SMauro Carvalho Chehab	#
56524071ac1SMauro Carvalho Chehab	my %map = (
56624071ac1SMauro Carvalho Chehab		"sphinx-build" => "sphinx"
56724071ac1SMauro Carvalho Chehab	);
56824071ac1SMauro Carvalho Chehab	check_missing_tex(1) if ($pdf);
56924071ac1SMauro Carvalho Chehab	check_missing(\%map);
57024071ac1SMauro Carvalho Chehab	print "I don't know distro $system_release.\n";
57124071ac1SMauro Carvalho Chehab	print "So, I can't provide you a hint with the install procedure.\n";
57224071ac1SMauro Carvalho Chehab	print "There are likely missing dependencies.\n";
57324071ac1SMauro Carvalho Chehab}
57424071ac1SMauro Carvalho Chehab
57524071ac1SMauro Carvalho Chehab#
57624071ac1SMauro Carvalho Chehab# Common dependencies
57724071ac1SMauro Carvalho Chehab#
57824071ac1SMauro Carvalho Chehab
57924071ac1SMauro Carvalho Chehabsub check_needs()
58024071ac1SMauro Carvalho Chehab{
58124071ac1SMauro Carvalho Chehab	# Check for needed programs/tools
58224071ac1SMauro Carvalho Chehab	check_sphinx();
5839b88ad54SMauro Carvalho Chehab
5849b88ad54SMauro Carvalho Chehab	if ($system_release) {
5859b88ad54SMauro Carvalho Chehab		print "Detected OS: $system_release.\n\n";
5869b88ad54SMauro Carvalho Chehab	} else {
5879b88ad54SMauro Carvalho Chehab		print "Unknown OS\n\n";
5889b88ad54SMauro Carvalho Chehab	}
5899b88ad54SMauro Carvalho Chehab
5909b88ad54SMauro Carvalho Chehab	print "To upgrade Sphinx, use:\n\n" if ($rec_sphinx_upgrade);
5919b88ad54SMauro Carvalho Chehab
5929b88ad54SMauro Carvalho Chehab	# Check for needed programs/tools
59324071ac1SMauro Carvalho Chehab	check_perl_module("Pod::Usage", 0);
59424071ac1SMauro Carvalho Chehab	check_program("make", 0);
59524071ac1SMauro Carvalho Chehab	check_program("gcc", 0);
59624071ac1SMauro Carvalho Chehab	check_python_module("sphinx_rtd_theme", 1) if (!$virtualenv);
59724071ac1SMauro Carvalho Chehab	check_program("xelatex", 1) if ($pdf);
59824071ac1SMauro Carvalho Chehab	check_program("dot", 1);
59924071ac1SMauro Carvalho Chehab	check_program("convert", 1);
6008e7d5d15SMauro Carvalho Chehab	check_program("rsvg-convert", 1) if ($pdf);
6015f6df00fSMauro Carvalho Chehab	check_program("latexmk", 1) if ($pdf);
60224071ac1SMauro Carvalho Chehab
60324071ac1SMauro Carvalho Chehab	check_distros();
60424071ac1SMauro Carvalho Chehab
60524071ac1SMauro Carvalho Chehab	if ($need_symlink) {
60624071ac1SMauro Carvalho Chehab		printf "\tsudo ln -sf %s /usr/bin/sphinx-build\n\n",
60724071ac1SMauro Carvalho Chehab		       which("sphinx-build-3");
60824071ac1SMauro Carvalho Chehab	}
60977d09ad9SMauro Carvalho Chehab	if ($need_sphinx || $rec_sphinx_upgrade) {
61044f42165SMauro Carvalho Chehab		my $min_activate = "$ENV{'PWD'}/${virtenv_prefix}${min_version}/bin/activate";
61144f42165SMauro Carvalho Chehab		my @activates = glob "$ENV{'PWD'}/${virtenv_prefix}*/bin/activate";
61244f42165SMauro Carvalho Chehab
61344f42165SMauro Carvalho Chehab		@activates = sort {$b cmp $a} @activates;
61444f42165SMauro Carvalho Chehab
6159b88ad54SMauro Carvalho Chehab		if ($need_sphinx && scalar @activates > 0 && $activates[0] ge $min_activate) {
6169b88ad54SMauro Carvalho Chehab			printf "\nNeed to activate a compatible Sphinx version on virtualenv with:\n";
61744f42165SMauro Carvalho Chehab			printf "\t. $activates[0]\n";
6189b88ad54SMauro Carvalho Chehab			exit (1);
6195be33182SMauro Carvalho Chehab		} else {
62044f42165SMauro Carvalho Chehab			my $rec_activate = "$virtenv_dir/bin/activate";
62124071ac1SMauro Carvalho Chehab			my $virtualenv = findprog("virtualenv-3");
622800d408aSMauro Carvalho Chehab			$virtualenv = findprog("virtualenv-3.5") if (!$virtualenv);
62324071ac1SMauro Carvalho Chehab			$virtualenv = findprog("virtualenv") if (!$virtualenv);
62424071ac1SMauro Carvalho Chehab			$virtualenv = "virtualenv" if (!$virtualenv);
62524071ac1SMauro Carvalho Chehab
6265be33182SMauro Carvalho Chehab			printf "\t$virtualenv $virtenv_dir\n";
62744f42165SMauro Carvalho Chehab			printf "\t. $rec_activate\n";
628fb947f3fSMauro Carvalho Chehab			printf "\tpip install -r $requirement_file\n";
62977d09ad9SMauro Carvalho Chehab
63077d09ad9SMauro Carvalho Chehab			$need++ if (!$rec_sphinx_upgrade);
63124071ac1SMauro Carvalho Chehab		}
6325be33182SMauro Carvalho Chehab	}
63324071ac1SMauro Carvalho Chehab	printf "\n";
63424071ac1SMauro Carvalho Chehab
635*54002b56SBjorn Helgaas	print "All optional dependencies are met.\n" if (!$optional);
63624071ac1SMauro Carvalho Chehab
63724071ac1SMauro Carvalho Chehab	if ($need == 1) {
63824071ac1SMauro Carvalho Chehab		die "Can't build as $need mandatory dependency is missing";
63924071ac1SMauro Carvalho Chehab	} elsif ($need) {
64024071ac1SMauro Carvalho Chehab		die "Can't build as $need mandatory dependencies are missing";
64124071ac1SMauro Carvalho Chehab	}
64224071ac1SMauro Carvalho Chehab
64324071ac1SMauro Carvalho Chehab	print "Needed package dependencies are met.\n";
64424071ac1SMauro Carvalho Chehab}
64524071ac1SMauro Carvalho Chehab
64624071ac1SMauro Carvalho Chehab#
64724071ac1SMauro Carvalho Chehab# Main
64824071ac1SMauro Carvalho Chehab#
64924071ac1SMauro Carvalho Chehab
65024071ac1SMauro Carvalho Chehabwhile (@ARGV) {
65124071ac1SMauro Carvalho Chehab	my $arg = shift(@ARGV);
65224071ac1SMauro Carvalho Chehab
65324071ac1SMauro Carvalho Chehab	if ($arg eq "--no-virtualenv") {
65424071ac1SMauro Carvalho Chehab		$virtualenv = 0;
65524071ac1SMauro Carvalho Chehab	} elsif ($arg eq "--no-pdf"){
65624071ac1SMauro Carvalho Chehab		$pdf = 0;
6579b88ad54SMauro Carvalho Chehab	} elsif ($arg eq "--version-check"){
6589b88ad54SMauro Carvalho Chehab		$version_check = 1;
65924071ac1SMauro Carvalho Chehab	} else {
6609b88ad54SMauro Carvalho Chehab		print "Usage:\n\t$0 <--no-virtualenv> <--no-pdf> <--version-check>\n\n";
6619b88ad54SMauro Carvalho Chehab		print "Where:\n";
6629b88ad54SMauro Carvalho Chehab		print "\t--no-virtualenv\t- Recommend installing Sphinx instead of using a virtualenv\n";
6639b88ad54SMauro Carvalho Chehab		print "\t--version-check\t- if version is compatible, don't check for missing dependencies\n";
6649b88ad54SMauro Carvalho Chehab		print "\t--no-pdf\t- don't check for dependencies required to build PDF docs\n\n";
66524071ac1SMauro Carvalho Chehab		exit -1;
66624071ac1SMauro Carvalho Chehab	}
66724071ac1SMauro Carvalho Chehab}
66824071ac1SMauro Carvalho Chehab
66924071ac1SMauro Carvalho Chehab#
67024071ac1SMauro Carvalho Chehab# Determine the system type. There's no standard unique way that would
67124071ac1SMauro Carvalho Chehab# work with all distros with a minimal package install. So, several
67224071ac1SMauro Carvalho Chehab# methods are used here.
67324071ac1SMauro Carvalho Chehab#
67424071ac1SMauro Carvalho Chehab# By default, it will use lsb_release function. If not available, it will
67524071ac1SMauro Carvalho Chehab# fail back to reading the known different places where the distro name
67624071ac1SMauro Carvalho Chehab# is stored
67724071ac1SMauro Carvalho Chehab#
67824071ac1SMauro Carvalho Chehab
67924071ac1SMauro Carvalho Chehab$system_release = qx(lsb_release -d) if which("lsb_release");
68024071ac1SMauro Carvalho Chehab$system_release =~ s/Description:\s*// if ($system_release);
68124071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/system-release") if !$system_release;
68224071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/redhat-release") if !$system_release;
68324071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/lsb-release") if !$system_release;
68424071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/gentoo-release") if !$system_release;
68524071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/issue") if !$system_release;
68624071ac1SMauro Carvalho Chehab$system_release =~ s/\s+$//;
68724071ac1SMauro Carvalho Chehab
68824071ac1SMauro Carvalho Chehabcheck_needs;
689