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";
32 # DO NOT EDIT THIS FILE
33 # It is autogenerated by make/calcdep.pl, and will be overwritten
34 # every time you rerun make in the main directory
35 VPATH = \$(SOURCEPATH)/src
38 \@echo "This Makefile must be run by a sub-make from the source"
39 \@echo "in order to set the correct environment variables"
42 all: inspircd commands modules
45 my(@core_deps, @cmdlist, @modlist);
46 for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, "threadengines/threadengine_pthread.cpp") {
47 my $out = find_output $file;
49 next if $file =~ m#^socketengines/# && $file ne "socketengines/$ENV{SOCKETENGINE}.cpp";
50 push @core_deps, $out;
53 for my $file (<commands/*.cpp>) {
54 my $out = find_output $file;
59 opendir my $moddir, 'modules';
60 for my $file (sort readdir $moddir) {
61 next if $file =~ /^\./;
62 if (-e "modules/extra/$file" && !-l "modules/$file") {
64 print "Replacing symlink for $file found in modules/extra\n";
65 rename "modules/$file", "modules/$file~";
66 symlink "extra/$file", "modules/$file";
68 if ($file =~ /^m_/ && -d "modules/$file" && dep_dir "modules/$file") {
69 mkdir "$build/obj/$file";
70 push @modlist, "modules/$file.so";
72 if ($file =~ /^m_.*\.cpp$/) {
73 my $out = find_output "modules/$file";
74 dep_cpp "modules/$file", $out;
79 my $core_mk = join ' ', @core_deps;
80 my $cmds = join ' ', @cmdlist;
81 my $mods = join ' ', @modlist;
84 bin/inspircd: $core_mk
85 \$(RUNCC) -o \$\@ \$(CORELDFLAGS) \$(LDLIBS) \$^ \$>
87 inspircd: bin/inspircd
93 .PHONY: inspircd commands modules
100 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
101 if ($path eq 'modules/' || $path eq 'commands/') {
102 return "modules/$base.so";
103 } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
104 return "obj/$base.o";
105 } elsif ($path =~ m#modules/(m_.*)/#) {
106 return "obj/$1/$base.o";
108 die "Can't determine output for $file";
114 my $basedir = $f =~ m#(.*)/# ? $1 : '.';
115 return $f2dep{$f} if exists $f2dep{$f};
118 my $link = readlink $f;
120 $link = "$basedir/$link" unless $link =~ m#^/#;
123 open my $in, '<', $f or die "Could not read $f";
125 if (/^\s*#\s*include\s*"([^"]+)"/) {
127 next if $inc eq 'inspircd_version.h' && $f eq '../include/inspircd.h';
129 for my $loc ("$basedir/$inc", "../include/$inc") {
132 $dep{$_}++ for split / /, gendep $loc;
136 if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
137 print STDERR "WARNING: could not find header $inc for $f\n";
138 } elsif ($found > 1 && $basedir ne '../include') {
139 print STDERR "WARNING: ambiguous include $inc in $f\n";
144 $f2dep{$f} = join ' ', sort keys %dep;
149 my($file, $out) = @_;
152 print MAKE "$out: $file $f2dep{$file}\n";
153 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl \$(VERBOSE) \$\@ \$< \$>\n";
160 for my $file (sort readdir DIR) {
161 next unless $file =~ /(.*)\.cpp$/;
162 my $ofile = find_output "$dir/$file";
163 dep_cpp "$dir/$file", $ofile;
164 push @ofiles, $ofile;
168 my $ofiles = join ' ', @ofiles;
169 print MAKE "$dir.so: $ofiles\n\t\$(RUNCC) \$(PICLDFLAGS) -o \$\@ \$^ \$>\n";