]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/unit-cc.pl
Rename CXXFLAGS to CORECXXFLAGS to respect users enviroment.
[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 use strict;
23 use warnings;
24 BEGIN { push @INC, $ENV{SOURCEPATH}; }
25 use make::configure;
26
27 chdir $ENV{BUILDPATH};
28
29 my $type = shift;
30 my $out = shift;
31 my $verbose = ($type =~ s/-v$//);
32
33 if ($type eq 'gen-ld') {
34         do_static_find(@ARGV);
35 } elsif ($type eq 'static-ld') {
36         do_static_link(@ARGV);
37 } elsif ($type eq 'core-ld') {
38         do_core_link(@ARGV);
39 } elsif ($type eq 'link-dir') {
40         do_link_dir(@ARGV);
41 } elsif ($type eq 'gen-o') {
42         do_compile(1, 0, @ARGV);
43 } elsif ($type eq 'gen-so') {
44         do_compile(1, 1, @ARGV);
45 } elsif ($type eq 'link-so') {
46         do_compile(0, 1, @ARGV);
47 } else {
48         print STDERR "Unknown unit-cc subcommand $type!\n";
49 }
50 exit 1;
51
52 sub do_static_find {
53         my @flags;
54         for my $file (@ARGV) {
55                 push @flags, getlinkerflags($file);
56         }
57         open F, '>', $out;
58         print F join ' ', @flags;
59         close F;
60         exit 0;
61 }
62
63 sub do_static_link {
64         my $execstr = "$ENV{RUNLD} -o $out $ENV{CORELDFLAGS}";
65         for (@ARGV) {
66                 if (/\.cmd$/) {
67                         open F, '<', $_;
68                         my $libs = <F>;
69                         chomp $libs;
70                         $execstr .= ' '.$libs;
71                         close F;
72                 } else {
73                         $execstr .= ' '.$_;
74                 }
75         }
76         $execstr .= ' '.$ENV{LDLIBS};
77         print "$execstr\n" if $verbose;
78         exec $execstr;
79 }
80
81 sub do_core_link {
82         my $execstr = "$ENV{RUNLD} -o $out $ENV{CORELDFLAGS} @_ $ENV{LDLIBS}";
83         print "$execstr\n" if $verbose;
84         exec $execstr;
85 }
86
87 sub do_link_dir {
88         my $execstr = "$ENV{RUNLD} -o $out $ENV{PICLDFLAGS} @_";
89         print "$execstr\n" if $verbose;
90         exec $execstr;
91 }
92
93 sub do_compile {
94         my ($do_compile, $do_link, $file) = @_;
95
96         my $flags = '';
97         my $libs = '';
98         my $binary = $ENV{RUNCC};
99         if ($do_compile) {
100                 $flags = $ENV{CORECXXFLAGS};
101                 $flags =~ s/ -pedantic// if nopedantic($file);
102                 $flags .= ' ' . getcompilerflags($file);
103
104                 if ($file =~ m#(?:^|/)((?:m|cmd)_[^/. ]+)(?:\.cpp|/.*\.cpp)$#) {
105                         $flags .= ' -DMODNAME='.$1.'.so';
106                 }
107         } else {
108                 $binary = $ENV{RUNLD};
109         }
110
111         if ($do_link) {
112                 $flags = join ' ', $flags, $ENV{PICLDFLAGS};
113                 $libs = join ' ', getlinkerflags($file);
114         } else {
115                 $flags .= ' -c';
116         }
117
118         my $execstr = "$binary -o $out $flags $file $libs";
119         print "$execstr\n" if $verbose;
120         exec $execstr;
121 }