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;
127 if ($out =~ m#obj/([^/]+)/[^/]+.o$#) {
128 mkdir "$ENV{BUILDPATH}/obj/$1";
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 -f\$(VERBOSE) \$\@ \$^ \$>
143 bin/inspircd: obj/ld-extra.cmd $core_mk
144 \@\$(SOURCEPATH)/make/unit-cc.pl -l\$(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) = @_;
207 print MAKE "$out: $file $f2dep{$file}\n";
208 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl \$(VERBOSE) \$\@ \$< \$>\n";
215 for my $file (sort readdir DIR) {
216 next unless $file =~ /(.*)\.cpp$/;
217 my $ofile = find_output "$dir/$file";
218 dep_cpp "$dir/$file", $ofile;
219 push @ofiles, $ofile;
223 my $ofiles = join ' ', @ofiles;
224 print MAKE "$dir.so: $ofiles\n\t\$(RUNCC) \$(PICLDFLAGS) -o \$\@ \$^ \$>\n";