-
- # formerly generated below this foreach, now it's not! magic.
- my $all_core = "";
-
- 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 \*\//i)
- {
- my $sname = $name;
- $sname =~ s/\.cpp$/.o/;
-
- # append it to list to be built
- $all_core = $all_core . $sname . " ";
- $filelist{$name} = $sname;
-
- # mark it as a core file, so it won't get shared object cflags
- if (!exists($core_files_list{$name}))
- {
- $core_files_list{$name} = 1;
- }
- }
- 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";
- }
-
- # modes need to be compiled in too
- $all_core = $all_core . "modes/modeclasses.a";
-
- my $freebsd4libs = (defined $config{CRAQ} ? $config{CRAQ} : "");
-
- my $libraryext = "";
- my $binary_rule = "";
-
- if ($config{IS_DARWIN} eq "YES")
- {
- $libraryext = "dylib";
- $binary_rule = " \$(RUNCC) -dynamic -bind_at_load -L. -o inspircd \$(LDLIBS) inspircd.o "
- }
- else
- {
- $libraryext = "so";
- $binary_rule = " \$(RUNCC) \$(FLAGS) $freebsd4libs -rdynamic -L. -o inspircd \$(LDLIBS) ";
- }
-
- open(FH,">src/Makefile") or die("Could not write src/Makefile");
- print FH <<'EOM';
-
-CXXFLAGS = ${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)
-
-all:
- @echo "Don't run make here! Run it in the parent directory"
- false
-
-EOM
-
- my $buildstring = "";
- my $deps = "";
-
- foreach my $cpp (sort keys %filelist)
- {
- my $objs = $cpp;
- my $rawcpp = $cpp;
- $objs =~ s/\.cpp$/.o/;
- if (exists($extraobjects{$cpp}))
- {
- $objs = $objs . " " . $extraobjects{$cpp};
- $all_core = $all_core . " " . $extraobjects{$cpp};
- }
- if (exists($extrasources{$cpp}))
- {
- $rawcpp = $rawcpp . " " . $extrasources{$cpp};
- }
-
- $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 . " ";
- }
- }
- }
- $buildstring = $buildstring . $objs . ": $cpp $deps ". (defined($specialdeps{$cpp}) ? $specialdeps{$cpp} : "") . "\n";
-
- if (exists($core_files_list{$cpp}))
- {
- # core files are statically linked into the binary and do not require $SHARED shared libs switches
- $buildstring = $buildstring . " \$(RUNCC) \$(FLAGS) -c $rawcpp\n";
- }
- else
- {
- $buildstring = $buildstring . " \$(RUNCC) \$(FLAGS) $SHARED -c $rawcpp\n";
- }
-
- if (exists($extrabuildlines{$cpp}))
- {
- $buildstring = $buildstring . " " . $extrabuildlines{$cpp} . "\n";
- }
- }
-
- print FH "inspircd: $all_core\n";
- print FH "$binary_rule $all_core\n\n";
-
- print FH $buildstring;
- print FH <<'EOM';
-
-.PHONY: all commands
-
-commands:
- @${MAKE} -C commands $(MAKEARGS) commands
-
-modes/modeclasses.a: $(RELCPPFILES) ../include/inspircd.h ../include/inspircd_config.h
- @${MAKE} -C modes $(MAKEARGS) CPPFILES="$(CPPFILES)" modeclasses.a
-
-EOM
-
- # close main makefile
- close(FH);
-
- my $cmdobjs = "";
- # generate a list of .so
- foreach my $cmd (@cmdlist) {
- $cmdobjs = $cmdobjs . "cmd_$cmd.so ";
- }
-
- # and now reopen the commands makefile
- open(FH,">src/commands/Makefile") or die("Could not write src/commands/Makefile");
- print FH <<ITEM;
-CXXFLAGS = \${FLAGS}
-
-all:
- \@echo "Don't run make here! Run it in the root directory"
- false
-
-.PHONY: all commands
-
-commands: $cmdobjs
-
-ITEM
-
- # now print the command file detail
- foreach my $cmd (@cmdlist) {
- print FH <<ITEM;
-cmd_$cmd.so: cmd_$cmd.cpp ../../include/base.h ../../include/modules.h ../../include/inspircd.h ../../include/channels.h ../../include/users.h ../../include/inspircd_config.h ../../include/commands/cmd_$cmd.h
- \$(RUNCC) \$(FLAGS) $SHARED -o cmd_$cmd.so cmd_$cmd.cpp
-
-ITEM
- }