2007-11-19  Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	This patch is based on the patch submitted by Eli Zaretskii to
	bug-make@gnu.org.  It can be inspected at:
	http://lists.gnu.org/archive/html/bug-make/2005-02/msg00022.html 

	This is patch 1 of 3 and must be applied first.


	* configh.dos [__DJGPP__]: Replace HAVE_SYS_SIGLIST with HAVE_DECL_SYS_SIGLIST.

	* glob.c (my_realloc): Don't define, and don't redefine realloc to
	call it, under __MSDOS__, since the DJGPP realloc handles NULL
	pointers.  From Eli Zaretskii.

	* function.c (abspath): Use IS_PATHSEP instead of a literal '/'.
	If HAVE_DOS_PATHS is defined, support d:foo style absolute file
	names.  From Eli Zaretskii.

	* job.c (child_execute_job): Remove __MSDOS__ because MSDOS/DJGPP build
	do not use child_execute_job.

	* variable.c (define_automatic_variables) [__MSDOS__]: Export always
	the SHELL environment variable before calling system().

       	* hash.c (round_up_2): Use 4294967295U to avoid compiler
	warnings.  From Eli Zaretskii.

	* Makefile.DOS (INCLUDES): Use paths with $(prefix) instead of
	hardcoded ones.
	(info_TEXINFOS, TEXINFOS, .info, .dvi, .texinfo): Replace .texinfo with
	.texi.  The documentation now recides in /doc; adjust paths accordingly.



diff -aprNU5 make-3.81.orig/Makefile.DOS make-3.81/Makefile.DOS
--- make-3.81.orig/Makefile.DOS	2006-04-01 06:42:38 +0000
+++ make-3.81/Makefile.DOS	2007-11-19 17:11:42 +0000
@@ -80,14 +80,14 @@ bin_PROGRAMS =	make$(EXEEXT)
 make_SOURCES =	ar.c arscan.c commands.c default.c dir.c expand.c file.c function.c getopt.c getopt1.c implicit.c job.c main.c misc.c read.c remake.c rule.c signame.c strcache.c variable.c version.c vpath.c hash.c remote-$(REMOTE).c
 # This should include the glob/ prefix
 libglob_a_SOURCES =	glob/fnmatch.c glob/glob.c glob/fnmatch.h glob/glob.h
 make_LDADD =	  glob/libglob.a
 
-info_TEXINFOS =	make.texinfo
+info_TEXINFOS =	make.texi
 man_MANS =	make.1
 
-INCLUDES =	-I$(srcdir)/glob -DLIBDIR=\"c:/djgpp/lib\" -DINCLUDEDIR=\"c:/djgpp/include\" -DLOCALEDIR=\"$(localedir)\"
+INCLUDES =	-I$(srcdir)/glob -DLIBDIR=\"$(prefix)$(libdir)\" -DINCLUDEDIR=\"$(prefix)$(includedir)\" -DLOCALEDIR=\"$(prefix)$(localedir)\"
 
 BUILT_SOURCES =	README build.sh-in
 
 EXTRA_DIST = 	$(BUILT_SOURCES) $(man_MANS) README.customs remote-cstms.c  make-stds.texi texinfo.tex SCOPTIONS SMakefile  Makefile.ami README.Amiga config.ami amiga.c amiga.h  NMakefile README.DOS configh.dos configure.bat makefile.com  README.W32 build_w32.bat config.h-W32 subproc.bat make.lnk  config.h-vms makefile.vms readme.vms vmsdir.h vmsfunctions.c  vmsify.c
 
@@ -113,13 +113,13 @@ noinst_LIBRARIES =	glob/libglob.a
 CFLAGS = -O2 -g
 COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
 LINK = $(CC) $(CFLAGS) $(LDFLAGS) -o $@
 TEXI2DVI = texi2dvi
 TEXINFO_TEX = $(srcdir)/config/texinfo.tex
-INFO_DEPS = make.info
-DVIS = make.dvi
-TEXINFOS = make.texinfo
+INFO_DEPS = doc/make.info
+DVIS = doc/make.dvi
+TEXINFOS = doc/make.texi doc/fdl.texi doc/make-stds.texi
 man1dir = $(mandir)/man1
 MANS = $(man_MANS)
 
 NROFF = nroff
 DIST_COMMON =  README ABOUT-NLS AUTHORS COPYING ChangeLog INSTALL Makefile.am  Makefile.in NEWS acconfig.h aclocal.m4 alloca.c build.sh-in config.h-in  configure configure.in getloadavg.c
