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/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
2009-09-01 15:04:40 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2009-09-18 14:05:49 +00:00
|
|
|
BEGIN { push @INC, $ENV{SOURCEPATH}; }
|
2009-09-01 15:04:40 +00:00
|
|
|
use make::configure;
|
|
|
|
|
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;
|
2010-05-07 13:39:49 -05:00
|
|
|
my $verbose = ($type =~ s/-v$//);
|
2009-09-01 15:04:40 +00:00
|
|
|
|
2010-05-07 13:39:49 -05:00
|
|
|
if ($type eq 'gen-ld') {
|
|
|
|
do_static_find(@ARGV);
|
|
|
|
} elsif ($type eq 'static-ld') {
|
|
|
|
do_static_link(@ARGV);
|
|
|
|
} elsif ($type eq 'core-ld') {
|
|
|
|
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
|
|
|
|
|
|
|
sub do_static_find {
|
|
|
|
my @flags;
|
|
|
|
for my $file (@ARGV) {
|
2013-08-15 18:55:16 +01:00
|
|
|
push @flags, get_property($file, 'LinkerFlags');
|
2010-01-17 03:17:25 +00:00
|
|
|
}
|
|
|
|
open F, '>', $out;
|
|
|
|
print F join ' ', @flags;
|
|
|
|
close F;
|
2010-05-07 13:39:49 -05:00
|
|
|
exit 0;
|
2010-01-17 03:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub do_static_link {
|
2010-07-02 11:27:17 -04:00
|
|
|
my $execstr = "$ENV{RUNLD} -o $out $ENV{CORELDFLAGS}";
|
2010-01-17 03:17:25 +00:00
|
|
|
for (@ARGV) {
|
|
|
|
if (/\.cmd$/) {
|
|
|
|
open F, '<', $_;
|
|
|
|
my $libs = <F>;
|
|
|
|
chomp $libs;
|
|
|
|
$execstr .= ' '.$libs;
|
|
|
|
close F;
|
|
|
|
} else {
|
|
|
|
$execstr .= ' '.$_;
|
|
|
|
}
|
|
|
|
}
|
2010-07-02 11:27:17 -04:00
|
|
|
$execstr .= ' '.$ENV{LDLIBS};
|
2010-01-17 03:17:25 +00:00
|
|
|
print "$execstr\n" if $verbose;
|
|
|
|
exec $execstr;
|
2010-05-07 13:39:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sub do_core_link {
|
2010-07-02 11:27:17 -04:00
|
|
|
my $execstr = "$ENV{RUNLD} -o $out $ENV{CORELDFLAGS} @_ $ENV{LDLIBS}";
|
2010-05-07 13:39:49 -05:00
|
|
|
print "$execstr\n" if $verbose;
|
|
|
|
exec $execstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub do_link_dir {
|
|
|
|
my $execstr = "$ENV{RUNLD} -o $out $ENV{PICLDFLAGS} @_";
|
|
|
|
print "$execstr\n" if $verbose;
|
|
|
|
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
|
|
|
my $binary = $ENV{RUNCC};
|
|
|
|
if ($do_compile) {
|
2013-08-15 18:55:16 +01:00
|
|
|
$flags = $ENV{CORECXXFLAGS} . ' ' . get_property($file, 'CompileFlags');
|
2010-05-07 13:39:49 -05:00
|
|
|
|
|
|
|
if ($file =~ m#(?:^|/)((?:m|cmd)_[^/. ]+)(?:\.cpp|/.*\.cpp)$#) {
|
2013-07-07 20:01:44 +01:00
|
|
|
$flags .= ' -DMODNAME=\\"'.$1.'\\"';
|
2010-05-07 13:39:49 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$binary = $ENV{RUNLD};
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($do_link) {
|
2010-07-02 11:27:17 -04:00
|
|
|
$flags = join ' ', $flags, $ENV{PICLDFLAGS};
|
2013-08-15 18:55:16 +01:00
|
|
|
$libs = get_property($file, 'LinkerFlags');
|
2010-05-07 13:39:49 -05:00
|
|
|
} else {
|
|
|
|
$flags .= ' -c';
|
|
|
|
}
|
|
|
|
|
2010-07-02 11:27:17 -04:00
|
|
|
my $execstr = "$binary -o $out $flags $file $libs";
|
2010-05-07 13:39:49 -05:00
|
|
|
print "$execstr\n" if $verbose;
|
|
|
|
exec $execstr;
|
2010-01-17 03:17:25 +00:00
|
|
|
}
|