xref: /openbmc/linux/scripts/sphinx-pre-install (revision 24071ac1a6176dda89b441cc4c757c51e2f523e0)
1*24071ac1SMauro Carvalho Chehab#!/usr/bin/perl
2*24071ac1SMauro Carvalho Chehabuse strict;
3*24071ac1SMauro Carvalho Chehab
4*24071ac1SMauro Carvalho Chehab# Copyright (c) 2017 Mauro Carvalho Chehab <mchehab@kernel.org>
5*24071ac1SMauro Carvalho Chehab#
6*24071ac1SMauro Carvalho Chehab# This program is free software; you can redistribute it and/or
7*24071ac1SMauro Carvalho Chehab# modify it under the terms of the GNU General Public License
8*24071ac1SMauro Carvalho Chehab# as published by the Free Software Foundation; either version 2
9*24071ac1SMauro Carvalho Chehab# of the License, or (at your option) any later version.
10*24071ac1SMauro Carvalho Chehab#
11*24071ac1SMauro Carvalho Chehab# This program is distributed in the hope that it will be useful,
12*24071ac1SMauro Carvalho Chehab# but WITHOUT ANY WARRANTY; without even the implied warranty of
13*24071ac1SMauro Carvalho Chehab# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*24071ac1SMauro Carvalho Chehab# GNU General Public License for more details.
15*24071ac1SMauro Carvalho Chehab
16*24071ac1SMauro Carvalho Chehab#
17*24071ac1SMauro Carvalho Chehab# Static vars
18*24071ac1SMauro Carvalho Chehab#
19*24071ac1SMauro Carvalho Chehab
20*24071ac1SMauro Carvalho Chehabmy %missing;
21*24071ac1SMauro Carvalho Chehabmy $system_release;
22*24071ac1SMauro Carvalho Chehabmy $need = 0;
23*24071ac1SMauro Carvalho Chehabmy $optional = 0;
24*24071ac1SMauro Carvalho Chehabmy $need_symlink = 0;
25*24071ac1SMauro Carvalho Chehabmy $need_sphinx = 0;
26*24071ac1SMauro Carvalho Chehabmy $install = "";
27*24071ac1SMauro Carvalho Chehab
28*24071ac1SMauro Carvalho Chehab#
29*24071ac1SMauro Carvalho Chehab# Command line arguments
30*24071ac1SMauro Carvalho Chehab#
31*24071ac1SMauro Carvalho Chehab
32*24071ac1SMauro Carvalho Chehabmy $pdf = 1;
33*24071ac1SMauro Carvalho Chehabmy $virtualenv = 1;
34*24071ac1SMauro Carvalho Chehab
35*24071ac1SMauro Carvalho Chehab#
36*24071ac1SMauro Carvalho Chehab# List of required texlive packages on Fedora and OpenSuse
37*24071ac1SMauro Carvalho Chehab#
38*24071ac1SMauro Carvalho Chehab
39*24071ac1SMauro Carvalho Chehabmy %texlive = (
40*24071ac1SMauro Carvalho Chehab	'adjustbox.sty'      => 'texlive-adjustbox',
41*24071ac1SMauro Carvalho Chehab	'amsfonts.sty'       => 'texlive-amsfonts',
42*24071ac1SMauro Carvalho Chehab	'amsmath.sty'        => 'texlive-amsmath',
43*24071ac1SMauro Carvalho Chehab	'amssymb.sty'        => 'texlive-amsfonts',
44*24071ac1SMauro Carvalho Chehab	'amsthm.sty'         => 'texlive-amscls',
45*24071ac1SMauro Carvalho Chehab	'anyfontsize.sty'    => 'texlive-anyfontsize',
46*24071ac1SMauro Carvalho Chehab	'atbegshi.sty'       => 'texlive-oberdiek',
47*24071ac1SMauro Carvalho Chehab	'bm.sty'             => 'texlive-tools',
48*24071ac1SMauro Carvalho Chehab	'capt-of.sty'        => 'texlive-capt-of',
49*24071ac1SMauro Carvalho Chehab	'cmap.sty'           => 'texlive-cmap',
50*24071ac1SMauro Carvalho Chehab	'ecrm1000.tfm'       => 'texlive-ec',
51*24071ac1SMauro Carvalho Chehab	'eqparbox.sty'       => 'texlive-eqparbox',
52*24071ac1SMauro Carvalho Chehab	'eu1enc.def'         => 'texlive-euenc',
53*24071ac1SMauro Carvalho Chehab	'fancybox.sty'       => 'texlive-fancybox',
54*24071ac1SMauro Carvalho Chehab	'fancyvrb.sty'       => 'texlive-fancyvrb',
55*24071ac1SMauro Carvalho Chehab	'float.sty'          => 'texlive-float',
56*24071ac1SMauro Carvalho Chehab	'fncychap.sty'       => 'texlive-fncychap',
57*24071ac1SMauro Carvalho Chehab	'footnote.sty'       => 'texlive-mdwtools',
58*24071ac1SMauro Carvalho Chehab	'framed.sty'         => 'texlive-framed',
59*24071ac1SMauro Carvalho Chehab	'luatex85.sty'       => 'texlive-luatex85',
60*24071ac1SMauro Carvalho Chehab	'multirow.sty'       => 'texlive-multirow',
61*24071ac1SMauro Carvalho Chehab	'needspace.sty'      => 'texlive-needspace',
62*24071ac1SMauro Carvalho Chehab	'palatino.sty'       => 'texlive-psnfss',
63*24071ac1SMauro Carvalho Chehab	'parskip.sty'        => 'texlive-parskip',
64*24071ac1SMauro Carvalho Chehab	'polyglossia.sty'    => 'texlive-polyglossia',
65*24071ac1SMauro Carvalho Chehab	'tabulary.sty'       => 'texlive-tabulary',
66*24071ac1SMauro Carvalho Chehab	'threeparttable.sty' => 'texlive-threeparttable',
67*24071ac1SMauro Carvalho Chehab	'titlesec.sty'       => 'texlive-titlesec',
68*24071ac1SMauro Carvalho Chehab	'ucs.sty'            => 'texlive-ucs',
69*24071ac1SMauro Carvalho Chehab	'upquote.sty'        => 'texlive-upquote',
70*24071ac1SMauro Carvalho Chehab	'wrapfig.sty'        => 'texlive-wrapfig',
71*24071ac1SMauro Carvalho Chehab);
72*24071ac1SMauro Carvalho Chehab
73*24071ac1SMauro Carvalho Chehab#
74*24071ac1SMauro Carvalho Chehab# Subroutines that checks if a feature exists
75*24071ac1SMauro Carvalho Chehab#
76*24071ac1SMauro Carvalho Chehab
77*24071ac1SMauro Carvalho Chehabsub check_missing(%)
78*24071ac1SMauro Carvalho Chehab{
79*24071ac1SMauro Carvalho Chehab	my %map = %{$_[0]};
80*24071ac1SMauro Carvalho Chehab
81*24071ac1SMauro Carvalho Chehab	foreach my $prog (sort keys %missing) {
82*24071ac1SMauro Carvalho Chehab		my $is_optional = $missing{$prog};
83*24071ac1SMauro Carvalho Chehab
84*24071ac1SMauro Carvalho Chehab		if ($is_optional) {
85*24071ac1SMauro Carvalho Chehab			print "Warning: better to also install \"$prog\".\n";
86*24071ac1SMauro Carvalho Chehab		} else {
87*24071ac1SMauro Carvalho Chehab			print "ERROR: please install \"$prog\", otherwise, build won't work.\n";
88*24071ac1SMauro Carvalho Chehab		}
89*24071ac1SMauro Carvalho Chehab		if (defined($map{$prog})) {
90*24071ac1SMauro Carvalho Chehab			$install .= " " . $map{$prog};
91*24071ac1SMauro Carvalho Chehab		} else {
92*24071ac1SMauro Carvalho Chehab			$install .= " " . $prog;
93*24071ac1SMauro Carvalho Chehab		}
94*24071ac1SMauro Carvalho Chehab	}
95*24071ac1SMauro Carvalho Chehab
96*24071ac1SMauro Carvalho Chehab	$install =~ s/^\s//;
97*24071ac1SMauro Carvalho Chehab}
98*24071ac1SMauro Carvalho Chehab
99*24071ac1SMauro Carvalho Chehabsub add_package($$)
100*24071ac1SMauro Carvalho Chehab{
101*24071ac1SMauro Carvalho Chehab	my $package = shift;
102*24071ac1SMauro Carvalho Chehab	my $is_optional = shift;
103*24071ac1SMauro Carvalho Chehab
104*24071ac1SMauro Carvalho Chehab	$missing{$package} = $is_optional;
105*24071ac1SMauro Carvalho Chehab	if ($is_optional) {
106*24071ac1SMauro Carvalho Chehab		$optional++;
107*24071ac1SMauro Carvalho Chehab	} else {
108*24071ac1SMauro Carvalho Chehab		$need++;
109*24071ac1SMauro Carvalho Chehab	}
110*24071ac1SMauro Carvalho Chehab}
111*24071ac1SMauro Carvalho Chehab
112*24071ac1SMauro Carvalho Chehabsub check_missing_file($$$)
113*24071ac1SMauro Carvalho Chehab{
114*24071ac1SMauro Carvalho Chehab	my $file = shift;
115*24071ac1SMauro Carvalho Chehab	my $package = shift;
116*24071ac1SMauro Carvalho Chehab	my $is_optional = shift;
117*24071ac1SMauro Carvalho Chehab
118*24071ac1SMauro Carvalho Chehab	return if(-e $file);
119*24071ac1SMauro Carvalho Chehab
120*24071ac1SMauro Carvalho Chehab	add_package($package, $is_optional);
121*24071ac1SMauro Carvalho Chehab}
122*24071ac1SMauro Carvalho Chehab
123*24071ac1SMauro Carvalho Chehabsub findprog($)
124*24071ac1SMauro Carvalho Chehab{
125*24071ac1SMauro Carvalho Chehab	foreach(split(/:/, $ENV{PATH})) {
126*24071ac1SMauro Carvalho Chehab		return "$_/$_[0]" if(-x "$_/$_[0]");
127*24071ac1SMauro Carvalho Chehab	}
128*24071ac1SMauro Carvalho Chehab}
129*24071ac1SMauro Carvalho Chehab
130*24071ac1SMauro Carvalho Chehabsub check_program($$)
131*24071ac1SMauro Carvalho Chehab{
132*24071ac1SMauro Carvalho Chehab	my $prog = shift;
133*24071ac1SMauro Carvalho Chehab	my $is_optional = shift;
134*24071ac1SMauro Carvalho Chehab
135*24071ac1SMauro Carvalho Chehab	return if findprog($prog);
136*24071ac1SMauro Carvalho Chehab
137*24071ac1SMauro Carvalho Chehab	add_package($prog, $is_optional);
138*24071ac1SMauro Carvalho Chehab}
139*24071ac1SMauro Carvalho Chehab
140*24071ac1SMauro Carvalho Chehabsub check_perl_module($$)
141*24071ac1SMauro Carvalho Chehab{
142*24071ac1SMauro Carvalho Chehab	my $prog = shift;
143*24071ac1SMauro Carvalho Chehab	my $is_optional = shift;
144*24071ac1SMauro Carvalho Chehab
145*24071ac1SMauro Carvalho Chehab	my $err = system("perl -M$prog -e 1 2>/dev/null /dev/null");
146*24071ac1SMauro Carvalho Chehab	return if ($err == 0);
147*24071ac1SMauro Carvalho Chehab
148*24071ac1SMauro Carvalho Chehab	add_package($prog, $is_optional);
149*24071ac1SMauro Carvalho Chehab}
150*24071ac1SMauro Carvalho Chehab
151*24071ac1SMauro Carvalho Chehabsub check_python_module($$)
152*24071ac1SMauro Carvalho Chehab{
153*24071ac1SMauro Carvalho Chehab	my $prog = shift;
154*24071ac1SMauro Carvalho Chehab	my $is_optional = shift;
155*24071ac1SMauro Carvalho Chehab
156*24071ac1SMauro Carvalho Chehab	my $err = system("python3 -c 'import $prog' 2>/dev/null /dev/null");
157*24071ac1SMauro Carvalho Chehab	return if ($err == 0);
158*24071ac1SMauro Carvalho Chehab	my $err = system("python -c 'import $prog' 2>/dev/null /dev/null");
159*24071ac1SMauro Carvalho Chehab	return if ($err == 0);
160*24071ac1SMauro Carvalho Chehab
161*24071ac1SMauro Carvalho Chehab	add_package($prog, $is_optional);
162*24071ac1SMauro Carvalho Chehab}
163*24071ac1SMauro Carvalho Chehab
164*24071ac1SMauro Carvalho Chehabsub check_rpm_missing($$)
165*24071ac1SMauro Carvalho Chehab{
166*24071ac1SMauro Carvalho Chehab	my @pkgs = @{$_[0]};
167*24071ac1SMauro Carvalho Chehab	my $is_optional = $_[1];
168*24071ac1SMauro Carvalho Chehab
169*24071ac1SMauro Carvalho Chehab	foreach my $prog(@pkgs) {
170*24071ac1SMauro Carvalho Chehab		my $err = system("rpm -q '$prog' 2>/dev/null >/dev/null");
171*24071ac1SMauro Carvalho Chehab		add_package($prog, $is_optional) if ($err);
172*24071ac1SMauro Carvalho Chehab	}
173*24071ac1SMauro Carvalho Chehab}
174*24071ac1SMauro Carvalho Chehab
175*24071ac1SMauro Carvalho Chehabsub check_pacman_missing($$)
176*24071ac1SMauro Carvalho Chehab{
177*24071ac1SMauro Carvalho Chehab	my @pkgs = @{$_[0]};
178*24071ac1SMauro Carvalho Chehab	my $is_optional = $_[1];
179*24071ac1SMauro Carvalho Chehab
180*24071ac1SMauro Carvalho Chehab	foreach my $prog(@pkgs) {
181*24071ac1SMauro Carvalho Chehab		my $err = system("pacman -Q '$prog' 2>/dev/null >/dev/null");
182*24071ac1SMauro Carvalho Chehab		add_package($prog, $is_optional) if ($err);
183*24071ac1SMauro Carvalho Chehab	}
184*24071ac1SMauro Carvalho Chehab}
185*24071ac1SMauro Carvalho Chehab
186*24071ac1SMauro Carvalho Chehabsub check_missing_tex($)
187*24071ac1SMauro Carvalho Chehab{
188*24071ac1SMauro Carvalho Chehab	my $is_optional = shift;
189*24071ac1SMauro Carvalho Chehab	my $kpsewhich = findprog("kpsewhich");
190*24071ac1SMauro Carvalho Chehab
191*24071ac1SMauro Carvalho Chehab	foreach my $prog(keys %texlive) {
192*24071ac1SMauro Carvalho Chehab		my $package = $texlive{$prog};
193*24071ac1SMauro Carvalho Chehab		if (!$kpsewhich) {
194*24071ac1SMauro Carvalho Chehab			add_package($package, $is_optional);
195*24071ac1SMauro Carvalho Chehab			next;
196*24071ac1SMauro Carvalho Chehab		}
197*24071ac1SMauro Carvalho Chehab		my $file = qx($kpsewhich $prog);
198*24071ac1SMauro Carvalho Chehab		add_package($package, $is_optional) if ($file =~ /^\s*$/);
199*24071ac1SMauro Carvalho Chehab	}
200*24071ac1SMauro Carvalho Chehab}
201*24071ac1SMauro Carvalho Chehab
202*24071ac1SMauro Carvalho Chehabsub check_sphinx()
203*24071ac1SMauro Carvalho Chehab{
204*24071ac1SMauro Carvalho Chehab	return if findprog("sphinx-build");
205*24071ac1SMauro Carvalho Chehab
206*24071ac1SMauro Carvalho Chehab	if (findprog("sphinx-build-3")) {
207*24071ac1SMauro Carvalho Chehab		$need_symlink = 1;
208*24071ac1SMauro Carvalho Chehab		return;
209*24071ac1SMauro Carvalho Chehab	}
210*24071ac1SMauro Carvalho Chehab
211*24071ac1SMauro Carvalho Chehab	if ($virtualenv) {
212*24071ac1SMauro Carvalho Chehab		check_program("virtualenv", 0) if (!findprog("virtualenv-3"));
213*24071ac1SMauro Carvalho Chehab		check_program("pip", 0) if (!findprog("pip3"));
214*24071ac1SMauro Carvalho Chehab		$need_sphinx = 1;
215*24071ac1SMauro Carvalho Chehab	} else {
216*24071ac1SMauro Carvalho Chehab		add_package("python-sphinx", 0);
217*24071ac1SMauro Carvalho Chehab	}
218*24071ac1SMauro Carvalho Chehab}
219*24071ac1SMauro Carvalho Chehab
220*24071ac1SMauro Carvalho Chehab#
221*24071ac1SMauro Carvalho Chehab# Ancillary subroutines
222*24071ac1SMauro Carvalho Chehab#
223*24071ac1SMauro Carvalho Chehab
224*24071ac1SMauro Carvalho Chehabsub catcheck($)
225*24071ac1SMauro Carvalho Chehab{
226*24071ac1SMauro Carvalho Chehab  my $res = "";
227*24071ac1SMauro Carvalho Chehab  $res = qx(cat $_[0]) if (-r $_[0]);
228*24071ac1SMauro Carvalho Chehab  return $res;
229*24071ac1SMauro Carvalho Chehab}
230*24071ac1SMauro Carvalho Chehab
231*24071ac1SMauro Carvalho Chehabsub which($)
232*24071ac1SMauro Carvalho Chehab{
233*24071ac1SMauro Carvalho Chehab	my $file = shift;
234*24071ac1SMauro Carvalho Chehab	my @path = split ":", $ENV{PATH};
235*24071ac1SMauro Carvalho Chehab
236*24071ac1SMauro Carvalho Chehab	foreach my $dir(@path) {
237*24071ac1SMauro Carvalho Chehab		my $name = $dir.'/'.$file;
238*24071ac1SMauro Carvalho Chehab		return $name if (-x $name );
239*24071ac1SMauro Carvalho Chehab	}
240*24071ac1SMauro Carvalho Chehab	return undef;
241*24071ac1SMauro Carvalho Chehab}
242*24071ac1SMauro Carvalho Chehab
243*24071ac1SMauro Carvalho Chehab#
244*24071ac1SMauro Carvalho Chehab# Subroutines that check distro-specific hints
245*24071ac1SMauro Carvalho Chehab#
246*24071ac1SMauro Carvalho Chehab
247*24071ac1SMauro Carvalho Chehabsub give_debian_hints()
248*24071ac1SMauro Carvalho Chehab{
249*24071ac1SMauro Carvalho Chehab	my %map = (
250*24071ac1SMauro Carvalho Chehab		"python-sphinx"		=> "python3-sphinx",
251*24071ac1SMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "python3-sphinx-rtd-theme",
252*24071ac1SMauro Carvalho Chehab		"virtualenv"		=> "virtualenv",
253*24071ac1SMauro Carvalho Chehab		"pip"			=> "python3-pip",
254*24071ac1SMauro Carvalho Chehab		"dot"			=> "graphviz",
255*24071ac1SMauro Carvalho Chehab		"convert"		=> "imagemagick",
256*24071ac1SMauro Carvalho Chehab		"Pod::Usage"		=> "perl-modules",
257*24071ac1SMauro Carvalho Chehab		"xelatex"		=> "texlive-xetex",
258*24071ac1SMauro Carvalho Chehab	);
259*24071ac1SMauro Carvalho Chehab
260*24071ac1SMauro Carvalho Chehab	if ($pdf) {
261*24071ac1SMauro Carvalho Chehab		check_missing_file("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
262*24071ac1SMauro Carvalho Chehab				   "fonts-dejavu", 1);
263*24071ac1SMauro Carvalho Chehab	}
264*24071ac1SMauro Carvalho Chehab
265*24071ac1SMauro Carvalho Chehab	check_program("dvipng", 1) if ($pdf);
266*24071ac1SMauro Carvalho Chehab	check_missing(\%map);
267*24071ac1SMauro Carvalho Chehab
268*24071ac1SMauro Carvalho Chehab	return if (!$need && !$optional);
269*24071ac1SMauro Carvalho Chehab	printf("You should run:\n\n\tsudo apt-get install $install\n");
270*24071ac1SMauro Carvalho Chehab}
271*24071ac1SMauro Carvalho Chehab
272*24071ac1SMauro Carvalho Chehabsub give_redhat_hints()
273*24071ac1SMauro Carvalho Chehab{
274*24071ac1SMauro Carvalho Chehab	my %map = (
275*24071ac1SMauro Carvalho Chehab		"python-sphinx"		=> "python3-sphinx",
276*24071ac1SMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "python3-sphinx_rtd_theme",
277*24071ac1SMauro Carvalho Chehab		"virtualenv"		=> "python3-virtualenv",
278*24071ac1SMauro Carvalho Chehab		"pip"			=> "python3-pip",
279*24071ac1SMauro Carvalho Chehab		"dot"			=> "graphviz",
280*24071ac1SMauro Carvalho Chehab		"convert"		=> "ImageMagick",
281*24071ac1SMauro Carvalho Chehab		"Pod::Usage"		=> "perl-Pod-Usage",
282*24071ac1SMauro Carvalho Chehab		"xelatex"		=> "texlive-xetex-bin",
283*24071ac1SMauro Carvalho Chehab	);
284*24071ac1SMauro Carvalho Chehab
285*24071ac1SMauro Carvalho Chehab	my @fedora_tex_pkgs = (
286*24071ac1SMauro Carvalho Chehab		"texlive-collection-fontsrecommended",
287*24071ac1SMauro Carvalho Chehab		"texlive-collection-latex",
288*24071ac1SMauro Carvalho Chehab		"dejavu-sans-fonts",
289*24071ac1SMauro Carvalho Chehab		"dejavu-serif-fonts",
290*24071ac1SMauro Carvalho Chehab		"dejavu-sans-mono-fonts",
291*24071ac1SMauro Carvalho Chehab	);
292*24071ac1SMauro Carvalho Chehab
293*24071ac1SMauro Carvalho Chehab	check_rpm_missing(\@fedora_tex_pkgs, 1) if ($pdf);
294*24071ac1SMauro Carvalho Chehab	check_missing_tex(1) if ($pdf);
295*24071ac1SMauro Carvalho Chehab	check_missing(\%map);
296*24071ac1SMauro Carvalho Chehab
297*24071ac1SMauro Carvalho Chehab	return if (!$need && !$optional);
298*24071ac1SMauro Carvalho Chehab	printf("You should run:\n\n\tsudo dnf install -y $install\n");
299*24071ac1SMauro Carvalho Chehab}
300*24071ac1SMauro Carvalho Chehab
301*24071ac1SMauro Carvalho Chehabsub give_opensuse_hints()
302*24071ac1SMauro Carvalho Chehab{
303*24071ac1SMauro Carvalho Chehab	my %map = (
304*24071ac1SMauro Carvalho Chehab		"python-sphinx"		=> "python3-sphinx",
305*24071ac1SMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "python3-sphinx_rtd_theme",
306*24071ac1SMauro Carvalho Chehab		"virtualenv"		=> "python3-virtualenv",
307*24071ac1SMauro Carvalho Chehab		"pip"			=> "python3-pip",
308*24071ac1SMauro Carvalho Chehab		"dot"			=> "graphviz",
309*24071ac1SMauro Carvalho Chehab		"convert"		=> "ImageMagick",
310*24071ac1SMauro Carvalho Chehab		"Pod::Usage"		=> "perl-Pod-Usage",
311*24071ac1SMauro Carvalho Chehab		"xelatex"		=> "texlive-xetex-bin",
312*24071ac1SMauro Carvalho Chehab	);
313*24071ac1SMauro Carvalho Chehab
314*24071ac1SMauro Carvalho Chehab	my @suse_tex_pkgs = (
315*24071ac1SMauro Carvalho Chehab		"texlive-babel-english",
316*24071ac1SMauro Carvalho Chehab		"texlive-caption",
317*24071ac1SMauro Carvalho Chehab		"texlive-colortbl",
318*24071ac1SMauro Carvalho Chehab		"texlive-courier",
319*24071ac1SMauro Carvalho Chehab		"texlive-dvips",
320*24071ac1SMauro Carvalho Chehab		"texlive-helvetic",
321*24071ac1SMauro Carvalho Chehab		"texlive-makeindex",
322*24071ac1SMauro Carvalho Chehab		"texlive-metafont",
323*24071ac1SMauro Carvalho Chehab		"texlive-metapost",
324*24071ac1SMauro Carvalho Chehab		"texlive-palatino",
325*24071ac1SMauro Carvalho Chehab		"texlive-preview",
326*24071ac1SMauro Carvalho Chehab		"texlive-times",
327*24071ac1SMauro Carvalho Chehab		"texlive-zapfchan",
328*24071ac1SMauro Carvalho Chehab		"texlive-zapfding",
329*24071ac1SMauro Carvalho Chehab	);
330*24071ac1SMauro Carvalho Chehab
331*24071ac1SMauro Carvalho Chehab	check_rpm_missing(\@suse_tex_pkgs, 1) if ($pdf);
332*24071ac1SMauro Carvalho Chehab	check_missing_tex(1) if ($pdf);
333*24071ac1SMauro Carvalho Chehab	check_missing(\%map);
334*24071ac1SMauro Carvalho Chehab
335*24071ac1SMauro Carvalho Chehab	return if (!$need && !$optional);
336*24071ac1SMauro Carvalho Chehab	printf("You should run:\n\n\tsudo zypper install --no-recommends $install\n");
337*24071ac1SMauro Carvalho Chehab}
338*24071ac1SMauro Carvalho Chehab
339*24071ac1SMauro Carvalho Chehabsub give_arch_linux_hints()
340*24071ac1SMauro Carvalho Chehab{
341*24071ac1SMauro Carvalho Chehab	my %map = (
342*24071ac1SMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "python-sphinx_rtd_theme",
343*24071ac1SMauro Carvalho Chehab		"virtualenv"		=> "python-virtualenv",
344*24071ac1SMauro Carvalho Chehab		"pip"			=> "python-pip",
345*24071ac1SMauro Carvalho Chehab		"dot"			=> "graphviz",
346*24071ac1SMauro Carvalho Chehab		"convert"		=> "imagemagick",
347*24071ac1SMauro Carvalho Chehab		"xelatex"		=> "texlive-bin",
348*24071ac1SMauro Carvalho Chehab	);
349*24071ac1SMauro Carvalho Chehab
350*24071ac1SMauro Carvalho Chehab	my @archlinux_tex_pkgs = (
351*24071ac1SMauro Carvalho Chehab		"texlive-core",
352*24071ac1SMauro Carvalho Chehab		"texlive-latexextra",
353*24071ac1SMauro Carvalho Chehab		"ttf-dejavu",
354*24071ac1SMauro Carvalho Chehab	);
355*24071ac1SMauro Carvalho Chehab	check_pacman_missing(\@archlinux_tex_pkgs, 1) if ($pdf);
356*24071ac1SMauro Carvalho Chehab	check_missing(\%map);
357*24071ac1SMauro Carvalho Chehab
358*24071ac1SMauro Carvalho Chehab	return if (!$need && !$optional);
359*24071ac1SMauro Carvalho Chehab	printf("You should run:\n\n\tsudo pacman -S $install\n");
360*24071ac1SMauro Carvalho Chehab}
361*24071ac1SMauro Carvalho Chehab
362*24071ac1SMauro Carvalho Chehabsub give_gentoo_hints()
363*24071ac1SMauro Carvalho Chehab{
364*24071ac1SMauro Carvalho Chehab	my %map = (
365*24071ac1SMauro Carvalho Chehab		"sphinx_rtd_theme"	=> "dev-python/sphinx_rtd_theme",
366*24071ac1SMauro Carvalho Chehab		"virtualenv"		=> "dev-python/virtualenv",
367*24071ac1SMauro Carvalho Chehab		"pip"			=> "dev-python/pip",
368*24071ac1SMauro Carvalho Chehab		"dot"			=> "media-gfx/graphviz",
369*24071ac1SMauro Carvalho Chehab		"convert"		=> "media-gfx/imagemagick",
370*24071ac1SMauro Carvalho Chehab		"xelatex"		=> "dev-texlive/texlive-xetex media-fonts/dejavu",
371*24071ac1SMauro Carvalho Chehab	);
372*24071ac1SMauro Carvalho Chehab
373*24071ac1SMauro Carvalho Chehab	check_missing_file("/usr/share/fonts/dejavu/DejaVuSans.ttf",
374*24071ac1SMauro Carvalho Chehab			   "media-fonts/dejavu", 1) if ($pdf);
375*24071ac1SMauro Carvalho Chehab
376*24071ac1SMauro Carvalho Chehab	check_missing(\%map);
377*24071ac1SMauro Carvalho Chehab
378*24071ac1SMauro Carvalho Chehab	return if (!$need && !$optional);
379*24071ac1SMauro Carvalho Chehab	printf("You should run:\n\n\tsudo emerge --ask $install\n");
380*24071ac1SMauro Carvalho Chehab}
381*24071ac1SMauro Carvalho Chehab
382*24071ac1SMauro Carvalho Chehabsub check_distros()
383*24071ac1SMauro Carvalho Chehab{
384*24071ac1SMauro Carvalho Chehab	# Distro-specific hints
385*24071ac1SMauro Carvalho Chehab	if ($system_release =~ /Red Hat Enterprise Linux/) {
386*24071ac1SMauro Carvalho Chehab		give_redhat_hints;
387*24071ac1SMauro Carvalho Chehab		return;
388*24071ac1SMauro Carvalho Chehab	}
389*24071ac1SMauro Carvalho Chehab	if ($system_release =~ /Fedora/) {
390*24071ac1SMauro Carvalho Chehab		give_redhat_hints;
391*24071ac1SMauro Carvalho Chehab		return;
392*24071ac1SMauro Carvalho Chehab	}
393*24071ac1SMauro Carvalho Chehab	if ($system_release =~ /Ubuntu/) {
394*24071ac1SMauro Carvalho Chehab		give_debian_hints;
395*24071ac1SMauro Carvalho Chehab		return;
396*24071ac1SMauro Carvalho Chehab	}
397*24071ac1SMauro Carvalho Chehab	if ($system_release =~ /Debian/) {
398*24071ac1SMauro Carvalho Chehab		give_debian_hints;
399*24071ac1SMauro Carvalho Chehab		return;
400*24071ac1SMauro Carvalho Chehab	}
401*24071ac1SMauro Carvalho Chehab	if ($system_release =~ /openSUSE/) {
402*24071ac1SMauro Carvalho Chehab		give_opensuse_hints;
403*24071ac1SMauro Carvalho Chehab		return;
404*24071ac1SMauro Carvalho Chehab	}
405*24071ac1SMauro Carvalho Chehab	if ($system_release =~ /Arch Linux/) {
406*24071ac1SMauro Carvalho Chehab		give_arch_linux_hints;
407*24071ac1SMauro Carvalho Chehab		return;
408*24071ac1SMauro Carvalho Chehab	}
409*24071ac1SMauro Carvalho Chehab	if ($system_release =~ /Gentoo/) {
410*24071ac1SMauro Carvalho Chehab		give_gentoo_hints;
411*24071ac1SMauro Carvalho Chehab		return;
412*24071ac1SMauro Carvalho Chehab	}
413*24071ac1SMauro Carvalho Chehab
414*24071ac1SMauro Carvalho Chehab	#
415*24071ac1SMauro Carvalho Chehab	# Fall-back to generic hint code for other distros
416*24071ac1SMauro Carvalho Chehab	# That's far from ideal, specially for LaTeX dependencies.
417*24071ac1SMauro Carvalho Chehab	#
418*24071ac1SMauro Carvalho Chehab	my %map = (
419*24071ac1SMauro Carvalho Chehab		"sphinx-build" => "sphinx"
420*24071ac1SMauro Carvalho Chehab	);
421*24071ac1SMauro Carvalho Chehab	check_missing_tex(1) if ($pdf);
422*24071ac1SMauro Carvalho Chehab	check_missing(\%map);
423*24071ac1SMauro Carvalho Chehab	print "I don't know distro $system_release.\n";
424*24071ac1SMauro Carvalho Chehab	print "So, I can't provide you a hint with the install procedure.\n";
425*24071ac1SMauro Carvalho Chehab	print "There are likely missing dependencies.\n";
426*24071ac1SMauro Carvalho Chehab}
427*24071ac1SMauro Carvalho Chehab
428*24071ac1SMauro Carvalho Chehab#
429*24071ac1SMauro Carvalho Chehab# Common dependencies
430*24071ac1SMauro Carvalho Chehab#
431*24071ac1SMauro Carvalho Chehab
432*24071ac1SMauro Carvalho Chehabsub check_needs()
433*24071ac1SMauro Carvalho Chehab{
434*24071ac1SMauro Carvalho Chehab	if ($system_release) {
435*24071ac1SMauro Carvalho Chehab		print "Checking if the needed tools for $system_release are available\n";
436*24071ac1SMauro Carvalho Chehab	} else {
437*24071ac1SMauro Carvalho Chehab		print "Checking if the needed tools are present\n";
438*24071ac1SMauro Carvalho Chehab	}
439*24071ac1SMauro Carvalho Chehab
440*24071ac1SMauro Carvalho Chehab	# Check for needed programs/tools
441*24071ac1SMauro Carvalho Chehab	check_sphinx();
442*24071ac1SMauro Carvalho Chehab	check_perl_module("Pod::Usage", 0);
443*24071ac1SMauro Carvalho Chehab	check_program("make", 0);
444*24071ac1SMauro Carvalho Chehab	check_program("gcc", 0);
445*24071ac1SMauro Carvalho Chehab	check_python_module("sphinx_rtd_theme", 1) if (!$virtualenv);
446*24071ac1SMauro Carvalho Chehab	check_program("xelatex", 1) if ($pdf);
447*24071ac1SMauro Carvalho Chehab	check_program("dot", 1);
448*24071ac1SMauro Carvalho Chehab	check_program("convert", 1);
449*24071ac1SMauro Carvalho Chehab
450*24071ac1SMauro Carvalho Chehab	check_distros();
451*24071ac1SMauro Carvalho Chehab
452*24071ac1SMauro Carvalho Chehab	if ($need_symlink) {
453*24071ac1SMauro Carvalho Chehab		printf "\tsudo ln -sf %s /usr/bin/sphinx-build\n\n",
454*24071ac1SMauro Carvalho Chehab		       which("sphinx-build-3");
455*24071ac1SMauro Carvalho Chehab	}
456*24071ac1SMauro Carvalho Chehab	if ($need_sphinx) {
457*24071ac1SMauro Carvalho Chehab		my $virtualenv = findprog("virtualenv-3");
458*24071ac1SMauro Carvalho Chehab		$virtualenv = findprog("virtualenv") if (!$virtualenv);
459*24071ac1SMauro Carvalho Chehab		$virtualenv = "virtualenv" if (!$virtualenv);
460*24071ac1SMauro Carvalho Chehab
461*24071ac1SMauro Carvalho Chehab		printf "\t$virtualenv sphinx_1.4\n";
462*24071ac1SMauro Carvalho Chehab		printf "\t. sphinx_1.4/bin/activate\n";
463*24071ac1SMauro Carvalho Chehab		printf "\tpip install 'docutils==0.12'\n";
464*24071ac1SMauro Carvalho Chehab		printf "\tpip install 'Sphinx==1.4.9'\n";
465*24071ac1SMauro Carvalho Chehab		printf "\tpip install sphinx_rtd_theme\n";
466*24071ac1SMauro Carvalho Chehab		$need++;
467*24071ac1SMauro Carvalho Chehab	}
468*24071ac1SMauro Carvalho Chehab	printf "\n";
469*24071ac1SMauro Carvalho Chehab
470*24071ac1SMauro Carvalho Chehab	print "All optional dependenties are met.\n" if (!$optional);
471*24071ac1SMauro Carvalho Chehab
472*24071ac1SMauro Carvalho Chehab	if ($need == 1) {
473*24071ac1SMauro Carvalho Chehab		die "Can't build as $need mandatory dependency is missing";
474*24071ac1SMauro Carvalho Chehab	} elsif ($need) {
475*24071ac1SMauro Carvalho Chehab		die "Can't build as $need mandatory dependencies are missing";
476*24071ac1SMauro Carvalho Chehab	}
477*24071ac1SMauro Carvalho Chehab
478*24071ac1SMauro Carvalho Chehab	print "Needed package dependencies are met.\n";
479*24071ac1SMauro Carvalho Chehab}
480*24071ac1SMauro Carvalho Chehab
481*24071ac1SMauro Carvalho Chehab#
482*24071ac1SMauro Carvalho Chehab# Main
483*24071ac1SMauro Carvalho Chehab#
484*24071ac1SMauro Carvalho Chehab
485*24071ac1SMauro Carvalho Chehabwhile (@ARGV) {
486*24071ac1SMauro Carvalho Chehab	my $arg = shift(@ARGV);
487*24071ac1SMauro Carvalho Chehab
488*24071ac1SMauro Carvalho Chehab	if ($arg eq "--no-virtualenv") {
489*24071ac1SMauro Carvalho Chehab		$virtualenv = 0;
490*24071ac1SMauro Carvalho Chehab	} elsif ($arg eq "--no-pdf"){
491*24071ac1SMauro Carvalho Chehab		$pdf = 0;
492*24071ac1SMauro Carvalho Chehab	} else {
493*24071ac1SMauro Carvalho Chehab		print "Usage:\n\t$0 <--no-virtualenv> <--no-pdf>\n\n";
494*24071ac1SMauro Carvalho Chehab		exit -1;
495*24071ac1SMauro Carvalho Chehab	}
496*24071ac1SMauro Carvalho Chehab}
497*24071ac1SMauro Carvalho Chehab
498*24071ac1SMauro Carvalho Chehab#
499*24071ac1SMauro Carvalho Chehab# Determine the system type. There's no standard unique way that would
500*24071ac1SMauro Carvalho Chehab# work with all distros with a minimal package install. So, several
501*24071ac1SMauro Carvalho Chehab# methods are used here.
502*24071ac1SMauro Carvalho Chehab#
503*24071ac1SMauro Carvalho Chehab# By default, it will use lsb_release function. If not available, it will
504*24071ac1SMauro Carvalho Chehab# fail back to reading the known different places where the distro name
505*24071ac1SMauro Carvalho Chehab# is stored
506*24071ac1SMauro Carvalho Chehab#
507*24071ac1SMauro Carvalho Chehab
508*24071ac1SMauro Carvalho Chehab$system_release = qx(lsb_release -d) if which("lsb_release");
509*24071ac1SMauro Carvalho Chehab$system_release =~ s/Description:\s*// if ($system_release);
510*24071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/system-release") if !$system_release;
511*24071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/redhat-release") if !$system_release;
512*24071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/lsb-release") if !$system_release;
513*24071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/gentoo-release") if !$system_release;
514*24071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/issue") if !$system_release;
515*24071ac1SMauro Carvalho Chehab$system_release =~ s/\s+$//;
516*24071ac1SMauro Carvalho Chehab
517*24071ac1SMauro Carvalho Chehabcheck_needs;
518