]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/unit-cc.pl
Improve support for NetBSD
[user/henk/code/inspircd.git] / make / unit-cc.pl
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 BEGIN { push @INC, $ENV{SOURCEPATH}; }
5 use make::configure;
6
7 chdir $ENV{BUILDPATH};
8
9 my $out = shift;
10 my $verbose;
11
12 if ($out =~ /^-/) {
13         $_ = $out;
14         $out = shift;
15         $verbose = /v/;
16         if (/f/) {
17                 do_static_find(@ARGV);
18                 exit;
19         }
20         if (/l/) {
21                 do_static_link(@ARGV);
22                 exit;
23         }
24 }
25
26 my $file = shift;
27
28 my $cflags = $ENV{CXXFLAGS};
29 $cflags =~ s/ -pedantic// if nopedantic($file);
30 $cflags .= ' ' . getcompilerflags($file);
31
32 my $flags;
33 if ($out =~ /\.so$/) {
34         $flags = join ' ', $cflags, $ENV{PICLDFLAGS}, getlinkerflags($file);
35 } else {
36         $flags = "$cflags -c";
37 }
38
39 my $execstr = "$ENV{RUNCC} $flags -o $out $file";
40 print "$execstr\n" if $verbose;
41 exec $execstr;
42 exit 1;
43
44 sub do_static_find {
45         my @flags;
46         for my $file (@ARGV) {
47                 push @flags, getlinkerflags($file);
48         }
49         open F, '>', $out;
50         print F join ' ', @flags;
51         close F;
52 }
53
54 sub do_static_link {
55         my $execstr = "$ENV{RUNCC} -o $out $ENV{CORELDFLAGS} $ENV{LDLIBS}";
56         for (@ARGV) {
57                 if (/\.cmd$/) {
58                         open F, '<', $_;
59                         my $libs = <F>;
60                         chomp $libs;
61                         $execstr .= ' '.$libs;
62                         close F;
63                 } else {
64                         $execstr .= ' '.$_;
65                 }
66         }
67         print "$execstr\n" if $verbose;
68         exec $execstr;
69         exit 1;
70 }