X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=make%2Funit-cc.pl;h=a494fb74b06d712a21278c5f22c91cee0e6ef139;hb=4c751dbbe8945e5efc230a59b0ed51c2ba10cf92;hp=d4786b8fee330213e4d0d087ded9c9f038f5f0fc;hpb=d5e36aa2b2ca26fe689ae9e29c74b3565dd018c7;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/make/unit-cc.pl b/make/unit-cc.pl index d4786b8fe..a494fb74b 100755 --- a/make/unit-cc.pl +++ b/make/unit-cc.pl @@ -1,32 +1,137 @@ -#!/usr/bin/perl +#!/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 . +# + + use strict; use warnings; BEGIN { push @INC, $ENV{SOURCEPATH}; } use make::configure; +chdir $ENV{BUILDPATH}; + +my $type = shift; my $out = shift; -my $verbose; +my $verbose = ($type =~ s/-v$//); -if ($out =~ /^-/) { - $_ = $out; - $out = shift; - $verbose = /v/; +## BEGIN HACK: REMOVE IN 2.2! +sub read_config_cache { + my %cfg = (); + open(CACHE, '../.config.cache') or return %cfg; + while (my $line = ) { + next if $line =~ /^\s*($|\#)/; + my ($key, $value) = ($line =~ /^(\S+)="(.*)"$/); + $cfg{$key} = $value; + } + close(CACHE); + return %cfg; } -my $file = shift; - -my $cflags = $ENV{CXXFLAGS}; -$cflags =~ s/ -pedantic// if nopedantic($file); -$cflags .= ' ' . getcompilerflags($file); +our %config = read_config_cache(); +## END HACK -my $flags; -if ($out =~ /\.so$/) { - $flags = join ' ', $cflags, $ENV{PICLDFLAGS}, getlinkerflags($file); +if ($type eq 'gen-ld') { + do_static_find(@ARGV); +} elsif ($type eq 'static-ld') { + do_static_link(@ARGV); +} elsif ($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 do_static_find { + my @flags; + for my $file (@ARGV) { + push @flags, getlinkerflags($file); + } + open F, '>', $out; + print F join ' ', @flags; + close F; + exit 0; +} + +sub do_static_link { + my $execstr = "$ENV{RUNLD} -o $out $ENV{CORELDFLAGS}"; + for (@ARGV) { + if (/\.cmd$/) { + open F, '<', $_; + my $libs = ; + chomp $libs; + $execstr .= ' '.$libs; + close F; + } else { + $execstr .= ' '.$_; + } + } + $execstr .= ' '.$ENV{LDLIBS}; + print "$execstr\n" if $verbose; + exec $execstr; +} + +sub do_core_link { + my $execstr = "$ENV{RUNLD} -o $out $ENV{CORELDFLAGS} @_ $ENV{LDLIBS}"; + print "$execstr\n" if $verbose; + exec $execstr; +} + +sub do_link_dir { + my $execstr = "$ENV{RUNLD} -o $out $ENV{PICLDFLAGS} @_"; + print "$execstr\n" if $verbose; + exec $execstr; +} + +sub do_compile { + my ($do_compile, $do_link, $file) = @_; + + my $flags = ''; + my $libs = ''; + my $binary = $ENV{RUNCC}; + if ($do_compile) { + $flags = $ENV{CXXFLAGS}; + $flags =~ s/ -pedantic// if nopedantic($file); + $flags .= ' ' . getcompilerflags($file); + + if ($file =~ m#(?:^|/)((?:m|cmd)_[^/. ]+)(?:\.cpp|/.*\.cpp)$#) { + $flags .= ' -DMODNAME='.$1.'.so'; + } + } else { + $binary = $ENV{RUNLD}; + } + + if ($do_link) { + $flags = join ' ', $flags, $ENV{PICLDFLAGS}; + $libs = join ' ', getlinkerflags($file); + } else { + $flags .= ' -c'; + } + + my $execstr = "$binary -o $out $flags $file $libs"; + print "$execstr\n" if $verbose; + exec $execstr; +}