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 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 commands modules
77 my(@core_deps, @cmdlist, @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/$ENV{SOCKETENGINE}.cpp";
82 push @core_deps, $out;
85 for my $file (<commands/*.cpp>) {
86 my $out = dep_so $file;
90 opendir my $moddir, 'modules';
91 for my $file (sort readdir $moddir) {
92 next if $file =~ /^\./;
93 if (-e "modules/extra/$file" && !-l "modules/$file") {
95 print "Replacing symlink for $file found in modules/extra\n";
96 rename "modules/$file", "modules/$file~";
97 symlink "extra/$file", "modules/$file";
99 if ($file =~ /^m_/ && -d "modules/$file" && dep_dir "modules/$file") {
100 mkdir "$build/obj/$file";
101 push @modlist, "modules/$file.so";
103 if ($file =~ /^m_.*\.cpp$/) {
104 my $out = dep_so "modules/$file";
109 my $core_mk = join ' ', @core_deps;
110 my $cmds = join ' ', @cmdlist;
111 my $mods = join ' ', @modlist;
114 bin/inspircd: $core_mk
115 @\$(SOURCEPATH)/make/unit-cc.pl core-ld\$(VERBOSE) \$\@ \$^ \$>
117 inspircd: bin/inspircd
123 .PHONY: all bad-target inspircd commands modules
130 # DO NOT EDIT THIS FILE
131 # It is autogenerated by make/calcdep.pl, and will be overwritten
132 # every time you rerun make in the main directory
133 VPATH = \$(SOURCEPATH)/src
136 \@echo "This Makefile must be run by a sub-make from the source"
137 \@echo "in order to set the correct environment variables"
144 for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, <commands/*.cpp>,
145 <modules/*.cpp>, <modules/m_*/*.cpp>, "threadengines/threadengine_pthread.cpp") {
146 my $out = find_output $file, 1;
147 if ($out =~ m#obj/([^/]+)/[^/]+.o$#) {
148 mkdir "$ENV{BUILDPATH}/obj/$1";
150 dep_cpp $file, $out, 'gen-o';
151 next if $file =~ m#^socketengines/# && $file ne "socketengines/$ENV{SOCKETENGINE}.cpp";
156 my $core_mk = join ' ', @deps;
157 my $core_src = join ' ', @srcs;
160 obj/ld-extra.cmd: $core_src
161 \@\$(SOURCEPATH)/make/unit-cc.pl gen-ld\$(VERBOSE) \$\@ \$^ \$>
163 bin/inspircd: obj/ld-extra.cmd $core_mk
164 \@\$(SOURCEPATH)/make/unit-cc.pl static-ld\$(VERBOSE) \$\@ \$^ \$>
166 inspircd: bin/inspircd
168 .PHONY: all bad-target inspircd
174 my($file, $static) = @_;
175 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
176 if ($path eq 'modules/' || $path eq 'commands/') {
177 return $static ? "obj/$base.o" : "modules/$base.so";
178 } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
179 return "obj/$base.o";
180 } elsif ($path =~ m#modules/(m_.*)/#) {
181 return "obj/$1/$base.o";
183 die "Can't determine output for $file";
189 my $basedir = $f =~ m#(.*)/# ? $1 : '.';
190 return $f2dep{$f} if exists $f2dep{$f};
193 my $link = readlink $f;
195 $link = "$basedir/$link" unless $link =~ m#^/#;
198 open my $in, '<', $f or die "Could not read $f";
200 if (/^\s*#\s*include\s*"([^"]+)"/) {
202 next if $inc eq 'inspircd_version.h' && $f eq '../include/inspircd.h';
204 for my $loc ("$basedir/$inc", "../include/$inc") {
207 $dep{$_}++ for split / /, gendep $loc;
211 if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
212 print STDERR "WARNING: could not find header $inc for $f\n";
213 } elsif ($found > 1 && $basedir ne '../include') {
214 print STDERR "WARNING: ambiguous include $inc in $f\n";
219 $f2dep{$f} = join ' ', sort keys %dep;
224 my($file, $out, $type) = @_;
227 print MAKE "$out: $file $f2dep{$file}\n";
228 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl $type\$(VERBOSE) \$\@ \$< \$>\n";
233 my $out = find_output $file;
234 my $split = find_output $file, 1;
236 if ($ENV{SPLIT_CC}) {
237 dep_cpp $file, $split, 'gen-o';
238 print MAKE "$out: $split\n";
239 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl link-so\$(VERBOSE) \$\@ \$< \$>\n";
241 dep_cpp $file, $out, 'gen-so';
250 for my $file (sort readdir DIR) {
251 next unless $file =~ /(.*)\.cpp$/;
252 my $ofile = find_output "$dir/$file";
253 dep_cpp "$dir/$file", $ofile, 'gen-o';
254 push @ofiles, $ofile;
258 my $ofiles = join ' ', @ofiles;
259 print MAKE "$dir.so: $ofiles\n";
260 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl link-dir\$(VERBOSE) \$\@ \$^ \$>\n";