]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/unit-cc.pl
Remove run-cc.pl and all associated code.
[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 File::Spec::Functions qw(abs2rel);
31
32 use make::configure;
33 use make::console;
34
35 chdir $ENV{BUILDPATH};
36
37 my $type = shift;
38 my $out = shift;
39 my $verbose = ($type =~ s/-v$//);
40
41 our %config = read_configure_cache();
42
43 if ($type eq 'gen-ld') {
44         do_static_find(@ARGV);
45 } elsif ($type eq 'static-ld') {
46         do_static_link(@ARGV);
47 } elsif ($type eq 'core-ld') {
48         do_core_link(@ARGV);
49 } elsif ($type eq 'link-dir') {
50         do_link_dir(@ARGV);
51 } elsif ($type eq 'gen-o') {
52         do_compile(1, 0, @ARGV);
53 } elsif ($type eq 'gen-so') {
54         do_compile(1, 1, @ARGV);
55 } elsif ($type eq 'link-so') {
56         do_compile(0, 1, @ARGV);
57 } else {
58         print STDERR "Unknown unit-cc subcommand $type!\n";
59 }
60 exit 1;
61
62 sub message($$$) {
63         my ($type, $file, $command) = @_;
64         if ($verbose) {
65                 print "$command\n";
66         } else {
67                 print_format "\t<|GREEN $type:|>\t\t$file\n";
68         }
69 }
70
71 sub do_static_find {
72         my @flags;
73         for my $file (@ARGV) {
74                 push @flags, get_property($file, 'LinkerFlags');
75         }
76         open F, '>', $out;
77         print F join ' ', @flags;
78         close F;
79         exit 0;
80 }
81
82 sub do_static_link {
83         my $execstr = "$ENV{CXX} -o $out $ENV{CORELDFLAGS}";
84         for (@ARGV) {
85                 if (/\.cmd$/) {
86                         open F, '<', $_;
87                         my $libs = <F>;
88                         chomp $libs;
89                         $execstr .= ' '.$libs;
90                         close F;
91                 } else {
92                         $execstr .= ' '.$_;
93                 }
94         }
95         $execstr .= ' '.$ENV{LDLIBS};
96         message 'LINK', $out, $execstr;
97         exec $execstr;
98 }
99
100 sub do_core_link {
101         my $execstr = "$ENV{CXX} -o $out $ENV{CORELDFLAGS} @_ $ENV{LDLIBS}";
102         message 'LINK', $out, $execstr;
103         exec $execstr;
104 }
105
106 sub do_link_dir {
107         my $execstr = "$ENV{CXX} -o $out $ENV{PICLDFLAGS} @_";
108         message 'LINK', $out, $execstr;
109         exec $execstr;
110 }
111
112 sub do_compile {
113         my ($do_compile, $do_link, $file) = @_;
114
115         my $flags = '';
116         my $libs = '';
117         if ($do_compile) {
118                 $flags = $ENV{CORECXXFLAGS} . ' ' . get_property($file, 'CompileFlags');
119
120                 if ($file =~ m#(?:^|/)((?:m|core)_[^/. ]+)(?:\.cpp|/.*\.cpp)$#) {
121                         $flags .= ' -DMODNAME=\\"'.$1.'\\"';
122                 }
123         }
124
125         if ($do_link) {
126                 $flags = join ' ', $flags, $ENV{PICLDFLAGS};
127                 $libs = get_property($file, 'LinkerFlags');
128         } else {
129                 $flags .= ' -c';
130         }
131
132         my $execstr = "$ENV{CXX} -o $out $flags $file $libs";
133         message 'BUILD', abs2rel($file, "$ENV{SOURCEPATH}/src"), $execstr;
134         exec $execstr;
135 }