-sub writefiles {
- my($writeheader) = @_;
- # First File.. inspircd_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;32minspircd_config.h\e[0m\n";
- open(FILEHANDLE, ">include/inspircd_config.h.tmp");
- print FILEHANDLE <<EOF;
-/* Auto generated by configure, do not modify! */
-#ifndef __CONFIGURATION_AUTO__
-#define __CONFIGURATION_AUTO__
-
-/* this is for windows support. */
-#define CoreExport /**/
-#define DllExport /**/
-
-#define CONFIG_PATH "$config{CONFIG_DIR}"
-#define DATA_PATH "$config{DATA_DIR}"
-#define LOG_PATH "$config{LOG_DIR}"
-#define MOD_PATH "$config{MODULE_DIR}"
-#define SOMAXCONN_S "$config{_SOMAXCONN}"
-#define ENTRYPOINT int main(int argc, char** argv)
-
-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_STRLCPY} eq "true") {
- print FILEHANDLE "#define HAS_STRLCPY\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{OSNAME} !~ /DARWIN/i) {
- 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\n#endif\n";
- close(FILEHANDLE);
-
- open(FILEHANDLE, ">include/inspircd_version.h.tmp");
- print FILEHANDLE <<EOF;
-#define BRANCH "$branch"
-#define VERSION "$version"
-#define REVISION "$revision2"
-#define SYSTEM "$incos"
-EOF
- close FILEHANDLE;
-
- for my $file (qw(include/inspircd_config.h include/inspircd_version.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 LOG_DIR
- )) {
- 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;
- }
-}