124071ac1SMauro Carvalho Chehab#!/usr/bin/perl 224071ac1SMauro Carvalho Chehabuse strict; 324071ac1SMauro Carvalho Chehab 424071ac1SMauro Carvalho Chehab# Copyright (c) 2017 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 165be33182SMauro Carvalho Chehabmy $virtenv_dir = "sphinx_1.4"; 17fb947f3fSMauro Carvalho Chehabmy $requirement_file = "Documentation/sphinx/requirements.txt"; 185be33182SMauro Carvalho Chehab 1924071ac1SMauro Carvalho Chehab# 2024071ac1SMauro Carvalho Chehab# Static vars 2124071ac1SMauro Carvalho Chehab# 2224071ac1SMauro Carvalho Chehab 2324071ac1SMauro Carvalho Chehabmy %missing; 2424071ac1SMauro Carvalho Chehabmy $system_release; 2524071ac1SMauro Carvalho Chehabmy $need = 0; 2624071ac1SMauro Carvalho Chehabmy $optional = 0; 2724071ac1SMauro Carvalho Chehabmy $need_symlink = 0; 2824071ac1SMauro Carvalho Chehabmy $need_sphinx = 0; 2924071ac1SMauro Carvalho Chehabmy $install = ""; 3024071ac1SMauro Carvalho Chehab 3124071ac1SMauro Carvalho Chehab# 3224071ac1SMauro Carvalho Chehab# Command line arguments 3324071ac1SMauro Carvalho Chehab# 3424071ac1SMauro Carvalho Chehab 3524071ac1SMauro Carvalho Chehabmy $pdf = 1; 3624071ac1SMauro Carvalho Chehabmy $virtualenv = 1; 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 'adjustbox.sty' => 'texlive-adjustbox', 4424071ac1SMauro Carvalho Chehab 'amsfonts.sty' => 'texlive-amsfonts', 4524071ac1SMauro Carvalho Chehab 'amsmath.sty' => 'texlive-amsmath', 4624071ac1SMauro Carvalho Chehab 'amssymb.sty' => 'texlive-amsfonts', 4724071ac1SMauro Carvalho Chehab 'amsthm.sty' => 'texlive-amscls', 4824071ac1SMauro Carvalho Chehab 'anyfontsize.sty' => 'texlive-anyfontsize', 4924071ac1SMauro Carvalho Chehab 'atbegshi.sty' => 'texlive-oberdiek', 5024071ac1SMauro Carvalho Chehab 'bm.sty' => 'texlive-tools', 5124071ac1SMauro Carvalho Chehab 'capt-of.sty' => 'texlive-capt-of', 5224071ac1SMauro Carvalho Chehab 'cmap.sty' => 'texlive-cmap', 5324071ac1SMauro Carvalho Chehab 'ecrm1000.tfm' => 'texlive-ec', 5424071ac1SMauro Carvalho Chehab 'eqparbox.sty' => 'texlive-eqparbox', 5524071ac1SMauro Carvalho Chehab 'eu1enc.def' => 'texlive-euenc', 5624071ac1SMauro Carvalho Chehab 'fancybox.sty' => 'texlive-fancybox', 5724071ac1SMauro Carvalho Chehab 'fancyvrb.sty' => 'texlive-fancyvrb', 5824071ac1SMauro Carvalho Chehab 'float.sty' => 'texlive-float', 5924071ac1SMauro Carvalho Chehab 'fncychap.sty' => 'texlive-fncychap', 6024071ac1SMauro Carvalho Chehab 'footnote.sty' => 'texlive-mdwtools', 6124071ac1SMauro Carvalho Chehab 'framed.sty' => 'texlive-framed', 6224071ac1SMauro Carvalho Chehab 'luatex85.sty' => 'texlive-luatex85', 6324071ac1SMauro Carvalho Chehab 'multirow.sty' => 'texlive-multirow', 6424071ac1SMauro Carvalho Chehab 'needspace.sty' => 'texlive-needspace', 6524071ac1SMauro Carvalho Chehab 'palatino.sty' => 'texlive-psnfss', 6624071ac1SMauro Carvalho Chehab 'parskip.sty' => 'texlive-parskip', 6724071ac1SMauro Carvalho Chehab 'polyglossia.sty' => 'texlive-polyglossia', 6824071ac1SMauro Carvalho Chehab 'tabulary.sty' => 'texlive-tabulary', 6924071ac1SMauro Carvalho Chehab 'threeparttable.sty' => 'texlive-threeparttable', 7024071ac1SMauro Carvalho Chehab 'titlesec.sty' => 'texlive-titlesec', 7124071ac1SMauro Carvalho Chehab 'ucs.sty' => 'texlive-ucs', 7224071ac1SMauro Carvalho Chehab 'upquote.sty' => 'texlive-upquote', 7324071ac1SMauro Carvalho Chehab 'wrapfig.sty' => 'texlive-wrapfig', 7424071ac1SMauro Carvalho Chehab); 7524071ac1SMauro Carvalho Chehab 7624071ac1SMauro Carvalho Chehab# 7724071ac1SMauro Carvalho Chehab# Subroutines that checks if a feature exists 7824071ac1SMauro Carvalho Chehab# 7924071ac1SMauro Carvalho Chehab 8024071ac1SMauro Carvalho Chehabsub check_missing(%) 8124071ac1SMauro Carvalho Chehab{ 8224071ac1SMauro Carvalho Chehab my %map = %{$_[0]}; 8324071ac1SMauro Carvalho Chehab 8424071ac1SMauro Carvalho Chehab foreach my $prog (sort keys %missing) { 8524071ac1SMauro Carvalho Chehab my $is_optional = $missing{$prog}; 8624071ac1SMauro Carvalho Chehab 8724071ac1SMauro Carvalho Chehab if ($is_optional) { 8824071ac1SMauro Carvalho Chehab print "Warning: better to also install \"$prog\".\n"; 8924071ac1SMauro Carvalho Chehab } else { 9024071ac1SMauro Carvalho Chehab print "ERROR: please install \"$prog\", otherwise, build won't work.\n"; 9124071ac1SMauro Carvalho Chehab } 9224071ac1SMauro Carvalho Chehab if (defined($map{$prog})) { 9324071ac1SMauro Carvalho Chehab $install .= " " . $map{$prog}; 9424071ac1SMauro Carvalho Chehab } else { 9524071ac1SMauro Carvalho Chehab $install .= " " . $prog; 9624071ac1SMauro Carvalho Chehab } 9724071ac1SMauro Carvalho Chehab } 9824071ac1SMauro Carvalho Chehab 9924071ac1SMauro Carvalho Chehab $install =~ s/^\s//; 10024071ac1SMauro Carvalho Chehab} 10124071ac1SMauro Carvalho Chehab 10224071ac1SMauro Carvalho Chehabsub add_package($$) 10324071ac1SMauro Carvalho Chehab{ 10424071ac1SMauro Carvalho Chehab my $package = shift; 10524071ac1SMauro Carvalho Chehab my $is_optional = shift; 10624071ac1SMauro Carvalho Chehab 10724071ac1SMauro Carvalho Chehab $missing{$package} = $is_optional; 10824071ac1SMauro Carvalho Chehab if ($is_optional) { 10924071ac1SMauro Carvalho Chehab $optional++; 11024071ac1SMauro Carvalho Chehab } else { 11124071ac1SMauro Carvalho Chehab $need++; 11224071ac1SMauro Carvalho Chehab } 11324071ac1SMauro Carvalho Chehab} 11424071ac1SMauro Carvalho Chehab 11524071ac1SMauro Carvalho Chehabsub check_missing_file($$$) 11624071ac1SMauro Carvalho Chehab{ 11724071ac1SMauro Carvalho Chehab my $file = shift; 11824071ac1SMauro Carvalho Chehab my $package = shift; 11924071ac1SMauro Carvalho Chehab my $is_optional = shift; 12024071ac1SMauro Carvalho Chehab 12124071ac1SMauro Carvalho Chehab return if(-e $file); 12224071ac1SMauro Carvalho Chehab 12324071ac1SMauro Carvalho Chehab add_package($package, $is_optional); 12424071ac1SMauro Carvalho Chehab} 12524071ac1SMauro Carvalho Chehab 12624071ac1SMauro Carvalho Chehabsub findprog($) 12724071ac1SMauro Carvalho Chehab{ 12824071ac1SMauro Carvalho Chehab foreach(split(/:/, $ENV{PATH})) { 12924071ac1SMauro Carvalho Chehab return "$_/$_[0]" if(-x "$_/$_[0]"); 13024071ac1SMauro Carvalho Chehab } 13124071ac1SMauro Carvalho Chehab} 13224071ac1SMauro Carvalho Chehab 13324071ac1SMauro Carvalho Chehabsub check_program($$) 13424071ac1SMauro Carvalho Chehab{ 13524071ac1SMauro Carvalho Chehab my $prog = shift; 13624071ac1SMauro Carvalho Chehab my $is_optional = shift; 13724071ac1SMauro Carvalho Chehab 13824071ac1SMauro Carvalho Chehab return if findprog($prog); 13924071ac1SMauro Carvalho Chehab 14024071ac1SMauro Carvalho Chehab add_package($prog, $is_optional); 14124071ac1SMauro Carvalho Chehab} 14224071ac1SMauro Carvalho Chehab 14324071ac1SMauro Carvalho Chehabsub check_perl_module($$) 14424071ac1SMauro Carvalho Chehab{ 14524071ac1SMauro Carvalho Chehab my $prog = shift; 14624071ac1SMauro Carvalho Chehab my $is_optional = shift; 14724071ac1SMauro Carvalho Chehab 14824071ac1SMauro Carvalho Chehab my $err = system("perl -M$prog -e 1 2>/dev/null /dev/null"); 14924071ac1SMauro Carvalho Chehab return if ($err == 0); 15024071ac1SMauro Carvalho Chehab 15124071ac1SMauro Carvalho Chehab add_package($prog, $is_optional); 15224071ac1SMauro Carvalho Chehab} 15324071ac1SMauro Carvalho Chehab 15424071ac1SMauro Carvalho Chehabsub check_python_module($$) 15524071ac1SMauro Carvalho Chehab{ 15624071ac1SMauro Carvalho Chehab my $prog = shift; 15724071ac1SMauro Carvalho Chehab my $is_optional = shift; 15824071ac1SMauro Carvalho Chehab 15924071ac1SMauro Carvalho Chehab my $err = system("python3 -c 'import $prog' 2>/dev/null /dev/null"); 16024071ac1SMauro Carvalho Chehab return if ($err == 0); 16124071ac1SMauro Carvalho Chehab my $err = system("python -c 'import $prog' 2>/dev/null /dev/null"); 16224071ac1SMauro Carvalho Chehab return if ($err == 0); 16324071ac1SMauro Carvalho Chehab 16424071ac1SMauro Carvalho Chehab add_package($prog, $is_optional); 16524071ac1SMauro Carvalho Chehab} 16624071ac1SMauro Carvalho Chehab 16724071ac1SMauro Carvalho Chehabsub check_rpm_missing($$) 16824071ac1SMauro Carvalho Chehab{ 16924071ac1SMauro Carvalho Chehab my @pkgs = @{$_[0]}; 17024071ac1SMauro Carvalho Chehab my $is_optional = $_[1]; 17124071ac1SMauro Carvalho Chehab 17224071ac1SMauro Carvalho Chehab foreach my $prog(@pkgs) { 17324071ac1SMauro Carvalho Chehab my $err = system("rpm -q '$prog' 2>/dev/null >/dev/null"); 17424071ac1SMauro Carvalho Chehab add_package($prog, $is_optional) if ($err); 17524071ac1SMauro Carvalho Chehab } 17624071ac1SMauro Carvalho Chehab} 17724071ac1SMauro Carvalho Chehab 17824071ac1SMauro Carvalho Chehabsub check_pacman_missing($$) 17924071ac1SMauro Carvalho Chehab{ 18024071ac1SMauro Carvalho Chehab my @pkgs = @{$_[0]}; 18124071ac1SMauro Carvalho Chehab my $is_optional = $_[1]; 18224071ac1SMauro Carvalho Chehab 18324071ac1SMauro Carvalho Chehab foreach my $prog(@pkgs) { 18424071ac1SMauro Carvalho Chehab my $err = system("pacman -Q '$prog' 2>/dev/null >/dev/null"); 18524071ac1SMauro Carvalho Chehab add_package($prog, $is_optional) if ($err); 18624071ac1SMauro Carvalho Chehab } 18724071ac1SMauro Carvalho Chehab} 18824071ac1SMauro Carvalho Chehab 18924071ac1SMauro Carvalho Chehabsub check_missing_tex($) 19024071ac1SMauro Carvalho Chehab{ 19124071ac1SMauro Carvalho Chehab my $is_optional = shift; 19224071ac1SMauro Carvalho Chehab my $kpsewhich = findprog("kpsewhich"); 19324071ac1SMauro Carvalho Chehab 19424071ac1SMauro Carvalho Chehab foreach my $prog(keys %texlive) { 19524071ac1SMauro Carvalho Chehab my $package = $texlive{$prog}; 19624071ac1SMauro Carvalho Chehab if (!$kpsewhich) { 19724071ac1SMauro Carvalho Chehab add_package($package, $is_optional); 19824071ac1SMauro Carvalho Chehab next; 19924071ac1SMauro Carvalho Chehab } 20024071ac1SMauro Carvalho Chehab my $file = qx($kpsewhich $prog); 20124071ac1SMauro Carvalho Chehab add_package($package, $is_optional) if ($file =~ /^\s*$/); 20224071ac1SMauro Carvalho Chehab } 20324071ac1SMauro Carvalho Chehab} 20424071ac1SMauro Carvalho Chehab 20524071ac1SMauro Carvalho Chehabsub check_sphinx() 20624071ac1SMauro Carvalho Chehab{ 20724071ac1SMauro Carvalho Chehab return if findprog("sphinx-build"); 20824071ac1SMauro Carvalho Chehab 20924071ac1SMauro Carvalho Chehab if (findprog("sphinx-build-3")) { 21024071ac1SMauro Carvalho Chehab $need_symlink = 1; 21124071ac1SMauro Carvalho Chehab return; 21224071ac1SMauro Carvalho Chehab } 21324071ac1SMauro Carvalho Chehab 21424071ac1SMauro Carvalho Chehab if ($virtualenv) { 21524071ac1SMauro Carvalho Chehab check_program("virtualenv", 0) if (!findprog("virtualenv-3")); 21624071ac1SMauro Carvalho Chehab check_program("pip", 0) if (!findprog("pip3")); 21724071ac1SMauro Carvalho Chehab $need_sphinx = 1; 21824071ac1SMauro Carvalho Chehab } else { 21924071ac1SMauro Carvalho Chehab add_package("python-sphinx", 0); 22024071ac1SMauro Carvalho Chehab } 22124071ac1SMauro Carvalho Chehab} 22224071ac1SMauro Carvalho Chehab 22324071ac1SMauro Carvalho Chehab# 22424071ac1SMauro Carvalho Chehab# Ancillary subroutines 22524071ac1SMauro Carvalho Chehab# 22624071ac1SMauro Carvalho Chehab 22724071ac1SMauro Carvalho Chehabsub catcheck($) 22824071ac1SMauro Carvalho Chehab{ 22924071ac1SMauro Carvalho Chehab my $res = ""; 23024071ac1SMauro Carvalho Chehab $res = qx(cat $_[0]) if (-r $_[0]); 23124071ac1SMauro Carvalho Chehab return $res; 23224071ac1SMauro Carvalho Chehab} 23324071ac1SMauro Carvalho Chehab 23424071ac1SMauro Carvalho Chehabsub which($) 23524071ac1SMauro Carvalho Chehab{ 23624071ac1SMauro Carvalho Chehab my $file = shift; 23724071ac1SMauro Carvalho Chehab my @path = split ":", $ENV{PATH}; 23824071ac1SMauro Carvalho Chehab 23924071ac1SMauro Carvalho Chehab foreach my $dir(@path) { 24024071ac1SMauro Carvalho Chehab my $name = $dir.'/'.$file; 24124071ac1SMauro Carvalho Chehab return $name if (-x $name ); 24224071ac1SMauro Carvalho Chehab } 24324071ac1SMauro Carvalho Chehab return undef; 24424071ac1SMauro Carvalho Chehab} 24524071ac1SMauro Carvalho Chehab 24624071ac1SMauro Carvalho Chehab# 24724071ac1SMauro Carvalho Chehab# Subroutines that check distro-specific hints 24824071ac1SMauro Carvalho Chehab# 24924071ac1SMauro Carvalho Chehab 25024071ac1SMauro Carvalho Chehabsub give_debian_hints() 25124071ac1SMauro Carvalho Chehab{ 25224071ac1SMauro Carvalho Chehab my %map = ( 25324071ac1SMauro Carvalho Chehab "python-sphinx" => "python3-sphinx", 25424071ac1SMauro Carvalho Chehab "sphinx_rtd_theme" => "python3-sphinx-rtd-theme", 25524071ac1SMauro Carvalho Chehab "virtualenv" => "virtualenv", 25624071ac1SMauro Carvalho Chehab "pip" => "python3-pip", 25724071ac1SMauro Carvalho Chehab "dot" => "graphviz", 25824071ac1SMauro Carvalho Chehab "convert" => "imagemagick", 25924071ac1SMauro Carvalho Chehab "Pod::Usage" => "perl-modules", 26024071ac1SMauro Carvalho Chehab "xelatex" => "texlive-xetex", 261*8e7d5d15SMauro Carvalho Chehab "rsvg-convert" => "librsvg2-bin", 26224071ac1SMauro Carvalho Chehab ); 26324071ac1SMauro Carvalho Chehab 26424071ac1SMauro Carvalho Chehab if ($pdf) { 26524071ac1SMauro Carvalho Chehab check_missing_file("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 26624071ac1SMauro Carvalho Chehab "fonts-dejavu", 1); 26724071ac1SMauro Carvalho Chehab } 26824071ac1SMauro Carvalho Chehab 26924071ac1SMauro Carvalho Chehab check_program("dvipng", 1) if ($pdf); 27024071ac1SMauro Carvalho Chehab check_missing(\%map); 27124071ac1SMauro Carvalho Chehab 27224071ac1SMauro Carvalho Chehab return if (!$need && !$optional); 27324071ac1SMauro Carvalho Chehab printf("You should run:\n\n\tsudo apt-get install $install\n"); 27424071ac1SMauro Carvalho Chehab} 27524071ac1SMauro Carvalho Chehab 27624071ac1SMauro Carvalho Chehabsub give_redhat_hints() 27724071ac1SMauro Carvalho Chehab{ 27824071ac1SMauro Carvalho Chehab my %map = ( 27924071ac1SMauro Carvalho Chehab "python-sphinx" => "python3-sphinx", 28024071ac1SMauro Carvalho Chehab "sphinx_rtd_theme" => "python3-sphinx_rtd_theme", 28124071ac1SMauro Carvalho Chehab "virtualenv" => "python3-virtualenv", 28224071ac1SMauro Carvalho Chehab "pip" => "python3-pip", 28324071ac1SMauro Carvalho Chehab "dot" => "graphviz", 28424071ac1SMauro Carvalho Chehab "convert" => "ImageMagick", 28524071ac1SMauro Carvalho Chehab "Pod::Usage" => "perl-Pod-Usage", 28624071ac1SMauro Carvalho Chehab "xelatex" => "texlive-xetex-bin", 287*8e7d5d15SMauro Carvalho Chehab "rsvg-convert" => "librsvg2-tools", 28824071ac1SMauro Carvalho Chehab ); 28924071ac1SMauro Carvalho Chehab 2905d88953cSMauro Carvalho Chehab my @fedora26_opt_pkgs = ( 2915d88953cSMauro Carvalho Chehab "graphviz-gd", # Fedora 26: needed for PDF support 2925d88953cSMauro Carvalho Chehab ); 2935d88953cSMauro Carvalho Chehab 29424071ac1SMauro Carvalho Chehab my @fedora_tex_pkgs = ( 29524071ac1SMauro Carvalho Chehab "texlive-collection-fontsrecommended", 29624071ac1SMauro Carvalho Chehab "texlive-collection-latex", 29724071ac1SMauro Carvalho Chehab "dejavu-sans-fonts", 29824071ac1SMauro Carvalho Chehab "dejavu-serif-fonts", 29924071ac1SMauro Carvalho Chehab "dejavu-sans-mono-fonts", 30024071ac1SMauro Carvalho Chehab ); 30124071ac1SMauro Carvalho Chehab 3025d88953cSMauro Carvalho Chehab my $release; 3035d88953cSMauro Carvalho Chehab 3045d88953cSMauro Carvalho Chehab $release = $1 if ($system_release =~ /Fedora\s+release\s+(\d+)/); 3055d88953cSMauro Carvalho Chehab 3065d88953cSMauro Carvalho Chehab check_rpm_missing(\@fedora26_opt_pkgs, 1) if ($pdf && $release >= 26); 30724071ac1SMauro Carvalho Chehab check_rpm_missing(\@fedora_tex_pkgs, 1) if ($pdf); 30824071ac1SMauro Carvalho Chehab check_missing_tex(1) if ($pdf); 30924071ac1SMauro Carvalho Chehab check_missing(\%map); 31024071ac1SMauro Carvalho Chehab 31124071ac1SMauro Carvalho Chehab return if (!$need && !$optional); 31224071ac1SMauro Carvalho Chehab printf("You should run:\n\n\tsudo dnf install -y $install\n"); 31324071ac1SMauro Carvalho Chehab} 31424071ac1SMauro Carvalho Chehab 31524071ac1SMauro Carvalho Chehabsub give_opensuse_hints() 31624071ac1SMauro Carvalho Chehab{ 31724071ac1SMauro Carvalho Chehab my %map = ( 31824071ac1SMauro Carvalho Chehab "python-sphinx" => "python3-sphinx", 31924071ac1SMauro Carvalho Chehab "sphinx_rtd_theme" => "python3-sphinx_rtd_theme", 32024071ac1SMauro Carvalho Chehab "virtualenv" => "python3-virtualenv", 32124071ac1SMauro Carvalho Chehab "pip" => "python3-pip", 32224071ac1SMauro Carvalho Chehab "dot" => "graphviz", 32324071ac1SMauro Carvalho Chehab "convert" => "ImageMagick", 32424071ac1SMauro Carvalho Chehab "Pod::Usage" => "perl-Pod-Usage", 32524071ac1SMauro Carvalho Chehab "xelatex" => "texlive-xetex-bin", 326*8e7d5d15SMauro Carvalho Chehab "rsvg-convert" => "rsvg-view", 32724071ac1SMauro Carvalho Chehab ); 32824071ac1SMauro Carvalho Chehab 32924071ac1SMauro Carvalho Chehab my @suse_tex_pkgs = ( 33024071ac1SMauro Carvalho Chehab "texlive-babel-english", 33124071ac1SMauro Carvalho Chehab "texlive-caption", 33224071ac1SMauro Carvalho Chehab "texlive-colortbl", 33324071ac1SMauro Carvalho Chehab "texlive-courier", 33424071ac1SMauro Carvalho Chehab "texlive-dvips", 33524071ac1SMauro Carvalho Chehab "texlive-helvetic", 33624071ac1SMauro Carvalho Chehab "texlive-makeindex", 33724071ac1SMauro Carvalho Chehab "texlive-metafont", 33824071ac1SMauro Carvalho Chehab "texlive-metapost", 33924071ac1SMauro Carvalho Chehab "texlive-palatino", 34024071ac1SMauro Carvalho Chehab "texlive-preview", 34124071ac1SMauro Carvalho Chehab "texlive-times", 34224071ac1SMauro Carvalho Chehab "texlive-zapfchan", 34324071ac1SMauro Carvalho Chehab "texlive-zapfding", 34424071ac1SMauro Carvalho Chehab ); 34524071ac1SMauro Carvalho Chehab 34624071ac1SMauro Carvalho Chehab check_rpm_missing(\@suse_tex_pkgs, 1) if ($pdf); 34724071ac1SMauro Carvalho Chehab check_missing_tex(1) if ($pdf); 34824071ac1SMauro Carvalho Chehab check_missing(\%map); 34924071ac1SMauro Carvalho Chehab 35024071ac1SMauro Carvalho Chehab return if (!$need && !$optional); 35124071ac1SMauro Carvalho Chehab printf("You should run:\n\n\tsudo zypper install --no-recommends $install\n"); 35224071ac1SMauro Carvalho Chehab} 35324071ac1SMauro Carvalho Chehab 35424071ac1SMauro Carvalho Chehabsub give_arch_linux_hints() 35524071ac1SMauro Carvalho Chehab{ 35624071ac1SMauro Carvalho Chehab my %map = ( 35724071ac1SMauro Carvalho Chehab "sphinx_rtd_theme" => "python-sphinx_rtd_theme", 35824071ac1SMauro Carvalho Chehab "virtualenv" => "python-virtualenv", 35924071ac1SMauro Carvalho Chehab "pip" => "python-pip", 36024071ac1SMauro Carvalho Chehab "dot" => "graphviz", 36124071ac1SMauro Carvalho Chehab "convert" => "imagemagick", 36224071ac1SMauro Carvalho Chehab "xelatex" => "texlive-bin", 363*8e7d5d15SMauro Carvalho Chehab "rsvg-convert" => "extra/librsvg", 36424071ac1SMauro Carvalho Chehab ); 36524071ac1SMauro Carvalho Chehab 36624071ac1SMauro Carvalho Chehab my @archlinux_tex_pkgs = ( 36724071ac1SMauro Carvalho Chehab "texlive-core", 36824071ac1SMauro Carvalho Chehab "texlive-latexextra", 36924071ac1SMauro Carvalho Chehab "ttf-dejavu", 37024071ac1SMauro Carvalho Chehab ); 37124071ac1SMauro Carvalho Chehab check_pacman_missing(\@archlinux_tex_pkgs, 1) if ($pdf); 37224071ac1SMauro Carvalho Chehab check_missing(\%map); 37324071ac1SMauro Carvalho Chehab 37424071ac1SMauro Carvalho Chehab return if (!$need && !$optional); 37524071ac1SMauro Carvalho Chehab printf("You should run:\n\n\tsudo pacman -S $install\n"); 37624071ac1SMauro Carvalho Chehab} 37724071ac1SMauro Carvalho Chehab 37824071ac1SMauro Carvalho Chehabsub give_gentoo_hints() 37924071ac1SMauro Carvalho Chehab{ 38024071ac1SMauro Carvalho Chehab my %map = ( 38124071ac1SMauro Carvalho Chehab "sphinx_rtd_theme" => "dev-python/sphinx_rtd_theme", 38224071ac1SMauro Carvalho Chehab "virtualenv" => "dev-python/virtualenv", 38324071ac1SMauro Carvalho Chehab "pip" => "dev-python/pip", 38424071ac1SMauro Carvalho Chehab "dot" => "media-gfx/graphviz", 38524071ac1SMauro Carvalho Chehab "convert" => "media-gfx/imagemagick", 38624071ac1SMauro Carvalho Chehab "xelatex" => "dev-texlive/texlive-xetex media-fonts/dejavu", 387*8e7d5d15SMauro Carvalho Chehab "rsvg-convert" => "gnome-base/librsvg", 38824071ac1SMauro Carvalho Chehab ); 38924071ac1SMauro Carvalho Chehab 39024071ac1SMauro Carvalho Chehab check_missing_file("/usr/share/fonts/dejavu/DejaVuSans.ttf", 39124071ac1SMauro Carvalho Chehab "media-fonts/dejavu", 1) if ($pdf); 39224071ac1SMauro Carvalho Chehab 39324071ac1SMauro Carvalho Chehab check_missing(\%map); 39424071ac1SMauro Carvalho Chehab 39524071ac1SMauro Carvalho Chehab return if (!$need && !$optional); 39624071ac1SMauro Carvalho Chehab printf("You should run:\n\n\tsudo emerge --ask $install\n"); 39724071ac1SMauro Carvalho Chehab} 39824071ac1SMauro Carvalho Chehab 39924071ac1SMauro Carvalho Chehabsub check_distros() 40024071ac1SMauro Carvalho Chehab{ 40124071ac1SMauro Carvalho Chehab # Distro-specific hints 40224071ac1SMauro Carvalho Chehab if ($system_release =~ /Red Hat Enterprise Linux/) { 40324071ac1SMauro Carvalho Chehab give_redhat_hints; 40424071ac1SMauro Carvalho Chehab return; 40524071ac1SMauro Carvalho Chehab } 40624071ac1SMauro Carvalho Chehab if ($system_release =~ /Fedora/) { 40724071ac1SMauro Carvalho Chehab give_redhat_hints; 40824071ac1SMauro Carvalho Chehab return; 40924071ac1SMauro Carvalho Chehab } 41024071ac1SMauro Carvalho Chehab if ($system_release =~ /Ubuntu/) { 41124071ac1SMauro Carvalho Chehab give_debian_hints; 41224071ac1SMauro Carvalho Chehab return; 41324071ac1SMauro Carvalho Chehab } 41424071ac1SMauro Carvalho Chehab if ($system_release =~ /Debian/) { 41524071ac1SMauro Carvalho Chehab give_debian_hints; 41624071ac1SMauro Carvalho Chehab return; 41724071ac1SMauro Carvalho Chehab } 41824071ac1SMauro Carvalho Chehab if ($system_release =~ /openSUSE/) { 41924071ac1SMauro Carvalho Chehab give_opensuse_hints; 42024071ac1SMauro Carvalho Chehab return; 42124071ac1SMauro Carvalho Chehab } 42224071ac1SMauro Carvalho Chehab if ($system_release =~ /Arch Linux/) { 42324071ac1SMauro Carvalho Chehab give_arch_linux_hints; 42424071ac1SMauro Carvalho Chehab return; 42524071ac1SMauro Carvalho Chehab } 42624071ac1SMauro Carvalho Chehab if ($system_release =~ /Gentoo/) { 42724071ac1SMauro Carvalho Chehab give_gentoo_hints; 42824071ac1SMauro Carvalho Chehab return; 42924071ac1SMauro Carvalho Chehab } 43024071ac1SMauro Carvalho Chehab 43124071ac1SMauro Carvalho Chehab # 43224071ac1SMauro Carvalho Chehab # Fall-back to generic hint code for other distros 43324071ac1SMauro Carvalho Chehab # That's far from ideal, specially for LaTeX dependencies. 43424071ac1SMauro Carvalho Chehab # 43524071ac1SMauro Carvalho Chehab my %map = ( 43624071ac1SMauro Carvalho Chehab "sphinx-build" => "sphinx" 43724071ac1SMauro Carvalho Chehab ); 43824071ac1SMauro Carvalho Chehab check_missing_tex(1) if ($pdf); 43924071ac1SMauro Carvalho Chehab check_missing(\%map); 44024071ac1SMauro Carvalho Chehab print "I don't know distro $system_release.\n"; 44124071ac1SMauro Carvalho Chehab print "So, I can't provide you a hint with the install procedure.\n"; 44224071ac1SMauro Carvalho Chehab print "There are likely missing dependencies.\n"; 44324071ac1SMauro Carvalho Chehab} 44424071ac1SMauro Carvalho Chehab 44524071ac1SMauro Carvalho Chehab# 44624071ac1SMauro Carvalho Chehab# Common dependencies 44724071ac1SMauro Carvalho Chehab# 44824071ac1SMauro Carvalho Chehab 44924071ac1SMauro Carvalho Chehabsub check_needs() 45024071ac1SMauro Carvalho Chehab{ 45124071ac1SMauro Carvalho Chehab if ($system_release) { 45224071ac1SMauro Carvalho Chehab print "Checking if the needed tools for $system_release are available\n"; 45324071ac1SMauro Carvalho Chehab } else { 45424071ac1SMauro Carvalho Chehab print "Checking if the needed tools are present\n"; 45524071ac1SMauro Carvalho Chehab } 45624071ac1SMauro Carvalho Chehab 45724071ac1SMauro Carvalho Chehab # Check for needed programs/tools 45824071ac1SMauro Carvalho Chehab check_sphinx(); 45924071ac1SMauro Carvalho Chehab check_perl_module("Pod::Usage", 0); 46024071ac1SMauro Carvalho Chehab check_program("make", 0); 46124071ac1SMauro Carvalho Chehab check_program("gcc", 0); 46224071ac1SMauro Carvalho Chehab check_python_module("sphinx_rtd_theme", 1) if (!$virtualenv); 46324071ac1SMauro Carvalho Chehab check_program("xelatex", 1) if ($pdf); 46424071ac1SMauro Carvalho Chehab check_program("dot", 1); 46524071ac1SMauro Carvalho Chehab check_program("convert", 1); 466*8e7d5d15SMauro Carvalho Chehab check_program("rsvg-convert", 1) if ($pdf); 46724071ac1SMauro Carvalho Chehab 46824071ac1SMauro Carvalho Chehab check_distros(); 46924071ac1SMauro Carvalho Chehab 47024071ac1SMauro Carvalho Chehab if ($need_symlink) { 47124071ac1SMauro Carvalho Chehab printf "\tsudo ln -sf %s /usr/bin/sphinx-build\n\n", 47224071ac1SMauro Carvalho Chehab which("sphinx-build-3"); 47324071ac1SMauro Carvalho Chehab } 47424071ac1SMauro Carvalho Chehab if ($need_sphinx) { 4755be33182SMauro Carvalho Chehab my $activate = "$virtenv_dir/bin/activate"; 4765be33182SMauro Carvalho Chehab if (-e "$ENV{'PWD'}/$activate") { 4775be33182SMauro Carvalho Chehab printf "\nNeed to activate virtualenv with:\n"; 4785be33182SMauro Carvalho Chehab printf "\t. $activate\n"; 4795be33182SMauro Carvalho Chehab } else { 48024071ac1SMauro Carvalho Chehab my $virtualenv = findprog("virtualenv-3"); 48124071ac1SMauro Carvalho Chehab $virtualenv = findprog("virtualenv") if (!$virtualenv); 48224071ac1SMauro Carvalho Chehab $virtualenv = "virtualenv" if (!$virtualenv); 48324071ac1SMauro Carvalho Chehab 4845be33182SMauro Carvalho Chehab printf "\t$virtualenv $virtenv_dir\n"; 4855be33182SMauro Carvalho Chehab printf "\t. $activate\n"; 486fb947f3fSMauro Carvalho Chehab printf "\tpip install -r $requirement_file\n"; 48724071ac1SMauro Carvalho Chehab $need++; 48824071ac1SMauro Carvalho Chehab } 4895be33182SMauro Carvalho Chehab } 49024071ac1SMauro Carvalho Chehab printf "\n"; 49124071ac1SMauro Carvalho Chehab 49224071ac1SMauro Carvalho Chehab print "All optional dependenties are met.\n" if (!$optional); 49324071ac1SMauro Carvalho Chehab 49424071ac1SMauro Carvalho Chehab if ($need == 1) { 49524071ac1SMauro Carvalho Chehab die "Can't build as $need mandatory dependency is missing"; 49624071ac1SMauro Carvalho Chehab } elsif ($need) { 49724071ac1SMauro Carvalho Chehab die "Can't build as $need mandatory dependencies are missing"; 49824071ac1SMauro Carvalho Chehab } 49924071ac1SMauro Carvalho Chehab 50024071ac1SMauro Carvalho Chehab print "Needed package dependencies are met.\n"; 50124071ac1SMauro Carvalho Chehab} 50224071ac1SMauro Carvalho Chehab 50324071ac1SMauro Carvalho Chehab# 50424071ac1SMauro Carvalho Chehab# Main 50524071ac1SMauro Carvalho Chehab# 50624071ac1SMauro Carvalho Chehab 50724071ac1SMauro Carvalho Chehabwhile (@ARGV) { 50824071ac1SMauro Carvalho Chehab my $arg = shift(@ARGV); 50924071ac1SMauro Carvalho Chehab 51024071ac1SMauro Carvalho Chehab if ($arg eq "--no-virtualenv") { 51124071ac1SMauro Carvalho Chehab $virtualenv = 0; 51224071ac1SMauro Carvalho Chehab } elsif ($arg eq "--no-pdf"){ 51324071ac1SMauro Carvalho Chehab $pdf = 0; 51424071ac1SMauro Carvalho Chehab } else { 51524071ac1SMauro Carvalho Chehab print "Usage:\n\t$0 <--no-virtualenv> <--no-pdf>\n\n"; 51624071ac1SMauro Carvalho Chehab exit -1; 51724071ac1SMauro Carvalho Chehab } 51824071ac1SMauro Carvalho Chehab} 51924071ac1SMauro Carvalho Chehab 52024071ac1SMauro Carvalho Chehab# 52124071ac1SMauro Carvalho Chehab# Determine the system type. There's no standard unique way that would 52224071ac1SMauro Carvalho Chehab# work with all distros with a minimal package install. So, several 52324071ac1SMauro Carvalho Chehab# methods are used here. 52424071ac1SMauro Carvalho Chehab# 52524071ac1SMauro Carvalho Chehab# By default, it will use lsb_release function. If not available, it will 52624071ac1SMauro Carvalho Chehab# fail back to reading the known different places where the distro name 52724071ac1SMauro Carvalho Chehab# is stored 52824071ac1SMauro Carvalho Chehab# 52924071ac1SMauro Carvalho Chehab 53024071ac1SMauro Carvalho Chehab$system_release = qx(lsb_release -d) if which("lsb_release"); 53124071ac1SMauro Carvalho Chehab$system_release =~ s/Description:\s*// if ($system_release); 53224071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/system-release") if !$system_release; 53324071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/redhat-release") if !$system_release; 53424071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/lsb-release") if !$system_release; 53524071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/gentoo-release") if !$system_release; 53624071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/issue") if !$system_release; 53724071ac1SMauro Carvalho Chehab$system_release =~ s/\s+$//; 53824071ac1SMauro Carvalho Chehab 53924071ac1SMauro Carvalho Chehabcheck_needs; 540