]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/unit-cc.pl
Merge pull request #1157 from SaberUK/insp20+fix-cron-restart
[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 ## BEGIN HACK: REMOVE IN 2.2!
34 sub read_config_cache {
35         my %cfg = ();
36         open(CACHE, '../.config.cache') or return %cfg;
37         while (my $line = <CACHE>) {
38                 next if $line =~ /^\s*($|\#)/;
39                 my ($key, $value) = ($line =~ /^(\S+)="(.*)"$/);
40                 $cfg{$key} = $value;
41         }
42         close(CACHE);
43         return %cfg;
44 }
45
46 our %config = read_config_cache();
47 ## END HACK
48
49 if ($type eq 'gen-ld') {
50         do_static_find(@ARGV);
51 } elsif ($type eq 'static-ld') {
52         do_static_link(@ARGV);
53 } elsif ($type eq 'core-ld') {
54         do_core_link(@ARGV);
55 } elsif ($type eq 'link-dir') {
56         do_link_dir(@ARGV);
57 } elsif ($type eq 'gen-o') {
58         do_compile(1, 0, @ARGV);
59 } elsif ($type eq 'gen-so') {
60         do_compile(1, 1, @ARGV);
61 } elsif ($type eq 'link-so') {
62         do_compile(0, 1, @ARGV);
63 } else {
64         print STDERR "Unknown unit-cc subcommand $type!\n";
65 }
66 exit 1;
67
68 sub do_static_find {
69         my @flags;
70         for my $file (@ARGV) {
71                 push @flags, getlinkerflags($file);
72         }
73         open F, '>', $out;
74         print F join ' ', @flags;
75         close F;
76         exit 0;
77 }
78
79 sub do_static_link {
80         my $execstr = "$ENV{RUNLD} -o $out $ENV{CORELDFLAGS}";
81         for (@ARGV) {
82                 if (/\.cmd$/) {
83                         open F, '<', $_;
84                         my $libs = <F>;
85                         chomp $libs;
86                         $execstr .= ' '.$libs;
87                         close F;
88                 } else {
89                         $execstr .= ' '.$_;
90                 }
91         }
92         $execstr .= ' '.$ENV{LDLIBS};
93         print "$execstr\n" if $verbose;
94         exec $execstr;
95 }
96
97 sub do_core_link {
98         my $execstr = "$ENV{RUNLD} -o $out $ENV{CORELDFLAGS} @_ $ENV{LDLIBS}";
99         print "$execstr\n" if $verbose;
100         exec $execstr;
101 }
102
103 sub do_link_dir {
104         my $execstr = "$ENV{RUNLD} -o $out $ENV{PICLDFLAGS} @_";
105         print "$execstr\n" if $verbose;
106         exec $execstr;
107 }
108
109 sub do_compile {
110         my ($do_compile, $do_link, $file) = @_;
111
112         my $flags = '';
113         my $libs = '';
114         my $binary = $ENV{RUNCC};
115         if ($do_compile) {
116                 $flags = $ENV{CXXFLAGS};
117                 $flags =~ s/ -pedantic// if nopedantic($file);
118                 $flags .= ' ' . getcompilerflags($file);
119
120                 if ($file =~ m#(?:^|/)((?:m|cmd)_[^/. ]+)(?:\.cpp|/.*\.cpp)$#) {
121                         $flags .= ' -DMODNAME='.$1.'.so';
122                 }
123         } else {
124                 $binary = $ENV{RUNLD};
125         }
126
127         if ($do_link) {
128                 $flags = join ' ', $flags, $ENV{PICLDFLAGS};
129                 $libs = join ' ', getlinkerflags($file);
130         } else {
131                 $flags .= ' -c';
132         }
133
134         my $execstr = "$binary -o $out $flags $file $libs";
135         print "$execstr\n" if $verbose;
136         exec $execstr;
137 }