From 3a186342c975a8bbd3f588d180a55e381b31883c Mon Sep 17 00:00:00 2001 From: danieldg Date: Thu, 17 Sep 2009 03:04:27 +0000 Subject: 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 --- .Makefile.inc | 27 ++++----- .gitignore | 42 ++++--------- configure | 6 +- make/bsd-real.mk | 22 ------- make/calcdep.pl | 178 +++++++++++++++++++++++++++++++------------------------ make/gnu-real.mk | 23 ------- 6 files changed, 131 insertions(+), 167 deletions(-) delete mode 100644 make/bsd-real.mk delete mode 100644 make/gnu-real.mk diff --git a/.Makefile.inc b/.Makefile.inc index ebe4391b3..4f619feac 100644 --- a/.Makefile.inc +++ b/.Makefile.inc @@ -8,6 +8,7 @@ CC = @CC@ SYSTEM = @SYSTEM@ +BUILDPATH = @BUILD_DIR@ SOCKETENGINE = @SOCKETENGINE@ CXXFLAGS += -pipe -fPIC -DPIC LDLIBS = -pthread -lstdc++ @@ -51,17 +52,12 @@ INSTMODE = 0755 @ENDIF FOOTER = finishmessage -CXXFLAGS += -I../include +CXXFLAGS += -Iinclude @GNU_ONLY MAKEFLAGS += --no-print-directory @GNU_ONLY SOURCEPATH = $(shell /bin/pwd) @BSD_ONLY SOURCEPATH != /bin/pwd -@IFDEF O - BUILDPATH = $(O) -@ELSE - BUILDPATH = src -@ENDIF @IFDEF V RUNCC = $(CC) @@ -73,7 +69,7 @@ CXXFLAGS += -I../include @ENDIF @DO_EXPORT RUNCC CXXFLAGS CC LDLIBS PICLDFLAGS VERBOSE SOCKETENGINE CORELDFLAGS -@DO_EXPORT BASE CONPATH MODPATH BINPATH SOURCEPATH +@DO_EXPORT BASE CONPATH MODPATH BINPATH SOURCEPATH BUILDPATH # Default target TARGET = all @@ -94,8 +90,8 @@ TARGET = all all: $(FOOTER) target: $(HEADER) -@GNU_ONLY $(MAKEENV) $(MAKE) -C $(BUILDPATH) -f ../make/gnu-real.mk $(TARGET) -@BSD_ONLY $(MAKEENV) $(MAKE) -C $(BUILDPATH) -f ../make/bsd-real.mk $(TARGET) + $(MAKEENV) perl make/calcdep.pl + $(MAKEENV) $(MAKE) -C $(BUILDPATH) -f real.mk $(TARGET) debug: @${MAKE} D=1 all @@ -118,7 +114,7 @@ mod-header: @echo 'Building single module:' mod-footer: target - @echo 'To install, copy src/$(TARGET) to $(MODPATH)' + @echo 'To install, copy $(BUILDPATH)/$(TARGET) to $(MODPATH)' @echo 'Or, run "make install"' std-header: @@ -145,10 +141,9 @@ install: target@EXTRA_DIR@ @-install -d -m $(INSTMODE) $(BINPATH) @-install -d -m $(INSTMODE) $(CONPATH) @-install -d -m $(INSTMODE) $(MODPATH) - -install -m $(INSTMODE) src/commands/*.so $(MODPATH) - -install -m $(INSTMODE) src/modules/*.so $(MODPATH) + -install -m $(INSTMODE) $(BUILDPATH)/modules/*.so $(MODPATH) + -install -m $(INSTMODE) $(BUILDPATH)/bin/inspircd $(BINPATH) -install -m $(INSTMODE) @STARTSCRIPT@ $(@DESTINATION@) 2>/dev/null - -install -m $(INSTMODE) src/inspircd $(BINPATH) @$(MAKEENV) make/install-extras.pl install @echo "" @echo "*************************************" @@ -163,9 +158,13 @@ install: target@EXTRA_DIR@ clean: @echo Cleaning... @rm -f src/inspircd src/modes/modeclasses.a - @rm -f src/*.so src/modules/*.so src/commands/*.so src/modules/*/*.so + @rm -f src/*.so src/modules/*.so src/commands/*.so @rm -f src/*.o src/*/*.o src/modules/*/*.o @rm -f src/.*.d src/*/.*.d src/modules/*/.*.d + @rm -f $(BUILDPATH)/bin/inspircd $(BUILDPATH)/include $(BUILDPATH)/real.mk + @rm -rf $(BUILDPATH)/obj $(BUILDPATH)/modules + @-rmdir $(BUILDPATH)/bin + @-rmdir $(BUILDPATH) @echo Completed. deinstall: diff --git a/.gitignore b/.gitignore index ad297dd30..16f1fa69a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,53 +3,35 @@ *.so *.o .*.d +*.cpp.* -/GNUmakefile -/BSDmakefile -/.modulemanager +/*.diff +/*.orig +/*.patch +/*.rej /.config.cache +/.modulemanager +/BSDmakefile +/GNUmakefile +/bin +/build /inspircd -/inspircd.pid /inspircd.core +/inspircd.pid /modules /org.inspircd.plist -/*.patch -/*.diff -/*.orig -/*.rej - -# /bin/ -/bin/inspircd -/bin/ircd.log -/bin/*core* -# /conf/ /conf/*.conf /conf/*.pem /conf/inspircd.conf.example /conf/*.pid -# /include/ /include/inspircd_config.h /include/inspircd_version.h /include/inspircd_se_config.h -# /src/ /src/inspircd -/src/Makefile -/src/*.cpp.* - -# /src/commands/ -/src/commands/Makefile -/src/commands/*.so -/src/commands/*.cpp.* - -# /src/modes/ -/src/modes/*.a -/src/modes/*.o -/src/modes/*.cpp.* -# /src/modules/ /src/modules/m_geoip.cpp /src/modules/m_ldapauth.cpp /src/modules/m_ldapoper.cpp @@ -73,5 +55,3 @@ /src/modules/m_testclient.cpp /src/modules/m_ziplink.cpp /src/modules/ssl_cert.h -/src/modules/Makefile -/src/modules/README diff --git a/configure b/configure index efa957c82..e0b2dd6b5 100755 --- a/configure +++ b/configure @@ -611,6 +611,7 @@ should NOT be used. You should probably specify a newer compiler.\n\n"; dir_check("are the configuration files", "CONFIG_DIR"); dir_check("are the modules to be compiled to", "MODULE_DIR"); dir_check("is the IRCd binary to be placed", "BINARY_DIR"); + dir_check("do you want the build to take place", "BUILD_DIR"); my $chose_hiperf = 0; if ($has_kqueue) { @@ -1075,8 +1076,11 @@ EOF close(FILEHANDLE); print "Writing \e[1;32m$file\e[0m ...\n"; + + $config{BUILD_DIR} ||= 'build'; + for my $var (qw( - CC SYSTEM BASE_DIR CONFIG_DIR MODULE_DIR BINARY_DIR + CC SYSTEM BASE_DIR CONFIG_DIR MODULE_DIR BINARY_DIR BUILD_DIR STARTSCRIPT DESTINATION EXTRA_DIR SOCKETENGINE )) { s/\@$var\@/$config{$var}/g; 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>, ' -CMD_TARGS != perl -e 'chdir "$$ENV{SOURCEPATH}/src"; print join " ", grep s/\.cpp/.so/, ' -MOD_TARGS != perl -e 'chdir "$$ENV{SOURCEPATH}/src"; print join " ", grep s/\.cpp/.so/, ' -MDIR_TARGS != perl -e 'chdir "$$ENV{SOURCEPATH}/src"; print join " ", grep s!/?$$!.so!, grep -d, ' - -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 <, , "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 (, ) { + 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 <) { 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 "; - $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>, , , , ); - push @files, "socketengines/$ENV{SOCKETENGINE}.cpp", "threadengines/threadengine_pthread.cpp"; - my @dirs = grep -d, ; - 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, ') - -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) -- cgit v1.2.3