summaryrefslogtreecommitdiff
path: root/make/unit-cc.pl
diff options
context:
space:
mode:
authorDaniel De Graaf <danieldg@inspircd.org>2010-05-07 13:39:49 -0500
committerDaniel De Graaf <danieldg@inspircd.org>2010-05-07 14:04:53 -0500
commitdf347edbdbb6d1d0f81795214674da8a4007850a (patch)
tree287ad3751d923ff14ea9a2506c2bcdfeee4332f2 /make/unit-cc.pl
parente11ae4f39cbcd169e725b680015d73c127f4a70e (diff)
Use unit-cc for all compile and and link tasks
This allows splitting .o and .so generation for distcc builds, and also removes some unneeded autodetection of build stage.
Diffstat (limited to 'make/unit-cc.pl')
-rwxr-xr-xmake/unit-cc.pl94
1 files changed, 59 insertions, 35 deletions
diff --git a/make/unit-cc.pl b/make/unit-cc.pl
index aefefa4ac..30b536343 100755
--- a/make/unit-cc.pl
+++ b/make/unit-cc.pl
@@ -6,43 +6,27 @@ 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/;
- if (/f/) {
- do_static_find(@ARGV);
- exit;
- }
- if (/l/) {
- do_static_link(@ARGV);
- exit;
- }
-}
-
-my $file = shift;
-
-my $cflags = $ENV{CXXFLAGS};
-$cflags =~ s/ -pedantic// if nopedantic($file);
-$cflags .= ' ' . getcompilerflags($file);
-
-if ($file =~ m#(?:^|/)((?:m|cmd)_[^/. ]+)(?:\.cpp|/.*\.cpp)$#) {
- $cflags .= ' -DMODNAME='.$1.'.so';
-}
-
-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 {
@@ -53,10 +37,11 @@ sub do_static_find {
open F, '>', $out;
print F join ' ', @flags;
close F;
+ exit 0;
}
sub do_static_link {
- my $execstr = "$ENV{RUNCC} -o $out $ENV{CORELDFLAGS} $ENV{LDLIBS}";
+ my $execstr = "$ENV{RUNLD} -o $out $ENV{CORELDFLAGS} $ENV{LDLIBS}";
for (@ARGV) {
if (/\.cmd$/) {
open F, '<', $_;
@@ -70,5 +55,44 @@ sub do_static_link {
}
print "$execstr\n" if $verbose;
exec $execstr;
- exit 1;
+}
+
+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 $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;
}