-chomp($topdir = getcwd());
-$this = resolve_directory($topdir); # PWD, Regardless.
-@modlist = (); # Declare for Module List..
-%config = (); # Initiate Configuration Hash..
-$config{ME} = resolve_directory($topdir); # Present Working Directory
-$config{BASE_DIR} = $config{ME}; # Use CWD as 'Base' Directory.
-$config{CONFIG_DIR} = resolve_directory($config{ME}."/conf"); # Configuration Directory
-$config{MODULE_DIR} = resolve_directory($config{ME}."/modules"); # Modules Directory
-$config{BINARY_DIR} = resolve_directory($config{ME}."/bin"); # Binary Directory
-$config{LIBRARY_DIR} = resolve_directory($config{ME}."/lib"); # Library Directory
-chomp($config{HAS_GNUTLS} = `libgnutls-config --version 2>/dev/null | cut -c 1,2,3`); # GNUTLS Version.
-chomp($config{HAS_OPENSSL} = `openssl version 2>/dev/null`); # Openssl version
-$config{USE_GNUTLS} = "n"; # Use gnutls.
-$config{USE_OPENSSL} = "n"; # Use openssl.
-$config{OPTIMITEMP} = "0"; # Default Optimisation Value
-$config{OPTIMISATI} = "-g"; # Optimisation Flag
-$config{NICK_LENGT} = "31"; # Default Nick Length
-$config{CHAN_LENGT} = "64"; # Default Channel Name Length
-$config{MAX_CHANNE} = "20"; # Default Max. Channels per user
-$config{MAX_OPERCH} = "60"; # Default Max. Channels per oper
-$config{MAXI_MODES} = "20"; # Default Max. Number of Modes set at once.
-$config{HAS_STRLCPY} = "false"; # strlcpy Check.
-$config{HAS_STDINT} = "false"; # stdint.h check
-$config{HAS_EXECINFO} = "0"; # execinfo.h Check.
-$config{USE_KQUEUE} = "y"; # kqueue enabled
-$config{USE_EPOLL} = "y"; # epoll enabled
-$config{THREADED_DNS} = "n"; # threaded dns
-$config{IPV6} = "n"; # IPv6 support (experimental)
-$config{SUPPORT_IP6LINKS} = "y"; # IPv4 supporting IPv6 links (experimental)
-$config{STATIC_LINK} = "no"; # are doing static modules?
-chomp($config{MAX_CLIENT_T} = `sh -c \"ulimit -n\"`); # FD Limit
-chomp($config{MAX_DESCRIPTORS} = `sh -c \"ulimit -n\"`); # Hard FD Limit
-chomp($config{GCCVER} = `g++ -dumpversion | cut -c 1`); # Major GCC Version
-chomp($config{OSNAME} = `/bin/uname`); # Operating System Name
-$config{CC} = "g++"; # C++ compiler
-$config{MAKEORDER} = "ircd mods"; # build order
-$config{STATICLIBS} = ""; # library archive path
-$config{MAX_IDENT} = "12"; # max ident size
-$config{MAX_QUIT} = "255"; # max quit message size
-$config{MAX_TOPIC} = "307"; # max topic size
-$config{MAX_KICK} = "255"; # max kick message size
-$config{MAX_GECOS} = "128"; # max GECOS size
-$config{MAX_AWAY} = "200"; # max AWAY size
-
-$no_svn = 0;
-
-$config{HAS_OPENSSL} =~ /OpenSSL (\S+) \d+ \S+ \d{4}/;
-$config{HAS_OPENSSL} = $1;
-
-if ($config{GCCVER} eq "") {
- print "g++ was not found! You require g++ (the GNU C++ compiler, part of GCC) to build InspIRCd!\n";
- exit;
+# Utility functions for our buildsystem
+use make::utilities;
+use make::configure;
+use make::gnutlscert;
+use make::opensslcert;
+
+###############################################################################################
+#
+# EDITABLE VARIABLES
+#
+###############################################################################################
+
+# If you wish to ignore a dependency throughout the entire core, add it here.
+
+our @ignoredeps = (
+ "inspircd_win32wrapper.h", # windows has its own configure program
+);
+
+# If you wish for all files in the entire core to have a given dependency, insert it here.
+# You should keep this to an absolute minimum to avoid rebuilds that are not neccessary.
+
+our @immutabledeps = (
+ "inspircd_config.h", # auto re-generated by configure
+ "inspircd.h",
+);
+
+###############################################################################################
+#
+# NON-EDITABLE VARIABLES
+#
+###############################################################################################
+
+# List of commands that make up 'make install' and 'make deinstall'
+
+our $install_list = "";
+our $uninstall_list = "";
+
+# This is a list of all files in the core. Each cpp file is mapped to a shared object file,
+# whos file extension is omitted (these can vary from system to system). Auto detected by
+# scanning the src/*.cpp files for files containing /* $Core: */ identifiers.
+
+our %filelist = ();
+
+# If you wish for a file to have special dependencies in the makefile, add an entry here.
+# Auto populated by /* $ExtraDeps: */ instruction
+
+our %specialdeps = ();
+
+# If you wish for a file to have extra make lines (in between the compile and link steps)
+# then insert them here.
+# Auto populated by /* $ExtraBuild: */ instruction
+
+our %extrabuildlines = ();
+
+# If you wish for a file to be linked against extra objects or arctives, insert them here.
+# Auto populated by /* $ExtraObjects: */ instruction
+
+our %extraobjects = ();
+
+# If you wish to compile extra cpp sources into an object, define them here.
+# NOTE: Certain cpp files such as the socket engines have a value auto calculated
+# for this table so that their derived class is built.
+# Auto populated by /* $ExtraSources: */ instruction
+
+our %extrasources = ();
+
+our ($opt_use_gnutls, $opt_rebuild, $opt_use_openssl, $opt_nointeractive, $opt_ports,
+ $opt_epoll, $opt_kqueue, $opt_noports, $opt_noepoll, $opt_nokqueue, $opt_disablerpath,
+ $opt_ipv6, $opt_ipv6links, $opt_noipv6links, $opt_maxbuf, $opt_disable_debug,
+ $opt_freebsd_port);
+
+our ($opt_cc, $opt_base_dir, $opt_config_dir, $opt_module_dir, $opt_binary_dir,
+ $opt_library_dir);
+
+sub list_extras ();
+
+sub enable_extras (@);
+
+sub disable_extras (@);
+
+my @opt_enableextras;
+my @opt_disableextras;
+
+GetOptions (
+ 'enable-gnutls' => \$opt_use_gnutls,
+ 'rebuild' => \$opt_rebuild,
+ 'enable-openssl' => \$opt_use_openssl,
+ 'disable-interactive' => \$opt_nointeractive,
+ 'enable-ports' => \$opt_ports,
+ 'enable-epoll' => \$opt_epoll,
+ 'enable-kqueue' => \$opt_kqueue,
+ 'disable-ports' => \$opt_noports,
+ 'disable-epoll' => \$opt_noepoll,
+ 'disable-kqueue' => \$opt_nokqueue,
+ 'disable-rpath' => \$opt_disablerpath,
+ 'enable-ipv6' => \$opt_ipv6,
+ 'enable-remote-ipv6' => \$opt_ipv6links,
+ 'disable-remote-ipv6' => \$opt_noipv6links,
+ 'with-cc=s' => \$opt_cc,
+ 'with-maxbuf=i' => \$opt_maxbuf,
+ 'enable-freebsd-ports-openssl' => \$opt_freebsd_port,
+ 'prefix=s' => \$opt_base_dir,
+ 'config-dir=s' => \$opt_config_dir,
+ 'module-dir=s' => \$opt_module_dir,
+ 'binary-dir=s' => \$opt_binary_dir,
+ 'library-dir=s' => \$opt_library_dir,
+ 'disable-debuginfo' => sub { $opt_disable_debug = 1 },
+ 'help' => sub { showhelp(); },
+ 'modupdate' => sub { modupdate(); },
+ 'update' => sub { update(); },
+ 'svnupdate' => sub { svnupdate(); },
+ 'clean' => sub { clean(); },
+ 'list-extras' => sub { list_extras; exit 0; }, # This, --enable-extras, and --disable-extras are for non-interactive managing.
+ 'enable-extras=s@' => \@opt_enableextras, # ^
+ 'disable-extras=s@' => \@opt_disableextras, # ^
+);
+
+if (scalar(@opt_enableextras) + scalar(@opt_disableextras) > 0) {
+ @opt_enableextras = split /,/, join(',', @opt_enableextras);
+ @opt_disableextras = split /,/, join(',', @opt_disableextras);
+ enable_extras(@opt_enableextras);
+ disable_extras(@opt_disableextras);
+ list_extras;
+ print "Remember: YOU are responsible for making sure any libraries needed have been installed!\n";
+ print "Run $0 -modupdate after you've done this to update the makefiles.\n";
+ exit 0;
+}
+
+our $non_interactive = (
+ (defined $opt_library_dir) ||
+ (defined $opt_base_dir) ||
+ (defined $opt_config_dir) ||
+ (defined $opt_module_dir) ||
+ (defined $opt_base_dir) ||
+ (defined $opt_binary_dir) ||
+ (defined $opt_nointeractive) ||
+ (defined $opt_cc) ||
+ (defined $opt_ipv6) ||
+ (defined $opt_ipv6links) ||
+ (defined $opt_noipv6links) ||
+ (defined $opt_kqueue) ||
+ (defined $opt_epoll) ||
+ (defined $opt_ports) ||
+ (defined $opt_use_openssl) ||
+ (defined $opt_nokqueue) ||
+ (defined $opt_noepoll) ||
+ (defined $opt_noports) ||
+ (defined $opt_maxbuf) ||
+ (defined $opt_use_gnutls) ||
+ (defined $opt_freebsd_port)
+);
+our $interactive = !$non_interactive;
+
+chomp(our $topdir = getcwd());
+our $this = resolve_directory($topdir); # PWD, Regardless.
+our @modlist = (); # Declare for Module List..
+our %config = (); # Initiate Configuration Hash..
+$config{ME} = resolve_directory($topdir); # Present Working Directory
+
+$config{BASE_DIR} = $config{ME};
+
+if (defined $opt_base_dir)
+{
+ $config{BASE_DIR} = $opt_base_dir;