]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Allow make on a read-only source tree using make O=objdir
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 16 Sep 2009 20:00:15 +0000 (20:00 +0000)
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 16 Sep 2009 20:00:15 +0000 (20:00 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11733 e03df62e-2008-0410-955e-edbf42e46eb7

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

index 6b8d7274feeeb23fa71590283f613bae2d710108..ebe4391b3fd47265114aa62f35125f0d90f3df94 100644 (file)
@@ -55,17 +55,25 @@ CXXFLAGS += -I../include
 
 @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)
     VERBOSE = -v
 @ELSE
     @GNU_ONLY MAKEFLAGS += --silent
     @BSD_ONLY MAKE += -s
-    RUNCC = ../make/run-cc.pl $(CC)
+    RUNCC = $(SOURCEPATH)/make/run-cc.pl $(CC)
 @ENDIF
 
 @DO_EXPORT RUNCC CXXFLAGS CC LDLIBS PICLDFLAGS VERBOSE SOCKETENGINE CORELDFLAGS
-@DO_EXPORT BASE CONPATH MODPATH BINPATH
+@DO_EXPORT BASE CONPATH MODPATH BINPATH SOURCEPATH
 
 # Default target
 TARGET = all
@@ -86,8 +94,8 @@ TARGET = all
 all: $(FOOTER)
 
 target: $(HEADER)
-@GNU_ONLY      $(MAKEENV) $(MAKE) -C src -f ../make/gnu-real.mk $(TARGET)
-@BSD_ONLY      $(MAKEENV) $(MAKE) -C src -f ../make/bsd-real.mk $(TARGET)
+@GNU_ONLY      $(MAKEENV) $(MAKE) -C $(BUILDPATH) -f ../make/gnu-real.mk $(TARGET)
+@BSD_ONLY      $(MAKEENV) $(MAKE) -C $(BUILDPATH) -f ../make/bsd-real.mk $(TARGET)
 
 debug:
        @${MAKE} D=1 all
@@ -191,6 +199,7 @@ help:
        @echo 'Flags:'
        @echo ' V=1       Show the full command being executed instead of "BUILD: dns.cpp"'
        @echo ' D=1       Enable debug build, for module development or crash tracing'
+       @echo ' O=objdir  Use an alternate location for storing object files'
        @echo ' -j <N>    Run a parallel build using N jobs'
        @echo ''
        @echo 'User targets:'
index 4ccc11be3bc7eae4250364f0cc70ad8fe5895c51..13cb2cce8d46732edddba571a3c491d3a2f1065d 100644 (file)
@@ -1,11 +1,12 @@
-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!, grep -d, <modules/m_*>'
+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 ../make/calcdep.pl -all
+DFILES != perl $(SOURCEPATH)/make/calcdep.pl -all
 
 all: inspircd commands modules
 
@@ -14,7 +15,7 @@ commands: $(CMD_TARGS)
 modules: $(MOD_TARGS) $(MDIR_TARGS)
 
 inspircd: $(CORE_TARGS)
-       $(RUNCC) -o $@ $(CORELDFLAGS) $(LDLIBS) $(CORE_TARGS)
+       $(RUNCC) -o $@ $(CORELDFLAGS) $(LDLIBS) $^
 
 .for FILE in $(DFILES)
 .include "$(FILE)"
index a4bb7f4d6e44c7738eb6fff80158cca51def9227..261b6ec18cdc8829bdcf1ace890aa2700fb95dcf 100755 (executable)
@@ -3,6 +3,12 @@ use strict;
 use warnings;
 use Getopt::Long;
 
+my $basesrc = "$ENV{SOURCEPATH}/src";
+my $baseinc = "$ENV{SOURCEPATH}/include";
+my $baseout = `pwd`;
+chomp $baseout;
+chdir $basesrc;
+
 my %f2dep;
 
 sub gendep;
