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"
80 all: inspircd coremods modules
83 my(@core_deps, @cmodlist, @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 opendir my $coremoddir, 'coremods';
92 for my $file (sort readdir $coremoddir) {
93 next if $file =~ /^\./;
94 if ($file =~ /^core_/ && -d "coremods/$file" && dep_dir "coremods/$file", "modules/$file") {
95 mkdir "${\BUILDPATH}/obj/$file";
96 push @cmodlist, "modules/$file.so";
98 if ($file =~ /^core_.*\.cpp$/) {
99 my $out = dep_so "coremods/$file";
100 push @cmodlist, $out;
104 opendir my $moddir, 'modules';
105 for my $file (sort readdir $moddir) {
106 next if $file =~ /^\./;
107 if (-e "modules/extra/$file" && !-l "modules/$file") {
109 print "Replacing symlink for $file found in modules/extra\n";
110 rename "modules/$file", "modules/$file~";
111 symlink "extra/$file", "modules/$file";
113 if ($file =~ /^m_/ && -d "modules/$file" && dep_dir "modules/$file", "modules/$file") {
114 mkdir "${\BUILDPATH}/obj/$file";
115 push @modlist, "modules/$file.so";
117 if ($file =~ /^m_.*\.cpp$/) {
118 my $out = dep_so "modules/$file";
123 my $core_mk = join ' ', @core_deps;
124 my $cmods = join ' ', @cmodlist;
125 my $mods = join ' ', @modlist;
128 bin/inspircd: $core_mk
129 @\$(SOURCEPATH)/make/unit-cc.pl core-ld\$(VERBOSE) \$\@ \$^ \$>
131 inspircd: bin/inspircd
137 .PHONY: all bad-target inspircd coremods modules
144 # DO NOT EDIT THIS FILE
145 # It is autogenerated by make/calcdep.pl, and will be overwritten
146 # every time you rerun make in the main directory
147 VPATH = \$(SOURCEPATH)/src
150 \@echo "This Makefile must be run by a sub-make from the source"
151 \@echo "in order to set the correct environment variables"
158 for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, <coremods/*.cpp>, <coremods/core_*/*.cpp>,
159 <modules/*.cpp>, <modules/m_*/*.cpp>, "threadengines/threadengine_pthread.cpp") {
160 my $out = find_output $file, 1;
161 if ($out =~ m#obj/([^/]+)/[^/]+.o$#) {
162 mkdir "${\BUILDPATH}/obj/$1";
164 dep_cpp $file, $out, 'gen-o';
165 next if $file =~ m#^socketengines/# && $file ne "socketengines/socketengine_$ENV{SOCKETENGINE}.cpp";
170 my $core_mk = join ' ', @deps;
171 my $core_src = join ' ', @srcs;
174 obj/ld-extra.cmd: $core_src
175 \@\$(SOURCEPATH)/make/unit-cc.pl gen-ld\$(VERBOSE) \$\@ \$^ \$>
177 bin/inspircd: obj/ld-extra.cmd $core_mk
178 \@\$(SOURCEPATH)/make/unit-cc.pl static-ld\$(VERBOSE) \$\@ \$^ \$>
180 inspircd: bin/inspircd
182 .PHONY: all bad-target inspircd
188 my($file, $static) = @_;
189 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
190 if ($path eq 'modules/' || $path eq 'coremods/') {
191 return $static ? "obj/$base.o" : "modules/$base.so";
192 } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
193 return "obj/$base.o";
194 } elsif ($path =~ m#modules/(m_.*)/# || $path =~ m#coremods/(core_.*)/#) {
195 return "obj/$1/$base.o";
197 die "Can't determine output for $file";
203 my $basedir = $f =~ m#(.*)/# ? $1 : '.';
204 return $f2dep{$f} if exists $f2dep{$f};
207 my $link = readlink $f;
209 $link = "$basedir/$link" unless $link =~ m#^/#;
212 open my $in, '<', $f or die "Could not read $f";
214 if (/^\s*#\s*include\s*"([^"]+)"/) {
216 next if $inc eq 'config.h' && $f eq '../include/inspircd.h';
218 for my $loc ("$basedir/$inc", "../include/$inc") {
221 $dep{$_}++ for split / /, gendep $loc;
225 if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
226 print STDERR "WARNING: could not find header $inc for $f\n";
227 } elsif ($found > 1 && $basedir ne '../include') {
228 print STDERR "WARNING: ambiguous include $inc in $f\n";
233 $f2dep{$f} = join ' ', sort keys %dep;
238 my($file, $out, $type) = @_;
241 print MAKE "$out: $file $f2dep{$file}\n";
242 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl $type\$(VERBOSE) \$\@ \$(SOURCEPATH)/src/$file \$>\n";
247 my $out = find_output $file;
249 dep_cpp $file, $out, 'gen-so';
254 my($dir, $outdir) = @_;
257 for my $file (sort readdir DIR) {
258 next unless $file =~ /(.*)\.cpp$/;
259 my $ofile = find_output "$dir/$file";
260 dep_cpp "$dir/$file", $ofile, 'gen-o';
261 push @ofiles, $ofile;
265 my $ofiles = join ' ', @ofiles;
266 print MAKE "$outdir.so: $ofiles\n";
267 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl link-dir\$(VERBOSE) \$\@ \$^ \$>\n";