summaryrefslogtreecommitdiff
path: root/make/utilities.pm
diff options
context:
space:
mode:
Diffstat (limited to 'make/utilities.pm')
-rw-r--r--make/utilities.pm83
1 files changed, 50 insertions, 33 deletions
diff --git a/make/utilities.pm b/make/utilities.pm
index 9281246fb..87aa46d6e 100644
--- a/make/utilities.pm
+++ b/make/utilities.pm
@@ -20,18 +20,22 @@
#
-package make::utilities;
+BEGIN {
+ require 5.8.0;
+}
-require 5.8.0;
+package make::utilities;
use strict;
use warnings FATAL => qw(all);
use Exporter 'import';
-use POSIX;
-use Getopt::Long;
use Fcntl;
-our @EXPORT = qw(make_rpath pkgconfig_get_include_dirs pkgconfig_get_lib_dirs pkgconfig_check_version translate_functions promptstring);
+use File::Path;
+use File::Spec::Functions qw(rel2abs);
+use Getopt::Long;
+
+our @EXPORT = qw(module_installed prompt_bool prompt_dir prompt_string make_rpath pkgconfig_get_include_dirs pkgconfig_get_lib_dirs pkgconfig_check_version translate_functions promptstring);
# Parse the output of a *_config program,
# such as pcre_config, take out the -L
@@ -42,6 +46,47 @@ our @EXPORT = qw(make_rpath pkgconfig_get_include_dirs pkgconfig_get_lib_dirs pk
my %already_added = ();
my $if_skip_lines = 0;
+sub module_installed($)
+{
+ my $module = shift;
+ eval("use $module;");
+ return !$@;
+}
+
+sub prompt_bool($$$) {
+ my ($interactive, $question, $default) = @_;
+ my $answer = prompt_string($interactive, $question, $default ? 'y' : 'n');
+ return $answer =~ /y/i;
+}
+
+sub prompt_dir($$$) {
+ my ($interactive, $question, $default) = @_;
+ my ($answer, $create) = (undef, 'y');
+ do {
+ $answer = rel2abs(prompt_string($interactive, $question, $default));
+ $create = prompt_bool($interactive && !-d $answer, "$answer does not exist. Create it?", 'y');
+ my $mkpath = eval {
+ mkpath($answer, 0, 0750);
+ return 1;
+ };
+ unless (defined $mkpath) {
+ print "Error: unable to create $answer!\n\n";
+ $create = 0;
+ }
+ } while (!$create);
+ return $answer;
+}
+
+sub prompt_string($$$) {
+ my ($interactive, $question, $default) = @_;
+ return $default unless $interactive;
+ print $question, "\n";
+ print "[\e[1;32m$default\e[0m] => ";
+ chomp(my $answer = <STDIN>);
+ print "\n";
+ return $answer ? $answer : $default;
+}
+
sub promptstring($$$$$)
{
my ($prompt, $configitem, $default, $package, $commandlineswitch) = @_;
@@ -108,15 +153,6 @@ sub pkgconfig_get_include_dirs($$$;$)
{
my ($packagename, $headername, $defaults, $module) = @_;
- my $key = "default_includedir_$packagename";
- if (exists $main::config{$key})
- {
- print "Locating include directory for package \e[1;32m$packagename\e[0m for module \e[1;32m$module\e[0m... ";
- my $ret = $main::config{$key};
- print "\e[1;32m$ret\e[0m (cached)\n";
- return $ret;
- }
-
extend_pkg_path();
print "Locating include directory for package \e[1;32m$packagename\e[0m for module \e[1;32m$module\e[0m... ";
@@ -223,15 +259,6 @@ sub pkgconfig_get_lib_dirs($$$;$)
{
my ($packagename, $libname, $defaults, $module) = @_;
- my $key = "default_libdir_$packagename";
- if (exists $main::config{$key})
- {
- print "Locating library directory for package \e[1;32m$packagename\e[0m for module \e[1;32m$module\e[0m... ";
- my $ret = $main::config{$key};
- print "\e[1;32m$ret\e[0m (cached)\n";
- return $ret;
- }
-
extend_pkg_path();
print "Locating library directory for package \e[1;32m$packagename\e[0m for module \e[1;32m$module\e[0m... ";
@@ -305,16 +332,6 @@ sub translate_functions($$)
$module =~ /modules*\/(.+?)$/;
$module = $1;
- # This is only a cursory check, just designed to catch casual accidental use of backticks.
- # There are pleanty of ways around it, but its not supposed to be for security, just checking
- # that people are using the new configuration api as theyre supposed to and not just using
- # backticks instead of eval(), being as eval has accountability. People wanting to get around
- # the accountability will do so anyway.
- if (($line =~ /`/) && ($line !~ /eval\(.+?`.+?\)/))
- {
- die "Developers should no longer use backticks in configuration macros. Please use exec() and eval() macros instead. Offending line: $line (In module: $module)";
- }
-
if ($line =~ /ifuname\(\!"(\w+)"\)/)
{
my $uname = $1;