From e6d245a3e80c0e0c05476e5bd9c45a77e16fecec Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Mon, 14 Apr 2014 12:42:22 +0100 Subject: [PATCH] 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. --- .gitignore | 1 + configure | 118 +---------------- include/compat.h | 4 +- make/configure.pm | 213 ++++++++++++++++++++++++++++--- make/template/config.h | 38 ++++++ {tools => make/template}/gdbargs | 1 + make/template/inspircd | 3 +- make/template/main.mk | 30 +++-- make/template/org.inspircd.plist | 1 + make/utilities.pm | 45 +++++-- 10 files changed, 296 insertions(+), 158 deletions(-) create mode 100644 make/template/config.h rename {tools => make/template}/gdbargs (81%) diff --git a/.gitignore b/.gitignore index 244c938a5..d473e66cc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.swp /.config.cache +/.gdbargs /.modulemanager /BSDmakefile /GNUmakefile diff --git a/configure b/configure index 857541189..45bb0e911 100755 --- a/configure +++ b/configure @@ -253,8 +253,7 @@ if ($interactive) # Clear the screen. system 'tput', 'clear'; - my $revision = get_revision(); - chomp(my $version = `sh src/version.sh`); + my %version = get_version(); # Display Introduction Message.. print <<"STOP" ; @@ -272,12 +271,12 @@ dir, otherwise you won't have a config file! Your operating system is: \e[1;32m$^O\e[0m STOP print "Your InspIRCd version is: \e[1;32m"; - print $revision eq 'release' ? substr($version, 9) : substr($revision, 1); + print "$version{MAJOR}.$version{MINOR}.$version{PATCH}+$version{LABEL}"; print "\e[0m\n\n"; print "The following compiler has been detected: \e[1;32m$cxx{NAME} $cxx{VERSION}\e[0m ($config{CXX})\n\n"; # Check that the user actually wants this version. - if (index($version, '+') != -1) { + if ($version{LABEL} ne 'release') { print <<"EOW" ; \e[1;31mWARNING!\e[0m You are building a development version. This contains code which has not been tested as heavily and may contain various faults which could seriously @@ -417,7 +416,7 @@ if ($config{USE_GNUTLS} || $config{USE_OPENSSL}) { print "Writing \e[1;32m.config.cache\e[0m ...\n"; write_configure_cache(%config); -writefiles(); +parse_templates(\%config, \%cxx); dump_hash(); print "\n"; @@ -430,115 +429,6 @@ if ($config{USE_GNUTLS} || $config{USE_OPENSSL}) { } print "*** \e[1;32mRemember to edit your configuration files!!!\e[0m ***\n\n"; -sub writefiles { - chomp(my $incos = `uname -n -s -r`); - chomp(my $version = `sh src/version.sh`); - my $revision = get_revision(); - my $branch = "InspIRCd-0.0"; - if ($version =~ /^(InspIRCd-[0-9]+\.[0-9]+)\.[0-9]+/) - { - $branch = $1; - } - print "Writing \e[1;32mconfig.h\e[0m\n"; - open(FILEHANDLE, ">include/config.h.tmp"); - print FILEHANDLE <; - close(FILEHANDLE); - - $config{COMPILER} = lc $cxx{NAME}; - $config{SYSTEM} = lc $^O; - - for my $var (qw( - CXX COMPILER SYSTEM BASE_DIR CONFIG_DIR MODULE_DIR BINARY_DIR DATA_DIR UID SOCKETENGINE - )) { - s/\@$var\@/$config{$var}/g; - } - - s/\@VERSION\@/$version/ if defined $version; - - if ($file eq 'main.mk') { - print "Writing \e[1;32mGNUmakefile\e[0m ...\n"; - - my $mk_tmp = $_; - s/\@IFDEF (\S+)/ifdef $1/g; - s/\@IFNDEF (\S+)/ifndef $1/g; - s/\@IFEQ (\S+) (\S+)/ifeq ($1,$2)/g; - s/\@IFNEQ (\S+) (\S+)/ifneq ($1,$2)/g; - s/\@ELSIFEQ (\S+) (\S+)/else ifeq ($1,$2)/g; - s/\@ELSE/else/g; - s/\@ENDIF/endif/g; - s/ *\@BSD_ONLY .*\n//g; - s/\@GNU_ONLY //g; - s/\@DO_EXPORT (.*)/export $1/g; - open MKF, '>GNUmakefile' or die "Can't write to GNUmakefile: $!"; - print MKF $_; - close MKF; - - print "Writing \e[1;32mBSDmakefile\e[0m ...\n"; - $_ = $mk_tmp; - s/\@IFDEF (\S+)/.if defined($1)/g; - s/\@IFNDEF (\S+)/.if !defined($1)/g; - s/\@IFEQ (\S+) (\S+)/.if $1 == $2/g; - s/\@IFNEQ (\S+) (\S+)/.if $1 != $2/g; - s/\@ELSIFEQ (\S+) (\S+)/.elif $1 == $2/g; - s/\@ELSE/.else/g; - s/\@ENDIF/.endif/g; - s/\@BSD_ONLY //g; - s/ *\@GNU_ONLY .*\n//g; - $mk_tmp = $_; - $mk_tmp =~ s#\@DO_EXPORT (.*)#"MAKEENV += ".join ' ', map "$_='\${$_}'", split /\s/, $1#eg; - open MKF, '>BSDmakefile' or die "Can't write to BSDmakefile: $!"; - print MKF $mk_tmp; - close MKF; - } else { - print "Writing \e[1;32m$file\e[0m ...\n"; - open(FILEHANDLE, ">$file") or die("Can't write to $file: $!\n"); - print FILEHANDLE $_; - close(FILEHANDLE); - } - } - - chmod 0750, 'inspircd'; -} - # Routine to list out the extra/ modules that have been enabled. # Note: when getting any filenames out and comparing, it's important to lc it if the # file system is not case-sensitive (== Epoc, MacOS, OS/2 (incl DOS/DJGPP), VMS, Win32 diff --git a/include/compat.h b/include/compat.h index fa75cd754..9302c573f 100644 --- a/include/compat.h +++ b/include/compat.h @@ -106,9 +106,11 @@ */ #if defined _WIN32 # include "inspircd_win32wrapper.h" +# include "threadengines/threadengine_win32.h" #else -# include # define ENTRYPOINT int main(int argc, char** argv) # define DllExport __attribute__ ((visibility ("default"))) # define CoreExport __attribute__ ((visibility ("default"))) +# include +# include "threadengines/threadengine_pthread.h" #endif 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 =