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/>.
23 push @INC, $ENV{SOURCEPATH};
25 unless (-f 'configure') {
26 print "Error: $0 must be run from the main source directory!\n";
32 use warnings FATAL => qw(all);
34 use File::Basename qw(basename);
39 BUILDPATH => $ENV{BUILDPATH},
40 SOURCEPATH => $ENV{SOURCEPATH}
56 create_directory(BUILDPATH, 0770) or die "Could not create build directory: $!";
57 chdir BUILDPATH or die "Could not open build directory: $!";
59 symlink "${\SOURCEPATH}/include", 'include';
60 mkdir $_ for qw/bin modules obj/;
62 open MAKE, '>real.mk' or die "Could not write real.mk: $!";
63 chdir "${\SOURCEPATH}/src";
71 # DO NOT EDIT THIS FILE
72 # It is autogenerated by make/calcdep.pl, and will be overwritten
73 # every time you rerun make in the main directory
74 VPATH = \$(SOURCEPATH)/src
77 \@echo "This Makefile must be run by a sub-make from the source"
78 \@echo "in order to set the correct environment variables"
84 my(@core_deps, @modlist);
85 for my $file (<*.cpp>, <socketengines/*.cpp>, "threadengines/threadengine_pthread.cpp") {
86 my $out = find_output $file;
87 dep_cpp $file, $out, 'gen-o';
88 next if $file =~ m#^socketengines/# && $file ne "socketengines/socketengine_$ENV{SOCKETENGINE}.cpp";
89 # Having a module in the src directory is a bad idea because it will be linked to the core binary
90 if ($file =~ /^(m|core)_.*\.cpp/) {
91 my $correctsubdir = ($file =~ /^m_/ ? "modules" : "coremods");
92 print "Error: module $file is in the src directory, put it in src/$correctsubdir instead!\n";
95 push @core_deps, $out;
98 foreach my $directory (qw(coremods modules)) {
99 opendir(my $moddir, $directory);
100 for my $file (sort readdir $moddir) {
101 next if $file =~ /^\./;
102 if ($directory eq 'modules' && -e "modules/extra/$file" && !-l "modules/$file") {
104 print "Replacing symlink for $file found in modules/extra\n";
105 rename "modules/$file", "modules/$file~";
106 symlink "extra/$file", "modules/$file";
108 if ($file =~ /^(?:core|m)_/ && -d "$directory/$file" && dep_dir "$directory/$file", "modules/$file") {
109 mkdir "${\BUILDPATH}/obj/$file";
110 push @modlist, "modules/$file.so";
112 if ($file =~ /^.*\.cpp$/) {
113 my $out = dep_so "$directory/$file";
119 my $core_mk = join ' ', @core_deps;
120 my $mods = join ' ', @modlist;
123 bin/inspircd: $core_mk
124 @\$(SOURCEPATH)/make/unit-cc.pl core-ld \$\@ \$^ \$>
126 inspircd: bin/inspircd
130 .PHONY: all bad-target inspircd modules
137 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
138 if ($path eq 'modules/' || $path eq 'coremods/') {
139 return "modules/$base.so";
140 } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
141 return "obj/$base.o";
142 } elsif ($path =~ m#modules/(m_.*)/# || $path =~ m#coremods/(core_.*)/#) {
143 return "obj/$1/$base.o";
145 die "Can't determine output for $file";
151 my $basedir = $f =~ m#(.*)/# ? $1 : '.';
152 return $f2dep{$f} if exists $f2dep{$f};
155 my $link = readlink $f;
157 $link = "$basedir/$link" unless $link =~ m#^/#;
160 open my $in, '<', $f or die "Could not read $f";
162 if (/^\s*#\s*include\s*"([^"]+)"/) {
164 next if $inc eq 'config.h' && $f eq '../include/inspircd.h';
166 for my $loc ("$basedir/$inc", "../include/$inc") {
169 $dep{$_}++ for split / /, gendep $loc;
173 if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
174 print STDERR "WARNING: could not find header $inc for $f\n";
175 } elsif ($found > 1 && $basedir ne '../include') {
176 print STDERR "WARNING: ambiguous include $inc in $f\n";
181 $f2dep{$f} = join ' ', sort keys %dep;
186 my($file, $out, $type) = @_;
189 print MAKE "$out: $file $f2dep{$file}\n";
190 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl $type \$\@ \$(SOURCEPATH)/src/$file \$>\n";
195 my $out = find_output $file;
197 my $name = basename $out, '.so';
198 print MAKE ".PHONY: $name\n";
199 print MAKE "$name: $out\n";
201 dep_cpp $file, $out, 'gen-so';
206 my($dir, $outdir) = @_;
209 for my $file (sort readdir DIR) {
210 next unless $file =~ /(.*)\.cpp$/;
211 my $ofile = find_output "$dir/$file";
212 dep_cpp "$dir/$file", $ofile, 'gen-o';
213 push @ofiles, $ofile;
217 my $ofiles = join ' ', @ofiles;
218 my $name = basename $outdir;
219 print MAKE ".PHONY: $name\n";
220 print MAKE "$name: $outdir.so\n";
221 print MAKE "$outdir.so: $ofiles\n";
222 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl link-dir \$\@ ${\SOURCEPATH}/src/$dir \$^ \$>\n";