]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/unit-cc.pl
unit-cc: Remove workaround which existed for 2.0.x only.
[user/henk/code/inspircd.git] / make / unit-cc.pl
1 #!/usr/bin/env perl
2
3 #
4 # InspIRCd -- Internet Relay Chat Daemon
5 #
6 #   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
7 #
8 # This file is part of InspIRCd.  InspIRCd is free software: you can
9 # redistribute it and/or modify it under the terms of the GNU General Public
10 # License as published by the Free Software Foundation, version 2.
11 #
12 # This program is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15 # details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21
22 BEGIN {
23         push @INC, $ENV{SOURCEPATH};
24         require 5.10.0;
25 }
26
27 use strict;
28 use warnings FATAL => qw(all);
29
30 use make::configure;
31
32 chdir $ENV{BUILDPATH};
33
34 my $type = shift;
35 my $out = shift;
36 my $verbose = ($type =~ s/-v$//);
37
38 our %config = read_configure_cache();
39
40 if ($type eq 'gen-ld') {
41         do_static_find(@ARGV);
42 } elsif ($type eq 'static-ld') {
43         do_static_link(@ARGV);
44 } elsif ($type eq 'core-ld') {
45         do_core_link(@ARGV);
46 } elsif ($type eq 'link-dir') {
47         do_link_dir(@ARGV);
48 } elsif ($type eq 'gen-o') {
49         do_compile(1, 0, @ARGV);
50 } elsif ($type eq 'gen-so') {
51         do_compile(1, 1, @ARGV);
52 } elsif ($type eq 'link-so') {
53         do_compile(0, 1, @ARGV);
54 } else {
55         print STDERR "Unknown unit-cc subcommand $type!\n";
56 }
57 exit 1;
58
59 sub do_static_find {
60         my @flags;
61         for my $file (@ARGV) {
62                 push @flags, get_property($file, 'LinkerFlags');
63         }
64         open F, '>', $out;
65         print F join ' ', @flags;
66         close F;
67         exit 0;
68 }
69
70 sub do_static_link {
71         my $execstr = "$ENV{RUNLD} -o $out $ENV{CORELDFLAGS}";
72         for (@ARGV) {
73                 if (/\.cmd$/) {
74                         open F, '<', $_;
75                         my $libs = <F>;
76                         chomp $libs;
77                         $execstr .= ' '.$libs;
78                         close F;
79                 } else {
80                         $execstr .= ' '.$_;
81                 }
82         }
83         $execstr .= ' '.$ENV{LDLIBS};
84         print "$execstr\n" if $verbose;
85         exec $execstr;
86 }
87
88 sub do_core_link {
89         my $execstr = "$ENV{RUNLD} -o $out $ENV{CORELDFLAGS} @_ $ENV{LDLIBS}";
90         print "$execstr\n" if $verbose;
91         exec $execstr;
92 }
93
94 sub do_link_dir {
95         my $execstr = "$ENV{RUNLD} -o $out $ENV{PICLDFLAGS} @_";
96         print "$execstr\n" if $verbose;
97         exec $execstr;
98 }
99
100 sub do_compile {
101         my ($do_compile, $do_link, $file) = @_;
102
103         my $flags = '';
104         my $libs = '';
105         my $binary = $ENV{RUNCC};
106         if ($do_compile) {
107                 $flags = $ENV{CORECXXFLAGS} . ' ' . get_property($file, 'CompileFlags');
108
109                 if ($file =~ m#(?:^|/)((?:m|core)_[^/. ]+)(?:\.cpp|/.*\.cpp)$#) {
110                         $flags .= ' -DMODNAME=\\"'.$1.'\\"';
111                 }
112         } else {
113                 $binary = $ENV{RUNLD};
114         }
115
116         if ($do_link) {
117                 $flags = join ' ', $flags, $ENV{PICLDFLAGS};
118                 $libs = get_property($file, 'LinkerFlags');
119         } else {
120                 $flags .= ' -c';
121         }
122
123         my $execstr = "$binary -o $out $flags $file $libs";
124         print "$execstr\n" if $verbose;
125         exec $execstr;
126 }