From 7c31c005fced1cad45b19c7e9d5c3f294a80281a Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Tue, 22 Mar 2016 22:14:35 +0000 Subject: Extract directory creation code to its own subroutine. --- make/common.pm | 12 +++++++++++- make/console.pm | 8 ++------ 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'make') diff --git a/make/common.pm b/make/common.pm index f5bbedb3f..ea4c2a50c 100644 --- a/make/common.pm +++ b/make/common.pm @@ -28,12 +28,22 @@ use strict; use warnings FATAL => qw(all); use Exporter qw(import); +use File::Path qw(mkpath); use File::Spec::Functions qw(rel2abs); -our @EXPORT = qw(get_cpu_count +our @EXPORT = qw(create_directory + get_cpu_count get_version module_installed); +sub create_directory($$) { + my ($location, $permissions) = @_; + return eval { + mkpath($location, 0, $permissions); + return 1; + } // 0; +} + sub get_version { state %version; return %version if %version; diff --git a/make/console.pm b/make/console.pm index 4e7b32d49..621de0274 100644 --- a/make/console.pm +++ b/make/console.pm @@ -88,12 +88,8 @@ sub prompt_dir($$$;$) { $answer = rel2abs(prompt_string($interactive, $question, $default)); $create = prompt_bool($interactive && !-d $answer, "$answer does not exist. Create it?", 'y'); if ($create && $create_now) { - my $mkpath = eval { - mkpath($answer, 0, 0750); - return 1; - }; - unless (defined $mkpath) { - print_warning "unable to create $answer!\n"; + unless (create_directory $answer, 0750) { + print_warning "unable to create $answer: $!\n"; $create = 0; } } -- cgit v1.2.3 From fb58d69bf5373d8aa3033d4440d2d5f05ed7e39f Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Tue, 22 Mar 2016 22:15:53 +0000 Subject: Fix a typo in parse_templates. --- make/configure.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'make') diff --git a/make/configure.pm b/make/configure.pm index e314e6d15..06dd4de19 100644 --- a/make/configure.pm +++ b/make/configure.pm @@ -419,7 +419,7 @@ sub parse_templates($$$) { # Write the template file. print_format "Writing <|GREEN $target|> ...\n"; - open(TARGET, '>', $target) or print_error "unable to write $_: $!"; + open(TARGET, '>', $target) or print_error "unable to write $target: $!"; foreach (@final_lines) { say TARGET $_; } -- cgit v1.2.3 From f79a55616b5ff05d4f2e6b031a17be5668d1d3ea Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Tue, 22 Mar 2016 22:40:59 +0000 Subject: Write generated templates to the .configure directory. --- .gitignore | 7 +------ make/configure.pm | 18 ++++++++++++++---- make/template/main.mk | 10 +++++----- 3 files changed, 20 insertions(+), 15 deletions(-) (limited to 'make') diff --git a/.gitignore b/.gitignore index 9400478be..af4d891e0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,17 +5,12 @@ .* !.git* +/.configure /BSDmakefile /GNUmakefile /build /docs/doxygen -/inspircd -/inspircd.1 -/inspircd-genssl.1 -/inspircd.service -/org.inspircd.plist /run -/bin /include/config.h diff --git a/make/configure.pm b/make/configure.pm index 06dd4de19..7614ca884 100644 --- a/make/configure.pm +++ b/make/configure.pm @@ -31,14 +31,16 @@ use feature ':5.10'; use strict; use warnings FATAL => qw(all); -use Cwd qw(getcwd); -use Exporter qw(import); -use File::Basename qw(basename); +use Cwd qw(getcwd); +use Exporter qw(import); +use File::Basename qw(basename dirname); +use File::Spec::Functions qw(catfile); use make::common; use make::console; use make::utilities; +use constant CONFIGURE_DIRECTORY => '.configure'; use constant CONFIGURE_CACHE_FILE => '.configure.cache'; use constant CONFIGURE_CACHE_VERSION => '1'; @@ -87,6 +89,7 @@ sub __get_template_settings($$$) { } # Miscellaneous information + $settings{CONFIGURE_DIRECTORY} = CONFIGURE_DIRECTORY; $settings{CONFIGURE_CACHE_FILE} = CONFIGURE_CACHE_FILE; $settings{SYSTEM_NAME} = lc $^O; chomp($settings{SYSTEM_NAME_VERSION} = `uname -sr 2>/dev/null`); @@ -337,7 +340,7 @@ sub parse_templates($$$) { # Add a default target if the template has not defined one. unless (scalar keys %targets) { - $targets{DEFAULT} = basename $_; + $targets{DEFAULT} = catfile(CONFIGURE_DIRECTORY, basename $_); } # Second pass: parse makefile junk and write files. @@ -417,6 +420,13 @@ sub parse_templates($$$) { push @final_lines, $line; } + # Create the directory if it doesn't already exist. + my $directory = dirname $target; + unless (-e $directory) { + print_format "Creating <|GREEN $directory|> ...\n"; + create_directory $directory, 0750 or print_error "unable to create $directory: $!"; + }; + # Write the template file. print_format "Writing <|GREEN $target|> ...\n"; open(TARGET, '>', $target) or print_error "unable to write $target: $!"; diff --git a/make/template/main.mk b/make/template/main.mk index cc201a126..7b153a924 100644 --- a/make/template/main.mk +++ b/make/template/main.mk @@ -229,16 +229,16 @@ install: target @IFNDEF PURE_STATIC [ $(BUILDPATH)/modules/ -ef $(MODPATH) ] || $(INSTALL) -m $(INSTMODE_LIB) $(BUILDPATH)/modules/*.so $(MODPATH) @ENDIF - -$(INSTALL) -m $(INSTMODE_BIN) inspircd $(BASE) 2>/dev/null + -$(INSTALL) -m $(INSTMODE_BIN) @CONFIGURE_DIRECTORY@/inspircd $(BASE) 2>/dev/null -$(INSTALL) -m $(INSTMODE_LIB) .gdbargs $(BASE)/.gdbargs 2>/dev/null @IFEQ $(SYSTEM) darwin - -$(INSTALL) -m $(INSTMODE_BIN) org.inspircd.plist $(BASE) 2>/dev/null + -$(INSTALL) -m $(INSTMODE_BIN) @CONFIGURE_DIRECTORY@/org.inspircd.plist $(BASE) 2>/dev/null @ENDIF @IFEQ $(SYSTEM) linux - -$(INSTALL) -m $(INSTMODE_LIB) inspircd.service $(BASE) 2>/dev/null + -$(INSTALL) -m $(INSTMODE_LIB) @CONFIGURE_DIRECTORY@/inspircd.service $(BASE) 2>/dev/null @ENDIF - -$(INSTALL) -m $(INSTMODE_LIB) inspircd.1 $(MANPATH) 2>/dev/null - -$(INSTALL) -m $(INSTMODE_LIB) inspircd-genssl.1 $(MANPATH) 2>/dev/null + -$(INSTALL) -m $(INSTMODE_LIB) @CONFIGURE_DIRECTORY@/inspircd.1 $(MANPATH) 2>/dev/null + -$(INSTALL) -m $(INSTMODE_LIB) @CONFIGURE_DIRECTORY@/inspircd-genssl.1 $(MANPATH) 2>/dev/null -$(INSTALL) -m $(INSTMODE_BIN) tools/genssl $(BINPATH)/inspircd-genssl 2>/dev/null -$(INSTALL) -m $(INSTMODE_LIB) docs/conf/*.example $(CONPATH)/examples -$(INSTALL) -m $(INSTMODE_LIB) *.pem $(CONPATH) 2>/dev/null -- cgit v1.2.3 From 37d939829bb51d6e697d5a654d7dcc32522f01aa Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Tue, 22 Mar 2016 23:14:22 +0000 Subject: Move the configure cache to the .configure directory too. --- make/configure.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'make') diff --git a/make/configure.pm b/make/configure.pm index 7614ca884..db9c42eb9 100644 --- a/make/configure.pm +++ b/make/configure.pm @@ -41,7 +41,7 @@ use make::console; use make::utilities; use constant CONFIGURE_DIRECTORY => '.configure'; -use constant CONFIGURE_CACHE_FILE => '.configure.cache'; +use constant CONFIGURE_CACHE_FILE => catfile(CONFIGURE_DIRECTORY, 'cache.cfg'); use constant CONFIGURE_CACHE_VERSION => '1'; our @EXPORT = qw(CONFIGURE_CACHE_FILE @@ -228,6 +228,11 @@ sub read_configure_cache { } sub write_configure_cache(%) { + unless (-e CONFIGURE_DIRECTORY) { + print_format "Creating <|GREEN ${\CONFIGURE_DIRECTORY}|> ...\n"; + create_directory CONFIGURE_DIRECTORY, 0750 or print_error "unable to create ${\CONFIGURE_DIRECTORY}: $!"; + } + print_format "Writing <|GREEN ${\CONFIGURE_CACHE_FILE}|> ...\n"; my %config = @_; open(CACHE, '>', CONFIGURE_CACHE_FILE) or print_error "unable to write ${\CONFIGURE_CACHE_FILE}: $!"; -- cgit v1.2.3 From 79f207e729eed41336779324262603bb03266d96 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Tue, 22 Mar 2016 23:21:24 +0000 Subject: Simplify the configure cache file format. This prevents the need to implement escaping of values which was a bug in the previous format. --- make/configure.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'make') diff --git a/make/configure.pm b/make/configure.pm index db9c42eb9..ee96e3c69 100644 --- a/make/configure.pm +++ b/make/configure.pm @@ -220,7 +220,7 @@ sub read_configure_cache { open(CACHE, CONFIGURE_CACHE_FILE) or return %config; while (my $line = ) { next if $line =~ /^\s*($|\#)/; - my ($key, $value) = ($line =~ /^(\S+)="(.*)"$/); + my ($key, $value) = ($line =~ /^(\S+)(?:\s(.+))?$/); $config{$key} = $value; } close(CACHE); @@ -238,7 +238,7 @@ sub write_configure_cache(%) { open(CACHE, '>', CONFIGURE_CACHE_FILE) or print_error "unable to write ${\CONFIGURE_CACHE_FILE}: $!"; while (my ($key, $value) = each %config) { $value //= ''; - say CACHE "$key=\"$value\""; + say CACHE "$key $value"; } close(CACHE); } -- cgit v1.2.3