summaryrefslogtreecommitdiff
path: root/make/unit-cc.pl
blob: aefefa4ac8511162e3b5b219a29efa0b44e51765 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env perl
use strict;
use warnings;
BEGIN { push @INC, $ENV{SOURCEPATH}; }
use make::configure;

chdir $ENV{BUILDPATH};

my $out = shift;
my $verbose;

if ($out =~ /^-/) {
	$_ = $out;
	$out = shift;
	$verbose = /v/;
	if (/f/) {
		do_static_find(@ARGV);
		exit;
	}
	if (/l/) {
		do_static_link(@ARGV);
		exit;
	}
}

my $file = shift;

my $cflags = $ENV{CXXFLAGS};
$cflags =~ s/ -pedantic// if nopedantic($file);
$cflags .= ' ' . getcompilerflags($file);

if ($file =~ m#(?:^|/)((?:m|cmd)_[^/. ]+)(?:\.cpp|/.*\.cpp)$#) {
	$cflags .= ' -DMODNAME='.$1.'.so';
}

my $flags;
if ($out =~ /\.so$/) {
	$flags = join ' ', $cflags, $ENV{PICLDFLAGS}, getlinkerflags($file);
} else {
	$flags = "$cflags -c";
}

my $execstr = "$ENV{RUNCC} $flags -o $out $file";
print "$execstr\n" if $verbose;
exec $execstr;
exit 1;

sub do_static_find {
	my @flags;
	for my $file (@ARGV) {
		push @flags, getlinkerflags($file);
	}
	open F, '>', $out;
	print F join ' ', @flags;
	close F;
}

sub do_static_link {
	my $execstr = "$ENV{RUNCC} -o $out $ENV{CORELDFLAGS} $ENV{LDLIBS}";
	for (@ARGV) {
		if (/\.cmd$/) {
			open F, '<', $_;
			my $libs = <F>;
			chomp $libs;
			$execstr .= ' '.$libs;
			close F;
		} else {
			$execstr .= ' '.$_;
		}
	}
	print "$execstr\n" if $verbose;
	exec $execstr;
	exit 1;
}