X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=make%2Funit-cc.pl;h=f4fa5a650a6fddfc513fe8348d6c679062d5da45;hb=c05f81cac83e80c7727594e3929e0709eccca689;hp=e64053b668c23773a7b387dc283c4cc406aa8645;hpb=bd6496191222fab41b364dfcad54ec52a753be7d;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/make/unit-cc.pl b/make/unit-cc.pl index e64053b66..f4fa5a650 100755 --- a/make/unit-cc.pl +++ b/make/unit-cc.pl @@ -1,70 +1,111 @@ #!/usr/bin/env perl +# +# InspIRCd -- Internet Relay Chat Daemon +# +# Copyright (C) 2019 iwalkalone +# Copyright (C) 2014 Attila Molnar +# Copyright (C) 2013, 2015-2016, 2018, 2021 Sadie Powell +# Copyright (C) 2012 Robby +# Copyright (C) 2009-2010 Daniel De Graaf +# +# This file is part of InspIRCd. InspIRCd is free software: you can +# redistribute it and/or modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation, version 2. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + + +use v5.10.0; use strict; -use warnings; -BEGIN { push @INC, $ENV{SOURCEPATH}; } -use make::configure; +use warnings FATAL => qw(all); + +use File::Basename qw(dirname); +use File::Spec::Functions qw(abs2rel); +use FindBin qw($RealDir); + +use lib dirname $RealDir; +use make::console; +use make::directive; chdir $ENV{BUILDPATH}; +my $type = shift; my $out = shift; -my $verbose; - -if ($out =~ /^-/) { - $_ = $out; - $out = shift; - $verbose = /v/; - if (/f/) { - do_static_find(@ARGV); - exit; - } - if (/l/) { - do_static_link(@ARGV); - exit; - } -} -my $file = shift; +if ($type eq 'core-ld') { + do_core_link(@ARGV); +} elsif ($type eq 'link-dir') { + do_link_dir(@ARGV); +} elsif ($type eq 'gen-o') { + do_compile(1, 0, @ARGV); +} elsif ($type eq 'gen-so') { + do_compile(1, 1, @ARGV); +} elsif ($type eq 'link-so') { + do_compile(0, 1, @ARGV); +} else { + print STDERR "Unknown unit-cc subcommand $type!\n"; +} +exit 1; -my $cflags = $ENV{CXXFLAGS}; -$cflags =~ s/ -pedantic// if nopedantic($file); -$cflags .= ' ' . getcompilerflags($file); +sub message($$$) { + my ($type, $file, $command) = @_; + if ($ENV{INSPIRCD_VERBOSE}) { + say $command; + } else { + say console_format "\t<|GREEN $type:|>\t\t$file"; + } +} -my $flags; -if ($out =~ /\.so$/) { - $flags = join ' ', $cflags, $ENV{PICLDFLAGS}, getlinkerflags($file); -} else { - $flags = "$cflags -c"; +sub rpath($) { + my $message = shift; + $message =~ s/-L(\S+)/-Wl,-rpath,$1 -L$1/g unless defined $ENV{INSPIRCD_DISABLE_RPATH}; + return $message; } -my $execstr = "$ENV{RUNCC} $flags -o $out $file"; -print "$execstr\n" if $verbose; -exec $execstr; -exit 1; +sub do_core_link { + my $execstr = "$ENV{CXX} -o $out $ENV{CORELDFLAGS} @_ $ENV{LDLIBS}"; + message 'LINK', $out, $execstr; + exec $execstr; +} -sub do_static_find { - my @flags; - for my $file (@ARGV) { - push @flags, getlinkerflags($file); +sub do_link_dir { + my ($dir, $link_flags) = (shift, ''); + for my $file (<$dir/*.cpp>) { + $link_flags .= rpath(get_directive($file, 'LinkerFlags', '')) . ' '; } - open F, '>', $out; - print F join ' ', @flags; - close F; + my $execstr = "$ENV{CXX} -o $out $ENV{PICLDFLAGS} @_ $link_flags"; + message 'LINK', $out, $execstr; + exec $execstr; } -sub do_static_link { - my $execstr = "$ENV{RUNCC} -o $out $ENV{CORELDFLAGS} $ENV{LDLIBS}"; - for (@ARGV) { - if (/\.cmd$/) { - open F, '<', $_; - my $libs = ; - chomp $libs; - $execstr .= ' '.$libs; - close F; - } else { - $execstr .= ' '.$_; +sub do_compile { + my ($do_compile, $do_link, $file) = @_; + + my $flags = ''; + my $libs = ''; + if ($do_compile) { + $flags = $ENV{CORECXXFLAGS} . ' ' . get_directive($file, 'CompilerFlags', ''); + + if ($file =~ m#(?:^|/)((?:m|core)_[^/. ]+)(?:\.cpp|/.*\.cpp)$#) { + $flags .= ' -DMODNAME=\\"'.$1.'\\"'; } } - print "$execstr\n" if $verbose; + + if ($do_link) { + $flags = join ' ', $flags, $ENV{PICLDFLAGS}; + $libs = rpath(get_directive($file, 'LinkerFlags', '')); + } else { + $flags .= ' -c'; + } + + my $execstr = "$ENV{CXX} -o $out $flags $file $libs"; + message 'BUILD', abs2rel($file, "$ENV{SOURCEPATH}/src"), $execstr; exec $execstr; - exit 1; }