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: inspircd commands modules
39 my(@core_deps, @cmdlist, @modlist);
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;
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 $cmds = join ' ', @cmdlist;
75 my $mods = join ' ', @modlist;
78 bin/inspircd: $core_mk
79 \$(RUNCC) -o \$\@ \$(CORELDFLAGS) \$(LDLIBS) \$^ \$>
81 inspircd: bin/inspircd
87 .PHONY: inspircd commands modules
94 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
95 if ($path eq 'modules/' || $path eq 'commands/') {
96 return "modules/$base.so";
97 } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
99 } elsif ($path =~ m#modules/(m_.*)/#) {
100 return "obj/$1/$base.o";
102 die "Can't determine output for $file";
108 my $basedir = $f =~ m#(.*)/# ? $1 : '.';
109 return $f2dep{$f} if exists $f2dep{$f};
112 my $link = readlink $f;
114 $link = "$basedir/$link" unless $link =~ m#^/#;
117 open my $in, '<', $f or die "Could not read $f";
119 if (/^\s*#\s*include\s*"([^"]+)"/) {
121 next if $inc eq 'inspircd_version.h' && $f eq '../include/inspircd.h';
123 for my $loc ("$basedir/$inc", "../include/$inc") {
126 $dep{$_}++ for split / /, gendep $loc;
130 if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
131 print STDERR "WARNING: could not find header $inc for $f\n";
132 } elsif ($found > 1 && $basedir ne '../include') {
133 print STDERR "WARNING: ambiguous include $inc in $f\n";
138 $f2dep{$f} = join ' ', sort keys %dep;
143 my($file, $out) = @_;
146 print MAKE "$out: $file $f2dep{$file}\n";
147 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl \$(VERBOSE) \$\@ \$< \$>\n";
154 for my $file (sort readdir DIR) {
155 next unless $file =~ /(.*)\.cpp$/;
156 my $ofile = find_output "$dir/$file";
157 dep_cpp "$dir/$file", $ofile;
158 push @ofiles, $ofile;
162 my $ofiles = join ' ', @ofiles;
163 print MAKE "$dir.so: $ofiles\n\t\$(RUNCC) \$(PICLDFLAGS) -o \$\@ \$^ \$>\n";