]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/unit-cc.pl
Switch systemd service to be non-forking & avoid using the helper.
[user/henk/code/inspircd.git] / make / unit-cc.pl
1 #!/usr/bin/env perl
2 #
3 # InspIRCd -- Internet Relay Chat Daemon
4 #
5 #   Copyright (C) 2019 iwalkalone <iwalkalone69@gmail.com>
6 #   Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
7 #   Copyright (C) 2013, 2015-2016, 2018 Sadie Powell <sadie@witchery.services>
8 #   Copyright (C) 2012 Robby <robby@chatbelgie.be>
9 #   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
10 #
11 # This file is part of InspIRCd.  InspIRCd is free software: you can
12 # redistribute it and/or modify it under the terms of the GNU General Public
13 # License as published by the Free Software Foundation, version 2.
14 #
15 # This program is distributed in the hope that it will be useful, but WITHOUT
16 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18 # details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 #
23
24
25 BEGIN {
26         push @INC, $ENV{SOURCEPATH};
27         require 5.10.0;
28 }
29
30 use strict;
31 use warnings FATAL => qw(all);
32
33 use File::Spec::Functions qw(abs2rel);
34
35 use make::console;
36 use make::directive;
37
38 chdir $ENV{BUILDPATH};
39
40 my $type = shift;
41 my $out = shift;
42
43 if ($type eq 'core-ld') {
44         do_core_link(@ARGV);
45 } elsif ($type eq 'link-dir') {
46         do_link_dir(@ARGV);
47 } elsif ($type eq 'gen-o') {
48         do_compile(1, 0, @ARGV);
49 } elsif ($type eq 'gen-so') {
50         do_compile(1, 1, @ARGV);
51 } elsif ($type eq 'link-so') {
52         do_compile(0, 1, @ARGV);
53 } else {
54         print STDERR "Unknown unit-cc subcommand $type!\n";
55 }
56 exit 1;
57
58 sub message($$$) {
59         my ($type, $file, $command) = @_;
60         if ($ENV{INSPIRCD_VERBOSE}) {
61                 print "$command\n";
62         } else {
63                 print_format "\t<|GREEN $type:|>\t\t$file\n";
64         }
65 }
66
67 sub rpath($) {
68         my $message = shift;
69         $message =~ s/-L(\S+)/-Wl,-rpath,$1 -L$1/g unless defined $ENV{INSPIRCD_DISABLE_RPATH};
70         return $message;
71 }
72
73 sub do_core_link {
74         my $execstr = "$ENV{CXX} -o $out $ENV{CORELDFLAGS} @_ $ENV{LDLIBS}";
75         message 'LINK', $out, $execstr;
76         exec $execstr;
77 }
78
79 sub do_link_dir {
80         my ($dir, $link_flags) = (shift, '');
81         for my $file (<$dir/*.cpp>) {
82                 $link_flags .= rpath(get_directive($file, 'LinkerFlags', '')) . ' ';
83         }
84         my $execstr = "$ENV{CXX} -o $out $ENV{PICLDFLAGS} @_ $link_flags";
85         message 'LINK', $out, $execstr;
86         exec $execstr;
87 }
88
89 sub do_compile {
90         my ($do_compile, $do_link, $file) = @_;
91
92         my $flags = '';
93         my $libs = '';
94         if ($do_compile) {
95                 $flags = $ENV{CORECXXFLAGS} . ' ' . get_directive($file, 'CompilerFlags', '');
96
97                 if ($file =~ m#(?:^|/)((?:m|core)_[^/. ]+)(?:\.cpp|/.*\.cpp)$#) {
98                         $flags .= ' -DMODNAME=\\"'.$1.'\\"';
99                 }
100         }
101
102         if ($do_link) {
103                 $flags = join ' ', $flags, $ENV{PICLDFLAGS};
104                 $libs = rpath(get_directive($file, 'LinkerFlags', ''));
105         } else {
106                 $flags .= ' -c';
107         }
108
109         my $execstr = "$ENV{CXX} -o $out $flags $file $libs";
110         message 'BUILD', abs2rel($file, "$ENV{SOURCEPATH}/src"), $execstr;
111         exec $execstr;
112 }