xref: /openbmc/linux/scripts/sphinx-pre-install (revision 56e5a633923793b31515795ad30156a307572c1e)
124071ac1SMauro Carvalho Chehab#!/usr/bin/perl
2c942fddfSThomas Gleixner# SPDX-License-Identifier: GPL-2.0-or-later
324071ac1SMauro Carvalho Chehabuse strict;
424071ac1SMauro Carvalho Chehab
544f42165SMauro Carvalho Chehab# Copyright (c) 2017-2019 Mauro Carvalho Chehab <mchehab@kernel.org>
624071ac1SMauro Carvalho Chehab#
724071ac1SMauro Carvalho Chehab
88c69b77aSMike Rapoportmy $prefix = "./";
98c69b77aSMike Rapoport$prefix = "$ENV{'srctree'}/" if ($ENV{'srctree'});
108c69b77aSMike Rapoport
118c69b77aSMike Rapoportmy $conf = $prefix . "Documentation/conf.py";
128c69b77aSMike Rapoportmy $requirement_file = $prefix . "Documentation/sphinx/requirements.txt";
1344f42165SMauro Carvalho Chehabmy $virtenv_prefix = "sphinx_";
145be33182SMauro Carvalho Chehab
1524071ac1SMauro Carvalho Chehab#
1624071ac1SMauro Carvalho Chehab# Static vars
1724071ac1SMauro Carvalho Chehab#
1824071ac1SMauro Carvalho Chehab
1924071ac1SMauro Carvalho Chehabmy %missing;
2024071ac1SMauro Carvalho Chehabmy $system_release;
2124071ac1SMauro Carvalho Chehabmy $need = 0;
2224071ac1SMauro Carvalho Chehabmy $optional = 0;
2324071ac1SMauro Carvalho Chehabmy $need_symlink = 0;
2424071ac1SMauro Carvalho Chehabmy $need_sphinx = 0;
2577d09ad9SMauro Carvalho Chehabmy $rec_sphinx_upgrade = 0;
2624071ac1SMauro Carvalho Chehabmy $install = "";
2744f42165SMauro Carvalho Chehabmy $virtenv_dir = "";
2844f42165SMauro Carvalho Chehabmy $min_version;
2924071ac1SMauro Carvalho Chehab
3024071ac1SMauro Carvalho Chehab#
3124071ac1SMauro Carvalho Chehab# Command line arguments
3224071ac1SMauro Carvalho Chehab#
3324071ac1SMauro Carvalho Chehab
3424071ac1SMauro Carvalho Chehabmy $pdf = 1;
3524071ac1SMauro Carvalho Chehabmy $virtualenv = 1;
369b88ad54SMauro Carvalho Chehabmy $version_check = 0;
3724071ac1SMauro Carvalho Chehab
3824071ac1SMauro Carvalho Chehab#
3924071ac1SMauro Carvalho Chehab# List of required texlive packages on Fedora and OpenSuse
4024071ac1SMauro Carvalho Chehab#
4124071ac1SMauro Carvalho Chehab
4224071ac1SMauro Carvalho Chehabmy %texlive = (
4324071ac1SMauro Carvalho Chehab	'amsfonts.sty'       => 'texlive-amsfonts',
4424071ac1SMauro Carvalho Chehab	'amsmath.sty'        => 'texlive-amsmath',
4524071ac1SMauro Carvalho Chehab	'amssymb.sty'        => 'texlive-amsfonts',
4624071ac1SMauro Carvalho Chehab	'amsthm.sty'         => 'texlive-amscls',
4724071ac1SMauro Carvalho Chehab	'anyfontsize.sty'    => 'texlive-anyfontsize',
4824071ac1SMauro Carvalho Chehab	'atbegshi.sty'       => 'texlive-oberdiek',
4924071ac1SMauro Carvalho Chehab	'bm.sty'             => 'texlive-tools',
5024071ac1SMauro Carvalho Chehab	'capt-of.sty'        => 'texlive-capt-of',
5124071ac1SMauro Carvalho Chehab	'cmap.sty'           => 'texlive-cmap',
5224071ac1SMauro Carvalho Chehab	'ecrm1000.tfm'       => 'texlive-ec',
5324071ac1SMauro Carvalho Chehab	'eqparbox.sty'       => 'texlive-eqparbox',
5424071ac1SMauro Carvalho Chehab	'eu1enc.def'         => 'texlive-euenc',
5524071ac1SMauro Carvalho Chehab	'fancybox.sty'       => 'texlive-fancybox',
5624071ac1SMauro Carvalho Chehab	'fancyvrb.sty'       => 'texlive-fancyvrb',
5724071ac1SMauro Carvalho Chehab	'float.sty'          => 'texlive-float',
5824071ac1SMauro Carvalho Chehab	'fncychap.sty'       => 'texlive-fncychap',
5924071ac1SMauro Carvalho Chehab	'footnote.sty'       => 'texlive-mdwtools',
6024071ac1SMauro Carvalho Chehab	'framed.sty'         => 'texlive-framed',
6124071ac1SMauro Carvalho Chehab	'luatex85.sty'       => 'texlive-luatex85',
6224071ac1SMauro Carvalho Chehab	'multirow.sty'       => 'texlive-multirow',
6324071ac1SMauro Carvalho Chehab	'needspace.sty'      => 'texlive-needspace',
6424071ac1SMauro Carvalho Chehab	'palatino.sty'       => 'texlive-psnfss',
6524071ac1SMauro Carvalho Chehab	'parskip.sty'        => 'texlive-parskip',
6624071ac1SMauro Carvalho Chehab	'polyglossia.sty'    => 'texlive-polyglossia',
6724071ac1SMauro Carvalho Chehab	'tabulary.sty'       => 'texlive-tabulary',
6824071ac1SMauro Carvalho Chehab	'threeparttable.sty' => 'texlive-threeparttable',
6924071ac1SMauro Carvalho Chehab	'titlesec.sty'       => 'texlive-titlesec',
7024071ac1SMauro Carvalho Chehab	'ucs.sty'            => 'texlive-ucs',
7124071ac1SMauro Carvalho Chehab	'upquote.sty'        => 'texlive-upquote',
7224071ac1SMauro Carvalho Chehab	'wrapfig.sty'        => 'texlive-wrapfig',
7324071ac1SMauro Carvalho Chehab);
7424071ac1SMauro Carvalho Chehab
7524071ac1SMauro Carvalho Chehab#
7624071ac1SMauro Carvalho Chehab# Subroutines that checks if a feature exists
7724071ac1SMauro Carvalho Chehab#
7824071ac1SMauro Carvalho Chehab
7924071ac1SMauro Carvalho Chehabsub check_missing(%)
8024071ac1SMauro Carvalho Chehab{
8124071ac1SMauro Carvalho Chehab	my %map = %{$_[0]};
8224071ac1SMauro Carvalho Chehab
8324071ac1SMauro Carvalho Chehab	foreach my $prog (sort keys %missing) {
8424071ac1SMauro Carvalho Chehab		my $is_optional = $missing{$prog};
8524071ac1SMauro Carvalho Chehab
86*56e5a633SMauro Carvalho Chehab		# At least on some LTS distros like CentOS 7, texlive doesn't
87*56e5a633SMauro Carvalho Chehab		# provide all packages we need. When such distros are
88*56e5a633SMauro Carvalho Chehab		# detected, we have to disable PDF output.
89*56e5a633SMauro Carvalho Chehab		#
90*56e5a633SMauro Carvalho Chehab		# So, we need to ignore the packages that distros would
91*56e5a633SMauro Carvalho Chehab		# need for LaTeX to work
92*56e5a633SMauro Carvalho Chehab		if ($is_optional == 2 && !$pdf) {
93*56e5a633SMauro Carvalho Chehab			$optional--;
94*56e5a633SMauro Carvalho Chehab			next;
95*56e5a633SMauro Carvalho Chehab		}
96*56e5a633SMauro Carvalho Chehab
9724071ac1SMauro Carvalho Chehab		if ($is_optional) {
9824071ac1SMauro Carvalho Chehab			print "Warning: better to also install \"$prog\".\n";
9924071ac1SMauro Carvalho Chehab		} else {
10024071ac1SMauro Carvalho Chehab			print "ERROR: please install \"$prog\", otherwise, build won't work.\n";
10124071ac1SMauro Carvalho Chehab		}
10224071ac1SMauro Carvalho Chehab		if (defined($map{$prog})) {
10324071ac1SMauro Carvalho Chehab			$install .= " " . $map{$prog};
10424071ac1SMauro Carvalho Chehab		} else {
10524071ac1SMauro Carvalho Chehab			$install .= " " . $prog;
10624071ac1SMauro Carvalho Chehab		}
10724071ac1SMauro Carvalho Chehab	}
10824071ac1SMauro Carvalho Chehab
10924071ac1SMauro Carvalho Chehab	$install =~ s/^\s//;
11024071ac1SMauro Carvalho Chehab}
11124071ac1SMauro Carvalho Chehab
11224071ac1SMauro Carvalho Chehabsub add_package($$)
11324071ac1SMauro Carvalho Chehab{
11424071ac1SMauro Carvalho Chehab	my $package = shift;
11524071ac1SMauro Carvalho Chehab	my $is_optional = shift;
11624071ac1SMauro Carvalho Chehab
11724071ac1SMauro Carvalho Chehab	$missing{$package} = $is_optional;
11824071ac1SMauro Carvalho Chehab	if ($is_optional) {
11924071ac1SMauro Carvalho Chehab		$optional++;
12024071ac1SMauro Carvalho Chehab	} else {
12124071ac1SMauro Carvalho Chehab		$need++;
12224071ac1SMauro Carvalho Chehab	}
12324071ac1SMauro Carvalho Chehab}
12424071ac1SMauro Carvalho Chehab
12524071ac1SMauro Carvalho Chehabsub check_missing_file($$$)
12624071ac1SMauro Carvalho Chehab{
12724071ac1SMauro Carvalho Chehab	my $file = shift;
12824071ac1SMauro Carvalho Chehab	my $package = shift;
12924071ac1SMauro Carvalho Chehab	my $is_optional = shift;
13024071ac1SMauro Carvalho Chehab
13124071ac1SMauro Carvalho Chehab	return if(-e $file);
13224071ac1SMauro Carvalho Chehab
13324071ac1SMauro Carvalho Chehab	add_package($package, $is_optional);
13424071ac1SMauro Carvalho Chehab}
13524071ac1SMauro Carvalho Chehab
13624071ac1SMauro Carvalho Chehabsub findprog($)
13724071ac1SMauro Carvalho Chehab{
13824071ac1SMauro Carvalho Chehab	foreach(split(/:/, $ENV{PATH})) {
13924071ac1SMauro Carvalho Chehab		return "$_/$_[0]" if(-x "$_/$_[0]");
14024071ac1SMauro Carvalho Chehab	}
14124071ac1SMauro Carvalho Chehab}
14224071ac1SMauro Carvalho Chehab
14324071ac1SMauro Carvalho Chehabsub check_program($$)
14424071ac1SMauro Carvalho Chehab{
14524071ac1SMauro Carvalho Chehab	my $prog = shift;
14624071ac1SMauro Carvalho Chehab	my $is_optional = shift;
14724071ac1SMauro Carvalho Chehab
14824071ac1SMauro Carvalho Chehab	return if findprog($prog);
14924071ac1SMauro Carvalho Chehab
15024071ac1SMauro Carvalho Chehab	add_package($prog, $is_optional);
15124071ac1SMauro Carvalho Chehab}
15224071ac1SMauro Carvalho Chehab
15324071ac1SMauro Carvalho Chehabsub check_perl_module($$)
15424071ac1SMauro Carvalho Chehab{
15524071ac1SMauro Carvalho Chehab	my $prog = shift;
15624071ac1SMauro Carvalho Chehab	my $is_optional = shift;
15724071ac1SMauro Carvalho Chehab
15824071ac1SMauro Carvalho Chehab	my $err = system("perl -M$prog -e 1 2>/dev/null /dev/null");
15924071ac1SMauro Carvalho Chehab	return if ($err == 0);
16024071ac1SMauro Carvalho Chehab
16124071ac1SMauro Carvalho Chehab	add_package($prog, $is_optional);
16224071ac1SMauro Carvalho Chehab}
16324071ac1SMauro Carvalho Chehab
16424071ac1SMauro Carvalho Chehabsub check_python_module($$)
16524071ac1SMauro Carvalho Chehab{
16624071ac1SMauro Carvalho Chehab	my $prog = shift;
16724071ac1SMauro Carvalho Chehab	my $is_optional = shift;
16824071ac1SMauro Carvalho Chehab
16924071ac1SMauro Carvalho Chehab	my $err = system("python3 -c 'import $prog' 2>/dev/null /dev/null");
17024071ac1SMauro Carvalho Chehab	return if ($err == 0);
17124071ac1SMauro Carvalho Chehab	my $err = system("python -c 'import $prog' 2>/dev/null /dev/null");
17224071ac1SMauro Carvalho Chehab	return if ($err == 0);
17324071ac1SMauro Carvalho Chehab
17424071ac1SMauro Carvalho Chehab	add_package($prog, $is_optional);
17524071ac1SMauro Carvalho Chehab}
17624071ac1SMauro Carvalho Chehab
17724071ac1SMauro Carvalho Chehabsub check_rpm_missing($$)
17824071ac1SMauro Carvalho Chehab{
17924071ac1SMauro Carvalho Chehab	my @pkgs = @{$_[0]};
18024071ac1SMauro Carvalho Chehab	my $is_optional = $_[1];
18124071ac1SMauro Carvalho Chehab
18224071ac1SMauro Carvalho Chehab	foreach my $prog(@pkgs) {
18324071ac1SMauro Carvalho Chehab		my $err = system("rpm -q '$prog' 2>/dev/null >/dev/null");
18424071ac1SMauro Carvalho Chehab		add_package($prog, $is_optional) if ($err);
18524071ac1SMauro Carvalho Chehab	}
18624071ac1SMauro Carvalho Chehab}
18724071ac1SMauro Carvalho Chehab
18824071ac1SMauro Carvalho Chehabsub check_pacman_missing($$)
18924071ac1SMauro Carvalho Chehab{
19024071ac1SMauro Carvalho Chehab	my @pkgs = @{$_[0]};
19124071ac1SMauro Carvalho Chehab	my $is_optional = $_[1];
19224071ac1SMauro Carvalho Chehab
19324071ac1SMauro Carvalho Chehab	foreach my $prog(@pkgs) {
19424071ac1SMauro Carvalho Chehab		my $err = system("pacman -Q '$prog' 2>/dev/null >/dev/null");
19524071ac1SMauro Carvalho Chehab		add_package($prog, $is_optional) if ($err);
19624071ac1SMauro Carvalho Chehab	}
19724071ac1SMauro Carvalho Chehab}
19824071ac1SMauro Carvalho Chehab
19924071ac1SMauro Carvalho Chehabsub check_missing_tex($)
20024071ac1SMauro Carvalho Chehab{
20124071ac1SMauro Carvalho Chehab	my $is_optional = shift;
20224071ac1SMauro Carvalho Chehab	my $kpsewhich = findprog("kpsewhich");
20324071ac1SMauro Carvalho Chehab
20424071ac1SMauro Carvalho Chehab	foreach my $prog(keys %texlive) {
20524071ac1SMauro Carvalho Chehab		my $package = $texlive{$prog};
20624071ac1SMauro Carvalho Chehab		if (!$kpsewhich) {
20724071ac1SMauro Carvalho Chehab			add_package($package, $is_optional);
20824071ac1SMauro Carvalho Chehab			next;
20924071ac1SMauro Carvalho Chehab		}
21024071ac1SMauro Carvalho Chehab		my $file = qx($kpsewhich $prog);
21124071ac1SMauro Carvalho Chehab		add_package($package, $is_optional) if ($file =~ /^\s*$/);
21224071ac1SMauro Carvalho Chehab	}
21324071ac1SMauro Carvalho Chehab}
21424071ac1SMauro Carvalho Chehab
21577d09ad9SMauro Carvalho Chehabsub get_sphinx_fname()
21624071ac1SMauro Carvalho Chehab{
21777d09ad9SMauro Carvalho Chehab	my $fname = "sphinx-build";
21877d09ad9SMauro Carvalho Chehab	return $fname if findprog($fname);
21924071ac1SMauro Carvalho Chehab
22077d09ad9SMauro Carvalho Chehab	$fname = "sphinx-build-3";
22177d09ad9SMauro Carvalho Chehab	if (findprog($fname)) {
22224071ac1SMauro Carvalho Chehab		$need_symlink = 1;
22377d09ad9SMauro Carvalho Chehab		return $fname;
22424071ac1SMauro Carvalho Chehab	}
22524071ac1SMauro Carvalho Chehab
22624071ac1SMauro Carvalho Chehab	if ($virtualenv) {
227800d408aSMauro Carvalho Chehab		my $prog = findprog("virtualenv-3");
228800d408aSMauro Carvalho Chehab		$prog = findprog("virtualenv-3.5") if (!$prog);
229800d408aSMauro Carvalho Chehab
230800d408aSMauro Carvalho Chehab		check_program("virtualenv", 0) if (!$prog);
23124071ac1SMauro Carvalho Chehab		$need_sphinx = 1;
23224071ac1SMauro Carvalho Chehab	} else {
23324071ac1SMauro Carvalho Chehab		add_package("python-sphinx", 0);
23424071ac1SMauro Carvalho Chehab	}
23577d09ad9SMauro Carvalho Chehab
23677d09ad9SMauro Carvalho Chehab	return "";
23777d09ad9SMauro Carvalho Chehab}
23877d09ad9SMauro Carvalho Chehab
23977d09ad9SMauro Carvalho Chehabsub check_sphinx()
24077d09ad9SMauro Carvalho Chehab{
24177d09ad9SMauro Carvalho Chehab	my $rec_version;
24277d09ad9SMauro Carvalho Chehab	my $cur_version;
24377d09ad9SMauro Carvalho Chehab
24477d09ad9SMauro Carvalho Chehab	open IN, $conf or die "Can't open $conf";
24577d09ad9SMauro Carvalho Chehab	while (<IN>) {
24677d09ad9SMauro Carvalho Chehab		if (m/^\s*needs_sphinx\s*=\s*[\'\"]([\d\.]+)[\'\"]/) {
24777d09ad9SMauro Carvalho Chehab			$min_version=$1;
24877d09ad9SMauro Carvalho Chehab			last;
24977d09ad9SMauro Carvalho Chehab		}
25077d09ad9SMauro Carvalho Chehab	}
25177d09ad9SMauro Carvalho Chehab	close IN;
25277d09ad9SMauro Carvalho Chehab
25377d09ad9SMauro Carvalho Chehab	die "Can't get needs_sphinx version from $conf" if (!$min_version);
25477d09ad9SMauro Carvalho Chehab
25577d09ad9SMauro Carvalho Chehab	open IN, $requirement_file or die "Can't open $requirement_file";
25677d09ad9SMauro Carvalho Chehab	while (<IN>) {
25777d09ad9SMauro Carvalho Chehab		if (m/^\s*Sphinx\s*==\s*([\d\.]+)$/) {
25877d09ad9SMauro Carvalho Chehab			$rec_version=$1;
25977d09ad9SMauro Carvalho Chehab			last;
26077d09ad9SMauro Carvalho Chehab		}
26177d09ad9SMauro Carvalho Chehab	}
26277d09ad9SMauro Carvalho Chehab	close IN;
26377d09ad9SMauro Carvalho Chehab
26477d09ad9SMauro Carvalho Chehab	die "Can't get recommended sphinx version from $requirement_file" if (!$min_version);
26577d09ad9SMauro Carvalho Chehab
26644f42165SMauro Carvalho Chehab	$virtenv_dir = $virtenv_prefix . $rec_version;
26777d09ad9SMauro Carvalho Chehab
26877d09ad9SMauro Carvalho Chehab	my $sphinx = get_sphinx_fname();
26977d09ad9SMauro Carvalho Chehab	return if ($sphinx eq "");
27077d09ad9SMauro Carvalho Chehab
27177d09ad9SMauro Carvalho Chehab	open IN, "$sphinx --version 2>&1 |" or die "$sphinx returned an error";
27277d09ad9SMauro Carvalho Chehab	while (<IN>) {
27377d09ad9SMauro Carvalho Chehab		if (m/^\s*sphinx-build\s+([\d\.]+)$/) {
27477d09ad9SMauro Carvalho Chehab			$cur_version=$1;
27577d09ad9SMauro Carvalho Chehab			last;
27677d09ad9SMauro Carvalho Chehab		}
27777d09ad9SMauro Carvalho Chehab		# Sphinx 1.2.x uses a different format
27877d09ad9SMauro Carvalho Chehab		if (m/^\s*Sphinx.*\s+([\d\.]+)$/) {
27977d09ad9SMauro Carvalho Chehab			$cur_version=$1;
28077d09ad9SMauro Carvalho Chehab			last;
28177d09ad9SMauro Carvalho Chehab		}
28277d09ad9SMauro Carvalho Chehab	}
28377d09ad9SMauro Carvalho Chehab	close IN;
28477d09ad9SMauro Carvalho Chehab
28577d09ad9SMauro Carvalho Chehab	die "$sphinx didn't return its version" if (!$cur_version);
28677d09ad9SMauro Carvalho Chehab
28777d09ad9SMauro Carvalho Chehab	if ($cur_version lt $min_version) {
2889b88ad54SMauro Carvalho Chehab		printf "ERROR: Sphinx version is %s. It should be >= %s (recommended >= %s)\n",
2899b88ad54SMauro Carvalho Chehab		       $cur_version, $min_version, $rec_version;;
29077d09ad9SMauro Carvalho Chehab		$need_sphinx = 1;
29177d09ad9SMauro Carvalho Chehab		return;
29277d09ad9SMauro Carvalho Chehab	}
29377d09ad9SMauro Carvalho Chehab
29477d09ad9SMauro Carvalho Chehab	if ($cur_version lt $rec_version) {
2959b88ad54SMauro Carvalho Chehab		printf "Sphinx version %s\n", $cur_version;
29677d09ad9SMauro Carvalho Chehab		print "Warning: It is recommended at least Sphinx version $rec_version.\n";
29777d09ad9SMauro Carvalho Chehab		$rec_sphinx_upgrade = 1;
2989b88ad54SMauro Carvalho Chehab		return;
29977d09ad9SMauro Carvalho Chehab	}
3009b88ad54SMauro Carvalho Chehab
3019b88ad54SMauro Carvalho Chehab	# On version check mode, just assume Sphinx has all mandatory deps
3029b88ad54SMauro Carvalho Chehab	exit (0) if ($version_check);
30324071ac1SMauro Carvalho Chehab}
30424071ac1SMauro Carvalho Chehab
30524071ac1SMauro Carvalho Chehab#
30624071ac1SMauro Carvalho Chehab# Ancillary subroutines
30724071ac1SMauro Carvalho Chehab#
30824071ac1SMauro Carvalho Chehab
30924071ac1SMauro Carvalho Chehabsub catcheck($)
31024071ac1SMauro Carvalho Chehab{
31124071ac1SMauro Carvalho Chehab  my $res = "";
31224071ac1SMauro Carvalho Chehab  $res = qx(cat $_[0]) if (-r $_[0]);
31324071ac1SMauro Carvalho Chehab  return $res;
31424071ac1SMauro Carvalho Chehab}
31524071ac1SMauro Carvalho Chehab
31624071ac1SMauro Carvalho Chehabsub which($)
31724071ac1SMauro Carvalho Chehab{
31824071ac1SMauro Carvalho Chehab	my $file = shift;
31924071ac1SMauro Carvalho Chehab	my @path = split ":", $ENV{PATH};
32024071ac1SMauro Carvalho Chehab
32124071ac1SMauro Carvalho Chehab	foreach my $dir(@path) {
32224071ac1SMauro Carvalho Chehab		my $name = $dir.'/'.$file;
32324071ac1SMauro Carvalho Chehab		return $name if (-x $name );
32424071ac1SMauro Carvalho Chehab	}
32524071ac1SMauro Carvalho Chehab	return undef;
32624071ac1SMauro Carvalho Chehab}
32724071ac1SMauro Carvalho Chehab
32824071ac1SMauro Carvalho Chehab#
32924071ac1SMauro Carvalho Chehab# Subroutines that check distro-specific hints
33024071ac1SMauro Carvalho Chehab#
33124071ac1SMauro Carvalho Chehab
33224071ac1SMauro Carvalho Chehabsub give_debian_hints()
33324071ac1SMauro Carvalho Chehab{
33424071ac1SMauro Carvalho Chehab	my %map = (
33524071ac1SMauro Carvalho Chehab		"python-sphinx"		=> "python3-sphinx",
33624071ac1SMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "python3-sphinx-rtd-theme",
33724071ac1SMauro Carvalho Chehab		"virtualenv"		=> "virtualenv",
33824071ac1SMauro Carvalho Chehab		"dot"			=> "graphviz",
33924071ac1SMauro Carvalho Chehab		"convert"		=> "imagemagick",
34024071ac1SMauro Carvalho Chehab		"Pod::Usage"		=> "perl-modules",
34124071ac1SMauro Carvalho Chehab		"xelatex"		=> "texlive-xetex",
3428e7d5d15SMauro Carvalho Chehab		"rsvg-convert"		=> "librsvg2-bin",
34324071ac1SMauro Carvalho Chehab	);
34424071ac1SMauro Carvalho Chehab
34524071ac1SMauro Carvalho Chehab	if ($pdf) {
34624071ac1SMauro Carvalho Chehab		check_missing_file("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
347*56e5a633SMauro Carvalho Chehab				   "fonts-dejavu", 2);
34824071ac1SMauro Carvalho Chehab	}
34924071ac1SMauro Carvalho Chehab
350*56e5a633SMauro Carvalho Chehab	check_program("dvipng", 2) if ($pdf);
35124071ac1SMauro Carvalho Chehab	check_missing(\%map);
35224071ac1SMauro Carvalho Chehab
35324071ac1SMauro Carvalho Chehab	return if (!$need && !$optional);
35424071ac1SMauro Carvalho Chehab	printf("You should run:\n\n\tsudo apt-get install $install\n");
35524071ac1SMauro Carvalho Chehab}
35624071ac1SMauro Carvalho Chehab
35724071ac1SMauro Carvalho Chehabsub give_redhat_hints()
35824071ac1SMauro Carvalho Chehab{
35924071ac1SMauro Carvalho Chehab	my %map = (
36024071ac1SMauro Carvalho Chehab		"python-sphinx"		=> "python3-sphinx",
36124071ac1SMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "python3-sphinx_rtd_theme",
36224071ac1SMauro Carvalho Chehab		"virtualenv"		=> "python3-virtualenv",
36324071ac1SMauro Carvalho Chehab		"dot"			=> "graphviz",
36424071ac1SMauro Carvalho Chehab		"convert"		=> "ImageMagick",
36524071ac1SMauro Carvalho Chehab		"Pod::Usage"		=> "perl-Pod-Usage",
36624071ac1SMauro Carvalho Chehab		"xelatex"		=> "texlive-xetex-bin",
3678e7d5d15SMauro Carvalho Chehab		"rsvg-convert"		=> "librsvg2-tools",
36824071ac1SMauro Carvalho Chehab	);
36924071ac1SMauro Carvalho Chehab
3705d88953cSMauro Carvalho Chehab	my @fedora26_opt_pkgs = (
3715d88953cSMauro Carvalho Chehab		"graphviz-gd",		# Fedora 26: needed for PDF support
3725d88953cSMauro Carvalho Chehab	);
3735d88953cSMauro Carvalho Chehab
37424071ac1SMauro Carvalho Chehab	my @fedora_tex_pkgs = (
37524071ac1SMauro Carvalho Chehab		"texlive-collection-fontsrecommended",
37624071ac1SMauro Carvalho Chehab		"texlive-collection-latex",
37724071ac1SMauro Carvalho Chehab		"dejavu-sans-fonts",
37824071ac1SMauro Carvalho Chehab		"dejavu-serif-fonts",
37924071ac1SMauro Carvalho Chehab		"dejavu-sans-mono-fonts",
38024071ac1SMauro Carvalho Chehab	);
38124071ac1SMauro Carvalho Chehab
3829b756a9dSMauro Carvalho Chehab	#
3839b756a9dSMauro Carvalho Chehab	# Checks valid for RHEL/CentOS version 7.x.
3849b756a9dSMauro Carvalho Chehab	#
385*56e5a633SMauro Carvalho Chehab	my $old = 0;
386*56e5a633SMauro Carvalho Chehab	my $rel;
387*56e5a633SMauro Carvalho Chehab	$rel = $1 if ($system_release =~ /release\s+(\d+)/);
388*56e5a633SMauro Carvalho Chehab
389b308467cSMauro Carvalho Chehab	if (!($system_release =~ /Fedora/)) {
3909b756a9dSMauro Carvalho Chehab		$map{"virtualenv"} = "python-virtualenv";
391*56e5a633SMauro Carvalho Chehab
392*56e5a633SMauro Carvalho Chehab		if ($rel && $rel < 8) {
393*56e5a633SMauro Carvalho Chehab			$old = 1;
394*56e5a633SMauro Carvalho Chehab			$pdf = 0;
395*56e5a633SMauro Carvalho Chehab
396*56e5a633SMauro Carvalho Chehab			printf("Note: texlive packages on RHEL/CENTOS <= 7 are incomplete. Can't support PDF output\n");
397*56e5a633SMauro Carvalho Chehab			printf("If you want to build PDF, please read:\n");
398*56e5a633SMauro Carvalho Chehab			printf("\thttps://www.systutorials.com/241660/how-to-install-tex-live-on-centos-7-linux/\n");
399*56e5a633SMauro Carvalho Chehab		}
400*56e5a633SMauro Carvalho Chehab	} else {
401*56e5a633SMauro Carvalho Chehab		if ($rel && $rel < 26) {
402*56e5a633SMauro Carvalho Chehab			$old = 1;
403*56e5a633SMauro Carvalho Chehab		}
404*56e5a633SMauro Carvalho Chehab	}
405*56e5a633SMauro Carvalho Chehab	if (!$rel) {
406*56e5a633SMauro Carvalho Chehab		printf("Couldn't identify release number\n");
407*56e5a633SMauro Carvalho Chehab		$old = 1;
408*56e5a633SMauro Carvalho Chehab		$pdf = 0;
4099b756a9dSMauro Carvalho Chehab	}
4109b756a9dSMauro Carvalho Chehab
411*56e5a633SMauro Carvalho Chehab	check_rpm_missing(\@fedora26_opt_pkgs, 2) if ($pdf && !$old);
412*56e5a633SMauro Carvalho Chehab	check_rpm_missing(\@fedora_tex_pkgs, 2) if ($pdf);
413*56e5a633SMauro Carvalho Chehab	check_missing_tex(2) if ($pdf);
41424071ac1SMauro Carvalho Chehab	check_missing(\%map);
41524071ac1SMauro Carvalho Chehab
41624071ac1SMauro Carvalho Chehab	return if (!$need && !$optional);
4179b756a9dSMauro Carvalho Chehab
418*56e5a633SMauro Carvalho Chehab	if (!$old) {
4199b756a9dSMauro Carvalho Chehab		# dnf, for Fedora 18+
42024071ac1SMauro Carvalho Chehab		printf("You should run:\n\n\tsudo dnf install -y $install\n");
4219b756a9dSMauro Carvalho Chehab	} else {
4229b756a9dSMauro Carvalho Chehab		# yum, for RHEL (and clones) or Fedora version < 18
4239b756a9dSMauro Carvalho Chehab		printf("You should run:\n\n\tsudo yum install -y $install\n");
4249b756a9dSMauro Carvalho Chehab	}
42524071ac1SMauro Carvalho Chehab}
42624071ac1SMauro Carvalho Chehab
42724071ac1SMauro Carvalho Chehabsub give_opensuse_hints()
42824071ac1SMauro Carvalho Chehab{
42924071ac1SMauro Carvalho Chehab	my %map = (
43024071ac1SMauro Carvalho Chehab		"python-sphinx"		=> "python3-sphinx",
43124071ac1SMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "python3-sphinx_rtd_theme",
43224071ac1SMauro Carvalho Chehab		"virtualenv"		=> "python3-virtualenv",
43324071ac1SMauro Carvalho Chehab		"dot"			=> "graphviz",
43424071ac1SMauro Carvalho Chehab		"convert"		=> "ImageMagick",
43524071ac1SMauro Carvalho Chehab		"Pod::Usage"		=> "perl-Pod-Usage",
43624071ac1SMauro Carvalho Chehab		"xelatex"		=> "texlive-xetex-bin",
4378e7d5d15SMauro Carvalho Chehab		"rsvg-convert"		=> "rsvg-view",
43824071ac1SMauro Carvalho Chehab	);
43924071ac1SMauro Carvalho Chehab
44024071ac1SMauro Carvalho Chehab	my @suse_tex_pkgs = (
44124071ac1SMauro Carvalho Chehab		"texlive-babel-english",
44224071ac1SMauro Carvalho Chehab		"texlive-caption",
44324071ac1SMauro Carvalho Chehab		"texlive-colortbl",
44424071ac1SMauro Carvalho Chehab		"texlive-courier",
44524071ac1SMauro Carvalho Chehab		"texlive-dvips",
44624071ac1SMauro Carvalho Chehab		"texlive-helvetic",
44724071ac1SMauro Carvalho Chehab		"texlive-makeindex",
44824071ac1SMauro Carvalho Chehab		"texlive-metafont",
44924071ac1SMauro Carvalho Chehab		"texlive-metapost",
45024071ac1SMauro Carvalho Chehab		"texlive-palatino",
45124071ac1SMauro Carvalho Chehab		"texlive-preview",
45224071ac1SMauro Carvalho Chehab		"texlive-times",
45324071ac1SMauro Carvalho Chehab		"texlive-zapfchan",
45424071ac1SMauro Carvalho Chehab		"texlive-zapfding",
45524071ac1SMauro Carvalho Chehab	);
45624071ac1SMauro Carvalho Chehab
457*56e5a633SMauro Carvalho Chehab	check_rpm_missing(\@suse_tex_pkgs, 2) if ($pdf);
458*56e5a633SMauro Carvalho Chehab	check_missing_tex(2) if ($pdf);
45924071ac1SMauro Carvalho Chehab	check_missing(\%map);
46024071ac1SMauro Carvalho Chehab
46124071ac1SMauro Carvalho Chehab	return if (!$need && !$optional);
46224071ac1SMauro Carvalho Chehab	printf("You should run:\n\n\tsudo zypper install --no-recommends $install\n");
46324071ac1SMauro Carvalho Chehab}
46424071ac1SMauro Carvalho Chehab
465800d408aSMauro Carvalho Chehabsub give_mageia_hints()
466800d408aSMauro Carvalho Chehab{
467800d408aSMauro Carvalho Chehab	my %map = (
468800d408aSMauro Carvalho Chehab		"python-sphinx"		=> "python3-sphinx",
469800d408aSMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "python3-sphinx_rtd_theme",
470800d408aSMauro Carvalho Chehab		"virtualenv"		=> "python3-virtualenv",
471800d408aSMauro Carvalho Chehab		"dot"			=> "graphviz",
472800d408aSMauro Carvalho Chehab		"convert"		=> "ImageMagick",
473800d408aSMauro Carvalho Chehab		"Pod::Usage"		=> "perl-Pod-Usage",
474800d408aSMauro Carvalho Chehab		"xelatex"		=> "texlive",
475800d408aSMauro Carvalho Chehab		"rsvg-convert"		=> "librsvg2-tools",
476800d408aSMauro Carvalho Chehab	);
477800d408aSMauro Carvalho Chehab
478800d408aSMauro Carvalho Chehab	my @tex_pkgs = (
479800d408aSMauro Carvalho Chehab		"texlive-fontsextra",
480800d408aSMauro Carvalho Chehab	);
481800d408aSMauro Carvalho Chehab
482*56e5a633SMauro Carvalho Chehab	check_rpm_missing(\@tex_pkgs, 2) if ($pdf);
483800d408aSMauro Carvalho Chehab	check_missing(\%map);
484800d408aSMauro Carvalho Chehab
485800d408aSMauro Carvalho Chehab	return if (!$need && !$optional);
486800d408aSMauro Carvalho Chehab	printf("You should run:\n\n\tsudo urpmi $install\n");
487800d408aSMauro Carvalho Chehab}
488800d408aSMauro Carvalho Chehab
48924071ac1SMauro Carvalho Chehabsub give_arch_linux_hints()
49024071ac1SMauro Carvalho Chehab{
49124071ac1SMauro Carvalho Chehab	my %map = (
49224071ac1SMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "python-sphinx_rtd_theme",
49324071ac1SMauro Carvalho Chehab		"virtualenv"		=> "python-virtualenv",
49424071ac1SMauro Carvalho Chehab		"dot"			=> "graphviz",
49524071ac1SMauro Carvalho Chehab		"convert"		=> "imagemagick",
49624071ac1SMauro Carvalho Chehab		"xelatex"		=> "texlive-bin",
4978e7d5d15SMauro Carvalho Chehab		"rsvg-convert"		=> "extra/librsvg",
49824071ac1SMauro Carvalho Chehab	);
49924071ac1SMauro Carvalho Chehab
50024071ac1SMauro Carvalho Chehab	my @archlinux_tex_pkgs = (
50124071ac1SMauro Carvalho Chehab		"texlive-core",
50224071ac1SMauro Carvalho Chehab		"texlive-latexextra",
50324071ac1SMauro Carvalho Chehab		"ttf-dejavu",
50424071ac1SMauro Carvalho Chehab	);
505*56e5a633SMauro Carvalho Chehab	check_pacman_missing(\@archlinux_tex_pkgs, 2) if ($pdf);
506*56e5a633SMauro Carvalho Chehab
50724071ac1SMauro Carvalho Chehab	check_missing(\%map);
50824071ac1SMauro Carvalho Chehab
50924071ac1SMauro Carvalho Chehab	return if (!$need && !$optional);
51024071ac1SMauro Carvalho Chehab	printf("You should run:\n\n\tsudo pacman -S $install\n");
51124071ac1SMauro Carvalho Chehab}
51224071ac1SMauro Carvalho Chehab
51324071ac1SMauro Carvalho Chehabsub give_gentoo_hints()
51424071ac1SMauro Carvalho Chehab{
51524071ac1SMauro Carvalho Chehab	my %map = (
51624071ac1SMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "dev-python/sphinx_rtd_theme",
51724071ac1SMauro Carvalho Chehab		"virtualenv"		=> "dev-python/virtualenv",
51824071ac1SMauro Carvalho Chehab		"dot"			=> "media-gfx/graphviz",
51924071ac1SMauro Carvalho Chehab		"convert"		=> "media-gfx/imagemagick",
52024071ac1SMauro Carvalho Chehab		"xelatex"		=> "dev-texlive/texlive-xetex media-fonts/dejavu",
5218e7d5d15SMauro Carvalho Chehab		"rsvg-convert"		=> "gnome-base/librsvg",
52224071ac1SMauro Carvalho Chehab	);
52324071ac1SMauro Carvalho Chehab
52424071ac1SMauro Carvalho Chehab	check_missing_file("/usr/share/fonts/dejavu/DejaVuSans.ttf",
525*56e5a633SMauro Carvalho Chehab			   "media-fonts/dejavu", 2) if ($pdf);
52624071ac1SMauro Carvalho Chehab
52724071ac1SMauro Carvalho Chehab	check_missing(\%map);
52824071ac1SMauro Carvalho Chehab
52924071ac1SMauro Carvalho Chehab	return if (!$need && !$optional);
530bba1e4cbSMauro Carvalho Chehab
531bba1e4cbSMauro Carvalho Chehab	printf("You should run:\n\n");
532bba1e4cbSMauro Carvalho Chehab	printf("\tsudo su -c 'echo \"media-gfx/imagemagick svg png\" > /etc/portage/package.use/imagemagick'\n");
533bba1e4cbSMauro Carvalho Chehab	printf("\tsudo su -c 'echo \"media-gfx/graphviz cairo pdf\" > /etc/portage/package.use/graphviz'\n");
534bba1e4cbSMauro Carvalho Chehab	printf("\tsudo emerge --ask $install\n");
535bba1e4cbSMauro Carvalho Chehab
53624071ac1SMauro Carvalho Chehab}
53724071ac1SMauro Carvalho Chehab
53824071ac1SMauro Carvalho Chehabsub check_distros()
53924071ac1SMauro Carvalho Chehab{
54024071ac1SMauro Carvalho Chehab	# Distro-specific hints
54124071ac1SMauro Carvalho Chehab	if ($system_release =~ /Red Hat Enterprise Linux/) {
54224071ac1SMauro Carvalho Chehab		give_redhat_hints;
54324071ac1SMauro Carvalho Chehab		return;
54424071ac1SMauro Carvalho Chehab	}
5459b756a9dSMauro Carvalho Chehab	if ($system_release =~ /CentOS/) {
5469b756a9dSMauro Carvalho Chehab		give_redhat_hints;
5479b756a9dSMauro Carvalho Chehab		return;
5489b756a9dSMauro Carvalho Chehab	}
5499b756a9dSMauro Carvalho Chehab	if ($system_release =~ /Scientific Linux/) {
5509b756a9dSMauro Carvalho Chehab		give_redhat_hints;
5519b756a9dSMauro Carvalho Chehab		return;
5529b756a9dSMauro Carvalho Chehab	}
5539b756a9dSMauro Carvalho Chehab	if ($system_release =~ /Oracle Linux Server/) {
5549b756a9dSMauro Carvalho Chehab		give_redhat_hints;
5559b756a9dSMauro Carvalho Chehab		return;
5569b756a9dSMauro Carvalho Chehab	}
55724071ac1SMauro Carvalho Chehab	if ($system_release =~ /Fedora/) {
55824071ac1SMauro Carvalho Chehab		give_redhat_hints;
55924071ac1SMauro Carvalho Chehab		return;
56024071ac1SMauro Carvalho Chehab	}
56124071ac1SMauro Carvalho Chehab	if ($system_release =~ /Ubuntu/) {
56224071ac1SMauro Carvalho Chehab		give_debian_hints;
56324071ac1SMauro Carvalho Chehab		return;
56424071ac1SMauro Carvalho Chehab	}
56524071ac1SMauro Carvalho Chehab	if ($system_release =~ /Debian/) {
56624071ac1SMauro Carvalho Chehab		give_debian_hints;
56724071ac1SMauro Carvalho Chehab		return;
56824071ac1SMauro Carvalho Chehab	}
56924071ac1SMauro Carvalho Chehab	if ($system_release =~ /openSUSE/) {
57024071ac1SMauro Carvalho Chehab		give_opensuse_hints;
57124071ac1SMauro Carvalho Chehab		return;
57224071ac1SMauro Carvalho Chehab	}
573800d408aSMauro Carvalho Chehab	if ($system_release =~ /Mageia/) {
574800d408aSMauro Carvalho Chehab		give_mageia_hints;
575800d408aSMauro Carvalho Chehab		return;
576800d408aSMauro Carvalho Chehab	}
57724071ac1SMauro Carvalho Chehab	if ($system_release =~ /Arch Linux/) {
57824071ac1SMauro Carvalho Chehab		give_arch_linux_hints;
57924071ac1SMauro Carvalho Chehab		return;
58024071ac1SMauro Carvalho Chehab	}
58124071ac1SMauro Carvalho Chehab	if ($system_release =~ /Gentoo/) {
58224071ac1SMauro Carvalho Chehab		give_gentoo_hints;
58324071ac1SMauro Carvalho Chehab		return;
58424071ac1SMauro Carvalho Chehab	}
58524071ac1SMauro Carvalho Chehab
58624071ac1SMauro Carvalho Chehab	#
58724071ac1SMauro Carvalho Chehab	# Fall-back to generic hint code for other distros
58824071ac1SMauro Carvalho Chehab	# That's far from ideal, specially for LaTeX dependencies.
58924071ac1SMauro Carvalho Chehab	#
59024071ac1SMauro Carvalho Chehab	my %map = (
59124071ac1SMauro Carvalho Chehab		"sphinx-build" => "sphinx"
59224071ac1SMauro Carvalho Chehab	);
593*56e5a633SMauro Carvalho Chehab	check_missing_tex(2) if ($pdf);
59424071ac1SMauro Carvalho Chehab	check_missing(\%map);
59524071ac1SMauro Carvalho Chehab	print "I don't know distro $system_release.\n";
59624071ac1SMauro Carvalho Chehab	print "So, I can't provide you a hint with the install procedure.\n";
59724071ac1SMauro Carvalho Chehab	print "There are likely missing dependencies.\n";
59824071ac1SMauro Carvalho Chehab}
59924071ac1SMauro Carvalho Chehab
60024071ac1SMauro Carvalho Chehab#
60124071ac1SMauro Carvalho Chehab# Common dependencies
60224071ac1SMauro Carvalho Chehab#
60324071ac1SMauro Carvalho Chehab
60424071ac1SMauro Carvalho Chehabsub check_needs()
60524071ac1SMauro Carvalho Chehab{
60624071ac1SMauro Carvalho Chehab	# Check for needed programs/tools
60724071ac1SMauro Carvalho Chehab	check_sphinx();
6089b88ad54SMauro Carvalho Chehab
6099b88ad54SMauro Carvalho Chehab	if ($system_release) {
6109b88ad54SMauro Carvalho Chehab		print "Detected OS: $system_release.\n\n";
6119b88ad54SMauro Carvalho Chehab	} else {
6129b88ad54SMauro Carvalho Chehab		print "Unknown OS\n\n";
6139b88ad54SMauro Carvalho Chehab	}
6149b88ad54SMauro Carvalho Chehab
6159b88ad54SMauro Carvalho Chehab	print "To upgrade Sphinx, use:\n\n" if ($rec_sphinx_upgrade);
6169b88ad54SMauro Carvalho Chehab
6179b88ad54SMauro Carvalho Chehab	# Check for needed programs/tools
61824071ac1SMauro Carvalho Chehab	check_perl_module("Pod::Usage", 0);
61924071ac1SMauro Carvalho Chehab	check_program("make", 0);
62024071ac1SMauro Carvalho Chehab	check_program("gcc", 0);
62124071ac1SMauro Carvalho Chehab	check_python_module("sphinx_rtd_theme", 1) if (!$virtualenv);
62224071ac1SMauro Carvalho Chehab	check_program("dot", 1);
62324071ac1SMauro Carvalho Chehab	check_program("convert", 1);
624*56e5a633SMauro Carvalho Chehab
625*56e5a633SMauro Carvalho Chehab	# Extra PDF files - should use 2 for is_optional
626*56e5a633SMauro Carvalho Chehab	check_program("xelatex", 2) if ($pdf);
627*56e5a633SMauro Carvalho Chehab	check_program("rsvg-convert", 2) if ($pdf);
628*56e5a633SMauro Carvalho Chehab	check_program("latexmk", 2) if ($pdf);
62924071ac1SMauro Carvalho Chehab
63024071ac1SMauro Carvalho Chehab	check_distros();
63124071ac1SMauro Carvalho Chehab
63224071ac1SMauro Carvalho Chehab	if ($need_symlink) {
63324071ac1SMauro Carvalho Chehab		printf "\tsudo ln -sf %s /usr/bin/sphinx-build\n\n",
63424071ac1SMauro Carvalho Chehab		       which("sphinx-build-3");
63524071ac1SMauro Carvalho Chehab	}
63677d09ad9SMauro Carvalho Chehab	if ($need_sphinx || $rec_sphinx_upgrade) {
63744f42165SMauro Carvalho Chehab		my $min_activate = "$ENV{'PWD'}/${virtenv_prefix}${min_version}/bin/activate";
63844f42165SMauro Carvalho Chehab		my @activates = glob "$ENV{'PWD'}/${virtenv_prefix}*/bin/activate";
63944f42165SMauro Carvalho Chehab
64044f42165SMauro Carvalho Chehab		@activates = sort {$b cmp $a} @activates;
64144f42165SMauro Carvalho Chehab
6429b88ad54SMauro Carvalho Chehab		if ($need_sphinx && scalar @activates > 0 && $activates[0] ge $min_activate) {
6439b88ad54SMauro Carvalho Chehab			printf "\nNeed to activate a compatible Sphinx version on virtualenv with:\n";
64444f42165SMauro Carvalho Chehab			printf "\t. $activates[0]\n";
6459b88ad54SMauro Carvalho Chehab			exit (1);
6465be33182SMauro Carvalho Chehab		} else {
64744f42165SMauro Carvalho Chehab			my $rec_activate = "$virtenv_dir/bin/activate";
64824071ac1SMauro Carvalho Chehab			my $virtualenv = findprog("virtualenv-3");
649800d408aSMauro Carvalho Chehab			$virtualenv = findprog("virtualenv-3.5") if (!$virtualenv);
65024071ac1SMauro Carvalho Chehab			$virtualenv = findprog("virtualenv") if (!$virtualenv);
65124071ac1SMauro Carvalho Chehab			$virtualenv = "virtualenv" if (!$virtualenv);
65224071ac1SMauro Carvalho Chehab
6535be33182SMauro Carvalho Chehab			printf "\t$virtualenv $virtenv_dir\n";
65444f42165SMauro Carvalho Chehab			printf "\t. $rec_activate\n";
655fb947f3fSMauro Carvalho Chehab			printf "\tpip install -r $requirement_file\n";
65677d09ad9SMauro Carvalho Chehab
65777d09ad9SMauro Carvalho Chehab			$need++ if (!$rec_sphinx_upgrade);
65824071ac1SMauro Carvalho Chehab		}
6595be33182SMauro Carvalho Chehab	}
66024071ac1SMauro Carvalho Chehab	printf "\n";
66124071ac1SMauro Carvalho Chehab
66254002b56SBjorn Helgaas	print "All optional dependencies are met.\n" if (!$optional);
66324071ac1SMauro Carvalho Chehab
66424071ac1SMauro Carvalho Chehab	if ($need == 1) {
66524071ac1SMauro Carvalho Chehab		die "Can't build as $need mandatory dependency is missing";
66624071ac1SMauro Carvalho Chehab	} elsif ($need) {
66724071ac1SMauro Carvalho Chehab		die "Can't build as $need mandatory dependencies are missing";
66824071ac1SMauro Carvalho Chehab	}
66924071ac1SMauro Carvalho Chehab
67024071ac1SMauro Carvalho Chehab	print "Needed package dependencies are met.\n";
67124071ac1SMauro Carvalho Chehab}
67224071ac1SMauro Carvalho Chehab
67324071ac1SMauro Carvalho Chehab#
67424071ac1SMauro Carvalho Chehab# Main
67524071ac1SMauro Carvalho Chehab#
67624071ac1SMauro Carvalho Chehab
67724071ac1SMauro Carvalho Chehabwhile (@ARGV) {
67824071ac1SMauro Carvalho Chehab	my $arg = shift(@ARGV);
67924071ac1SMauro Carvalho Chehab
68024071ac1SMauro Carvalho Chehab	if ($arg eq "--no-virtualenv") {
68124071ac1SMauro Carvalho Chehab		$virtualenv = 0;
68224071ac1SMauro Carvalho Chehab	} elsif ($arg eq "--no-pdf"){
68324071ac1SMauro Carvalho Chehab		$pdf = 0;
6849b88ad54SMauro Carvalho Chehab	} elsif ($arg eq "--version-check"){
6859b88ad54SMauro Carvalho Chehab		$version_check = 1;
68624071ac1SMauro Carvalho Chehab	} else {
6879b88ad54SMauro Carvalho Chehab		print "Usage:\n\t$0 <--no-virtualenv> <--no-pdf> <--version-check>\n\n";
6889b88ad54SMauro Carvalho Chehab		print "Where:\n";
6899b88ad54SMauro Carvalho Chehab		print "\t--no-virtualenv\t- Recommend installing Sphinx instead of using a virtualenv\n";
6909b88ad54SMauro Carvalho Chehab		print "\t--version-check\t- if version is compatible, don't check for missing dependencies\n";
6919b88ad54SMauro Carvalho Chehab		print "\t--no-pdf\t- don't check for dependencies required to build PDF docs\n\n";
69224071ac1SMauro Carvalho Chehab		exit -1;
69324071ac1SMauro Carvalho Chehab	}
69424071ac1SMauro Carvalho Chehab}
69524071ac1SMauro Carvalho Chehab
69624071ac1SMauro Carvalho Chehab#
69724071ac1SMauro Carvalho Chehab# Determine the system type. There's no standard unique way that would
69824071ac1SMauro Carvalho Chehab# work with all distros with a minimal package install. So, several
69924071ac1SMauro Carvalho Chehab# methods are used here.
70024071ac1SMauro Carvalho Chehab#
70124071ac1SMauro Carvalho Chehab# By default, it will use lsb_release function. If not available, it will
70224071ac1SMauro Carvalho Chehab# fail back to reading the known different places where the distro name
70324071ac1SMauro Carvalho Chehab# is stored
70424071ac1SMauro Carvalho Chehab#
70524071ac1SMauro Carvalho Chehab
70624071ac1SMauro Carvalho Chehab$system_release = qx(lsb_release -d) if which("lsb_release");
70724071ac1SMauro Carvalho Chehab$system_release =~ s/Description:\s*// if ($system_release);
70824071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/system-release") if !$system_release;
70924071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/redhat-release") if !$system_release;
71024071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/lsb-release") if !$system_release;
71124071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/gentoo-release") if !$system_release;
71224071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/issue") if !$system_release;
71324071ac1SMauro Carvalho Chehab$system_release =~ s/\s+$//;
71424071ac1SMauro Carvalho Chehab
71524071ac1SMauro Carvalho Chehabcheck_needs;
716