2010-02-12 00:03:44 +00:00
|
|
|
#!/usr/bin/env perl
|
2012-04-20 18:33:52 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# InspIRCd -- Internet Relay Chat Daemon
|
|
|
|
#
|
|
|
|
# Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
|
|
|
|
#
|
|
|
|
# This file is part of InspIRCd. InspIRCd is free software: you can
|
|
|
|
# redistribute it and/or modify it under the terms of the GNU General Public
|
|
|
|
# License as published by the Free Software Foundation, version 2.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
2015-02-07 17:55:20 +00:00
|
|
|
BEGIN {
|
2019-10-16 11:55:14 +01:00
|
|
|
push @INC, $ENV{SOURCEPATH};
|
2015-02-07 17:55:20 +00:00
|
|
|
require 5.10.0;
|
|
|
|
unless (-f 'configure') {
|
|
|
|
print "Error: $0 must be run from the main source directory!\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-01 15:04:40 +00:00
|
|
|
use strict;
|
2015-02-07 17:55:20 +00:00
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
|
2017-10-18 17:16:32 +01:00
|
|
|
use File::Basename qw(basename);
|
|
|
|
|
2019-10-16 11:55:14 +01:00
|
|
|
use make::common;
|
|
|
|
|
2015-02-07 17:58:16 +00:00
|
|
|
use constant {
|
|
|
|
BUILDPATH => $ENV{BUILDPATH},
|
|
|
|
SOURCEPATH => $ENV{SOURCEPATH}
|
|
|
|
};
|
2009-09-01 15:04:40 +00:00
|
|
|
|
2009-11-11 00:17:07 +00:00
|
|
|
sub find_output;
|
2009-09-17 03:04:27 +00:00
|
|
|
sub gendep($);
|
2010-05-07 13:39:49 -05:00
|
|
|
sub dep_cpp($$$);
|
|
|
|
sub dep_so($);
|
2014-03-05 16:28:29 +01:00
|
|
|
sub dep_dir($$);
|
2009-09-17 03:04:27 +00:00
|
|
|
sub run();
|
2009-09-16 20:00:15 +00:00
|
|
|
|
2009-09-01 15:05:11 +00:00
|
|
|
my %f2dep;
|
2009-09-01 15:04:40 +00:00
|
|
|
|
2009-09-17 03:04:27 +00:00
|
|
|
run;
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
sub run() {
|
2019-10-16 11:55:14 +01:00
|
|
|
create_directory(BUILDPATH, 0770) or die "Could not create build directory: $!";
|
2015-02-07 17:58:16 +00:00
|
|
|
chdir BUILDPATH or die "Could not open build directory: $!";
|
2010-09-08 20:06:25 -04:00
|
|
|
unlink 'include';
|
2015-02-07 17:58:16 +00:00
|
|
|
symlink "${\SOURCEPATH}/include", 'include';
|
2009-09-28 15:39:46 +00:00
|
|
|
mkdir $_ for qw/bin modules obj/;
|
|
|
|
|
2009-09-17 03:04:27 +00:00
|
|
|
open MAKE, '>real.mk' or die "Could not write real.mk: $!";
|
2015-02-07 17:58:16 +00:00
|
|
|
chdir "${\SOURCEPATH}/src";
|
2009-09-17 03:04:27 +00:00
|
|
|
|
2018-07-31 00:49:27 +01:00
|
|
|
run_dynamic();
|
2009-11-11 00:17:07 +00:00
|
|
|
close MAKE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub run_dynamic() {
|
2009-09-17 03:04:27 +00:00
|
|
|
print MAKE <<END;
|
2009-11-03 01:14:04 +00:00
|
|
|
# DO NOT EDIT THIS FILE
|
|
|
|
# It is autogenerated by make/calcdep.pl, and will be overwritten
|
|
|
|
# every time you rerun make in the main directory
|
2009-09-17 03:04:27 +00:00
|
|
|
VPATH = \$(SOURCEPATH)/src
|
|
|
|
|
2009-11-03 01:14:04 +00:00
|
|
|
bad-target:
|
|
|
|
\@echo "This Makefile must be run by a sub-make from the source"
|
|
|
|
\@echo "in order to set the correct environment variables"
|
|
|
|
\@exit 1
|
|
|
|
|
2015-02-07 19:19:56 +00:00
|
|
|
all: inspircd modules
|
2009-09-17 03:04:27 +00:00
|
|
|
|
|
|
|
END
|
2015-02-07 19:19:56 +00:00
|
|
|
my(@core_deps, @modlist);
|
2017-12-03 17:16:28 +00:00
|
|
|
for my $file (<*.cpp>, <socketengines/*.cpp>, "threadengines/threadengine_pthread.cpp") {
|
2009-09-17 03:04:27 +00:00
|
|
|
my $out = find_output $file;
|
2010-05-07 13:39:49 -05:00
|
|
|
dep_cpp $file, $out, 'gen-o';
|
2013-07-05 08:07:52 +01:00
|
|
|
next if $file =~ m#^socketengines/# && $file ne "socketengines/socketengine_$ENV{SOCKETENGINE}.cpp";
|
2015-11-16 10:26:27 +01:00
|
|
|
# Having a module in the src directory is a bad idea because it will be linked to the core binary
|
|
|
|
if ($file =~ /^(m|core)_.*\.cpp/) {
|
|
|
|
my $correctsubdir = ($file =~ /^m_/ ? "modules" : "coremods");
|
|
|
|
print "Error: module $file is in the src directory, put it in src/$correctsubdir instead!\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
2009-09-17 03:04:27 +00:00
|
|
|
push @core_deps, $out;
|
|
|
|
}
|
2009-10-10 17:06:52 +00:00
|
|
|
|
2015-02-07 19:19:56 +00:00
|
|
|
foreach my $directory (qw(coremods modules)) {
|
|
|
|
opendir(my $moddir, $directory);
|
|
|
|
for my $file (sort readdir $moddir) {
|
|
|
|
next if $file =~ /^\./;
|
|
|
|
if ($directory eq 'modules' && -e "modules/extra/$file" && !-l "modules/$file") {
|
|
|
|
# Incorrect symlink?
|
|
|
|
print "Replacing symlink for $file found in modules/extra\n";
|
|
|
|
rename "modules/$file", "modules/$file~";
|
|
|
|
symlink "extra/$file", "modules/$file";
|
|
|
|
}
|
|
|
|
if ($file =~ /^(?:core|m)_/ && -d "$directory/$file" && dep_dir "$directory/$file", "modules/$file") {
|
|
|
|
mkdir "${\BUILDPATH}/obj/$file";
|
|
|
|
push @modlist, "modules/$file.so";
|
|
|
|
}
|
|
|
|
if ($file =~ /^.*\.cpp$/) {
|
|
|
|
my $out = dep_so "$directory/$file";
|
|
|
|
push @modlist, $out;
|
|
|
|
}
|
2009-09-17 14:13:17 +00:00
|
|
|
}
|
2009-09-17 03:04:27 +00:00
|
|
|
}
|
2019-01-24 22:06:27 +00:00
|
|
|
|
2009-09-17 03:04:27 +00:00
|
|
|
my $core_mk = join ' ', @core_deps;
|
|
|
|
my $mods = join ' ', @modlist;
|
|
|
|
print MAKE <<END;
|
|
|
|
|
|
|
|
bin/inspircd: $core_mk
|
2016-04-04 15:37:33 +01:00
|
|
|
@\$(SOURCEPATH)/make/unit-cc.pl core-ld \$\@ \$^ \$>
|
2009-09-17 03:04:27 +00:00
|
|
|
|
|
|
|
inspircd: bin/inspircd
|
2009-10-10 17:06:52 +00:00
|
|
|
|
2009-09-17 03:04:27 +00:00
|
|
|
modules: $mods
|
|
|
|
|
2015-02-07 19:19:56 +00:00
|
|
|
.PHONY: all bad-target inspircd modules
|
2009-09-17 03:04:27 +00:00
|
|
|
|
|
|
|
END
|
|
|
|
}
|
|
|
|
|
2009-11-11 00:17:07 +00:00
|
|
|
sub find_output {
|
2018-07-31 00:49:27 +01:00
|
|
|
my $file = shift;
|
2009-09-17 03:04:27 +00:00
|
|
|
my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
|
2014-03-05 16:28:29 +01:00
|
|
|
if ($path eq 'modules/' || $path eq 'coremods/') {
|
2018-07-31 00:49:27 +01:00
|
|
|
return "modules/$base.so";
|
2009-09-17 03:04:27 +00:00
|
|
|
} elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
|
|
|
|
return "obj/$base.o";
|
2014-03-05 16:28:29 +01:00
|
|
|
} elsif ($path =~ m#modules/(m_.*)/# || $path =~ m#coremods/(core_.*)/#) {
|
2009-09-17 03:04:27 +00:00
|
|
|
return "obj/$1/$base.o";
|
|
|
|
} else {
|
|
|
|
die "Can't determine output for $file";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub gendep($) {
|
2009-09-01 15:05:11 +00:00
|
|
|
my $f = shift;
|
|
|
|
my $basedir = $f =~ m#(.*)/# ? $1 : '.';
|
|
|
|
return $f2dep{$f} if exists $f2dep{$f};
|
|
|
|
$f2dep{$f} = '';
|
|
|
|
my %dep;
|
2009-09-13 20:32:55 +00:00
|
|
|
my $link = readlink $f;
|
|
|
|
if (defined $link) {
|
|
|
|
$link = "$basedir/$link" unless $link =~ m#^/#;
|
|
|
|
$dep{$link}++;
|
|
|
|
}
|
2009-09-01 22:44:44 +00:00
|
|
|
open my $in, '<', $f or die "Could not read $f";
|
2009-09-01 15:05:11 +00:00
|
|
|
while (<$in>) {
|
|
|
|
if (/^\s*#\s*include\s*"([^"]+)"/) {
|
|
|
|
my $inc = $1;
|
2013-04-05 16:39:40 +01:00
|
|
|
next if $inc eq 'config.h' && $f eq '../include/inspircd.h';
|
2009-09-01 22:44:44 +00:00
|
|
|
my $found = 0;
|
2009-09-17 03:04:27 +00:00
|
|
|
for my $loc ("$basedir/$inc", "../include/$inc") {
|
2009-09-01 15:05:11 +00:00
|
|
|
next unless -e $loc;
|
2009-09-01 22:44:44 +00:00
|
|
|
$found++;
|
2009-09-01 15:05:11 +00:00
|
|
|
$dep{$_}++ for split / /, gendep $loc;
|
2009-09-17 03:04:27 +00:00
|
|
|
$loc =~ s#^\.\./##;
|
|
|
|
$dep{$loc}++;
|
2009-09-01 15:05:11 +00:00
|
|
|
}
|
2009-09-01 22:44:44 +00:00
|
|
|
if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
|
|
|
|
print STDERR "WARNING: could not find header $inc for $f\n";
|
2009-09-17 03:04:27 +00:00
|
|
|
} elsif ($found > 1 && $basedir ne '../include') {
|
2009-09-01 22:44:44 +00:00
|
|
|
print STDERR "WARNING: ambiguous include $inc in $f\n";
|
|
|
|
}
|
2009-09-01 15:05:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close $in;
|
|
|
|
$f2dep{$f} = join ' ', sort keys %dep;
|
|
|
|
$f2dep{$f};
|
|
|
|
}
|
2009-09-01 15:04:40 +00:00
|
|
|
|
2010-05-07 13:39:49 -05:00
|
|
|
sub dep_cpp($$$) {
|
|
|
|
my($file, $out, $type) = @_;
|
2009-09-01 22:44:44 +00:00
|
|
|
gendep $file;
|
2009-09-01 15:04:40 +00:00
|
|
|
|
2009-09-17 03:04:27 +00:00
|
|
|
print MAKE "$out: $file $f2dep{$file}\n";
|
2016-04-04 15:37:33 +01:00
|
|
|
print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl $type \$\@ \$(SOURCEPATH)/src/$file \$>\n";
|
2010-05-07 13:39:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sub dep_so($) {
|
|
|
|
my($file) = @_;
|
|
|
|
my $out = find_output $file;
|
|
|
|
|
2017-10-18 17:16:32 +01:00
|
|
|
my $name = basename $out, '.so';
|
|
|
|
print MAKE ".PHONY: $name\n";
|
|
|
|
print MAKE "$name: $out\n";
|
|
|
|
|
2014-02-26 20:19:58 +00:00
|
|
|
dep_cpp $file, $out, 'gen-so';
|
2010-05-07 13:39:49 -05:00
|
|
|
return $out;
|
2009-09-01 22:44:44 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 16:28:29 +01:00
|
|
|
sub dep_dir($$) {
|
|
|
|
my($dir, $outdir) = @_;
|
2009-09-17 03:04:27 +00:00
|
|
|
my @ofiles;
|
|
|
|
opendir DIR, $dir;
|
2009-09-30 17:12:08 +00:00
|
|
|
for my $file (sort readdir DIR) {
|
2009-09-17 03:04:27 +00:00
|
|
|
next unless $file =~ /(.*)\.cpp$/;
|
|
|
|
my $ofile = find_output "$dir/$file";
|
2010-05-07 13:39:49 -05:00
|
|
|
dep_cpp "$dir/$file", $ofile, 'gen-o';
|
2009-09-17 03:04:27 +00:00
|
|
|
push @ofiles, $ofile;
|
2009-09-01 22:44:44 +00:00
|
|
|
}
|
2009-09-17 03:04:27 +00:00
|
|
|
closedir DIR;
|
2009-09-17 14:13:17 +00:00
|
|
|
if (@ofiles) {
|
|
|
|
my $ofiles = join ' ', @ofiles;
|
2017-10-18 17:16:32 +01:00
|
|
|
my $name = basename $outdir;
|
|
|
|
print MAKE ".PHONY: $name\n";
|
|
|
|
print MAKE "$name: $outdir.so\n";
|
2014-03-05 16:28:29 +01:00
|
|
|
print MAKE "$outdir.so: $ofiles\n";
|
2016-04-04 15:37:33 +01:00
|
|
|
print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl link-dir \$\@ ${\SOURCEPATH}/src/$dir \$^ \$>\n";
|
2009-09-17 14:13:17 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-01 22:44:44 +00:00
|
|
|
}
|
|
|
|
|