X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=make%2Fcalcdep.pl;h=2ae03cc364c22681e3bfd9d02c42817ed4d8c22b;hb=b4b66ad9600ff64b62bbfeabc8dc2579918b77b3;hp=ad25875cfe782474c5dc37f35ff9c6915bfe84f2;hpb=d811ffeda29eff11fb0a381f5f17b6d65ae0460b;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/make/calcdep.pl b/make/calcdep.pl index ad25875cf..2ae03cc36 100755 --- a/make/calcdep.pl +++ b/make/calcdep.pl @@ -1,9 +1,9 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use strict; use warnings; use POSIX qw(getcwd); -sub find_output($); +sub find_output; sub gendep($); sub dep_cpp($$); sub dep_dir($); @@ -18,38 +18,56 @@ sub run() { my $build = $ENV{BUILDPATH}; mkdir $build; chdir $build or die "Could not open build directory: $!"; - mkdir 'bin'; - mkdir 'obj'; - mkdir 'modules'; symlink "$ENV{SOURCEPATH}/include", 'include'; + mkdir $_ for qw/bin modules obj/; +# BSD make has a horribly annoying bug resulting in an extra chdir of the make process +# Create symlinks to work around it + symlink "../$_", "obj/$_" for qw/bin modules obj/; + $build = getcwd(); open MAKE, '>real.mk' or die "Could not write real.mk: $!"; chdir "$ENV{SOURCEPATH}/src"; + if ($ENV{PURE_STATIC}) { + run_static(); + } else { + run_dynamic(); + } + close MAKE; +} + +sub run_dynamic() { + my $build = $ENV{BUILDPATH}; print MAKE <, , "socketengines/$ENV{SOCKETENGINE}.cpp", "threadengines/threadengine_pthread.cpp") { + my(@core_deps, @cmdlist, @modlist); + for my $file (<*.cpp>, , , "threadengines/threadengine_pthread.cpp") { my $out = find_output $file; dep_cpp $file, $out; + next if $file =~ m#^socketengines/# && $file ne "socketengines/$ENV{SOCKETENGINE}.cpp"; push @core_deps, $out; } - - my @modlist; + for my $file () { my $out = find_output $file; dep_cpp $file, $out; - push @modlist, $out; + push @cmdlist, $out; } opendir my $moddir, 'modules'; - for my $file (readdir $moddir) { + for my $file (sort readdir $moddir) { next if $file =~ /^\./; if (-e "modules/extra/$file" && !-l "modules/$file") { # Incorrect symlink? @@ -69,25 +87,74 @@ END } my $core_mk = join ' ', @core_deps; + my $cmds = join ' ', @cmdlist; my $mods = join ' ', @modlist; print MAKE < + \$(RUNCC) -o \$\@ \$(CORELDFLAGS) \$(LDLIBS) \$^ \$> inspircd: bin/inspircd + +commands: $cmds + modules: $mods -.PHONY: inspircd modules +.PHONY: all bad-target inspircd commands modules + +END +} + +sub run_static() { + print MAKE <, , , , + , , "threadengines/threadengine_pthread.cpp") { + my $out = find_output $file, 1; + if ($out =~ m#obj/([^/]+)/[^/]+.o$#) { + mkdir "$ENV{BUILDPATH}/obj/$1"; + } + dep_cpp $file, $out; + next if $file =~ m#^socketengines/# && $file ne "socketengines/$ENV{SOCKETENGINE}.cpp"; + push @deps, $out; + push @srcs, $file; + } + + my $core_mk = join ' ', @deps; + my $core_src = join ' ', @srcs; + print MAKE < + +bin/inspircd: obj/ld-extra.cmd $core_mk + \@\$(SOURCEPATH)/make/unit-cc.pl -l\$(VERBOSE) \$\@ \$^ \$> + +inspircd: bin/inspircd + +.PHONY: all bad-target inspircd END } -sub find_output($) { - my $file = shift; +sub find_output { + my($file, $static) = @_; my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file"; if ($path eq 'modules/' || $path eq 'commands/') { - return "modules/$base.so"; + return $static ? "obj/$base.o" : "modules/$base.so"; } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) { return "obj/$base.o"; } elsif ($path =~ m#modules/(m_.*)/#) { @@ -145,7 +212,7 @@ sub dep_dir($) { my($dir) = @_; my @ofiles; opendir DIR, $dir; - for my $file (readdir DIR) { + for my $file (sort readdir DIR) { next unless $file =~ /(.*)\.cpp$/; my $ofile = find_output "$dir/$file"; dep_cpp "$dir/$file", $ofile; @@ -154,7 +221,7 @@ sub dep_dir($) { closedir DIR; if (@ofiles) { my $ofiles = join ' ', @ofiles; - print MAKE "$dir.so: $ofiles\n\tcd \$(BUILDPATH); \$(RUNCC) \$(PICLDFLAGS) -o \$\@ \$^ \$>\n"; + print MAKE "$dir.so: $ofiles\n\t\$(RUNCC) \$(PICLDFLAGS) -o \$\@ \$^ \$>\n"; return 1; } else { return 0;