4 # InspIRCd -- Internet Relay Chat Daemon
6 # Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
8 # This file is part of InspIRCd. InspIRCd is free software: you can
9 # redistribute it and/or modify it under the terms of the GNU General Public
10 # License as published by the Free Software Foundation, version 2.
12 # This program is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 unless (-f 'configure') {
25 print "Error: $0 must be run from the main source directory!\n";
31 use warnings FATAL => qw(all);
34 BUILDPATH => $ENV{BUILDPATH},
35 SOURCEPATH => $ENV{SOURCEPATH}
52 chdir BUILDPATH or die "Could not open build directory: $!";
54 symlink "${\SOURCEPATH}/include", 'include';
55 mkdir $_ for qw/bin modules obj/;
57 open MAKE, '>real.mk' or die "Could not write real.mk: $!";
58 chdir "${\SOURCEPATH}/src";
60 if ($ENV{PURE_STATIC}) {
70 # DO NOT EDIT THIS FILE
71 # It is autogenerated by make/calcdep.pl, and will be overwritten
72 # every time you rerun make in the main directory
73 VPATH = \$(SOURCEPATH)/src
76 \@echo "This Makefile must be run by a sub-make from the source"
77 \@echo "in order to set the correct environment variables"
83 my(@core_deps, @modlist);
84 for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, "threadengines/threadengine_pthread.cpp") {
85 my $out = find_output $file;
86 dep_cpp $file, $out, 'gen-o';
87 next if $file =~ m#^socketengines/# && $file ne "socketengines/socketengine_$ENV{SOCKETENGINE}.cpp";
88 push @core_deps, $out;
91 foreach my $directory (qw(coremods modules)) {
92 opendir(my $moddir, $directory);
93 for my $file (sort readdir $moddir) {
94 next if $file =~ /^\./;
95 if ($directory eq 'modules' && -e "modules/extra/$file" && !-l "modules/$file") {
97 print "Replacing symlink for $file found in modules/extra\n";
98 rename "modules/$file", "modules/$file~";
99 symlink "extra/$file", "modules/$file";
101 if ($file =~ /^(?:core|m)_/ && -d "$directory/$file" && dep_dir "$directory/$file", "modules/$file") {
102 mkdir "${\BUILDPATH}/obj/$file";
103 push @modlist, "modules/$file.so";
105 if ($file =~ /^.*\.cpp$/) {
106 my $out = dep_so "$directory/$file";
112 my $core_mk = join ' ', @core_deps;
113 my $mods = join ' ', @modlist;
116 bin/inspircd: $core_mk
117 @\$(SOURCEPATH)/make/unit-cc.pl core-ld\$(VERBOSE) \$\@ \$^ \$>
119 inspircd: bin/inspircd
123 .PHONY: all bad-target inspircd modules
130 # DO NOT EDIT THIS FILE
131 # It is autogenerated by make/calcdep.pl, and will be overwritten
132 # every time you rerun make in the main directory
133 VPATH = \$(SOURCEPATH)/src
136 \@echo "This Makefile must be run by a sub-make from the source"
137 \@echo "in order to set the correct environment variables"
144 for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, <coremods/*.cpp>, <coremods/core_*/*.cpp>,
145 <modules/*.cpp>, <modules/m_*/*.cpp>, "threadengines/threadengine_pthread.cpp") {
146 my $out = find_output $file, 1;
147 if ($out =~ m#obj/([^/]+)/[^/]+.o$#) {
148 mkdir "${\BUILDPATH}/obj/$1";
150 dep_cpp $file, $out, 'gen-o';
151 next if $file =~ m#^socketengines/# && $file ne "socketengines/socketengine_$ENV{SOCKETENGINE}.cpp";
156 my $core_mk = join ' ', @deps;
157 my $core_src = join ' ', @srcs;
160 obj/ld-extra.cmd: $core_src
161 \@\$(SOURCEPATH)/make/unit-cc.pl gen-ld\$(VERBOSE) \$\@ \$^ \$>
163 bin/inspircd: obj/ld-extra.cmd $core_mk
164 \@\$(SOURCEPATH)/make/unit-cc.pl static-ld\$(VERBOSE) \$\@ \$^ \$>
166 inspircd: bin/inspircd
168 .PHONY: all bad-target inspircd
174 my($file, $static) = @_;
175 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
176 if ($path eq 'modules/' || $path eq 'coremods/') {
177 return $static ? "obj/$base.o" : "modules/$base.so";
178 } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
179 return "obj/$base.o";
180 } elsif ($path =~ m#modules/(m_.*)/# || $path =~ m#coremods/(core_.*)/#) {
181 return "obj/$1/$base.o";
183 die "Can't determine output for $file";
189 my $basedir = $f =~ m#(.*)/# ? $1 : '.';
190 return $f2dep{$f} if exists $f2dep{$f};
193 my $link = readlink $f;
195 $link = "$basedir/$link" unless $link =~ m#^/#;
198 open my $in, '<', $f or die "Could not read $f";
200 if (/^\s*#\s*include\s*"([^"]+)"/) {
202 next if $inc eq 'config.h' && $f eq '../include/inspircd.h';
204 for my $loc ("$basedir/$inc", "../include/$inc") {
207 $dep{$_}++ for split / /, gendep $loc;
211 if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
212 print STDERR "WARNING: could not find header $inc for $f\n";
213 } elsif ($found > 1 && $basedir ne '../include') {
214 print STDERR "WARNING: ambiguous include $inc in $f\n";
219 $f2dep{$f} = join ' ', sort keys %dep;
224 my($file, $out, $type) = @_;
227 print MAKE "$out: $file $f2dep{$file}\n";
228 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl $type\$(VERBOSE) \$\@ \$(SOURCEPATH)/src/$file \$>\n";
233 my $out = find_output $file;
235 dep_cpp $file, $out, 'gen-so';
240 my($dir, $outdir) = @_;
243 for my $file (sort readdir DIR) {
244 next unless $file =~ /(.*)\.cpp$/;
245 my $ofile = find_output "$dir/$file";
246 dep_cpp "$dir/$file", $ofile, 'gen-o';
247 push @ofiles, $ofile;
251 my $ofiles = join ' ', @ofiles;
252 print MAKE "$outdir.so: $ofiles\n";
253 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl link-dir\$(VERBOSE) \$\@ ${\SOURCEPATH}/src/$dir \$^ \$>\n";