summaryrefslogtreecommitdiff
path: root/make
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-01 15:04:40 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-01 15:04:40 +0000
commit990e04bab51bf1c3771938b8f598272c1b31cdca (patch)
tree8b077d8d3326feeb6736f5eb1fa719103a8822d5 /make
parent8f8e244f4f350a53a2a84296a66468b7e5ac4a2b (diff)
Move dependency tracking from ./configure to Makefile
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11556 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'make')
-rw-r--r--make/bsd-dep.mk10
-rw-r--r--make/bsd-real.mk25
-rwxr-xr-xmake/calcdep.pl23
-rw-r--r--make/gnu-dep.mk11
-rw-r--r--make/gnu-real.mk32
-rwxr-xr-xmake/unit-cc.pl31
6 files changed, 132 insertions, 0 deletions
diff --git a/make/bsd-dep.mk b/make/bsd-dep.mk
new file mode 100644
index 000000000..5fe31e89f
--- /dev/null
+++ b/make/bsd-dep.mk
@@ -0,0 +1,10 @@
+DFILES != perl -e 'print join " ", grep s/\.cpp/.d/, <*.cpp>, <commands/*.cpp>, <modes/*.cpp>, <modules/*.cpp>'
+DFILES += socketengines/$(SOCKETENGINE).d threadengines/threadengine_pthread.d
+
+all: $(DFILES)
+
+.SUFFIXES: .d .cpp
+
+.cpp.d:
+ @../make/calcdep.pl $<
+ @echo -n .
diff --git a/make/bsd-real.mk b/make/bsd-real.mk
new file mode 100644
index 000000000..ea3e1482c
--- /dev/null
+++ b/make/bsd-real.mk
@@ -0,0 +1,25 @@
+CORE_TARGS != perl -e 'print join " ", grep s/\.cpp/.o/, <*.cpp>'
+MODE_TARGS != perl -e 'print join " ", grep s/\.cpp/.o/, <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>'
+CORE_TARGS += modeclasses.a threadengines/threadengine_pthread.o
+CORE_TARGS += socketengines/$(SOCKETENGINE).o
+
+DFILES != perl -e 'print join " ", grep s/\.cpp/.d/, <*.cpp>, <commands/*.cpp>, <modes/*.cpp>, <modules/*.cpp>'
+DFILES += socketengines/$(SOCKETENGINE).d threadengines/threadengine_pthread.d
+
+all: inspircd commands modules
+
+commands: $(CMD_TARGS)
+
+modules: $(MOD_TARGS)
+
+modeclasses.a: $(MODE_TARGS)
+ @../make/run-cc.pl ar crs modeclasses.a $(MODE_TARGS)
+
+inspircd: $(CORE_TARGS)
+ $(RUNCC) $(FLAGS) -rdynamic -L. -o inspircd $(LDLIBS) $(CORE_TARGS)
+
+.for FILE in $(DFILES)
+.include "$(FILE)"
+.endfor
diff --git a/make/calcdep.pl b/make/calcdep.pl
new file mode 100755
index 000000000..2b6742be3
--- /dev/null
+++ b/make/calcdep.pl
@@ -0,0 +1,23 @@
+#!/usr/bin/perl
+use strict;
+BEGIN { push @INC, '..'; }
+use make::configure;
+
+my $file = shift;
+
+$file =~ /(.*)\.cpp$/ or die "Cannot process $file";
+my $base = $1;
+
+my $out = "$base.d";
+
+open IN, '<', $file or die "Could not read $file: $!";
+open OUT, '>', $out or die "Could not write $out: $!";
+
+my $cc_deps = qx($ENV{CC} $ENV{FLAGS} -MM $file);
+$cc_deps =~ s/.*?:\s*//;
+
+my $ext = $file =~ m#(modules|commands)/# ? '.so' : '.o';
+print OUT "$base$ext: $cc_deps";
+print OUT "\t@../make/unit-cc.pl \$(VERBOSE) $file $base$ext\n";
+print OUT "$base.d: $cc_deps";
+print OUT "\t../make/calcdep.pl $file\n";
diff --git a/make/gnu-dep.mk b/make/gnu-dep.mk
new file mode 100644
index 000000000..e8c70c0cd
--- /dev/null
+++ b/make/gnu-dep.mk
@@ -0,0 +1,11 @@
+DFILES = $(patsubst %.cpp,%.d,$(wildcard *.cpp))
+DFILES += $(patsubst %.cpp,%.d,$(wildcard commands/*.cpp))
+DFILES += $(patsubst %.cpp,%.d,$(wildcard modes/*.cpp))
+DFILES += $(patsubst %.cpp,%.d,$(wildcard modules/*.cpp))
+DFILES += socketengines/$(SOCKETENGINE).d threadengines/threadengine_pthread.d
+
+all: $(DFILES)
+
+%.d: %.cpp
+ @../make/calcdep.pl $<
+ @echo -n .
diff --git a/make/gnu-real.mk b/make/gnu-real.mk
new file mode 100644
index 000000000..263467038
--- /dev/null
+++ b/make/gnu-real.mk
@@ -0,0 +1,32 @@
+CORE_TARGS = $(patsubst %.cpp,%.o,$(wildcard *.cpp))
+MODE_TARGS = $(patsubst %.cpp,%.o,$(wildcard modes/*.cpp))
+CMD_TARGS = $(patsubst %.cpp,%.so,$(wildcard commands/*.cpp))
+MOD_TARGS = $(patsubst %.cpp,%.so,$(wildcard modules/*.cpp))
+
+CORE_TARGS += modeclasses.a threadengines/threadengine_pthread.o
+CORE_TARGS += socketengines/$(SOCKETENGINE).o
+
+DFILES = $(patsubst %.cpp,%.d,$(wildcard *.cpp))
+DFILES += $(patsubst %.cpp,%.d,$(wildcard commands/*.cpp))
+DFILES += $(patsubst %.cpp,%.d,$(wildcard modes/*.cpp))
+DFILES += $(patsubst %.cpp,%.d,$(wildcard modules/*.cpp))
+DFILES += socketengines/$(SOCKETENGINE).d threadengines/threadengine_pthread.d
+
+all: inspircd commands modules
+
+commands: $(CMD_TARGS)
+
+modules: $(MOD_TARGS)
+
+modeclasses.a: $(MODE_TARGS)
+ @../make/run-cc.pl ar crs modeclasses.a $(MODE_TARGS)
+
+inspircd: $(CORE_TARGS)
+ $(RUNCC) $(FLAGS) -rdynamic -L. -o inspircd $(LDLIBS) $(CORE_TARGS)
+
+%.d: %.cpp
+ @../make/calcdep.pl $<
+
+.PHONY: all commands modules
+
+-include $(DFILES)
diff --git a/make/unit-cc.pl b/make/unit-cc.pl
new file mode 100755
index 000000000..5110037ac
--- /dev/null
+++ b/make/unit-cc.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+BEGIN { push @INC, '..'; }
+use make::configure;
+
+my $file = shift;
+my $verbose;
+
+if ($file =~ /^-/) {
+ $_ = $file;
+ $file = shift;
+ $verbose = /v/;
+}
+
+my $out = shift;
+
+my $cflags = nopedantic($file) ? $ENV{NICEFLAGS} : $ENV{FLAGS};
+$cflags .= ' ' . getcompilerflags($file);
+
+my $flags;
+if ($out =~ /\.so$/) {
+ $flags = join ' ', $cflags, $ENV{PICLDFLAGS}, getlinkerflags($file);
+} else {
+ $flags = "$cflags -c";
+}
+
+my $execstr = "$ENV{RUNCC} $flags -o $out $file";
+print "$execstr\n" if $verbose;
+exec $execstr;
+exit 1;