19 my $build = $ENV{BUILDPATH};
21 chdir $build or die "Could not open build directory: $!";
23 symlink "$ENV{SOURCEPATH}/include", 'include';
24 mkdir $_ for qw/bin modules obj/;
25 # BSD make has a horribly annoying bug resulting in an extra chdir of the make process
26 # Create symlinks to work around it
27 symlink "../$_", "obj/$_" for qw/bin modules obj/;
30 open MAKE, '>real.mk' or die "Could not write real.mk: $!";
31 chdir "$ENV{SOURCEPATH}/src";
33 if ($ENV{PURE_STATIC}) {
42 my $build = $ENV{BUILDPATH};
44 # DO NOT EDIT THIS FILE
45 # It is autogenerated by make/calcdep.pl, and will be overwritten
46 # every time you rerun make in the main directory
47 VPATH = \$(SOURCEPATH)/src
50 \@echo "This Makefile must be run by a sub-make from the source"
51 \@echo "in order to set the correct environment variables"
54 all: inspircd commands modules
57 my(@core_deps, @cmdlist, @modlist);
58 for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, "threadengines/threadengine_pthread.cpp") {
59 my $out = find_output $file;
60 dep_cpp $file, $out, 'gen-o';
61 next if $file =~ m#^socketengines/# && $file ne "socketengines/$ENV{SOCKETENGINE}.cpp";
62 push @core_deps, $out;
65 for my $file (<commands/*.cpp>) {
66 my $out = dep_so $file;
70 opendir my $moddir, 'modules';
71 for my $file (sort readdir $moddir) {
72 next if $file =~ /^\./;
73 if (-e "modules/extra/$file" && !-l "modules/$file") {
75 print "Replacing symlink for $file found in modules/extra\n";
76 rename "modules/$file", "modules/$file~";
77 symlink "extra/$file", "modules/$file";
79 if ($file =~ /^m_/ && -d "modules/$file" && dep_dir "modules/$file") {
80 mkdir "$build/obj/$file";
81 push @modlist, "modules/$file.so";
83 if ($file =~ /^m_.*\.cpp$/) {
84 my $out = dep_so "modules/$file";
89 my $core_mk = join ' ', @core_deps;
90 my $cmds = join ' ', @cmdlist;
91 my $mods = join ' ', @modlist;
94 bin/inspircd: $core_mk
95 @\$(SOURCEPATH)/make/unit-cc.pl core-ld\$(VERBOSE) \$\@ \$^ \$>
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;
127 if ($out =~ m#obj/([^/]+)/[^/]+.o$#) {
128 mkdir "$ENV{BUILDPATH}/obj/$1";
130 dep_cpp $file, $out, 'gen-o';
131 next if $file =~ m#^socketengines/# && $file ne "socketengines/$ENV{SOCKETENGINE}.cpp";
136 my $core_mk = join ' ', @deps;
137 my $core_src = join ' ', @srcs;
140 obj/ld-extra.cmd: $core_src
141 \@\$(SOURCEPATH)/make/unit-cc.pl gen-ld\$(VERBOSE) \$\@ \$^ \$>
143 bin/inspircd: obj/ld-extra.cmd $core_mk
144 \@\$(SOURCEPATH)/make/unit-cc.pl static-ld\$(VERBOSE) \$\@ \$^ \$>
146 inspircd: bin/inspircd
148 .PHONY: all bad-target inspircd
154 my($file, $static) = @_;
155 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
156 if ($path eq 'modules/' || $path eq 'commands/') {
157 return $static ? "obj/$base.o" : "modules/$base.so";
158 } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
159 return "obj/$base.o";
160 } elsif ($path =~ m#modules/(m_.*)/#) {
161 return "obj/$1/$base.o";
163 die "Can't determine output for $file";
169 my $basedir = $f =~ m#(.*)/# ? $1 : '.';
170 return $f2dep{$f} if exists $f2dep{$f};
173 my $link = readlink $f;
175 $link = "$basedir/$link" unless $link =~ m#^/#;
178 open my $in, '<', $f or die "Could not read $f";
180 if (/^\s*#\s*include\s*"([^"]+)"/) {
182 next if $inc eq 'inspircd_version.h' && $f eq '../include/inspircd.h';
184 for my $loc ("$basedir/$inc", "../include/$inc") {
187 $dep{$_}++ for split / /, gendep $loc;
191 if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
192 print STDERR "WARNING: could not find header $inc for $f\n";
193 } elsif ($found > 1 && $basedir ne '../include') {
194 print STDERR "WARNING: ambiguous include $inc in $f\n";
199 $f2dep{$f} = join ' ', sort keys %dep;
204 my($file, $out, $type) = @_;
207 print MAKE "$out: $file $f2dep{$file}\n";
208 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl $type\$(VERBOSE) \$\@ \$< \$>\n";
213 my $out = find_output $file;
214 my $split = find_output $file, 1;
216 if ($ENV{SPLIT_CC}) {
217 dep_cpp $file, $split, 'gen-o';
218 print MAKE "$out: $split\n";
219 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl link-so\$(VERBOSE) \$\@ \$< \$>\n";
221 dep_cpp $file, $out, 'gen-so';
230 for my $file (sort readdir DIR) {
231 next unless $file =~ /(.*)\.cpp$/;
232 my $ofile = find_output "$dir/$file";
233 dep_cpp "$dir/$file", $ofile, 'gen-o';
234 push @ofiles, $ofile;
238 my $ofiles = join ' ', @ofiles;
239 print MAKE "$dir.so: $ofiles\n";
240 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl link-dir\$(VERBOSE) \$\@ \$^ \$>\n";