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 # Having a module in the src directory is a bad idea because it will be linked to the core binary
89 if ($file =~ /^(m|core)_.*\.cpp/) {
90 my $correctsubdir = ($file =~ /^m_/ ? "modules" : "coremods");
91 print "Error: module $file is in the src directory, put it in src/$correctsubdir instead!\n";
94 push @core_deps, $out;
97 foreach my $directory (qw(coremods modules)) {
98 opendir(my $moddir, $directory);
99 for my $file (sort readdir $moddir) {
100 next if $file =~ /^\./;
101 if ($directory eq 'modules' && -e "modules/extra/$file" && !-l "modules/$file") {
103 print "Replacing symlink for $file found in modules/extra\n";
104 rename "modules/$file", "modules/$file~";
105 symlink "extra/$file", "modules/$file";
107 if ($file =~ /^(?:core|m)_/ && -d "$directory/$file" && dep_dir "$directory/$file", "modules/$file") {
108 mkdir "${\BUILDPATH}/obj/$file";
109 push @modlist, "modules/$file.so";
111 if ($file =~ /^.*\.cpp$/) {
112 my $out = dep_so "$directory/$file";
118 my $core_mk = join ' ', @core_deps;
119 my $mods = join ' ', @modlist;
122 bin/inspircd: $core_mk
123 @\$(SOURCEPATH)/make/unit-cc.pl core-ld\$(VERBOSE) \$\@ \$^ \$>
125 inspircd: bin/inspircd
129 .PHONY: all bad-target inspircd modules
136 # DO NOT EDIT THIS FILE
137 # It is autogenerated by make/calcdep.pl, and will be overwritten
138 # every time you rerun make in the main directory
139 VPATH = \$(SOURCEPATH)/src
142 \@echo "This Makefile must be run by a sub-make from the source"
143 \@echo "in order to set the correct environment variables"
150 for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, <coremods/*.cpp>, <coremods/core_*/*.cpp>,
151 <modules/*.cpp>, <modules/m_*/*.cpp>, "threadengines/threadengine_pthread.cpp") {
152 my $out = find_output $file, 1;
153 if ($out =~ m#obj/([^/]+)/[^/]+.o$#) {
154 mkdir "${\BUILDPATH}/obj/$1";
156 dep_cpp $file, $out, 'gen-o';
157 next if $file =~ m#^socketengines/# && $file ne "socketengines/socketengine_$ENV{SOCKETENGINE}.cpp";
162 my $core_mk = join ' ', @deps;
163 my $core_src = join ' ', @srcs;
166 obj/ld-extra.cmd: $core_src
167 \@\$(SOURCEPATH)/make/unit-cc.pl gen-ld\$(VERBOSE) \$\@ \$^ \$>
169 bin/inspircd: obj/ld-extra.cmd $core_mk
170 \@\$(SOURCEPATH)/make/unit-cc.pl static-ld\$(VERBOSE) \$\@ \$^ \$>
172 inspircd: bin/inspircd
174 .PHONY: all bad-target inspircd
180 my($file, $static) = @_;
181 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
182 if ($path eq 'modules/' || $path eq 'coremods/') {
183 return $static ? "obj/$base.o" : "modules/$base.so";
184 } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
185 return "obj/$base.o";
186 } elsif ($path =~ m#modules/(m_.*)/# || $path =~ m#coremods/(core_.*)/#) {
187 return "obj/$1/$base.o";
189 die "Can't determine output for $file";
195 my $basedir = $f =~ m#(.*)/# ? $1 : '.';
196 return $f2dep{$f} if exists $f2dep{$f};
199 my $link = readlink $f;
201 $link = "$basedir/$link" unless $link =~ m#^/#;
204 open my $in, '<', $f or die "Could not read $f";
206 if (/^\s*#\s*include\s*"([^"]+)"/) {
208 next if $inc eq 'config.h' && $f eq '../include/inspircd.h';
210 for my $loc ("$basedir/$inc", "../include/$inc") {
213 $dep{$_}++ for split / /, gendep $loc;
217 if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
218 print STDERR "WARNING: could not find header $inc for $f\n";
219 } elsif ($found > 1 && $basedir ne '../include') {
220 print STDERR "WARNING: ambiguous include $inc in $f\n";
225 $f2dep{$f} = join ' ', sort keys %dep;
230 my($file, $out, $type) = @_;
233 print MAKE "$out: $file $f2dep{$file}\n";
234 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl $type\$(VERBOSE) \$\@ \$(SOURCEPATH)/src/$file \$>\n";
239 my $out = find_output $file;
241 dep_cpp $file, $out, 'gen-so';
246 my($dir, $outdir) = @_;
249 for my $file (sort readdir DIR) {
250 next unless $file =~ /(.*)\.cpp$/;
251 my $ofile = find_output "$dir/$file";
252 dep_cpp "$dir/$file", $ofile, 'gen-o';
253 push @ofiles, $ofile;
257 my $ofiles = join ' ', @ofiles;
258 print MAKE "$outdir.so: $ofiles\n";
259 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl link-dir\$(VERBOSE) \$\@ ${\SOURCEPATH}/src/$dir \$^ \$>\n";