X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=make%2Funit-cc.pl;h=30b5363430ec190e7094a394f92119518f2e6bfc;hb=df347edbdbb6d1d0f81795214674da8a4007850a;hp=75c206d8c0a8fc7f47b7e575268b0c8f45ce4f75;hpb=792d6d6725c7d80d223f5cccd9ee0c5b07229e9a;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/make/unit-cc.pl b/make/unit-cc.pl index 75c206d8c..30b536343 100755 --- a/make/unit-cc.pl +++ b/make/unit-cc.pl @@ -1,32 +1,98 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use strict; use warnings; BEGIN { push @INC, $ENV{SOURCEPATH}; } use make::configure; -my $file = shift; -my $verbose; +chdir $ENV{BUILDPATH}; -if ($file =~ /^-/) { - $_ = $file; - $file = shift; - $verbose = /v/; +my $type = shift; +my $out = shift; +my $verbose = ($type =~ s/-v$//); + +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 { + print STDERR "Unknown unit-cc subcommand $type!\n"; } +exit 1; -my $out = shift; +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; +} -my $cflags = $ENV{CXXFLAGS}; -$cflags =~ s/ -pedantic// if nopedantic($file); -$cflags .= ' ' . getcompilerflags($file); +sub do_static_link { + my $execstr = "$ENV{RUNLD} -o $out $ENV{CORELDFLAGS} $ENV{LDLIBS}"; + for (@ARGV) { + if (/\.cmd$/) { + open F, '<', $_; + my $libs = ; + chomp $libs; + $execstr .= ' '.$libs; + close F; + } else { + $execstr .= ' '.$_; + } + } + print "$execstr\n" if $verbose; + exec $execstr; +} -my $flags; -if ($out =~ /\.so$/) { - $flags = join ' ', $cflags, $ENV{PICLDFLAGS}, getlinkerflags($file); -} else { - $flags = "$cflags -c"; +sub do_core_link { + my $execstr = "$ENV{RUNLD} -o $out $ENV{CORELDFLAGS} $ENV{LDLIBS} @_"; + print "$execstr\n" if $verbose; + exec $execstr; } -my $execstr = "$ENV{RUNCC} $flags -o $out $file"; -print "$execstr\n" if $verbose; -exec $execstr; -exit 1; +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 $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}, getlinkerflags($file); + } else { + $flags .= ' -c'; + } + + my $execstr = "$binary -o $out $flags $file"; + print "$execstr\n" if $verbose; + exec $execstr; +}