18 my $build = $ENV{BUILDPATH};
20 chdir $build or die "Could not open build directory: $!";
21 symlink "$ENV{SOURCEPATH}/include", 'include';
22 mkdir $_ for qw/bin modules obj/;
23 # BSD make has a horribly annoying bug resulting in an extra chdir of the make process
24 # Create symlinks to work around it
25 symlink "../$_", "obj/$_" for qw/bin modules obj/;
28 open MAKE, '>real.mk' or die "Could not write real.mk: $!";
29 chdir "$ENV{SOURCEPATH}/src";
33 # Autogenerated by calcdep
34 VPATH = \$(SOURCEPATH)/src
36 all: bin/inspircd modules
40 for my $file (<*.cpp>, <modes/*.cpp>, "socketengines/$ENV{SOCKETENGINE}.cpp", "threadengines/threadengine_pthread.cpp") {
41 my $out = find_output $file;
43 push @core_deps, $out;
47 for my $file (<commands/*.cpp>) {
48 my $out = find_output $file;
53 opendir my $moddir, 'modules';
54 for my $file (sort readdir $moddir) {
55 next if $file =~ /^\./;
56 if (-e "modules/extra/$file" && !-l "modules/$file") {
58 print "Replacing symlink for $file found in modules/extra\n";
59 rename "modules/$file", "modules/$file~";
60 symlink "extra/$file", "modules/$file";
62 if ($file =~ /^m_/ && -d "modules/$file" && dep_dir "modules/$file") {
63 mkdir "$build/obj/$file";
64 push @modlist, "modules/$file.so";
66 if ($file =~ /^m_.*\.cpp$/) {
67 my $out = find_output "modules/$file";
68 dep_cpp "modules/$file", $out;
73 my $core_mk = join ' ', @core_deps;
74 my $mods = join ' ', @modlist;
77 bin/inspircd: $core_mk
78 \$(RUNCC) -o \$\@ \$(CORELDFLAGS) \$(LDLIBS) \$^ \$>
80 inspircd: bin/inspircd
83 .PHONY: inspircd modules
90 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
91 if ($path eq 'modules/' || $path eq 'commands/') {
92 return "modules/$base.so";
93 } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
95 } elsif ($path =~ m#modules/(m_.*)/#) {
96 return "obj/$1/$base.o";
98 die "Can't determine output for $file";
104 my $basedir = $f =~ m#(.*)/# ? $1 : '.';
105 return $f2dep{$f} if exists $f2dep{$f};
108 my $link = readlink $f;
110 $link = "$basedir/$link" unless $link =~ m#^/#;
113 open my $in, '<', $f or die "Could not read $f";
115 if (/^\s*#\s*include\s*"([^"]+)"/) {
117 next if $inc eq 'inspircd_version.h' && $f eq '../include/inspircd.h';
119 for my $loc ("$basedir/$inc", "../include/$inc") {
122 $dep{$_}++ for split / /, gendep $loc;
126 if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
127 print STDERR "WARNING: could not find header $inc for $f\n";
128 } elsif ($found > 1 && $basedir ne '../include') {
129 print STDERR "WARNING: ambiguous include $inc in $f\n";
134 $f2dep{$f} = join ' ', sort keys %dep;
139 my($file, $out) = @_;
142 print MAKE "$out: $file $f2dep{$file}\n";
143 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl \$(VERBOSE) \$\@ \$< \$>\n";
150 for my $file (readdir DIR) {
151 next unless $file =~ /(.*)\.cpp$/;
152 my $ofile = find_output "$dir/$file";
153 dep_cpp "$dir/$file", $ofile;
154 push @ofiles, $ofile;
158 my $ofiles = join ' ', @ofiles;
159 print MAKE "$dir.so: $ofiles\n\t\$(RUNCC) \$(PICLDFLAGS) -o \$\@ \$^ \$>\n";