- $tmp =~ s/\@CC\@/$config{CC}/ if defined $config{CC};
- $tmp =~ s/\@MAKEPROG\@/$config{MAKEPROG}/ if defined $config{MAKEPROG};
- $tmp =~ s/\@FLAGS\@/$config{FLAGS}/ if defined $config{FLAGS};
- $tmp =~ s/\@DEVELOPER\@/$config{DEVELOPER}/ if defined $config{DEVELOPER};
- $tmp =~ s/\@LDLIBS\@/$config{LDLIBS}/ if defined $config{LDLIBS};
- $tmp =~ s/\@BASE_DIR\@/$config{BASE_DIR}/ if defined $config{BASE_DIR};
- $tmp =~ s/\@CONFIG_DIR\@/$config{CONFIG_DIR}/ if defined $config{CONFIG_DIR};
- $tmp =~ s/\@MODULE_DIR\@/$config{MODULE_DIR}/ if defined $config{MODULE_DIR};
- $tmp =~ s/\@BINARY_DIR\@/$config{BINARY_DIR}/ if defined $config{BINARY_DIR};
- $tmp =~ s/\@LIBRARY_DIR\@/$config{LIBRARY_DIR}/ if defined $config{LIBRARY_DIR};
- $tmp =~ s/\@MODULES\@/$modules/ if defined $modules;
- $tmp =~ s/\@STARTSCRIPT\@/$config{STARTSCRIPT}/ if defined $config{STARTSCRIPT};
- $tmp =~ s/\@DESTINATION\@/$config{DESTINATION}/ if defined $config{DESTINATION};
- $tmp =~ s/\@EXTRA_DIR\@/$config{EXTRA_DIR}/ if defined $config{EXTRA_DIR};
- $tmp =~ s/\@EXECUTABLE\@/$exe/ if defined $exe;
- $tmp =~ s/\@MAKEORDER\@/$config{MAKEORDER}/ if defined $config{MAKEORDER};
- $tmp =~ s/\@VERSION\@/$version/ if defined $version;
- $tmp =~ s/\@INSTALL_LIST\@/$install_list/ if defined $install_list;
- $tmp =~ s/\@UNINSTALL_LIST\@/$uninstall_list/ if defined $uninstall_list;
-
- open(FILEHANDLE, ">$file");
- print FILEHANDLE $tmp;
- }
- }
- closedir(DIRHANDLE);
-
- # Make inspircd executable!
- chmod 0744, 'inspircd';
-}
-
-sub write_dynamic_modules_makefile {
- # Modules Makefile..
- print "Writing \e[1;32msrc/modules/Makefile\e[0m\n";
- open(FILEHANDLE, ">src/modules/Makefile");
-
-###
-# Module Makefile Header
-###
- print FILEHANDLE <<EOF;
-###################################################
-# Copyright 2002-2007 The InspIRCd Development Team
-# http://www.inspircd.org/wiki/index.php/Credits
-#
-# Thanks to Andrew Church <achurch\@achurch.org>
-# for assisting with making this work right.
-#
-# Automatically Generated by ./configure to add a
-# modules please run ./configure -modupdate
-###################################################
-
-all: \$(MODULES)
-
-EOF
-
-if ($config{OSNAME} =~ /darwin/) {
- print FILEHANDLE <<EOCHEESE;
-
-PICLDFLAGS = -twolevel_namespace -undefined dynamic_lookup -bundle
-
-EOCHEESE
-} else {
- print FILEHANDLE <<EOCHEESE;
-
-PICLDFLAGS = -fPIC -DPIC -shared
-
-EOCHEESE
-}
-
- ###
- # End Module Makefile Header
- ###
-
- # Create a Modules List..
- my $modules = "";
- my $cmflags = "";
- my $liflags = "";
- foreach my $i (@modlist) {
- ###
- # Write Entry to the MakeFile
- ###
- $cmflags = getcompilerflags("src/modules/m_".$i.".cpp");
- $liflags = getlinkerflags("src/modules/m_".$i.".cpp");
- my $deps = getdependencies("src/modules/m_".$i.".cpp");
-
- #print "file: $i: cmflags=$cmflags; liflags=$liflags; deps=$deps\n";
-
-
- if (nopedantic("src/modules/m_".$i.".cpp"))
- {
- print FILEHANDLE "
-m_$i.so: m_$i.cpp ../../include/modules.h ../../include/users.h ../../include/channels.h ../../include/base.h ../../include/inspircd_config.h ../../include/inspircd.h ../../include/configreader.h $deps
- \@../../make/run-cc.pl \$(CC) -pipe -I../../include \$(NICEFLAGS) $cmflags \$(PICLDFLAGS) $liflags -export-dynamic -o m_$i.so m_$i.cpp
-"
- }
- else
- {
- print FILEHANDLE "
-m_$i.so: m_$i.cpp ../../include/modules.h ../../include/users.h ../../include/channels.h ../../include/base.h ../../include/inspircd_config.h ../../include/inspircd.h ../../include/configreader.h $deps
- \@../../make/run-cc.pl \$(CC) -pipe -I../../include \$(FLAGS) $cmflags \$(PICLDFLAGS) $liflags -export-dynamic -o m_$i.so m_$i.cpp
-";
- }
- $install_list = $install_list . " install -m \$(INSTMODE) src/modules/m_$i.so \$(MODPATH)\n";
- $uninstall_list = $uninstall_list . " -rm \$(MODULES)/m_$i.so\n";
-###
- # End Write Entry to the MakeFile
- ###
- }
-
- opendir(DIRHANDLE, "src/modules");
- foreach my $name (sort readdir(DIRHANDLE)) {
- if ($name =~ /^m_(.+?)$/) {
- $mfrules = "";
- $mobjs = "";
- $mliflags = "";
- $mfcount = 0;
- # A module made of multiple files, in a dir, e.g. src/modules/m_spanningtree/
- if (defined(opendir(MDIRHANDLE, "src/modules/$name"))) {
- read_module_directory("src/modules/$name", $name);
- print "Composing Makefile rules for directory \e[1;32m$name\e[0m... (\e[1;32m$mfcount files found\e[0m)\n";
- print FILEHANDLE "$name.so: ../../include/modules.h ../../include/users.h ../../include/channels.h ../../include/base.h ../../include/inspircd_config.h ../../include/inspircd.h ../../include/configreader.h $mobjs\n";
- if ($config{IS_DARWIN} eq "YES") {
- print FILEHANDLE " \@../../make/run-cc.pl \$(CC) -pipe -twolevel_namespace -undefined dynamic_lookup \$(FLAGS) $mliflags -bundle -o $name.so $mobjs\n";
- } else {
- print FILEHANDLE " \@../../make/run-cc.pl \$(CC) -pipe \$(FLAGS) -shared $mliflags -o $name.so $mobjs\n";
- }
- print FILEHANDLE "\n$mfrules\n";
- closedir(MDIRHANDLE);
- $install_list = $install_list . " install -m \$(INSTMODE) src/modules/$name.so \$(MODPATH)\n";
- }
- }
- }
- closedir(DIRHANDLE);
-}
-
-sub read_module_directory {
- my ($dpath, $reldpath) = @_;
-
- if (opendir(MDIRHANDLE, $dpath) == 0) {
- return;
- }
-
- foreach my $fname (sort readdir(MDIRHANDLE)) {
- if ($fname =~ /\.cpp$/) {
- my $cmflags = getcompilerflags("$dpath/$fname");
- $mliflags = $mliflags . " " . getlinkerflags("$dpath/$fname");
- my $deps = getdependencies("$dpath/$fname");
- my $oname = $fname;
- $oname =~ s/\.cpp$/.o/g;
- $mfrules = $mfrules . "$reldpath/$oname: $reldpath/$fname ../../include/modules.h ../../include/users.h ../../include/channels.h ../../include/base.h ../../include/inspircd_config.h ../../include/inspircd.h ../../include/configreader.h $deps\n";
- $mfrules = $mfrules . " \@../../make/run-cc.pl \$(CC) -pipe -I../../include -I. \$(FLAGS) $cmflags -export-dynamic -o $reldpath/$oname -c $reldpath/$fname\n\n";
- $mobjs = $mobjs . " $reldpath/$oname";
- $mfcount++;
- }
- elsif ((-d "$dpath/$fname") && !($fname eq ".") && !($fname eq "..")) {
- read_module_directory($dpath."/".$fname, $reldpath."/".$fname);
- }
- }
-}
-
-sub calcdeps($)
-{
- # Yes i know we could use gcc -M but it seems to ideneify a lot of 'deep'
- # dependencies which are not relevent in C++.
-
- my $file = $_[0];
-
- open (CPP, "<$file") or die("Can't open $file for reading!");
-
- my %dupe = ();
- my $retlist = "";
-
- foreach my $d (@ignoredeps)
- {
- $dupe{$d} = 1;
- }
-
- my $immutable = "";
- foreach my $dep (@immutabledeps)
- {
- $immutable = $immutable . "../include/$dep ";
- }
- $immutable =~ s/ $//g;
-
- while (defined(my $line = <CPP>))
- {
- chomp($line);
- if ($line =~ /#include "(.+\.h)"/)
- {
- if (!exists($dupe{$1}))
- {
- $retlist = $retlist . "../include/$1 ";
- $dupe{$1} = 1;
- }
- }
- }
- close CPP;
- return length($immutable) ? $immutable . " " . $retlist : $retlist;
-}
-
-sub write_dynamic_makefile
-{
- my $i = 0;
- my @cmdlist = ();
- my %existing_install_list = ();
- opendir(DIRHANDLE, "src/commands");
- foreach my $name (sort readdir(DIRHANDLE))
- {
- if ($name =~ /^cmd_(.+)\.cpp$/)
- {
- $cmdlist[$i++] = $1;
- $install_list = $install_list . " -install -m \$(INSTMODE) src/commands/cmd_" . $1 . ".so \$(LIBPATH)\n";
- $uninstall_list = $uninstall_list . " -rm \$(LIBPATH)/cmd_$1.so\n";
- }
- }
- closedir(DIRHANDLE);
-
- if (!$has_epoll)
- {
- $config{USE_EPOLL} = 0;
- }
- if (!$has_kqueue)
- {
- $config{USE_KQUEUE} = 0;
- }
- if (!$has_ports)
- {
- $config{USE_PORTS} = 0;
- }
-
- foreach my $dir (("src","src/commands","src/modes","src/socketengines","src/modules"))
- {
- print "Scanning \e[1;32m$dir\e[0m for core files ";
- opendir(DIRHANDLE, $dir);
- foreach my $name (sort readdir(DIRHANDLE))
- {
- if ($name =~ /\.cpp$/)
- {
- open (CPP, "<$dir/$name") or die("Can't open $dir/$name to scan it! oh bugger");
- print ".";
- while (defined(my $line = <CPP>))
- {
- chomp($line);
- if ($line =~ /\/\* \$Core: (\w+) \*\//i)
- {
- $filelist{$name} = $1;
- }
- elsif ($line =~ /\/\* \$ExtraDeps: (.*?) \*\//i)
- {
- $specialdeps{$name} = $1;
- }
- elsif ($line =~ /\/\* \$ExtraObjects: (.*?) \*\//i)
- {
- $extraobjects{$name} = $1;
- }
- elsif ($line =~ /\/\* \$ExtraBuild: (.*?) \*\//i)
- {
- $extrabuildlines{$name} = $1;
- }
- elsif ($line =~ /\/\* \$ExtraSources: (.*?) \*\//i)
- {
- $extrasources{$name} = $1;
- }
- elsif ($line =~ /\/\* \$If: (\w+) \*\//i)
- {
- if (defined $config{$1})
- {
- if (($config{$1} !~ /y/i) and ($config{$1} ne "1"))
- {
- # Skip to 'endif'
- while (defined($line = <CPP>))
- {
- chomp($line);
- die ("\$If buildsystem instruction within another \$If in file $dir/$name") if ($line =~ /\/\* \$If: (\w+) \*\//i);
- last if ($line =~ /\/\* \$EndIf \*\//i);
- }
- }
- }
- }
- elsif ($line =~ /\/\* \$Install: (.*?) \*\//i)
- {
- if (!exists($existing_install_list{$1}))
- {
- $existing_install_list{$1} = 1;
- my $idir = (split(' ',$1))[1];
- my $ifile = (split(' ',$1))[0];
- $install_list = $install_list . " -install -m \$(INSTMODE) $1\n";
- $ifile =~ s/.*\///g;
- $uninstall_list = $uninstall_list . " -rm $idir/$ifile\n";
- }
- }
- elsif ($line =~ /\/\* \$CopyInstall: (.*?) \*\//i)
- {
- if (!exists($existing_install_list{$1}))
- {
- $existing_install_list{$1} = 1;
- my $idir = (split(' ',$1))[1];
- my $ifile = (split(' ',$1))[0];
- $install_list = $install_list . " -cp $1\n";
- $ifile =~ s/.*\///g;
- $uninstall_list = $uninstall_list . " -rm $idir/$ifile\n";
- }
- }
- }
- close CPP;
- }
- }
- closedir(DIRHANDLE);
- print " done!\n";
- }
-
- my $freebsd4libs = (defined $config{CRAQ} ? $config{CRAQ} : "");
-
- my $all = "all: ";
- my $all_libsonly = "";
- my $libraryext = "";
- my $othercrap = "";
- my $RPATH = "";
-
- if ($config{IS_DARWIN} eq "YES")
- {
- $libraryext = "dylib";
- $othercrap = " \@../make/run-cc.pl \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspircd.cpp\n \@../make/run-cc.pl \$(CC) -pipe -dynamic -bind_at_load -L. -o inspircd \$(LDLIBS) inspircd.o "
- }
- else
- {
- $libraryext = "so";
- $RPATH = "-Wl,--rpath -Wl,$config{LIBRARY_DIR}" unless defined $opt_disablerpath;
- $othercrap = " \@../make/run-cc.pl \$(CC) -pipe -I../include $RPATH \$(FLAGS) $freebsd4libs -rdynamic -L. inspircd.cpp -o inspircd \$(LDLIBS) ";
- }
-
- foreach my $cpp (sort keys %filelist)
- {
- $all = $all . $filelist{$cpp} . "." . $libraryext . " ";
- $all_libsonly = $all_libsonly . $filelist{$cpp} . "." . $libraryext . " ";
- $install_list = $install_list . " -install -m \$(INSTMODE) src/" . $filelist{$cpp} . "." . $libraryext . " \$(LIBPATH)\n";
- $uninstall_list = $uninstall_list . " -rm \$(LIBPATH)/" . $filelist{$cpp} . "." . $libraryext . "\n";
- }
- $all = $all . "moo inspircd\n";
-
- $othercrap = $othercrap . " $all_libsonly\n\n";
-
- open(FH,">src/Makefile") or die("Could not write src/Makefile");
- print FH <<EOM;
-
-CC = im a cheezeball
-CXXFLAGS = -I../include \${FLAGS}
-CPPFILES = \$(shell /bin/ls -l modes/ | grep '\\.cpp' | sed 's/^.* //' | grep -v svn)
-RELCPPFILES = \$(shell /bin/ls -l modes/ | grep '\\.cpp' | sed 's/^.* /modes\\//' | grep -v svn)
-
-EOM
-
- print FH "$all\n\n";
-
- my $deps = calcdeps("src/inspircd.cpp");
- print FH "inspircd: inspircd.cpp $deps $all_libsonly\n";
- print FH "$othercrap\n";
-
- foreach my $cpp (sort keys %filelist)
- {
- my $thislib = $filelist{$cpp} . "." . $libraryext;
- my $objs = $cpp;
- my $rawcpp = $cpp;
- my $libcrap = "";
- $objs =~ s/\.cpp$/.o/;
- if (exists($extraobjects{$cpp}))
- {
- $objs = $objs . " " . $extraobjects{$cpp};
- }
- if (exists($extrasources{$cpp}))
- {
- $rawcpp = $rawcpp . " " . $extrasources{$cpp};
- }
- if ($config{IS_DARWIN} eq "YES")
- {
- $libcrap = "-install_name " . $config{LIBRARY_DIR} . "/" . $thislib . " -dynamiclib -twolevel_namespace -undefined dynamic_lookup";
- }
- else
- {
- if (defined $opt_disablerpath)
- {
- $libcrap = " -shared";
- }
- else
- {
- $libcrap = "-Wl,--rpath -Wl," . $config{LIBRARY_DIR} . " -shared";
- }
- }
- $deps = calcdeps("src/$cpp");
- if (exists($extrasources{$cpp}))
- {
- foreach my $seperate (sort split(' ',$extrasources{$cpp}))
- {
- my $d = calcdeps("src/$extrasources{$cpp}") . " ";
- if ($d ne "")
- {
- $deps = $deps . $d . " ";
- }
- }
- }
- print FH $thislib . ": $cpp $deps ". (defined($specialdeps{$cpp}) ? $specialdeps{$cpp} : "") . "\n";
- print FH " \@../make/run-cc.pl \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c $rawcpp\n";
- if (exists($extrabuildlines{$cpp}))
- {
- print FH " " . $extrabuildlines{$cpp} . "\n";