X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=make%2Funit-cc.pl;h=311c4c2607fa922520efae5fe2d4a85ef30d01e7;hb=ff7bebe90c6b348b0df28864e4954d04bd17256b;hp=5110037ace2ce851c59980fb1b749aa05d1e3d8a;hpb=990e04bab51bf1c3771938b8f598272c1b31cdca;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/make/unit-cc.pl b/make/unit-cc.pl index 5110037ac..311c4c260 100755 --- a/make/unit-cc.pl +++ b/make/unit-cc.pl @@ -1,31 +1,109 @@ -#!/usr/bin/perl -use strict; -use warnings; -BEGIN { push @INC, '..'; } -use make::configure; +#!/usr/bin/env perl + +# +# InspIRCd -- Internet Relay Chat Daemon +# +# 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 . +# -my $file = shift; -my $verbose; -if ($file =~ /^-/) { - $_ = $file; - $file = shift; - $verbose = /v/; +BEGIN { + push @INC, $ENV{SOURCEPATH}; + require 5.10.0; } -my $out = shift; +use strict; +use warnings FATAL => qw(all); + +use File::Spec::Functions qw(abs2rel); + +use make::console; +use make::directive; -my $cflags = nopedantic($file) ? $ENV{NICEFLAGS} : $ENV{FLAGS}; -$cflags .= ' ' . getcompilerflags($file); +chdir $ENV{BUILDPATH}; -my $flags; -if ($out =~ /\.so$/) { - $flags = join ' ', $cflags, $ENV{PICLDFLAGS}, getlinkerflags($file); +my $type = shift; +my $out = 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 { - $flags = "$cflags -c"; + print STDERR "Unknown unit-cc subcommand $type!\n"; } - -my $execstr = "$ENV{RUNCC} $flags -o $out $file"; -print "$execstr\n" if $verbose; -exec $execstr; exit 1; + +sub message($$$) { + my ($type, $file, $command) = @_; + if ($ENV{INSPIRCD_VERBOSE}) { + print "$command\n"; + } else { + print_format "\t<|GREEN $type:|>\t\t$file\n"; + } +} + +sub rpath($) { + my $message = shift; + $message =~ s/-L(\S+)/-Wl,-rpath,$1 -L$1/g unless defined $ENV{INSPIRCD_DISABLE_RPATH}; + return $message; +} + +sub do_core_link { + my $execstr = "$ENV{CXX} -o $out $ENV{CORELDFLAGS} @_ $ENV{LDLIBS}"; + message 'LINK', $out, $execstr; + exec $execstr; +} + +sub do_link_dir { + my ($dir, $link_flags) = (shift, ''); + for my $file (<$dir/*.cpp>) { + $link_flags .= rpath(get_directive($file, 'LinkerFlags', '')) . ' '; + } + my $execstr = "$ENV{CXX} -o $out $ENV{PICLDFLAGS} $link_flags @_"; + message 'LINK', $out, $execstr; + exec $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.'\\"'; + } + } + + 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; +}