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";
31 if ($ENV{PURE_STATIC}) {
40 my $build = $ENV{BUILDPATH};
42 # DO NOT EDIT THIS FILE
43 # It is autogenerated by make/calcdep.pl, and will be overwritten
44 # every time you rerun make in the main directory
45 VPATH = \$(SOURCEPATH)/src
48 \@echo "This Makefile must be run by a sub-make from the source"
49 \@echo "in order to set the correct environment variables"
52 all: inspircd commands modules
55 my(@core_deps, @cmdlist, @modlist);
56 for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, "threadengines/threadengine_pthread.cpp") {
57 my $out = find_output $file;
59 next if $file =~ m#^socketengines/# && $file ne "socketengines/$ENV{SOCKETENGINE}.cpp";
60 push @core_deps, $out;
63 for my $file (<commands/*.cpp>) {
64 my $out = find_output $file;
69 opendir my $moddir, 'modules';
70 for my $file (sort readdir $moddir) {
71 next if $file =~ /^\./;
72 if (-e "modules/extra/$file" && !-l "modules/$file") {
74 print "Replacing symlink for $file found in modules/extra\n";
75 rename "modules/$file", "modules/$file~";
76 symlink "extra/$file", "modules/$file";
78 if ($file =~ /^m_/ && -d "modules/$file" && dep_dir "modules/$file") {
79 mkdir "$build/obj/$file";
80 push @modlist, "modules/$file.so";
82 if ($file =~ /^m_.*\.cpp$/) {
83 my $out = find_output "modules/$file";
84 dep_cpp "modules/$file", $out;
89 my $core_mk = join ' ', @core_deps;
90 my $cmds = join ' ', @cmdlist;
91 my $mods = join ' ', @modlist;
94 bin/inspircd: $core_mk
95 \$(RUNCC) -o \$\@ \$(CORELDFLAGS) \$(LDLIBS) \$^ \$>
97 inspircd: bin/inspircd
103 .PHONY: all bad-target inspircd commands modules
110 # DO NOT EDIT THIS FILE
111 # It is autogenerated by make/calcdep.pl, and will be overwritten
112 # every time you rerun make in the main directory
113 VPATH = \$(SOURCEPATH)/src
116 \@echo "This Makefile must be run by a sub-make from the source"
117 \@echo "in order to set the correct environment variables"
124 for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, <commands/*.cpp>,
125 <modules/*.cpp>, <modules/m_*/*.cpp>, "threadengines/threadengine_pthread.cpp") {
126 my $out = find_output $file, 1;
128 next if $file =~ m#^socketengines/# && $file ne "socketengines/$ENV{SOCKETENGINE}.cpp";
132 my $core_mk = join ' ', @deps;
135 bin/inspircd: $core_mk
136 \$(RUNCC) -o \$\@ \$(CORELDFLAGS) \$(LDLIBS) \$^ \$>
138 inspircd: bin/inspircd
140 .PHONY: all bad-target inspircd
146 my($file, $static) = @_;
147 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
148 if ($path eq 'modules/' || $path eq 'commands/') {
149 return $static ? "obj/$base.o" : "modules/$base.so";
150 } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
151 return "obj/$base.o";
152 } elsif ($path =~ m#modules/(m_.*)/#) {
153 return "obj/$1/$base.o";
155 die "Can't determine output for $file";
161 my $basedir = $f =~ m#(.*)/# ? $1 : '.';
162 return $f2dep{$f} if exists $f2dep{$f};
165 my $link = readlink $f;
167 $link = "$basedir/$link" unless $link =~ m#^/#;
170 open my $in, '<', $f or die "Could not read $f";
172 if (/^\s*#\s*include\s*"([^"]+)"/) {
174 next if $inc eq 'inspircd_version.h' && $f eq '../include/inspircd.h';
176 for my $loc ("$basedir/$inc", "../include/$inc") {
179 $dep{$_}++ for split / /, gendep $loc;
183 if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
184 print STDERR "WARNING: could not find header $inc for $f\n";
185 } elsif ($found > 1 && $basedir ne '../include') {
186 print STDERR "WARNING: ambiguous include $inc in $f\n";
191 $f2dep{$f} = join ' ', sort keys %dep;
196 my($file, $out) = @_;
199 print MAKE "$out: $file $f2dep{$file}\n";
200 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl \$(VERBOSE) \$\@ \$< \$>\n";
207 for my $file (sort readdir DIR) {
208 next unless $file =~ /(.*)\.cpp$/;
209 my $ofile = find_output "$dir/$file";
210 dep_cpp "$dir/$file", $ofile;
211 push @ofiles, $ofile;
215 my $ofiles = join ' ', @ofiles;
216 print MAKE "$dir.so: $ofiles\n\t\$(RUNCC) \$(PICLDFLAGS) -o \$\@ \$^ \$>\n";