diff options
author | Peter Powell <petpow@saberuk.com> | 2013-08-15 05:57:46 +0100 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2013-08-18 11:41:43 +0100 |
commit | 3070548ceeffd3c09ce26d816a1d225dbe9d137e (patch) | |
tree | 03139f43d6723876a8c9480a91207de62ed90028 /make/utilities.pm | |
parent | e950f568d0f571e9475aa38177486468714de4d3 (diff) |
Clean up and move various subroutines.
- Fix indentation of get_compiler_info and clean up slightly.
- Move module_installed to make::utilities.
- Remove promptnumeric (unused).
- Rename clean to cmd_clean and rewrite.
- Rename dir_check to prompt_bool and rewrite.
- Rename dumphash to dump_hash.
- Rename getcache to read_configure_cache and rewrite.
- Rename getrevision to get_revision.
- Rename makecache to write_configure_cache and rewrite.
- Rename promptstring_s to prompt_string and rewrite.
- Rename showhelp to cmd_help and rewrite.
- Rename update to cmd_update and rewrite.
- Rename yesno to prompt_bool and rewrite.
- Replace getmodules with a <src/modules/m_*.cpp> glob.
Diffstat (limited to 'make/utilities.pm')
-rw-r--r-- | make/utilities.pm | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/make/utilities.pm b/make/utilities.pm index 9bafe372e..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) = @_; |