-print "*** \e[1;32mRemember to edit your configuration files!!!\e[0m ***\n\n\n";
-if (($config{OSNAME} eq "OpenBSD") && ($config{CC} ne "eg++")) {
- print "\e[1;32mWARNING!\e[0m You are running OpenBSD but you are using the base gcc package\nrather than eg++. This compile will most likely fail, but i'm letting you\ngo ahead with it anyway, just in case i'm wrong :-)\n";
-}
-
-if ($config{GCCVER} < "3") {
- print <<FOO2;
-\e[1;32mWARNING!\e[0m You are attempting to compile InspIRCd on GCC 2.x!
-GCC 2.x series compilers only had partial (read as broken) C++ support, and
-your compile will most likely fail horribly! If you have any problems, do NOT
-report them to the bugtracker or forums without first upgrading your compiler
-to a newer 3.x or 4.x (or whatever is available currently) version.
-FOO2
-}
-
-################################################################################
-# HELPER FUNCTIONS #
-################################################################################
-sub getcache {
- # Retrieves the .config.cache file, and loads values into the main config hash.
- open(CACHE, ".config.cache") or return 0;
- while (<CACHE>) {
- chomp;
- # Ignore Blank lines, and comments..
- next if /^\s*$/;
- next if /^\s*#/;
- my ($key, $value) = split("=", $_, 2);
- $value =~ /^\"(.*)\"$/;
- # Do something with data here!
- $config{$key} = $1;
- }
- close(CACHE);
- return 1;
-}
-
-sub makecache {
- # Dump the contents of %config
- print "Writing \e[1;32mcache file\e[0m for future ./configures ...\n";
- open(FILEHANDLE, ">.config.cache");
- foreach my $key (keys %config) {
- print FILEHANDLE "$key=\"$config{$key}\"\n";
- }
- close(FILEHANDLE);
-}
-
-sub dir_check {
- my ($desc, $hash_key) = @_;
- my $complete = 0;
- while (!$complete) {
- print "In what directory $desc?\n";
- print "[\e[1;32m$config{$hash_key}\e[0m] -> ";
- chomp(my $var = <STDIN>);
- if ($var eq "") {
- $var = $config{$hash_key};
- }
- if ($var =~ /^\~\/(.+)$/) {
- # Convert it to a full path..
- $var = resolve_directory($ENV{HOME} . "/" . $1);
- }
- elsif ((($config{OSNAME} =~ /MINGW32/i) and ($var !~ /^[A-Z]{1}:\\.*/)) and (substr($var,0,1) ne "/"))
- {
- # Assume relative Path was given.. fill in the rest.
- $var = $this . "/$var";
- }
-
- $var = resolve_directory($var);
- if (! -e $var) {
- print "$var does not exist. Create it?\n[\e[1;32my\e[0m] ";
- chomp(my $tmp = <STDIN>);
- if (($tmp eq "") || ($tmp =~ /^y/i)) {
- # Attempt to Create the Dir..
- my $chk = eval {
- use File::Path ();
- File::Path::mkpath($var, 0, 0777);
- 1;
- };
- unless (defined($chk) && -d $var) {
- print "Unable to create directory. ($var)\n\n";
- # Restart Loop..
- next;
- }
- } else {
- # They said they don't want to create, and we can't install there.
- print "\n\n";
- next;
- }
- } else {
- if (!is_dir($var)) {
- # Target exists, but is not a directory.
- print "File $var exists, but is not a directory.\n\n";
- next;
- }
- }
- # Either Dir Exists, or was created fine.
- $config{$hash_key} = $var;
- $complete = 1;
- print "\n";
- }
-}
-
-our $SHARED = "";
-
-my ($mliflags, $mfrules, $mobjs, $mfcount) = ("", "", "", 0);
-
-sub writefiles {
- my($writeheader) = @_;
- # First File.. config.h
- chomp(my $incos = `uname -n -s -r`);
- chomp(my $version = `sh src/version.sh`);
- chomp(my $revision2 = getrevision());
- my $branch = "InspIRCd-0.0";
- if ($version =~ /^(InspIRCd-[0-9]+\.[0-9]+)\.[0-9]+/)
- {
- $branch = $1;
- }
- if ($writeheader == 1)
- {
- print "Writing \e[1;32mconfig.h\e[0m\n";
- open(FILEHANDLE, ">include/config.h.tmp");
- print FILEHANDLE <<EOF;
-/* Auto generated by configure, do not modify! */
-#pragma once
-
-#define BRANCH "$branch"
-#define VERSION "$version"
-#define REVISION "$revision2"
-#define SYSTEM "$incos"
-
-#define CONFIG_PATH "$config{CONFIG_DIR}"
-#define DATA_PATH "$config{DATA_DIR}"
-#define LOG_PATH "$config{LOG_DIR}"
-#define MOD_PATH "$config{MODULE_DIR}"
-
-EOF
-print FILEHANDLE "#define MAXBUF " . ($config{MAXBUF}+2) . "\n";
-
- if ($config{OSNAME} =~ /SunOS/i) {
- print FILEHANDLE "#define IS_SOLARIS\n";
- }
- if ($config{OSNAME} =~ /MINGW32/i) {
- print FILEHANDLE "#define IS_MINGW\n";
- }
- if ($config{GCCVER} >= 3) {
- print FILEHANDLE "#define GCC3\n";
- }
- if ($config{HAS_STDINT} eq "true") {
- print FILEHANDLE "#define HAS_STDINT\n";
- }
- if ($config{HAS_EVENTFD} eq 'true') {
- print FILEHANDLE "#define HAS_EVENTFD\n";
- }
- if ($config{HAS_CLOCK_GETTIME} eq 'true') {
- print FILEHANDLE "#define HAS_CLOCK_GETTIME\n";
- }
- my $use_hiperf = 0;
- if (($has_kqueue) && ($config{USE_KQUEUE} eq "y")) {
- print FILEHANDLE "#define USE_KQUEUE\n";
- $config{SOCKETENGINE} = "socketengine_kqueue";
- $use_hiperf = 1;
- }
- if (($has_epoll) && ($config{USE_EPOLL} eq "y")) {
- print FILEHANDLE "#define USE_EPOLL\n";
- $config{SOCKETENGINE} = "socketengine_epoll";
- $use_hiperf = 1;
- }
- if (($has_ports) && ($config{USE_PORTS} eq "y")) {
- print FILEHANDLE "#define USE_PORTS\n";
- $config{SOCKETENGINE} = "socketengine_ports";
- $use_hiperf = 1;
- }
- # user didn't choose either epoll or select for their OS.
- # default them to USE_SELECT (ewwy puke puke)
- if (!$use_hiperf) {
- print "no hi-perf, " . $config{USE_POLL};
- if ($config{USE_POLL} eq "y")
- {
- print FILEHANDLE "#define USE_POLL\n";
- $config{SOCKETENGINE} = "socketengine_poll";
- }
- else
- {
- print FILEHANDLE "#define USE_SELECT\n";
- $config{SOCKETENGINE} = "socketengine_select";
- }
- }
- print FILEHANDLE "\n#include \"threadengines/threadengine_pthread.h\"\n";
- close(FILEHANDLE);
-
- my $file = 'include/config.h';
- my $diff = 0;
- open my $fh1, $file or $diff = 1;
- open my $fh2, $file.'.tmp' or die "Can't read $file.tmp that we just wrote: $!";
- while (!$diff) {
- my $line1 = <$fh1>;
- my $line2 = <$fh2>;
- if (defined($line1) != defined($line2)) {
- $diff = 1;
- } elsif (!defined $line1) {
- last;
- } else {
- $diff = ($line1 ne $line2);
- }
- }
- if ($diff) {
- unlink $file;
- rename "$file.tmp", $file;
- } else {
- unlink "$file.tmp";
- }
- }
-
- # Write all .in files.
- my $tmp = "";
- my $file = "";
- my $exe = "inspircd";
-
- # Do this once here, and cache it in the .*.inc files,
- # rather than attempting to read src/version.sh from
- # compiled code -- we might not have the source to hand.
- # Fix for bug#177 by Brain.
-
- chomp($version = `sh ./src/version.sh`);
- chomp(my $revision = getrevision());
- $version = "$version(r$revision)";
-
- # We can actually parse any file starting with . and ending with .inc,
- # but right now we only parse .inspircd.inc to form './inspircd'
- prepare_dynamic_makefile();
-
- my @dotfiles = qw(main.mk inspircd);
- push @dotfiles, 'org.inspircd.plist' if $config{OSNAME} eq 'darwin';
-
- foreach my $file (@dotfiles) {
- open(FILEHANDLE, "make/template/$file") or die "Can't open make/template/$file: $!";
- $_ = join '', <FILEHANDLE>;
- close(FILEHANDLE);
-
- $config{BUILD_DIR} ||= resolve_directory($config{ME}."/build");
-
- for my $var (qw(
- CC SYSTEM BASE_DIR CONFIG_DIR MODULE_DIR BINARY_DIR BUILD_DIR DATA_DIR UID
- STARTSCRIPT DESTINATION SOCKETENGINE
- )) {
- s/\@$var\@/$config{$var}/g;
- }
- s/\@EXECUTABLE\@/$exe/ if defined $exe;
- 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/\@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/\@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 0755, 'inspircd';
-}
-
-sub depcheck
-{
- getmodules();
- for my $mod (@modlist) {
- getcompilerflags("src/modules/m_$mod.cpp");
- getlinkerflags("src/modules/m_$mod.cpp");
- }
-}
-
-sub prepare_dynamic_makefile
-{
- my $i = 0;
-
- if (!$has_epoll)
- {
- $config{USE_EPOLL} = 0;
- }
- if (!$has_kqueue)
- {
- $config{USE_KQUEUE} = 0;
- }
- if (!$has_ports)
- {
- $config{USE_PORTS} = 0;
- }
-}