Fix dependency generation for non-C files; support separate kernel
source/obj directories

diff --git a/MCONFIG b/MCONFIG
index d2aa236..7da150d 100644
--- a/MCONFIG
+++ b/MCONFIG
@@ -6,19 +6,23 @@
 # Eventually support separate compilation, but we don't have it yet...
 OBJROOT = $(SRCROOT)
 
+# Kernel trees (source and obj) - can potentially be different
+KRNLSRC = $(SRCROOT)/linux
+KRNLOBJ = $(SRCROOT)/linux
+
 ARCH    = $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
 CROSS   = 
 CC	= $(CROSS)gcc
 LD      = $(CROSS)ld
 KLIBSRC = $(SRCROOT)/klibc
 KLIBOBJ = $(OBJROOT)/klibc
-REQFLAGS = $(ARCHREQFLAGS) -nostdinc -iwithprefix include \
-	  -D__KLIBC__ -DBITSIZE=$(BITSIZE) \
-	  -I$(SRCROOT)/include/arch/$(ARCH) \
+INCLUDE = -I$(SRCROOT)/include/arch/$(ARCH) \
 	  -I$(SRCROOT)/include/bits$(BITSIZE) \
 	  -I$(SRCROOT)/include \
-	  -I$(SRCROOT)/linux/include -I$(SRCROOT)/linux/include2
- 
+	  -I$(KRNLOBJ)/include -I$(KRNLOBJ)/include2 -I$(KRNLSRC)/include
+REQFLAGS = $(ARCHREQFLAGS) -nostdinc -iwithprefix include \
+	  -D__KLIBC__ -DBITSIZE=$(BITSIZE) \
+	  $(INCLUDE)
 LDFLAGS =
 AR      = $(CROSS)ar
 RANLIB  = $(CROSS)ranlib
diff --git a/klibc/MCONFIG b/klibc/MCONFIG
index 5b6eecd..499b6e8 100644
--- a/klibc/MCONFIG
+++ b/klibc/MCONFIG
@@ -13,6 +13,6 @@
 REQFLAGS += -DWITH_ERRLIST
 endif
 
-CFLAGS  = -Wp,-MD,$(dir $*).$(notdir $*).d $(OPTFLAGS) $(REQFLAGS) $(WARNFLAGS)
+CFLAGS  = -Wp,-MT,$@,-MD,$(dir $@).$(notdir $@).d $(OPTFLAGS) $(REQFLAGS) $(WARNFLAGS)
 
 SOFLAGS = -fPIC
diff --git a/klibc/Makefile b/klibc/Makefile
index d7e75f1..e3907d8 100644
--- a/klibc/Makefile
+++ b/klibc/Makefile
@@ -120,14 +120,14 @@
 	cp arch/$(ARCH)/crt0.o .
 
 errlist.c:
-	$(PERL) makeerrlist.pl -errlist > $@ || rm -f $@
+	$(PERL) makeerrlist.pl $(INCLUDE) -errlist > $@ || rm -f $@
 
 # We pass -ansi to keep cpp from define e.g. "i386" as well as "__i386__"
 SYSCALLS.i: SYSCALLS.def
 	$(CC) $(CFLAGS) -D__ASSEMBLY__ -ansi -x assembler-with-cpp -E -o $@ $<
 
-syscalls.nrs: ../include/sys/syscall.h ../include/arch/$(ARCH)/klibc/archsys.h ../linux/include/asm/unistd.h
-	$(CC) $(CFLAGS) -Wp,-dM -x c -E -o $@ ../include/sys/syscall.h
+syscalls.nrs: $<
+	$(CC) $(CFLAGS) -Wp,-dM -x c -E -o $@ $<
 
 syscalls.dir: SYSCALLS.i syscalls.pl arch/$(ARCH)/sysstub.ph syscommon.h syscalls.nrs
 	rm -rf syscalls
diff --git a/klibc/makeerrlist.pl b/klibc/makeerrlist.pl
index f42704f..14498d8 100644
--- a/klibc/makeerrlist.pl
+++ b/klibc/makeerrlist.pl
@@ -10,20 +10,27 @@
 %errors  = ();
 %errmsg  = ();
 $maxerr  = -1;
-$rootdir = '../linux/include/';	# Must have trailing /
+@includelist = ();		# Include directories
 
 sub parse_file($) {
     my($file) = @_;
     my($fh) = new FileHandle;
     my($line, $error, $msg);
     my($kernelonly) = 0;
-
-    $file = $rootdir.$file;
+    my($root);
 
     print STDERR "opening $file\n" unless ( $quiet );
 
-    if ( !($fh->open("< ".$file)) ) {
-	die "$0: cannot open $file\n";
+    $ok = 0;
+    foreach $root ( @includelist ) {
+	if ( $fh->open($root.'//'.$file, '<') ) {
+	    $ok = 1;
+	    last;
+	}
+    }
+
+    if ( ! $ok ) {
+	die "$0: Cannot find file $file\n";
     }
 
     while ( defined($line = <$fh>) ) {
@@ -61,8 +68,10 @@
 	$quiet = 1;
     } elsif ( $arg =~ /^-(errlist|errnos|maxerr)$/ ) {
 	$type = $arg;
+    } elsif ( $arg =~ '^\-I' ) {
+	push(@includelist, "$'");
     } else {
-	die "$0: Unknown option: $arg\n";
+ 	die "$0: Unknown option: $arg\n";
     }
 }