4 # InspIRCd -- Internet Relay Chat Daemon
6 # Copyright (C) 2014-2015 Attila Molnar <attilamolnar@hush.com>
7 # Copyright (C) 2013, 2015-2019 Sadie Powell <sadie@witchery.services>
8 # Copyright (C) 2012 Robby <robby@chatbelgie.be>
9 # Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
11 # This file is part of InspIRCd. InspIRCd is free software: you can
12 # redistribute it and/or modify it under the terms of the GNU General Public
13 # License as published by the Free Software Foundation, version 2.
15 # This program is distributed in the hope that it will be useful, but WITHOUT
16 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 push @INC, $ENV{SOURCEPATH};
28 unless (-f 'configure') {
29 print "Error: $0 must be run from the main source directory!\n";
35 use warnings FATAL => qw(all);
37 use File::Basename qw(basename);
42 BUILDPATH => $ENV{BUILDPATH},
43 SOURCEPATH => $ENV{SOURCEPATH}
59 create_directory(BUILDPATH, 0770) or die "Could not create build directory: $!";
60 chdir BUILDPATH or die "Could not open build directory: $!";
62 symlink "${\SOURCEPATH}/include", 'include';
63 mkdir $_ for qw/bin modules obj/;
65 open MAKE, '>real.mk' or die "Could not write real.mk: $!";
66 chdir "${\SOURCEPATH}/src";
74 # DO NOT EDIT THIS FILE
75 # It is autogenerated by make/calcdep.pl, and will be overwritten
76 # every time you rerun make in the main directory
77 VPATH = \$(SOURCEPATH)/src
80 \@echo "This Makefile must be run by a sub-make from the source"
81 \@echo "in order to set the correct environment variables"
87 my(@core_deps, @modlist);
88 for my $file (<*.cpp>, <socketengines/*.cpp>, "threadengines/threadengine_pthread.cpp") {
89 my $out = find_output $file;
90 dep_cpp $file, $out, 'gen-o';
91 next if $file =~ m#^socketengines/# && $file ne "socketengines/socketengine_$ENV{SOCKETENGINE}.cpp";
92 # Having a module in the src directory is a bad idea because it will be linked to the core binary
93 if ($file =~ /^(m|core)_.*\.cpp/) {
94 my $correctsubdir = ($file =~ /^m_/ ? "modules" : "coremods");
95 print "Error: module $file is in the src directory, put it in src/$correctsubdir instead!\n";
98 push @core_deps, $out;
101 foreach my $directory (qw(coremods modules)) {
102 opendir(my $moddir, $directory);
103 for my $file (sort readdir $moddir) {
104 next if $file =~ /^\./;
105 if ($directory eq 'modules' && -e "modules/extra/$file" && !-l "modules/$file") {
107 print "Replacing symlink for $file found in modules/extra\n";
108 rename "modules/$file", "modules/$file~";
109 symlink "extra/$file", "modules/$file";
111 if ($file =~ /^(?:core|m)_/ && -d "$directory/$file" && dep_dir "$directory/$file", "modules/$file") {
112 mkdir "${\BUILDPATH}/obj/$file";
113 push @modlist, "modules/$file.so";
115 if ($file =~ /^.*\.cpp$/) {
116 my $out = dep_so "$directory/$file";
122 my $core_mk = join ' ', @core_deps;
123 my $mods = join ' ', @modlist;
126 bin/inspircd: $core_mk
127 @\$(SOURCEPATH)/make/unit-cc.pl core-ld \$\@ \$^ \$>
129 inspircd: bin/inspircd
133 .PHONY: all bad-target inspircd modules
140 my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
141 if ($path eq 'modules/' || $path eq 'coremods/') {
142 return "modules/$base.so";
143 } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
144 return "obj/$base.o";
145 } elsif ($path =~ m#modules/(m_.*)/# || $path =~ m#coremods/(core_.*)/#) {
146 return "obj/$1/$base.o";
148 die "Can't determine output for $file";
154 my $basedir = $f =~ m#(.*)/# ? $1 : '.';
155 return $f2dep{$f} if exists $f2dep{$f};
158 my $link = readlink $f;
160 $link = "$basedir/$link" unless $link =~ m#^/#;
163 open my $in, '<', $f or die "Could not read $f";
165 if (/^\s*#\s*include\s*"([^"]+)"/) {
167 next if $inc eq 'config.h' && $f eq '../include/inspircd.h';
169 for my $loc ("$basedir/$inc", "../include/$inc") {
172 $dep{$_}++ for split / /, gendep $loc;
176 if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
177 print STDERR "WARNING: could not find header $inc for $f\n";
178 } elsif ($found > 1 && $basedir ne '../include') {
179 print STDERR "WARNING: ambiguous include $inc in $f\n";
184 $f2dep{$f} = join ' ', sort keys %dep;
189 my($file, $out, $type) = @_;
192 print MAKE "$out: $file $f2dep{$file}\n";
193 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl $type \$\@ \$(SOURCEPATH)/src/$file \$>\n";
198 my $out = find_output $file;
200 my $name = basename $out, '.so';
201 print MAKE ".PHONY: $name\n";
202 print MAKE "$name: $out\n";
204 dep_cpp $file, $out, 'gen-so';
209 my($dir, $outdir) = @_;
212 for my $file (sort readdir DIR) {
213 next unless $file =~ /(.*)\.cpp$/;
214 my $ofile = find_output "$dir/$file";
215 dep_cpp "$dir/$file", $ofile, 'gen-o';
216 push @ofiles, $ofile;
220 my $ofiles = join ' ', @ofiles;
221 my $name = basename $outdir;
222 print MAKE ".PHONY: $name\n";
223 print MAKE "$name: $outdir.so\n";
224 print MAKE "$outdir.so: $ofiles\n";
225 print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl link-dir \$\@ ${\SOURCEPATH}/src/$dir \$^ \$>\n";