]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Move file inclusion logic into calcdep, and complain about ambiguous #include directi...
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Tue, 1 Sep 2009 22:44:44 +0000 (22:44 +0000)
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Tue, 1 Sep 2009 22:44:44 +0000 (22:44 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11587 e03df62e-2008-0410-955e-edbf42e46eb7

.Makefile.inc
make/bsd-real.mk
make/calcdep.pl
make/gnu-real.mk

index 901ced4fb214b9300d5772572d5165a4d325cf65..b2eaa4abe5ae3420f2a9ac2c914f81ea5ae9116d 100644 (file)
@@ -14,7 +14,7 @@
 CC = @CC@
 SYSTEM = @SYSTEM@
 SOCKETENGINE = @SOCKETENGINE@
-CXXFLAGS = -pipe -fPIC -DPIC
+CXXFLAGS += -pipe -fPIC -DPIC
 LDLIBS = -pthread -lstdc++
 LDFLAGS = 
 SHARED = -shared -rdynamic
@@ -91,10 +91,7 @@ TARGET = all
 
 all: $(FOOTER)
 
-dep:
-       @cd src; ../make/calcdep.pl `perl -e 'print join " ", <*.cpp>, <commands/*.cpp>, <modes/*.cpp>, <modules/*.cpp>, <modules/m_*/*.cpp>'` socketengines/$(SOCKETENGINE).cpp threadengines/threadengine_pthread.cpp
-
-target: $(HEADER) dep
+target: $(HEADER)
        $(MAKEENV) $(MAKE) -C src -f ../make/$(MAKESTYLE)-real.mk $(TARGET)
 
 debug:
@@ -221,4 +218,4 @@ help:
        @echo ' deinstall Removes the files created by "make install"'
        @echo
 
-.PHONY: all dep target debug debug-header mod-header mod-footer std-header finishmessage install clean deinstall squeakyclean launchd_dir configureclean help
+.PHONY: all target debug debug-header mod-header mod-footer std-header finishmessage install clean deinstall squeakyclean launchd_dir configureclean help
index 6fdf2e57f304445a90e071457fac6c0a7a7d4544..4ccc11be3bc7eae4250364f0cc70ad8fe5895c51 100644 (file)
@@ -1,13 +1,11 @@
 CORE_TARGS != perl -e 'print join " ", grep s/\.cpp/.o/, <*.cpp>, <modes/*.cpp>'
 CMD_TARGS != perl -e 'print join " ", grep s/\.cpp/.so/, <commands/*.cpp>'
 MOD_TARGS != perl -e 'print join " ", grep s/\.cpp/.so/, <modules/*.cpp>'
-MDIR_TARGS != perl -e 'print join " ", grep s!/?$$!.so!, <modules/m_*/>'
+MDIR_TARGS != perl -e 'print join " ", grep s!/?$$!.so!, grep -d, <modules/m_*>'
 
 CORE_TARGS += socketengines/$(SOCKETENGINE).o threadengines/threadengine_pthread.o
 
-DFILES != perl -e 'print join " ", grep s!([^/]+)\.cpp!.$$1.d!, <*.cpp>, <commands/*.cpp>, <modes/*.cpp>, <modules/*.cpp>, <modules/m_*/*.cpp>'
-DFILES2 != perl -e 'print join " ", grep s!([^/]+)/?$$!.$$1.d!, <modules/m_*/>'
-DFILES += $(DFILES2) socketengines/.$(SOCKETENGINE).d threadengines/.threadengine_pthread.d
+DFILES != perl ../make/calcdep.pl -all
 
 all: inspircd commands modules
 
index 06610c41626ec473026235d7c5878d8aa563b784..484c98cbd86079a12850f0a84039afd878cdd226 100755 (executable)
@@ -1,10 +1,7 @@
 #!/usr/bin/perl
 use strict;
 use warnings;
-
-# This used to be a wrapper around cc -M; however, this is a very slow
-# operation and we don't conditionally include our own files often enough
-# to justify the full preprocesor invocation for all ~200 files.
+use Getopt::Long;
 
 my %f2dep;
 
@@ -15,15 +12,22 @@ sub gendep {
        return $f2dep{$f} if exists $f2dep{$f};
        $f2dep{$f} = '';
        my %dep;
-       open my $in, '<', $f;
+       open my $in, '<', $f or die "Could not read $f";
        while (<$in>) {
                if (/^\s*#\s*include\s*"([^"]+)"/) {
                        my $inc = $1;
+                       my $found = 0;
                        for my $loc ("$basedir/$inc", "../include/$inc") {
                                next unless -e $loc;
+                               $found++;
                                $dep{$loc}++;
                                $dep{$_}++ for split / /, gendep $loc;
                        }
+                       if ($found == 0 && $inc ne 'inspircd_win32wrapper.h') {
+                               print STDERR "WARNING: could not find header $inc for $f\n";
+                       } elsif ($found > 1 && $basedir ne '../include') {
+                               print STDERR "WARNING: ambiguous include $inc in $f\n";
+                       }
                }
        }
        close $in;
@@ -31,32 +35,74 @@ sub gendep {
        $f2dep{$f};
 }
 
-for my $file (@ARGV) {
-       if (-e $file && $file =~ /cpp$/) {
-               gendep $file;
-               my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp#;
-               my $cmd = "$path.$base.d";
-               my $ext = $path eq 'modules/' || $path eq 'commands/' ? '.so' : '.o';
-               my $out = "$path$base$ext";
+sub dep_cpp {
+       my $file = shift;
+       gendep $file;
+       my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
+       my $cmd = "$path.$base.d";
+       my $ext = $path eq 'modules/' || $path eq 'commands/' ? '.so' : '.o';
+       my $out = "$path$base$ext";
 
-               open OUT, '>', $cmd;
-               print OUT "$out: $file $f2dep{$file}\n";
-               print OUT "\t@../make/unit-cc.pl \$(VERBOSE) $file $out\n";
-               print OUT "$cmd: $file $f2dep{$file}\n";
-               print OUT "\t../make/calcdep.pl $file\n";
-       } elsif (-d $file && $file =~ m#^(.*?)([^/]+)/?$#) {
+       open OUT, '>', $cmd;
+       print OUT "$out: $file $f2dep{$file}\n";
+       print OUT "\t@../make/unit-cc.pl \$(VERBOSE) $file $out\n";
+       print OUT "$cmd: $file $f2dep{$file}\n";
+       print OUT "\t../make/calcdep.pl -file $file\n";
+}
+
+sub dep_dir {
+       my $dir = shift;
+       if ($dir =~ m#^(.*?)([^/]+)/?$#) {
                my($path,$base) = ($1,$2);
                my $cmd = "$path.$base.d";
                my $out = "$path$base.so";
-               opendir DIR, $file;
-               my $ofiles = join ' ', grep s#(.*)\.cpp$#$path$base/$1.o#, readdir DIR;
+               opendir DIR, $dir;
+               my $ofiles = join ' ', grep s/(.*)\.cpp$/$path$base\/$1.o/, readdir DIR;
                closedir DIR;
                open OUT, '>', $cmd;
                print OUT "$out: $ofiles\n\t".'$(RUNCC) $(PICLDFLAGS) -o $@ '
                        .$ofiles."\n";
-               print OUT "$cmd: $file\n\t".'@../make/calcdep.pl '."$path$base\n";
+               print OUT "$cmd: $dir\n\t".'@../make/calcdep.pl -file '."$path$base\n";
+       } else {
+               print STDERR "Cannot generate depencency for $dir\n";
+               exit 1;
+       }
+}
+
+my($all,$quiet, $file);
+GetOptions(
+       'all' => \$all,
+       'quiet' => \$quiet,
+       'file=s' => \$file,
+);
+
+if (!$all && !defined $file) {
+       print "Use: $0 {-all|-file filename} [-quiet]\n";
+       exit 1;
+}
+
+if (defined $file) {
+       if (-f $file) {
+               dep_cpp $file;
+       } elsif (-d $file) {
+               dep_dir $file;
        } else {
-               print "Cannot generate depencency for $file\n";
+               print STDERR "Can't generate dependencies for $file\n";
                exit 1;
        }
+} else {
+       my @files = (<*.cpp>, <commands/*.cpp>, <modes/*.cpp>, <modules/*.cpp>, <modules/m_*/*.cpp>);
+       push @files, "socketengines/$ENV{SOCKETENGINE}.cpp", "threadengines/threadengine_pthread.cpp";
+       for my $file (@files) {
+               dep_cpp $file;
+       }
+
+       my @dirs = grep -d, <modules/m_*>;
+       for my $dir (@dirs) {
+               dep_dir $dir;
+       }
+
+       s#([^/]+)\.cpp#.$1.d# for @files;
+       s#([^/]+)/?$#.$1.d# for @dirs;
+       print join ' ', @files, @dirs;
 }
index 79fc2cd9ecad3d3ecbb788f402120a00f2dbbd63..e892295a6a044ae7823c59f3f91109f9ba3a9675 100644 (file)
@@ -1,16 +1,11 @@
-CORE_TARGS = $(patsubst %.cpp,%.o,$(wildcard *.cpp))
-MODE_TARGS = $(patsubst %.cpp,%.o,$(wildcard modes/*.cpp))
+CORE_TARGS = $(patsubst %.cpp,%.o,$(wildcard *.cpp) $(wildcard modes/*.cpp))
 CMD_TARGS = $(patsubst %.cpp,%.so,$(wildcard commands/*.cpp))
 MOD_TARGS = $(patsubst %.cpp,%.so,$(wildcard modules/*.cpp))
 
-CORE_TARGS += threadengines/threadengine_pthread.o
-CORE_TARGS += socketengines/$(SOCKETENGINE).o
-CORE_TARGS += $(MODE_TARGS)
-MOD_TARGS += $(shell perl -e 'print join " ", grep s!([^/]+)/$$!$$1.so!, <modules/m_*/>')
+CORE_TARGS += socketengines/$(SOCKETENGINE).o threadengines/threadengine_pthread.o
+MOD_TARGS += $(shell perl -e 'print join " ", grep s!/?$$!.so!, grep -d, <modules/m_*>')
 
-DFILES = $(shell perl -e 'print join " ", grep s!([^/]+)\.cpp!.$$1.d!, <*.cpp>, <commands/*.cpp>, <modes/*.cpp>, <modules/*.cpp>, <modules/m_*/*.cpp>')
-DFILES += $(shell perl -e 'print join " ", grep s!([^/]+)/?$$!.$$1.d!, <modules/m_*/>')
-DFILES += socketengines/.$(SOCKETENGINE).d threadengines/.threadengine_pthread.d
+DFILES = $(shell ../make/calcdep.pl -all)
 
 all: inspircd commands modules
 
@@ -22,10 +17,10 @@ inspircd: $(CORE_TARGS)
        $(RUNCC) -o $@ $(CORELDFLAGS) $(LDLIBS) $(CORE_TARGS)
 
 .%.d: %.cpp
-       @../make/calcdep.pl $<
+       @../make/calcdep.pl -file $<
 
 .%.d: %
-       @../make/calcdep.pl $<
+       @../make/calcdep.pl -file $<
 
 .PHONY: all alldep commands modules