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
|
|
|
|
#
|
2020-01-11 22:02:47 +00:00
|
|
|
# Copyright (C) 2019 iwalkalone <iwalkalone69@gmail.com>
|
|
|
|
# Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
|
2021-02-26 06:58:13 +00:00
|
|
|
# Copyright (C) 2013, 2015-2016, 2018, 2021 Sadie Powell <sadie@witchery.services>
|
2020-01-11 22:02:47 +00:00
|
|
|
# Copyright (C) 2012 Robby <robby@chatbelgie.be>
|
2012-04-20 18:33:52 +02:00
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
2021-02-28 19:20:08 +00:00
|
|
|
use v5.26.0;
|
2009-09-01 15:04:40 +00:00
|
|
|
use strict;
|
2015-03-22 01:52:10 +00:00
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
|
2021-01-25 12:13:54 +00:00
|
|
|
use File::Basename qw(dirname);
|
2015-03-22 00:54:56 +00:00
|
|
|
use File::Spec::Functions qw(abs2rel);
|
2021-01-25 12:13:54 +00:00
|
|
|
use FindBin qw($RealDir);
|
2015-03-22 00:54:56 +00:00
|
|
|
|
2021-01-25 12:13:54 +00:00
|
|
|
use lib dirname $RealDir;
|
2015-03-22 00:54:56 +00:00
|
|
|
use make::console;
|
2016-09-11 21:19:28 +01:00
|
|
|
use make::directive;
|
2009-09-01 15:04:40 +00:00
|
|
|
|
2009-09-28 01:43:47 +00:00
|
|
|
chdir $ENV{BUILDPATH};
|
|
|
|
|
2010-05-07 13:39:49 -05:00
|
|
|
my $type = shift;
|
2009-09-28 00:55:42 +00:00
|
|
|
my $out = shift;
|
2009-09-01 15:04:40 +00:00
|
|
|
|
2018-07-31 00:49:27 +01:00
|
|
|
if ($type eq 'core-ld') {
|
2010-05-07 13:39:49 -05:00
|
|
|
do_core_link(@ARGV);
|
|
|
|
} elsif ($type eq 'link-dir') {
|
|
|
|
do_link_dir(@ARGV);
|
|
|
|
} elsif ($type eq 'gen-o') {
|
|
|
|
do_compile(1, 0, @ARGV);
|
|
|
|
} elsif ($type eq 'gen-so') {
|
|
|
|
do_compile(1, 1, @ARGV);
|
|
|
|
} elsif ($type eq 'link-so') {
|
|
|
|
do_compile(0, 1, @ARGV);
|
2009-09-01 15:04:40 +00:00
|
|
|
} else {
|
2010-05-07 13:39:49 -05:00
|
|
|
print STDERR "Unknown unit-cc subcommand $type!\n";
|
2009-09-01 15:04:40 +00:00
|
|
|
}
|
|
|
|
exit 1;
|
2010-01-17 03:17:25 +00:00
|
|
|
|
2015-03-22 00:54:56 +00:00
|
|
|
sub message($$$) {
|
|
|
|
my ($type, $file, $command) = @_;
|
2016-04-04 15:37:33 +01:00
|
|
|
if ($ENV{INSPIRCD_VERBOSE}) {
|
2021-01-27 16:47:08 +00:00
|
|
|
say $command;
|
2015-03-22 00:54:56 +00:00
|
|
|
} else {
|
2021-01-27 16:47:08 +00:00
|
|
|
say console_format "\t<|GREEN $type:|>\t\t$file";
|
2015-03-22 00:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-11 21:19:28 +01:00
|
|
|
sub rpath($) {
|
|
|
|
my $message = shift;
|
|
|
|
$message =~ s/-L(\S+)/-Wl,-rpath,$1 -L$1/g unless defined $ENV{INSPIRCD_DISABLE_RPATH};
|
|
|
|
return $message;
|
|
|
|
}
|
|
|
|
|
2010-05-07 13:39:49 -05:00
|
|
|
sub do_core_link {
|
2015-03-22 00:54:56 +00:00
|
|
|
my $execstr = "$ENV{CXX} -o $out $ENV{CORELDFLAGS} @_ $ENV{LDLIBS}";
|
|
|
|
message 'LINK', $out, $execstr;
|
2010-05-07 13:39:49 -05:00
|
|
|
exec $execstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub do_link_dir {
|
2015-06-03 14:53:09 +01:00
|
|
|
my ($dir, $link_flags) = (shift, '');
|
|
|
|
for my $file (<$dir/*.cpp>) {
|
2016-09-11 21:19:28 +01:00
|
|
|
$link_flags .= rpath(get_directive($file, 'LinkerFlags', '')) . ' ';
|
2015-06-03 14:53:09 +01:00
|
|
|
}
|
2019-04-22 02:35:55 +02:00
|
|
|
my $execstr = "$ENV{CXX} -o $out $ENV{PICLDFLAGS} @_ $link_flags";
|
2015-03-22 00:54:56 +00:00
|
|
|
message 'LINK', $out, $execstr;
|
2010-05-07 13:39:49 -05:00
|
|
|
exec $execstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub do_compile {
|
|
|
|
my ($do_compile, $do_link, $file) = @_;
|
|
|
|
|
|
|
|
my $flags = '';
|
2010-07-02 11:27:17 -04:00
|
|
|
my $libs = '';
|
2010-05-07 13:39:49 -05:00
|
|
|
if ($do_compile) {
|
2016-09-11 21:19:28 +01:00
|
|
|
$flags = $ENV{CORECXXFLAGS} . ' ' . get_directive($file, 'CompilerFlags', '');
|
2010-05-07 13:39:49 -05:00
|
|
|
|
2014-03-05 16:28:29 +01:00
|
|
|
if ($file =~ m#(?:^|/)((?:m|core)_[^/. ]+)(?:\.cpp|/.*\.cpp)$#) {
|
2013-07-07 20:01:44 +01:00
|
|
|
$flags .= ' -DMODNAME=\\"'.$1.'\\"';
|
2010-05-07 13:39:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($do_link) {
|
2010-07-02 11:27:17 -04:00
|
|
|
$flags = join ' ', $flags, $ENV{PICLDFLAGS};
|
2016-09-11 21:19:28 +01:00
|
|
|
$libs = rpath(get_directive($file, 'LinkerFlags', ''));
|
2010-05-07 13:39:49 -05:00
|
|
|
} else {
|
|
|
|
$flags .= ' -c';
|
|
|
|
}
|
|
|
|
|
2015-03-22 00:54:56 +00:00
|
|
|
my $execstr = "$ENV{CXX} -o $out $flags $file $libs";
|
|
|
|
message 'BUILD', abs2rel($file, "$ENV{SOURCEPATH}/src"), $execstr;
|
2010-05-07 13:39:49 -05:00
|
|
|
exec $execstr;
|
2010-01-17 03:17:25 +00:00
|
|
|
}
|