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);
33 use File::Basename qw(basename);
36 BUILDPATH => $ENV{BUILDPATH},
37 SOURCEPATH => $ENV{SOURCEPATH}
54 chdir BUILDPATH or die "Could not open build directory: $!";
56 symlink "${\SOURCEPATH}/include", 'include';
57 mkdir $_ for qw/bin modules obj/;
59 open MAKE, '>real.mk' or die "Could not write real.mk: $!";
60 chdir "${\SOURCEPATH}/src";
68 # DO NOT EDIT THIS FILE
69 # It is autogenerated by make/calcdep.pl, and will be overwritten
70 # every time you rerun make in the main directory
71 VPATH = \$(SOURCEPATH)/src
74 \@echo "This Makefile must be run by a sub-make from the source"
75 \@echo "in order to set the correct environment variables"
81 my(@core_deps, @modlist);
82 for my $file (<*.cpp>, <socketengines/*.cpp>, "threadengines/threadengine_pthread.cpp") {
83 my $out = find_output $file;
84 dep_cpp $file, $out, 'gen-o';
85 next if $file =~ m#^socketengines/# && $file ne "socketengines/socketengine_$ENV{SOCKETENGINE}.cpp";
86 # Having a module in the src directory is a bad idea because it will be linked to the core binary
87 if ($file =~ /^(m|core)_.*\.cpp/) {
88 my $correctsubdir = ($file =~ /^m_/ ? "modules" : "coremods");
89 print "Error: module $file is in the src directory, put it in src/$correctsubdir instead!\n";
92 push @core_deps, $out;
95 foreach my $directory (qw(coremods modules)) {
96 opendir(my $moddir, $directory);
97 for my $file (sort readdir $moddir) {
98 next if $file =~ /^\./;
99 if ($directory eq 'modules' && -e "modules/extra/$file" && !-l "modules/$file") {
101 print "Replacing symlink for $file found in modules/extra\n";
102 rename "modules/$file", "modules/$file~";
103 symlink "extra/$file", "modules/$file";
105 if ($file =~ /^(?:core|m)_/ && -d "$directory/$file" && dep_dir "$directory/$file", "modules/$file") {
106 mkdir "${\BUILDPATH}/obj/$file";
107 push @modlist, "modules/$file.so";
109 if ($file =~ /^.*\.cpp$/) {
110 my $out = dep_so "$directory/$file";
116 my $core_mk = join ' ', @core_deps;
117 my $mods = join ' ', @modlist;
120 bin/inspircd: $core_mk
121 @\$(SOURCEPATH)/make/unit-cc.pl core-ld \$\@ \$^ \$>
123 inspircd: bin/inspircd
127 .PHONY: all bad-target inspircd modules
134 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
135 if ($path eq 'modules/' || $path eq 'coremods/') {
136 return "modules/$base.so";
137 } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
138 return "obj/$base.o";
139 } elsif ($path =~ m#modules/(m_.*)/# || $path =~ m#coremods/(core_.*)/#) {
140 return "obj/$1/$base.o";
142 die "Can't determine output for $file";
148 my $basedir = $f =~ m#(.*)/# ? $1 : '.';
149 return $f2dep{$f} if exists $f2dep{$f};
152 my $link = readlink $f;
154 $link = "$basedir/$link" unless $link =~ m#^/#;
157 open my $in, '<', $f or die "Could not read $f";
159 if (/^\s*#\s*include\s*"([^"]+)"/) {
161 next if $inc eq 'config.h' && $f eq '../include/inspircd.h';
163 for my $loc ("$basedir/$inc", "../include/$inc") {
166 $dep{$_}++ for split / /, gendep $loc;
170 if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
171 print STDERR "WARNING: could not find header $inc for $f\n";
172 } elsif ($found > 1 && $basedir ne '../include') {
173 print STDERR "WARNING: ambiguous include $inc in $f\n";
178 $f2dep{$f} = join ' ', sort keys %dep;
183 my($file, $out, $type) = @_;
186 print MAKE "$out: $file $f2dep{$file}\n";
187 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl $type \$\@ \$(SOURCEPATH)/src/$file \$>\n";
192 my $out = find_output $file;
194 my $name = basename $out, '.so';
195 print MAKE ".PHONY: $name\n";
196 print MAKE "$name: $out\n";
198 dep_cpp $file, $out, 'gen-so';
203 my($dir, $outdir) = @_;
206 for my $file (sort readdir DIR) {
207 next unless $file =~ /(.*)\.cpp$/;
208 my $ofile = find_output "$dir/$file";
209 dep_cpp "$dir/$file", $ofile, 'gen-o';
210 push @ofiles, $ofile;
214 my $ofiles = join ' ', @ofiles;
215 my $name = basename $outdir;
216 print MAKE ".PHONY: $name\n";
217 print MAKE "$name: $outdir.so\n";
218 print MAKE "$outdir.so: $ofiles\n";
219 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl link-dir \$\@ ${\SOURCEPATH}/src/$dir \$^ \$>\n";