From e6d245a3e80c0e0c05476e5bd9c45a77e16fecec Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Mon, 14 Apr 2014 12:42:22 +0100 Subject: Replace the configure templating system with something better. A large amount of this code can be removed when buildtool is done as we will not need to worry about the differences between BSD and GNU Make. --- make/configure.pm | 213 +++++++++++++++++++++++++++++++++++---- make/template/config.h | 38 +++++++ make/template/gdbargs | 4 + make/template/inspircd | 3 +- make/template/main.mk | 30 +++--- make/template/org.inspircd.plist | 1 + make/utilities.pm | 43 ++++++-- 7 files changed, 290 insertions(+), 42 deletions(-) create mode 100644 make/template/config.h create mode 100644 make/template/gdbargs (limited to 'make') diff --git a/make/configure.pm b/make/configure.pm index de95e9161..905233835 100644 --- a/make/configure.pm +++ b/make/configure.pm @@ -1,7 +1,7 @@ # # InspIRCd -- Internet Relay Chat Daemon # -# Copyright (C) 2012 Peter Powell +# Copyright (C) 2012-2014 Peter Powell # Copyright (C) 2008 Robin Burchell # Copyright (C) 2007-2008 Craig Edwards # Copyright (C) 2008 Thomas Stagner @@ -30,8 +30,9 @@ package make::configure; use strict; use warnings FATAL => qw(all); -use Cwd; +use Cwd 'getcwd'; use Exporter 'import'; +use File::Basename 'basename'; use make::utilities; @@ -39,10 +40,7 @@ our @EXPORT = qw(cmd_clean cmd_help cmd_update read_configure_cache write_configure_cache get_compiler_info find_compiler run_test test_file test_header - get_property get_revision - dump_hash); - -my $revision; + dump_hash get_property parse_templates); sub __get_socketengines() { my @socketengines; @@ -53,6 +51,34 @@ sub __get_socketengines() { return @socketengines; } +# TODO: when buildtool is done this can be mostly removed with +# the remainder being merged into parse_templates. +sub __get_template_settings($$) { + + # These are actually hash references + my ($config, $compiler) = @_; + + # Start off by populating with the config + my %settings = %$config; + + # Compiler information + while (my ($key, $value) = each %{$compiler}) { + $settings{'COMPILER_' . $key} = $value; + } + + # Version information + my %version = get_version(); + while (my ($key, $value) = each %version) { + $settings{'VERSION_' . $key} = $value; + } + + # Miscellaneous information + $settings{SYSTEM_NAME} = lc $^O; + chomp($settings{SYSTEM_NAME_VERSION} = `uname -sr 2>/dev/null`); + + return %settings; +} + sub cmd_clean { unlink '.config.cache'; } @@ -129,9 +155,9 @@ sub cmd_update { exit 1; } print "Updating...\n"; - %main::config = read_configure_cache(); - %main::cxx = get_compiler_info($main::config{CXX}); - main::writefiles(); + my %config = read_configure_cache(); + my %compiler = get_compiler_info($config{CXX}); + parse_templates(\%config, \%compiler); print "Update complete!\n"; exit 0; } @@ -241,15 +267,7 @@ sub get_property($$;$) return defined $default ? $default : ''; } -sub get_revision { - return $revision if defined $revision; - chomp(my $tags = `git describe --tags 2>/dev/null`); - $revision = $tags || 'release'; - return $revision; -} - -sub dump_hash() -{ +sub dump_hash() { print "\n\e[1;32mPre-build configuration is complete!\e[0m\n\n"; print "\e[0mBase install path:\e[1;32m\t\t$main::config{BASE_DIR}\e[0m\n"; print "\e[0mConfig path:\e[1;32m\t\t\t$main::config{CONFIG_DIR}\e[0m\n"; @@ -262,4 +280,163 @@ sub dump_hash() print "\e[0mOpenSSL support:\e[1;32m\t\t$main::config{USE_OPENSSL}\e[0m\n"; } +sub parse_templates($$) { + + # These are actually hash references + my ($config, $compiler) = @_; + + # Collect settings to be used when generating files + my %settings = __get_template_settings($config, $compiler); + + # Iterate through files in make/template. + foreach () { + print "Parsing $_...\n"; + open(TEMPLATE, $_); + my (@lines, $mode, @platforms, %targets); + + # First pass: parse template variables and directives. + while (my $line =