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/>.
39 my $build = $ENV{BUILDPATH};
41 chdir $build or die "Could not open build directory: $!";
43 symlink "$ENV{SOURCEPATH}/include", 'include';
44 mkdir $_ for qw/bin modules obj/;
45 # BSD make has a horribly annoying bug resulting in an extra chdir of the make process
46 # Create symlinks to work around it
47 symlink "../$_", "obj/$_" for qw/bin coremods modules obj/;
50 open MAKE, '>real.mk' or die "Could not write real.mk: $!";
51 chdir "$ENV{SOURCEPATH}/src";
53 if ($ENV{PURE_STATIC}) {
62 my $build = $ENV{BUILDPATH};
64 # DO NOT EDIT THIS FILE
65 # It is autogenerated by make/calcdep.pl, and will be overwritten
66 # every time you rerun make in the main directory
67 VPATH = \$(SOURCEPATH)/src
70 \@echo "This Makefile must be run by a sub-make from the source"
71 \@echo "in order to set the correct environment variables"
74 all: inspircd coremods modules
77 my(@core_deps, @cmodlist, @modlist);
78 for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, "threadengines/threadengine_pthread.cpp") {
79 my $out = find_output $file;
80 dep_cpp $file, $out, 'gen-o';
81 next if $file =~ m#^socketengines/# && $file ne "socketengines/socketengine_$ENV{SOCKETENGINE}.cpp";
82 push @core_deps, $out;
85 opendir my $coremoddir, 'coremods';
86 for my $file (sort readdir $coremoddir) {
87 next if $file =~ /^\./;
88 if ($file =~ /^core_/ && -d "coremods/$file" && dep_dir "coremods/$file", "modules/$file") {
89 mkdir "$build/obj/$file";
90 push @cmodlist, "modules/$file.so";
92 if ($file =~ /^core_.*\.cpp$/) {
93 my $out = dep_so "coremods/$file";
98 opendir my $moddir, 'modules';
99 for my $file (sort readdir $moddir) {
100 next if $file =~ /^\./;
101 if (-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 =~ /^m_/ && -d "modules/$file" && dep_dir "modules/$file", "modules/$file") {
108 mkdir "$build/obj/$file";
109 push @modlist, "modules/$file.so";
111 if ($file =~ /^m_.*\.cpp$/) {
112 my $out = dep_so "modules/$file";
117 my $core_mk = join ' ', @core_deps;
118 my $cmods = join ' ', @cmodlist;
119 my $mods = join ' ', @modlist;
122 bin/inspircd: $core_mk
123 @\$(SOURCEPATH)/make/unit-cc.pl core-ld\$(VERBOSE) \$\@ \$^ \$>
125 inspircd: bin/inspircd
131 .PHONY: all bad-target inspircd coremods modules
138 # DO NOT EDIT THIS FILE
139 # It is autogenerated by make/calcdep.pl, and will be overwritten
140 # every time you rerun make in the main directory
141 VPATH = \$(SOURCEPATH)/src
144 \@echo "This Makefile must be run by a sub-make from the source"
145 \@echo "in order to set the correct environment variables"
152 for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, <coremods/*.cpp>, <coremods/core_*/*.cpp>,
153 <modules/*.cpp>, <modules/m_*/*.cpp>, "threadengines/threadengine_pthread.cpp") {
154 my $out = find_output $file, 1;
155 if ($out =~ m#obj/([^/]+)/[^/]+.o$#) {
156 mkdir "$ENV{BUILDPATH}/obj/$1";
158 dep_cpp $file, $out, 'gen-o';
159 next if $file =~ m#^socketengines/# && $file ne "socketengines/socketengine_$ENV{SOCKETENGINE}.cpp";
164 my $core_mk = join ' ', @deps;
165 my $core_src = join ' ', @srcs;
168 obj/ld-extra.cmd: $core_src
169 \@\$(SOURCEPATH)/make/unit-cc.pl gen-ld\$(VERBOSE) \$\@ \$^ \$>
171 bin/inspircd: obj/ld-extra.cmd $core_mk
172 \@\$(SOURCEPATH)/make/unit-cc.pl static-ld\$(VERBOSE) \$\@ \$^ \$>
174 inspircd: bin/inspircd
176 .PHONY: all bad-target inspircd
182 my($file, $static) = @_;
183 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
184 if ($path eq 'modules/' || $path eq 'coremods/') {
185 return $static ? "obj/$base.o" : "modules/$base.so";
186 } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
187 return "obj/$base.o";
188 } elsif ($path =~ m#modules/(m_.*)/# || $path =~ m#coremods/(core_.*)/#) {
189 return "obj/$1/$base.o";
191 die "Can't determine output for $file";
197 my $basedir = $f =~ m#(.*)/# ? $1 : '.';
198 return $f2dep{$f} if exists $f2dep{$f};
201 my $link = readlink $f;
203 $link = "$basedir/$link" unless $link =~ m#^/#;
206 open my $in, '<', $f or die "Could not read $f";
208 if (/^\s*#\s*include\s*"([^"]+)"/) {
210 next if $inc eq 'config.h' && $f eq '../include/inspircd.h';
212 for my $loc ("$basedir/$inc", "../include/$inc") {
215 $dep{$_}++ for split / /, gendep $loc;
219 if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
220 print STDERR "WARNING: could not find header $inc for $f\n";
221 } elsif ($found > 1 && $basedir ne '../include') {
222 print STDERR "WARNING: ambiguous include $inc in $f\n";
227 $f2dep{$f} = join ' ', sort keys %dep;
232 my($file, $out, $type) = @_;
235 print MAKE "$out: $file $f2dep{$file}\n";
236 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl $type\$(VERBOSE) \$\@ \$(SOURCEPATH)/src/$file \$>\n";
241 my $out = find_output $file;
243 dep_cpp $file, $out, 'gen-so';
248 my($dir, $outdir) = @_;
251 for my $file (sort readdir DIR) {
252 next unless $file =~ /(.*)\.cpp$/;
253 my $ofile = find_output "$dir/$file";
254 dep_cpp "$dir/$file", $ofile, 'gen-o';
255 push @ofiles, $ofile;
259 my $ofiles = join ' ', @ofiles;
260 print MAKE "$outdir.so: $ofiles\n";
261 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl link-dir\$(VERBOSE) \$\@ \$^ \$>\n";