]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/unit-cc.pl
Change argument order of LDLIBS to work properly with -Wl,--as-needed
[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 $type = shift;
10 my $out = shift;
11 my $verbose = ($type =~ s/-v$//);
12
13 if ($type eq 'gen-ld') {
14         do_static_find(@ARGV);
15 } elsif ($type eq 'static-ld') {
16         do_static_link(@ARGV);
17 } elsif ($type eq 'core-ld') {
18         do_core_link(@ARGV);
19 } elsif ($type eq 'link-dir') {
20         do_link_dir(@ARGV);
21 } elsif ($type eq 'gen-o') {
22         do_compile(1, 0, @ARGV);
23 } elsif ($type eq 'gen-so') {
24         do_compile(1, 1, @ARGV);
25 } elsif ($type eq 'link-so') {
26         do_compile(0, 1, @ARGV);
27 } else {
28         print STDERR "Unknown unit-cc subcommand $type!\n";
29 }
30 exit 1;
31
32 sub do_static_find {
33         my @flags;
34         for my $file (@ARGV) {
35                 push @flags, getlinkerflags($file);
36         }
37         open F, '>', $out;
38         print F join ' ', @flags;
39         close F;
40         exit 0;
41 }
42
43 sub do_static_link {
44         my $execstr = "$ENV{RUNLD} -o $out $ENV{CORELDFLAGS}";
45         for (@ARGV) {
46                 if (/\.cmd$/) {
47                         open F, '<', $_;
48                         my $libs = <F>;
49                         chomp $libs;
50                         $execstr .= ' '.$libs;
51                         close F;
52                 } else {
53                         $execstr .= ' '.$_;
54                 }
55         }
56         $execstr .= ' '.$ENV{LDLIBS};
57         print "$execstr\n" if $verbose;
58         exec $execstr;
59 }
60
61 sub do_core_link {
62         my $execstr = "$ENV{RUNLD} -o $out $ENV{CORELDFLAGS} @_ $ENV{LDLIBS}";
63         print "$execstr\n" if $verbose;
64         exec $execstr;
65 }
66
67 sub do_link_dir {
68         my $execstr = "$ENV{RUNLD} -o $out $ENV{PICLDFLAGS} @_";
69         print "$execstr\n" if $verbose;
70         exec $execstr;
71 }
72
73 sub do_compile {
74         my ($do_compile, $do_link, $file) = @_;
75
76         my $flags = '';
77         my $libs = '';
78         my $binary = $ENV{RUNCC};
79         if ($do_compile) {
80                 $flags = $ENV{CXXFLAGS};
81                 $flags =~ s/ -pedantic// if nopedantic($file);
82                 $flags .= ' ' . getcompilerflags($file);
83
84                 if ($file =~ m#(?:^|/)((?:m|cmd)_[^/. ]+)(?:\.cpp|/.*\.cpp)$#) {
85                         $flags .= ' -DMODNAME='.$1.'.so';
86                 }
87         } else {
88                 $binary = $ENV{RUNLD};
89         }
90
91         if ($do_link) {
92                 $flags = join ' ', $flags, $ENV{PICLDFLAGS};
93                 $libs = join ' ', getlinkerflags($file);
94         } else {
95                 $flags .= ' -c';
96         }
97
98         my $execstr = "$binary -o $out $flags $file $libs";
99         print "$execstr\n" if $verbose;
100         exec $execstr;
101 }