@@ -21,9 +27,9 @@ sub gendep {
        while (<$in>) {
                if (/^\s*#\s*include\s*"([^"]+)"/) {
                        my $inc = $1;
-                       next if $inc eq 'inspircd_version.h' && $f eq '../include/inspircd.h';
+                       next if $inc eq 'inspircd_version.h' && $f eq $baseinc.'/inspircd.h';
                        my $found = 0;
-                       for my $loc ("$basedir/$inc", "../include/$inc") {
+                       for my $loc ("$basedir/$inc", "$baseinc/$inc") {
                                next unless -e $loc;
                                $found++;
                                $dep{$loc}++;
@@ -31,7 +37,7 @@ sub gendep {
                        }
                        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') {
+                       } elsif ($found > 1 && $basedir ne $baseinc) {
                                print STDERR "WARNING: ambiguous include $inc in $f\n";
                        }
                }
@@ -42,33 +48,30 @@ sub gendep {
 }
 
 sub dep_cpp {
-       my $file = shift;
+       my($file, $dfile) = @_;
        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";
+       $dfile = "$baseout/$path.$base.d" unless defined $dfile;
 
-       open OUT, '>', $cmd;
+       open OUT, '>', "$dfile" or die "Could not write $dfile: $!";
        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";
+       print OUT "\t@\$(SOURCEPATH)/make/unit-cc.pl \$(VERBOSE) \$< $out\n";
 }
 
 sub dep_dir {
-       my $dir = shift;
+       my($dir, $dfile) = @_;
        if ($dir =~ m#^(.*?)([^/]+)/?$#) {
                my($path,$base) = ($1,$2);
-               my $cmd = "$path.$base.d";
                my $out = "$path$base.so";
-               opendir DIR, $dir;
+               $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, '>', $cmd;
-               print OUT "$out: $ofiles\n\t".'$(RUNCC) $(PICLDFLAGS) -o $@ '
-                       .$ofiles."\n";
-               print OUT "$cmd: $dir\n\t".'@../make/calcdep.pl -file '."$path$base\n";
+               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;
@@ -83,15 +86,17 @@ GetOptions(
 );
 
 if (!$all && !defined $file) {
-       print "Use: $0 {-all|-file filename} [-quiet]\n";
+       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;
+               dep_cpp $file, $dfile;
        } elsif (-d $file) {
-               dep_dir $file;
+               dep_dir $file, $dfile;
        } else {
                print STDERR "Can't generate dependencies for $file\n";
                exit 1;
@@ -99,11 +104,13 @@ if (defined $file) {
 } 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;
        }
 
-       my @dirs = grep -d, <modules/m_*>;
        for my $dir (@dirs) {
                dep_dir $dir;
        }
index e892295a6a044ae7823c59f3f91109f9ba3a9675..338a5112d976df5e846ae8ec336e6f2be2a0e223 100644 (file)
@@ -1,11 +1,13 @@
-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))
+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 'print join " ", grep s!/?$$!.so!, grep -d, <modules/m_*>')
+MOD_TARGS += $(shell perl -e 'chdir "$$ENV{SOURCEPATH}/src"; print join " ", grep s!/?$$!.so!, grep -d, <modules/m_*>')
 
-DFILES = $(shell ../make/calcdep.pl -all)
+DFILES = $(shell perl $(SOURCEPATH)/make/calcdep.pl -all)
 
 all: inspircd commands modules
 
@@ -14,13 +16,7 @@ commands: $(CMD_TARGS)
 modules: $(MOD_TARGS)
 
 inspircd: $(CORE_TARGS)
-       $(RUNCC) -o $@ $(CORELDFLAGS) $(LDLIBS) $(CORE_TARGS)
-
-.%.d: %.cpp
-       @../make/calcdep.pl -file $<
-
-.%.d: %
-       @../make/calcdep.pl -file $<
+       $(RUNCC) -o $@ $(CORELDFLAGS) $(LDLIBS) $^
 
 .PHONY: all alldep commands modules
 
index 21c4fbd60bbc9616783eeeb7cc63ab84618ba3f2..07f6ace9890888c956021eb60e7328780b7ed42b 100755 (executable)
@@ -125,14 +125,18 @@ if ($cc eq "ar") {
        {
                if ($n =~ /\.cpp$/)
                {
+                       my $f = $n;
+                       if (defined $ENV{SOURCEPATH}) {
+                               $f =~ s#^$ENV{SOURCEPATH}/src/##;
+                       }
                        if ($action eq "BUILD")
                        {
-                               $name .= " " . $n;
+                               $name .= " " . $f;
                        }
                        else
                        {
                                $action = "BUILD";
-                               $name = $n;
+                               $name = $f;
                        }
                }
                elsif ($action eq "BUILD") # .cpp has priority.