19 my $build = $ENV{BUILDPATH};
21 chdir $build or die "Could not open build directory: $!";
22 symlink "$ENV{SOURCEPATH}/include", 'include';
23 mkdir $_ for qw/bin modules obj/;
24 # BSD make has a horribly annoying bug resulting in an extra chdir of the make process
25 # Create symlinks to work around it
26 symlink "../$_", "obj/$_" for qw/bin modules obj/;
29 open MAKE, '>real.mk' or die "Could not write real.mk: $!";
30 chdir "$ENV{SOURCEPATH}/src";
32 if ($ENV{PURE_STATIC}) {
41 my $build = $ENV{BUILDPATH};
43 # DO NOT EDIT THIS FILE
44 # It is autogenerated by make/calcdep.pl, and will be overwritten
45 # every time you rerun make in the main directory
46 VPATH = \$(SOURCEPATH)/src
49 \@echo "This Makefile must be run by a sub-make from the source"
50 \@echo "in order to set the correct environment variables"
53 all: inspircd commands modules
56 my(@core_deps, @cmdlist, @modlist);
57 for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, "threadengines/threadengine_pthread.cpp") {
58 my $out = find_output $file;
59 dep_cpp $file, $out, 'gen-o';
60 next if $file =~ m#^socketengines/# && $file ne "socketengines/$ENV{SOCKETENGINE}.cpp";
61 push @core_deps, $out;
64 for my $file (<commands/*.cpp>) {
65 my $out = dep_so $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 = dep_so "modules/$file";
88 my $core_mk = join ' ', @core_deps;
89 my $cmds = join ' ', @cmdlist;
90 my $mods = join ' ', @modlist;
93 bin/inspircd: $core_mk
94 @\$(SOURCEPATH)/make/unit-cc.pl core-ld\$(VERBOSE) \$\@ \$^ \$>
96 inspircd: bin/inspircd
102 .PHONY: all bad-target inspircd commands modules
109 # DO NOT EDIT THIS FILE
110 # It is autogenerated by make/calcdep.pl, and will be overwritten
111 # every time you rerun make in the main directory
112 VPATH = \$(SOURCEPATH)/src
115 \@echo "This Makefile must be run by a sub-make from the source"
116 \@echo "in order to set the correct environment variables"
123 for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, <commands/*.cpp>,
124 <modules/*.cpp>, <modules/m_*/*.cpp>, "threadengines/threadengine_pthread.cpp") {
125 my $out = find_output $file, 1;
126 if ($out =~ m#obj/([^/]+)/[^/]+.o$#) {
127 mkdir "$ENV{BUILDPATH}/obj/$1";
129 dep_cpp $file, $out, 'gen-o';
130 next if $file =~ m#^socketengines/# && $file ne "socketengines/$ENV{SOCKETENGINE}.cpp";
135 my $core_mk = join ' ', @deps;
136 my $core_src = join ' ', @srcs;
139 obj/ld-extra.cmd: $core_src
140 \@\$(SOURCEPATH)/make/unit-cc.pl gen-ld\$(VERBOSE) \$\@ \$^ \$>
142 bin/inspircd: obj/ld-extra.cmd $core_mk
143 \@\$(SOURCEPATH)/make/unit-cc.pl static-ld\$(VERBOSE) \$\@ \$^ \$>
145 inspircd: bin/inspircd
147 .PHONY: all bad-target inspircd
153 my($file, $static) = @_;
154 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
155 if ($path eq 'modules/' || $path eq 'commands/') {
156 return $static ? "obj/$base.o" : "modules/$base.so";
157 } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
158 return "obj/$base.o";
159 } elsif ($path =~ m#modules/(m_.*)/#) {
160 return "obj/$1/$base.o";
162 die "Can't determine output for $file";
168 my $basedir = $f =~ m#(.*)/# ? $1 : '.';
169 return $f2dep{$f} if exists $f2dep{$f};
172 my $link = readlink $f;
174 $link = "$basedir/$link" unless $link =~ m#^/#;
177 open my $in, '<', $f or die "Could not read $f";
179 if (/^\s*#\s*include\s*"([^"]+)"/) {
181 next if $inc eq 'inspircd_version.h' && $f eq '../include/inspircd.h';
183 for my $loc ("$basedir/$inc", "../include/$inc") {
186 $dep{$_}++ for split / /, gendep $loc;
190 if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
191 print STDERR "WARNING: could not find header $inc for $f\n";
192 } elsif ($found > 1 && $basedir ne '../include') {
193 print STDERR "WARNING: ambiguous include $inc in $f\n";
198 $f2dep{$f} = join ' ', sort keys %dep;
203 my($file, $out, $type) = @_;
206 print MAKE "$out: $file $f2dep{$file}\n";
207 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl $type\$(VERBOSE) \$\@ \$< \$>\n";
212 my $out = find_output $file;
213 my $split = find_output $file, 1;
215 if ($ENV{SPLIT_CC}) {
216 dep_cpp $file, $split, 'gen-o';
217 print MAKE "$out: $split\n";
218 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl link-so\$(VERBOSE) \$\@ \$< \$>\n";
220 dep_cpp $file, $out, 'gen-so';
229 for my $file (sort readdir DIR) {
230 next unless $file =~ /(.*)\.cpp$/;
231 my $ofile = find_output "$dir/$file";
232 dep_cpp "$dir/$file", $ofile, 'gen-o';
233 push @ofiles, $ofile;
237 my $ofiles = join ' ', @ofiles;
238 print MAKE "$dir.so: $ofiles\n";
239 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl link-dir\$(VERBOSE) \$\@ \$^ \$>\n";