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/*.cpp>, "threadengines/threadengine_pthread.cpp") {
41 my $out = find_output $file;
43 next if $file =~ m#^socketengines/# && $file ne "socketengines/$ENV{SOCKETENGINE}.cpp";
44 push @core_deps, $out;
48 for my $file (<commands/*.cpp>) {
49 my $out = find_output $file;
54 opendir my $moddir, 'modules';
55 for my $file (sort readdir $moddir) {
56 next if $file =~ /^\./;
57 if (-e "modules/extra/$file" && !-l "modules/$file") {
59 print "Replacing symlink for $file found in modules/extra\n";
60 rename "modules/$file", "modules/$file~";
61 symlink "extra/$file", "modules/$file";
63 if ($file =~ /^m_/ && -d "modules/$file" && dep_dir "modules/$file") {
64 mkdir "$build/obj/$file";
65 push @modlist, "modules/$file.so";
67 if ($file =~ /^m_.*\.cpp$/) {
68 my $out = find_output "modules/$file";
69 dep_cpp "modules/$file", $out;
74 my $core_mk = join ' ', @core_deps;
75 my $mods = join ' ', @modlist;
78 bin/inspircd: $core_mk
79 \$(RUNCC) -o \$\@ \$(CORELDFLAGS) \$(LDLIBS) \$^ \$>
81 inspircd: bin/inspircd
84 .PHONY: inspircd modules
91 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
92 if ($path eq 'modules/' || $path eq 'commands/') {
93 return "modules/$base.so";
94 } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
96 } elsif ($path =~ m#modules/(m_.*)/#) {
97 return "obj/$1/$base.o";
99 die "Can't determine output for $file";
105 my $basedir = $f =~ m#(.*)/# ? $1 : '.';
106 return $f2dep{$f} if exists $f2dep{$f};
109 my $link = readlink $f;
111 $link = "$basedir/$link" unless $link =~ m#^/#;
114 open my $in, '<', $f or die "Could not read $f";
116 if (/^\s*#\s*include\s*"([^"]+)"/) {
118 next if $inc eq 'inspircd_version.h' && $f eq '../include/inspircd.h';
120 for my $loc ("$basedir/$inc", "../include/$inc") {
123 $dep{$_}++ for split / /, gendep $loc;
127 if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
128 print STDERR "WARNING: could not find header $inc for $f\n";
129 } elsif ($found > 1 && $basedir ne '../include') {
130 print STDERR "WARNING: ambiguous include $inc in $f\n";
135 $f2dep{$f} = join ' ', sort keys %dep;
140 my($file, $out) = @_;
143 print MAKE "$out: $file $f2dep{$file}\n";
144 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl \$(VERBOSE) \$\@ \$< \$>\n";
151 for my $file (sort readdir DIR) {
152 next unless $file =~ /(.*)\.cpp$/;
153 my $ofile = find_output "$dir/$file";
154 dep_cpp "$dir/$file", $ofile;
155 push @ofiles, $ofile;
159 my $ofiles = join ' ', @ofiles;
160 print MAKE "$dir.so: $ofiles\n\t\$(RUNCC) \$(PICLDFLAGS) -o \$\@ \$^ \$>\n";