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", 26124071ac1SMauro Carvalho Chehab ); 26224071ac1SMauro Carvalho Chehab 26324071ac1SMauro Carvalho Chehab if ($pdf) { 26424071ac1SMauro Carvalho Chehab check_missing_file("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 26524071ac1SMauro Carvalho Chehab "fonts-dejavu", 1); 26624071ac1SMauro Carvalho Chehab } 26724071ac1SMauro Carvalho Chehab 26824071ac1SMauro Carvalho Chehab check_program("dvipng", 1) if ($pdf); 26924071ac1SMauro Carvalho Chehab check_missing(\%map); 27024071ac1SMauro Carvalho Chehab 27124071ac1SMauro Carvalho Chehab return if (!$need && !$optional); 27224071ac1SMauro Carvalho Chehab printf("You should run:\n\n\tsudo apt-get install $install\n"); 27324071ac1SMauro Carvalho Chehab} 27424071ac1SMauro Carvalho Chehab 27524071ac1SMauro Carvalho Chehabsub give_redhat_hints() 27624071ac1SMauro Carvalho Chehab{ 27724071ac1SMauro Carvalho Chehab my %map = ( 27824071ac1SMauro Carvalho Chehab "python-sphinx" => "python3-sphinx", 27924071ac1SMauro Carvalho Chehab "sphinx_rtd_theme" => "python3-sphinx_rtd_theme", 28024071ac1SMauro Carvalho Chehab "virtualenv" => "python3-virtualenv", 28124071ac1SMauro Carvalho Chehab "pip" => "python3-pip", 28224071ac1SMauro Carvalho Chehab "dot" => "graphviz", 28324071ac1SMauro Carvalho Chehab "convert" => "ImageMagick", 28424071ac1SMauro Carvalho Chehab "Pod::Usage" => "perl-Pod-Usage", 28524071ac1SMauro Carvalho Chehab "xelatex" => "texlive-xetex-bin", 28624071ac1SMauro Carvalho Chehab ); 28724071ac1SMauro Carvalho Chehab 288*5d88953cSMauro Carvalho Chehab my @fedora26_opt_pkgs = ( 289*5d88953cSMauro Carvalho Chehab "graphviz-gd", # Fedora 26: needed for PDF support 290*5d88953cSMauro Carvalho Chehab ); 291*5d88953cSMauro Carvalho Chehab 29224071ac1SMauro Carvalho Chehab my @fedora_tex_pkgs = ( 29324071ac1SMauro Carvalho Chehab "texlive-collection-fontsrecommended", 29424071ac1SMauro Carvalho Chehab "texlive-collection-latex", 29524071ac1SMauro Carvalho Chehab "dejavu-sans-fonts", 29624071ac1SMauro Carvalho Chehab "dejavu-serif-fonts", 29724071ac1SMauro Carvalho Chehab "dejavu-sans-mono-fonts", 29824071ac1SMauro Carvalho Chehab ); 29924071ac1SMauro Carvalho Chehab 300*5d88953cSMauro Carvalho Chehab my $release; 301*5d88953cSMauro Carvalho Chehab 302*5d88953cSMauro Carvalho Chehab $release = $1 if ($system_release =~ /Fedora\s+release\s+(\d+)/); 303*5d88953cSMauro Carvalho Chehab 304*5d88953cSMauro Carvalho Chehab check_rpm_missing(\@fedora26_opt_pkgs, 1) if ($pdf && $release >= 26); 30524071ac1SMauro Carvalho Chehab check_rpm_missing(\@fedora_tex_pkgs, 1) if ($pdf); 30624071ac1SMauro Carvalho Chehab check_missing_tex(1) if ($pdf); 30724071ac1SMauro Carvalho Chehab check_missing(\%map); 30824071ac1SMauro Carvalho Chehab 30924071ac1SMauro Carvalho Chehab return if (!$need && !$optional); 31024071ac1SMauro Carvalho Chehab printf("You should run:\n\n\tsudo dnf install -y $install\n"); 31124071ac1SMauro Carvalho Chehab} 31224071ac1SMauro Carvalho Chehab 31324071ac1SMauro Carvalho Chehabsub give_opensuse_hints() 31424071ac1SMauro Carvalho Chehab{ 31524071ac1SMauro Carvalho Chehab my %map = ( 31624071ac1SMauro Carvalho Chehab "python-sphinx" => "python3-sphinx", 31724071ac1SMauro Carvalho Chehab "sphinx_rtd_theme" => "python3-sphinx_rtd_theme", 31824071ac1SMauro Carvalho Chehab "virtualenv" => "python3-virtualenv", 31924071ac1SMauro Carvalho Chehab "pip" => "python3-pip", 32024071ac1SMauro Carvalho Chehab "dot" => "graphviz", 32124071ac1SMauro Carvalho Chehab "convert" => "ImageMagick", 32224071ac1SMauro Carvalho Chehab "Pod::Usage" => "perl-Pod-Usage", 32324071ac1SMauro Carvalho Chehab "xelatex" => "texlive-xetex-bin", 32424071ac1SMauro Carvalho Chehab ); 32524071ac1SMauro Carvalho Chehab 32624071ac1SMauro Carvalho Chehab my @suse_tex_pkgs = ( 32724071ac1SMauro Carvalho Chehab "texlive-babel-english", 32824071ac1SMauro Carvalho Chehab "texlive-caption", 32924071ac1SMauro Carvalho Chehab "texlive-colortbl", 33024071ac1SMauro Carvalho Chehab "texlive-courier", 33124071ac1SMauro Carvalho Chehab "texlive-dvips", 33224071ac1SMauro Carvalho Chehab "texlive-helvetic", 33324071ac1SMauro Carvalho Chehab "texlive-makeindex", 33424071ac1SMauro Carvalho Chehab "texlive-metafont", 33524071ac1SMauro Carvalho Chehab "texlive-metapost", 33624071ac1SMauro Carvalho Chehab "texlive-palatino", 33724071ac1SMauro Carvalho Chehab "texlive-preview", 33824071ac1SMauro Carvalho Chehab "texlive-times", 33924071ac1SMauro Carvalho Chehab "texlive-zapfchan", 34024071ac1SMauro Carvalho Chehab "texlive-zapfding", 34124071ac1SMauro Carvalho Chehab ); 34224071ac1SMauro Carvalho Chehab 34324071ac1SMauro Carvalho Chehab check_rpm_missing(\@suse_tex_pkgs, 1) if ($pdf); 34424071ac1SMauro Carvalho Chehab check_missing_tex(1) if ($pdf); 34524071ac1SMauro Carvalho Chehab check_missing(\%map); 34624071ac1SMauro Carvalho Chehab 34724071ac1SMauro Carvalho Chehab return if (!$need && !$optional); 34824071ac1SMauro Carvalho Chehab printf("You should run:\n\n\tsudo zypper install --no-recommends $install\n"); 34924071ac1SMauro Carvalho Chehab} 35024071ac1SMauro Carvalho Chehab 35124071ac1SMauro Carvalho Chehabsub give_arch_linux_hints() 35224071ac1SMauro Carvalho Chehab{ 35324071ac1SMauro Carvalho Chehab my %map = ( 35424071ac1SMauro Carvalho Chehab "sphinx_rtd_theme" => "python-sphinx_rtd_theme", 35524071ac1SMauro Carvalho Chehab "virtualenv" => "python-virtualenv", 35624071ac1SMauro Carvalho Chehab "pip" => "python-pip", 35724071ac1SMauro Carvalho Chehab "dot" => "graphviz", 35824071ac1SMauro Carvalho Chehab "convert" => "imagemagick", 35924071ac1SMauro Carvalho Chehab "xelatex" => "texlive-bin", 36024071ac1SMauro Carvalho Chehab ); 36124071ac1SMauro Carvalho Chehab 36224071ac1SMauro Carvalho Chehab my @archlinux_tex_pkgs = ( 36324071ac1SMauro Carvalho Chehab "texlive-core", 36424071ac1SMauro Carvalho Chehab "texlive-latexextra", 36524071ac1SMauro Carvalho Chehab "ttf-dejavu", 36624071ac1SMauro Carvalho Chehab ); 36724071ac1SMauro Carvalho Chehab check_pacman_missing(\@archlinux_tex_pkgs, 1) if ($pdf); 36824071ac1SMauro Carvalho Chehab check_missing(\%map); 36924071ac1SMauro Carvalho Chehab 37024071ac1SMauro Carvalho Chehab return if (!$need && !$optional); 37124071ac1SMauro Carvalho Chehab printf("You should run:\n\n\tsudo pacman -S $install\n"); 37224071ac1SMauro Carvalho Chehab} 37324071ac1SMauro Carvalho Chehab 37424071ac1SMauro Carvalho Chehabsub give_gentoo_hints() 37524071ac1SMauro Carvalho Chehab{ 37624071ac1SMauro Carvalho Chehab my %map = ( 37724071ac1SMauro Carvalho Chehab "sphinx_rtd_theme" => "dev-python/sphinx_rtd_theme", 37824071ac1SMauro Carvalho Chehab "virtualenv" => "dev-python/virtualenv", 37924071ac1SMauro Carvalho Chehab "pip" => "dev-python/pip", 38024071ac1SMauro Carvalho Chehab "dot" => "media-gfx/graphviz", 38124071ac1SMauro Carvalho Chehab "convert" => "media-gfx/imagemagick", 38224071ac1SMauro Carvalho Chehab "xelatex" => "dev-texlive/texlive-xetex media-fonts/dejavu", 38324071ac1SMauro Carvalho Chehab ); 38424071ac1SMauro Carvalho Chehab 38524071ac1SMauro Carvalho Chehab check_missing_file("/usr/share/fonts/dejavu/DejaVuSans.ttf", 38624071ac1SMauro Carvalho Chehab "media-fonts/dejavu", 1) if ($pdf); 38724071ac1SMauro Carvalho Chehab 38824071ac1SMauro Carvalho Chehab check_missing(\%map); 38924071ac1SMauro Carvalho Chehab 39024071ac1SMauro Carvalho Chehab return if (!$need && !$optional); 39124071ac1SMauro Carvalho Chehab printf("You should run:\n\n\tsudo emerge --ask $install\n"); 39224071ac1SMauro Carvalho Chehab} 39324071ac1SMauro Carvalho Chehab 39424071ac1SMauro Carvalho Chehabsub check_distros() 39524071ac1SMauro Carvalho Chehab{ 39624071ac1SMauro Carvalho Chehab # Distro-specific hints 39724071ac1SMauro Carvalho Chehab if ($system_release =~ /Red Hat Enterprise Linux/) { 39824071ac1SMauro Carvalho Chehab give_redhat_hints; 39924071ac1SMauro Carvalho Chehab return; 40024071ac1SMauro Carvalho Chehab } 40124071ac1SMauro Carvalho Chehab if ($system_release =~ /Fedora/) { 40224071ac1SMauro Carvalho Chehab give_redhat_hints; 40324071ac1SMauro Carvalho Chehab return; 40424071ac1SMauro Carvalho Chehab } 40524071ac1SMauro Carvalho Chehab if ($system_release =~ /Ubuntu/) { 40624071ac1SMauro Carvalho Chehab give_debian_hints; 40724071ac1SMauro Carvalho Chehab return; 40824071ac1SMauro Carvalho Chehab } 40924071ac1SMauro Carvalho Chehab if ($system_release =~ /Debian/) { 41024071ac1SMauro Carvalho Chehab give_debian_hints; 41124071ac1SMauro Carvalho Chehab return; 41224071ac1SMauro Carvalho Chehab } 41324071ac1SMauro Carvalho Chehab if ($system_release =~ /openSUSE/) { 41424071ac1SMauro Carvalho Chehab give_opensuse_hints; 41524071ac1SMauro Carvalho Chehab return; 41624071ac1SMauro Carvalho Chehab } 41724071ac1SMauro Carvalho Chehab if ($system_release =~ /Arch Linux/) { 41824071ac1SMauro Carvalho Chehab give_arch_linux_hints; 41924071ac1SMauro Carvalho Chehab return; 42024071ac1SMauro Carvalho Chehab } 42124071ac1SMauro Carvalho Chehab if ($system_release =~ /Gentoo/) { 42224071ac1SMauro Carvalho Chehab give_gentoo_hints; 42324071ac1SMauro Carvalho Chehab return; 42424071ac1SMauro Carvalho Chehab } 42524071ac1SMauro Carvalho Chehab 42624071ac1SMauro Carvalho Chehab # 42724071ac1SMauro Carvalho Chehab # Fall-back to generic hint code for other distros 42824071ac1SMauro Carvalho Chehab # That's far from ideal, specially for LaTeX dependencies. 42924071ac1SMauro Carvalho Chehab # 43024071ac1SMauro Carvalho Chehab my %map = ( 43124071ac1SMauro Carvalho Chehab "sphinx-build" => "sphinx" 43224071ac1SMauro Carvalho Chehab ); 43324071ac1SMauro Carvalho Chehab check_missing_tex(1) if ($pdf); 43424071ac1SMauro Carvalho Chehab check_missing(\%map); 43524071ac1SMauro Carvalho Chehab print "I don't know distro $system_release.\n"; 43624071ac1SMauro Carvalho Chehab print "So, I can't provide you a hint with the install procedure.\n"; 43724071ac1SMauro Carvalho Chehab print "There are likely missing dependencies.\n"; 43824071ac1SMauro Carvalho Chehab} 43924071ac1SMauro Carvalho Chehab 44024071ac1SMauro Carvalho Chehab# 44124071ac1SMauro Carvalho Chehab# Common dependencies 44224071ac1SMauro Carvalho Chehab# 44324071ac1SMauro Carvalho Chehab 44424071ac1SMauro Carvalho Chehabsub check_needs() 44524071ac1SMauro Carvalho Chehab{ 44624071ac1SMauro Carvalho Chehab if ($system_release) { 44724071ac1SMauro Carvalho Chehab print "Checking if the needed tools for $system_release are available\n"; 44824071ac1SMauro Carvalho Chehab } else { 44924071ac1SMauro Carvalho Chehab print "Checking if the needed tools are present\n"; 45024071ac1SMauro Carvalho Chehab } 45124071ac1SMauro Carvalho Chehab 45224071ac1SMauro Carvalho Chehab # Check for needed programs/tools 45324071ac1SMauro Carvalho Chehab check_sphinx(); 45424071ac1SMauro Carvalho Chehab check_perl_module("Pod::Usage", 0); 45524071ac1SMauro Carvalho Chehab check_program("make", 0); 45624071ac1SMauro Carvalho Chehab check_program("gcc", 0); 45724071ac1SMauro Carvalho Chehab check_python_module("sphinx_rtd_theme", 1) if (!$virtualenv); 45824071ac1SMauro Carvalho Chehab check_program("xelatex", 1) if ($pdf); 45924071ac1SMauro Carvalho Chehab check_program("dot", 1); 46024071ac1SMauro Carvalho Chehab check_program("convert", 1); 46124071ac1SMauro Carvalho Chehab 46224071ac1SMauro Carvalho Chehab check_distros(); 46324071ac1SMauro Carvalho Chehab 46424071ac1SMauro Carvalho Chehab if ($need_symlink) { 46524071ac1SMauro Carvalho Chehab printf "\tsudo ln -sf %s /usr/bin/sphinx-build\n\n", 46624071ac1SMauro Carvalho Chehab which("sphinx-build-3"); 46724071ac1SMauro Carvalho Chehab } 46824071ac1SMauro Carvalho Chehab if ($need_sphinx) { 4695be33182SMauro Carvalho Chehab my $activate = "$virtenv_dir/bin/activate"; 4705be33182SMauro Carvalho Chehab if (-e "$ENV{'PWD'}/$activate") { 4715be33182SMauro Carvalho Chehab printf "\nNeed to activate virtualenv with:\n"; 4725be33182SMauro Carvalho Chehab printf "\t. $activate\n"; 4735be33182SMauro Carvalho Chehab } else { 47424071ac1SMauro Carvalho Chehab my $virtualenv = findprog("virtualenv-3"); 47524071ac1SMauro Carvalho Chehab $virtualenv = findprog("virtualenv") if (!$virtualenv); 47624071ac1SMauro Carvalho Chehab $virtualenv = "virtualenv" if (!$virtualenv); 47724071ac1SMauro Carvalho Chehab 4785be33182SMauro Carvalho Chehab printf "\t$virtualenv $virtenv_dir\n"; 4795be33182SMauro Carvalho Chehab printf "\t. $activate\n"; 480fb947f3fSMauro Carvalho Chehab printf "\tpip install -r $requirement_file\n"; 48124071ac1SMauro Carvalho Chehab $need++; 48224071ac1SMauro Carvalho Chehab } 4835be33182SMauro Carvalho Chehab } 48424071ac1SMauro Carvalho Chehab printf "\n"; 48524071ac1SMauro Carvalho Chehab 48624071ac1SMauro Carvalho Chehab print "All optional dependenties are met.\n" if (!$optional); 48724071ac1SMauro Carvalho Chehab 48824071ac1SMauro Carvalho Chehab if ($need == 1) { 48924071ac1SMauro Carvalho Chehab die "Can't build as $need mandatory dependency is missing"; 49024071ac1SMauro Carvalho Chehab } elsif ($need) { 49124071ac1SMauro Carvalho Chehab die "Can't build as $need mandatory dependencies are missing"; 49224071ac1SMauro Carvalho Chehab } 49324071ac1SMauro Carvalho Chehab 49424071ac1SMauro Carvalho Chehab print "Needed package dependencies are met.\n"; 49524071ac1SMauro Carvalho Chehab} 49624071ac1SMauro Carvalho Chehab 49724071ac1SMauro Carvalho Chehab# 49824071ac1SMauro Carvalho Chehab# Main 49924071ac1SMauro Carvalho Chehab# 50024071ac1SMauro Carvalho Chehab 50124071ac1SMauro Carvalho Chehabwhile (@ARGV) { 50224071ac1SMauro Carvalho Chehab my $arg = shift(@ARGV); 50324071ac1SMauro Carvalho Chehab 50424071ac1SMauro Carvalho Chehab if ($arg eq "--no-virtualenv") { 50524071ac1SMauro Carvalho Chehab $virtualenv = 0; 50624071ac1SMauro Carvalho Chehab } elsif ($arg eq "--no-pdf"){ 50724071ac1SMauro Carvalho Chehab $pdf = 0; 50824071ac1SMauro Carvalho Chehab } else { 50924071ac1SMauro Carvalho Chehab print "Usage:\n\t$0 <--no-virtualenv> <--no-pdf>\n\n"; 51024071ac1SMauro Carvalho Chehab exit -1; 51124071ac1SMauro Carvalho Chehab } 51224071ac1SMauro Carvalho Chehab} 51324071ac1SMauro Carvalho Chehab 51424071ac1SMauro Carvalho Chehab# 51524071ac1SMauro Carvalho Chehab# Determine the system type. There's no standard unique way that would 51624071ac1SMauro Carvalho Chehab# work with all distros with a minimal package install. So, several 51724071ac1SMauro Carvalho Chehab# methods are used here. 51824071ac1SMauro Carvalho Chehab# 51924071ac1SMauro Carvalho Chehab# By default, it will use lsb_release function. If not available, it will 52024071ac1SMauro Carvalho Chehab# fail back to reading the known different places where the distro name 52124071ac1SMauro Carvalho Chehab# is stored 52224071ac1SMauro Carvalho Chehab# 52324071ac1SMauro Carvalho Chehab 52424071ac1SMauro Carvalho Chehab$system_release = qx(lsb_release -d) if which("lsb_release"); 52524071ac1SMauro Carvalho Chehab$system_release =~ s/Description:\s*// if ($system_release); 52624071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/system-release") if !$system_release; 52724071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/redhat-release") if !$system_release; 52824071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/lsb-release") if !$system_release; 52924071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/gentoo-release") if !$system_release; 53024071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/issue") if !$system_release; 53124071ac1SMauro Carvalho Chehab$system_release =~ s/\s+$//; 53224071ac1SMauro Carvalho Chehab 53324071ac1SMauro Carvalho Chehabcheck_needs; 534