@@ -133,11 +133,11 @@ OBJECTS = $(make_OBJECTS)
 HEADERS = $(wildcard $(srcdir)/*.h)
 
 default: all
 
 .SUFFIXES:
-.SUFFIXES: .c .dvi .info .o .obj .ps .texinfo .tex
+.SUFFIXES: .c .dvi .info .o .obj .ps .texi .tex
 
 mostlyclean-hdr:
 
 clean-hdr:
 
@@ -183,45 +183,44 @@ maintainer-clean-compile:
 make$(EXEEXT): $(make_OBJECTS) $(make_DEPENDENCIES)
 	@command.com /c if exist make del make
 	@command.com /c if exist make.exe del make.exe
 	$(LINK) $(make_LDFLAGS) $(make_OBJECTS) $(make_LDADD) $(LIBS)
 
-make.info: make.texinfo
-make.dvi: make.texinfo
-
+doc/make.info: ${TEXINFOS}
+doc/make.dvi: ${TEXINFOS)
 
 DVIPS = dvips
 
-.texinfo.info:
-	@command.com /c if exist make.info* del make.info*
-	@command.com /c if exist make.i* del make.i*
-	$(MAKEINFO) -I$(srcdir) $< -o ./$@
-
-.texinfo:
-	@command.com /c if exist make.info* del make.info*
-	@command.com /c if exist make.i* del make.i*
-	$(MAKEINFO) -I$(srcdir) $< -o ./$@
+.texi.info:
+	@command.com /c if exist doc\make.info* del doc\make.info*
+	@command.com /c if exist doc\make.i* del doc\make.i*
+	$(MAKEINFO) -I$(srcdir)/doc $< -o ./$@
+
+.texi:
+	@command.com /c if exist doc\make.info* del doc\make.info*
+	@command.com /c if exist doc\make.i* del doc\make.i*
+	$(MAKEINFO) -I$(srcdir)/doc $< -o ./$@
 
-.texinfo.dvi:
+.texi.dvi:
 	TEXINPUTS="$(srcdir);$$TEXINPUTS"    MAKEINFO='$(MAKEINFO) -I $(srcdir)' $(TEXI2DVI) $<
 
 
 .dvi.ps:
 	$(DVIPS) $< -o $@
 
 install-info-am: $(INFO_DEPS)
 	@$(NORMAL_INSTALL)
 	$(mkinstalldirs) $(DESTDIR)$(infodir)
-	@for file in $(INFO_DEPS) make.i; do    d=$(srcdir);    for ifile in `cd $$d && echo $$file $$file-[0-9] $$file-[0-9][0-9] $$file[0-9] $$file[0-9][0-9]`; do      if test -f $$d/$$ifile; then        echo " $(INSTALL_DATA) $$d/$$ifile $(DESTDIR)$(infodir)/$$ifile"; $(INSTALL_DATA) $$d/$$ifile $(DESTDIR)$(infodir)/$$ifile; else : ; fi;    done;  done
+	@for file in $(INFO_DEPS) doc/make.i; do    d=$(srcdir);    for ifile in `cd $$d && echo $$file $$file-[0-9] $$file-[0-9][0-9] $$file[0-9] $$file[0-9][0-9]`; do      if test -f $$d/$$ifile; then        echo " $(INSTALL_DATA) $$d/$$ifile $(DESTDIR)$(infodir)/`echo $$ifile | sed -e 's,doc/,,'`"; $(INSTALL_DATA) $$d/$$ifile $(DESTDIR)$(infodir)/`echo $$ifile | sed -e 's,doc/,,'`; else : ; fi;    done;  done
 	@$(POST_INSTALL)
-	@if $(SHELL) -c 'install-info --version | sed 1q | fgrep -s -v -i debian' >/dev/null 2>&1; then    for file in $(INFO_DEPS); do      echo " install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/$$file";     install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/$$file || :;   done;  else : ; fi
+	@if $(SHELL) -c 'install-info --version | sed 1q | fgrep -s -v -i debian' >/dev/null 2>&1; then    for file in $(INFO_DEPS); do      echo " install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/`echo $$file | sed -e 's,doc/,,'`";     install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/`echo $$file | sed -e 's,doc/,,'` || :;   done;  else : ; fi
 
 uninstall-info:
 	$(PRE_UNINSTALL)
-	@if $(SHELL) -c 'install-info --version | sed 1q | fgrep -s -v -i debian' >/dev/null 2>&1; then    ii=yes;  else ii=; fi;  for file in $(INFO_DEPS); do    test -z $ii || install-info --info-dir=$(DESTDIR)$(infodir) --remove $$file;  done
+	@if $(SHELL) -c 'install-info --version | sed 1q | fgrep -s -v -i debian' >/dev/null 2>&1; then    ii=yes;  else ii=; fi;  for file in $(INFO_DEPS); do    test -z $ii || install-info --info-dir=$(DESTDIR)$(infodir) --remove `echo $$file | sed -e 's,doc/,,'`;  done
 	$(NORMAL_UNINSTALL)
-	for file in $(INFO_DEPS) make.i; do    (cd $(DESTDIR)$(infodir) && rm -f $$file $$file-[0-9] $$file-[0-9][0-9] $$file[0-9] $$file[0-9][0-9]);  done
+	for file in $(INFO_DEPS) doc/make.i; do    (cd $(DESTDIR)$(infodir) && rm -f `echo $$file | sed -e 's,doc/,,'` `echo $$file | sed -e 's,doc/,,'`-[0-9] `echo $$file | sed -e 's,doc/,,'`-[0-9][0-9] `echo $$file | sed -e 's,doc/,,'`[0-9] `echo $$file | sed -e 's,doc/,,'`[0-9][0-9]);  done
 
 dist-info: $(INFO_DEPS)
 	for base in $(INFO_DEPS); do    d=$(srcdir);    for file in `cd $$d && eval echo $$base*`; do      test -f $(distdir)/$$file      || ln $$d/$$file $(distdir)/$$file 2> /dev/null      || cp -p $$d/$$file $(distdir)/$$file;    done;  done
 
 mostlyclean-aminfo:
diff -aprNU5 make-3.81.orig/configh.dos make-3.81/configh.dos
--- make-3.81.orig/configh.dos	2006-04-01 06:42:38 +0000
+++ make-3.81/configh.dos	2007-11-19 17:11:42 +0000
@@ -23,11 +23,11 @@ Foundation, Inc., 51 Franklin St, Fifth 
 
 /* Define if `sys_siglist' is declared by <signal.h>.  */
 # define SYS_SIGLIST_DECLARED 1
 
 /* Define this if the C library defines the variable `_sys_siglist'.  */
-# define HAVE_SYS_SIGLIST 1
+# define HAVE_DECL_SYS_SIGLIST 1
 
 #else
 
 /* Define NSIG.  */
 # define NSIG SIGMAX
diff -aprNU5 make-3.81.orig/function.c make-3.81/function.c
--- make-3.81.orig/function.c	2006-04-01 06:36:40 +0000
+++ make-3.81/function.c	2007-11-19 17:11:42 +0000
@@ -1887,11 +1887,25 @@ abspath (const char *name, char *apath)
   if (name[0] == '\0' || apath == NULL)
     return NULL;
 
   apath_limit = apath + GET_PATH_MAX;
 
-  if (name[0] != '/')
+#ifdef HAVE_DOS_PATHS
+  if (name[1] == ':')  /* DOS-style drive letter? */
+    {
+      strncpy (apath, name, 2);
+      dest = apath + 2;
+      name += 2;
+      if (IS_PATHSEP (*name))
+       {
+         *dest++ = *name++;
+       }
+      *dest = '\0';
+    }
+  else
+#endif
+  if (!IS_PATHSEP (name[0]))
     {
       /* It is unlikely we would make it until here but just to make sure. */
       if (!starting_directory)
 	return NULL;
 
@@ -1908,15 +1922,15 @@ abspath (const char *name, char *apath)
   for (start = end = name; *start != '\0'; start = end)
     {
       unsigned long len;
 
       /* Skip sequence of multiple path-separators.  */
-      while (*start == '/')
+      while (IS_PATHSEP (*start))
 	++start;
 
       /* Find end of path component.  */
-      for (end = start; *end != '\0' && *end != '/'; ++end)
+      for (end = start; *end != '\0' && !IS_PATHSEP (*end); ++end)
         ;
 
       len = end - start;
 
       if (len == 0)
@@ -1924,16 +1938,26 @@ abspath (const char *name, char *apath)
       else if (len == 1 && start[0] == '.')
 	/* nothing */;
       else if (len == 2 && start[0] == '.' && start[1] == '.')
 	{
 	  /* Back up to previous component, ignore if at root already.  */
+#ifdef HAVE_DOS_PATHS
+	  if (dest > apath + 1
+	      && (apath[1] != ':' || dest > apath + 2 + IS_PATHSEP (apath[2])))
+	    while (--dest, (!IS_PATHSEP (dest[-1]) && dest[-1] != ':'));
+#else
 	  if (dest > apath + 1)
-	    while ((--dest)[-1] != '/');
+	    while (--dest, (!IS_PATHSEP (dest[-1])));
+#endif
 	}
       else
 	{
-	  if (dest[-1] != '/')
+	  if (!IS_PATHSEP (dest[-1])
+#ifdef HAVE_DOS_PATHS
+	      && (dest[-1] != ':')
+#endif
+	     )
             *dest++ = '/';
 
 	  if (dest + len >= apath_limit)
             return NULL;
 
@@ -1942,11 +1966,15 @@ abspath (const char *name, char *apath)
 	  *dest = '\0';
 	}
     }
 
   /* Unless it is root strip trailing separator.  */
-  if (dest > apath + 1 && dest[-1] == '/')
+  if (dest > apath + 1 && IS_PATHSEP (dest[-1])
+#ifdef HAVE_DOS_PATHS
+      && (dest < apath + 3 || dest[-2] == ':')
+#endif
+      )
     --dest;
 
   *dest = '\0';
 
   return apath;
diff -aprNU5 make-3.81.orig/glob/glob.c make-3.81/glob/glob.c
--- make-3.81.orig/glob/glob.c	2006-03-10 02:20:44 +0000
+++ make-3.81/glob/glob.c	2007-11-19 17:11:42 +0000
@@ -179,11 +179,11 @@ extern void bcopy ();
 # define HAVE_MEMPCPY	1
 # undef  mempcpy
 # define mempcpy(Dest, Src, Len) __mempcpy (Dest, Src, Len)
 #endif
 
-#ifndef	__GNU_LIBRARY__
+#if !defined __GNU_LIBRARY__ && !defined __MSDOS__
 # ifdef	__GNUC__
 __inline
 # endif
 # ifndef __SASC
 #  ifdef WINDOWS32
@@ -202,11 +202,11 @@ my_realloc (p, n)
     return (char *) malloc (n);
   return (char *) realloc (p, n);
 }
 # define	realloc	my_realloc
 # endif /* __SASC */
-#endif /* __GNU_LIBRARY__ */
+#endif /* __GNU_LIBRARY__ || __MSDOS__ */
 
 
 #if !defined __alloca && !defined __GNU_LIBRARY__
 
 # ifdef	__GNUC__
diff -aprNU5 make-3.81.orig/hash.c make-3.81/hash.c
--- make-3.81.orig/hash.c	2006-02-11 20:00:38 +0000
+++ make-3.81/hash.c	2007-11-19 17:11:42 +0000
@@ -321,11 +321,11 @@ round_up_2 (unsigned long n)
   n |= (n >> 2);
   n |= (n >> 4);
   n |= (n >> 8);
   n |= (n >> 16);
 
-#if !defined(HAVE_LIMITS_H) || ULONG_MAX > 4294967295
+#if !defined(HAVE_LIMITS_H) || ULONG_MAX > 4294967295U
   /* We only need this on systems where unsigned long is >32 bits.  */
   n |= (n >> 32);
 #endif
 
   return n + 1;
diff -aprNU5 make-3.81.orig/job.c make-3.81/job.c
--- make-3.81.orig/job.c	2006-03-20 03:03:04 +0000
+++ make-3.81/job.c	2007-11-19 17:11:42 +0000
@@ -1890,11 +1890,11 @@ start_waiting_jobs (void)
 }
 
 #ifndef WINDOWS32
 
 /* EMX: Start a child process. This function returns the new pid.  */
-# if defined __MSDOS__ || defined __EMX__
+# if defined __EMX__
 int
 child_execute_job (int stdin_fd, int stdout_fd, char **argv, char **envp)
 {
   int pid;
   /* stdin_fd == 0 means: nothing to do for stdin;
diff -aprNU5 make-3.81.orig/variable.c make-3.81/variable.c
--- make-3.81.orig/variable.c	2006-03-08 20:15:08 +0000
+++ make-3.81/variable.c	2007-11-19 17:11:42 +0000
@@ -793,10 +793,13 @@ define_automatic_variables (void)
 #endif
 
   /* This won't override any definition, but it will provide one if there
      isn't one there.  */
   v = define_variable ("SHELL", 5, default_shell, o_default, 0);
+#ifdef __MSDOS__
+  v->export = v_export;  /*  Export always SHELL.  */
+#endif
 
   /* On MSDOS we do use SHELL from environment, since it isn't a standard
      environment variable on MSDOS, so whoever sets it, does that on purpose.
      On OS/2 we do not use SHELL from environment but we have already handled
      that problem above. */
