diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-17 03:04:27 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-17 03:04:27 +0000 |
commit | 3a186342c975a8bbd3f588d180a55e381b31883c (patch) | |
tree | 2efefce23e807e5479e0bf4e9fd7cfd5870b51f2 /make | |
parent | c9a998effe0ffe6e6a9d6c80cebb1a1e4b28b3ec (diff) |
Remove .*.d dependency garbage, and use a dedicated build directory
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11738 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'make')
-rw-r--r-- | make/bsd-real.mk | 22 | ||||
-rwxr-xr-x | make/calcdep.pl | 178 | ||||
-rw-r--r-- | make/gnu-real.mk | 23 |
3 files changed, 102 insertions, 121 deletions
diff --git a/make/bsd-real.mk b/make/bsd-real.mk deleted file mode 100644 index 13cb2cce8..000000000 --- a/make/bsd-real.mk +++ /dev/null @@ -1,22 +0,0 @@ -VPATH = $(SOURCEPATH)/src -CORE_TARGS != perl -e 'chdir "$$ENV{SOURCEPATH}/src"; print join " ", grep s/\.cpp/.o/, <*.cpp>, <modes/*.cpp>' -CMD_TARGS != perl -e 'chdir "$$ENV{SOURCEPATH}/src"; print join " ", grep s/\.cpp/.so/, <commands/*.cpp>' -MOD_TARGS != perl -e 'chdir "$$ENV{SOURCEPATH}/src"; print join " ", grep s/\.cpp/.so/, <modules/*.cpp>' -MDIR_TARGS != perl -e 'chdir "$$ENV{SOURCEPATH}/src"; print join " ", grep s!/?$$!.so!, grep -d, <modules/m_*>' - -CORE_TARGS += socketengines/$(SOCKETENGINE).o threadengines/threadengine_pthread.o - -DFILES != perl $(SOURCEPATH)/make/calcdep.pl -all - -all: inspircd commands modules - -commands: $(CMD_TARGS) - -modules: $(MOD_TARGS) $(MDIR_TARGS) - -inspircd: $(CORE_TARGS) - $(RUNCC) -o $@ $(CORELDFLAGS) $(LDLIBS) $^ - -.for FILE in $(DFILES) -.include "$(FILE)" -.endfor diff --git a/make/calcdep.pl b/make/calcdep.pl index 261b6ec18..1a65f836b 100755 --- a/make/calcdep.pl +++ b/make/calcdep.pl @@ -3,16 +3,90 @@ use strict; use warnings; use Getopt::Long; -my $basesrc = "$ENV{SOURCEPATH}/src"; -my $baseinc = "$ENV{SOURCEPATH}/include"; -my $baseout = `pwd`; -chomp $baseout; -chdir $basesrc; +sub find_output($); +sub gendep($); +sub dep_cpp($$); +sub dep_dir($); +sub run(); my %f2dep; -sub gendep; -sub gendep { +run; +exit 0; + +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'; + $build = `pwd`; + chomp $build; + open MAKE, '>real.mk' or die "Could not write real.mk: $!"; + chdir "$ENV{SOURCEPATH}/src"; + + print MAKE <<END; +# DO NOT EDIT +# Autogenerated by calcdep +VPATH = \$(SOURCEPATH)/src + +all: bin/inspircd modules + +END + my @core_deps; + for my $file (<*.cpp>, <modes/*.cpp>, "socketengines/$ENV{SOCKETENGINE}.cpp", "threadengines/threadengine_pthread.cpp") { + my $out = find_output $file; + dep_cpp $file, $out; + push @core_deps, $out; + } + + my @modlist; + for my $file (<commands/*.cpp>, <modules/*.cpp>) { + my $out = find_output $file; + dep_cpp $file, $out; + push @modlist, $out; + } + + opendir my $moddir, 'modules'; + for my $dir (readdir $moddir) { + next unless $dir =~ /^m_/ && -d "modules/$dir"; + mkdir "$build/obj/$dir"; + dep_dir "modules/$dir"; + push @modlist, "modules/$dir.so"; + } + + my $core_mk = join ' ', @core_deps; + my $mods = join ' ', @modlist; + print MAKE <<END; + +bin/inspircd: $core_mk + \$(RUNCC) -o \$\@ \$(CORELDFLAGS) \$(LDLIBS) \$^ + +inspircd: bin/inspircd +modules: $mods + +.PHONY: inspircd modules + +END +} + +sub find_output($) { + my $file = shift; + my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file"; + if ($path eq 'modules/' || $path eq 'commands/') { + return "modules/$base.so"; + } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) { + return "obj/$base.o"; + } elsif ($path =~ m#modules/(m_.*)/#) { + return "obj/$1/$base.o"; + } else { + die "Can't determine output for $file"; + } +} + +sub gendep($) { my $f = shift; my $basedir = $f =~ m#(.*)/# ? $1 : '.'; return $f2dep{$f} if exists $f2dep{$f}; @@ -27,17 +101,18 @@ sub gendep { while (<$in>) { if (/^\s*#\s*include\s*"([^"]+)"/) { my $inc = $1; - next if $inc eq 'inspircd_version.h' && $f eq $baseinc.'/inspircd.h'; + next if $inc eq 'inspircd_version.h' && $f eq '../include/inspircd.h'; my $found = 0; - for my $loc ("$basedir/$inc", "$baseinc/$inc") { + for my $loc ("$basedir/$inc", "../include/$inc") { next unless -e $loc; $found++; - $dep{$loc}++; $dep{$_}++ for split / /, gendep $loc; + $loc =~ s#^\.\./##; + $dep{$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 $baseinc) { + } elsif ($found > 1 && $basedir ne '../include') { print STDERR "WARNING: ambiguous include $inc in $f\n"; } } @@ -47,75 +122,26 @@ sub gendep { $f2dep{$f}; } -sub dep_cpp { - my($file, $dfile) = @_; +sub dep_cpp($$) { + my($file, $out) = @_; gendep $file; - my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file"; - my $ext = $path eq 'modules/' || $path eq 'commands/' ? '.so' : '.o'; - my $out = "$path$base$ext"; - $dfile = "$baseout/$path.$base.d" unless defined $dfile; - open OUT, '>', "$dfile" or die "Could not write $dfile: $!"; - print OUT "$out: $file $f2dep{$file}\n"; - print OUT "\t@\$(SOURCEPATH)/make/unit-cc.pl \$(VERBOSE) \$< $out\n"; + print MAKE "$out: $file $f2dep{$file}\n"; + print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl \$(VERBOSE) \$< \$\@\n"; } -sub dep_dir { - my($dir, $dfile) = @_; - if ($dir =~ m#^(.*?)([^/]+)/?$#) { - my($path,$base) = ($1,$2); - my $out = "$path$base.so"; - $dfile = "$baseout/$path.$base.d" unless defined $dfile; - opendir DIR, "$basesrc/$dir"; - my $ofiles = join ' ', grep s/(.*)\.cpp$/$path$base\/$1.o/, readdir DIR; - closedir DIR; - open OUT, '>', "$dfile" or die "Could not write $dfile: $!"; - print OUT "$out: $ofiles\n\t\$(RUNCC) \$(PICLDFLAGS) -o \$\@ \$^\n"; - close OUT; - } else { - print STDERR "Cannot generate depencency for $dir\n"; - exit 1; +sub dep_dir($) { + my($dir) = @_; + my @ofiles; + opendir DIR, $dir; + for my $file (readdir DIR) { + next unless $file =~ /(.*)\.cpp$/; + my $ofile = find_output "$dir/$file"; + dep_cpp "$dir/$file", $ofile; + push @ofiles, $ofile; } + closedir DIR; + my $ofiles = join ' ', @ofiles; + print MAKE "$dir.so: $ofiles\n\t\$(RUNCC) \$(PICLDFLAGS) -o \$\@ \$^\n"; } -my($all,$quiet, $file); -GetOptions( - 'all' => \$all, - 'quiet' => \$quiet, - 'file=s' => \$file, -); - -if (!$all && !defined $file) { - print "Use: $0 {-all|-file src dest} [-quiet]\n"; - exit 1; -} - -if (defined $file) { - my $dfile = shift or die "Syntax: -file <in> <out>"; - $dfile = "$baseout/$dfile" unless $dfile =~ m#^/#; - if (-f $file) { - dep_cpp $file, $dfile; - } elsif (-d $file) { - dep_dir $file, $dfile; - } else { - 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"; - my @dirs = grep -d, <modules/m_*>; - mkdir "$baseout/$_" for qw(commands modes modules socketengines threadengines), @dirs; - - for my $file (@files) { - dep_cpp $file; - } - - for my $dir (@dirs) { - dep_dir $dir; - } - - s#([^/]+)\.cpp#.$1.d# for @files; - s#([^/]+)/?$#.$1.d# for @dirs; - print join ' ', @files, @dirs; -} diff --git a/make/gnu-real.mk b/make/gnu-real.mk deleted file mode 100644 index 338a5112d..000000000 --- a/make/gnu-real.mk +++ /dev/null @@ -1,23 +0,0 @@ -SRC = $(SOURCEPATH)/src -VPATH = $(SRC) -CORE_TARGS = $(patsubst $(SRC)/%.cpp,%.o,$(wildcard $(SRC)/*.cpp $(SRC)/modes/*.cpp)) -CMD_TARGS = $(patsubst $(SRC)/%.cpp,%.so,$(wildcard $(SRC)/commands/*.cpp)) -MOD_TARGS = $(patsubst $(SRC)/%.cpp,%.so,$(wildcard $(SRC)/modules/*.cpp)) - -CORE_TARGS += socketengines/$(SOCKETENGINE).o threadengines/threadengine_pthread.o -MOD_TARGS += $(shell perl -e 'chdir "$$ENV{SOURCEPATH}/src"; print join " ", grep s!/?$$!.so!, grep -d, <modules/m_*>') - -DFILES = $(shell perl $(SOURCEPATH)/make/calcdep.pl -all) - -all: inspircd commands modules - -commands: $(CMD_TARGS) - -modules: $(MOD_TARGS) - -inspircd: $(CORE_TARGS) - $(RUNCC) -o $@ $(CORELDFLAGS) $(LDLIBS) $^ - -.PHONY: all alldep commands modules - --include $(DFILES) |