changeset 3337:8480924d2b85

[MSVC] Use POSIX compliant getopt version from mingw64. * src/build-msvctools/Makefile (getopt.c, getopt.h): Use versions from mingw64, as they're POSIX compliant. (posixcompat.lib): New target library, replaces dirent.lib and getopt.lib. (dirent.lib, getopt.lib): Removed targets. * src/build-msvctools/getopt.diff: Removed obsolete patch. * src/build-msvctools/cc-msvc.cc: Links against posixcompat.lib instead of dirent.lib * src/build-msvctools/unistd.h: Include getopt.h, for POSIX compliance.
author Michael Goffioul <michael.goffioul@gmail.com>
date Fri, 29 Nov 2013 18:46:45 -0500
parents 5c651d4db00c
children 1e9695b83a80
files dist-files.mk src/build-msvctools/Makefile src/build-msvctools/cc-msvc.cc src/build-msvctools/getopt.diff src/build-msvctools/unistd.h
diffstat 5 files changed, 11 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/dist-files.mk	Fri Nov 29 18:46:40 2013 -0500
+++ b/dist-files.mk	Fri Nov 29 18:46:45 2013 -0500
@@ -556,7 +556,6 @@
   cc-msvc.cc \
   fixlibtool2.in \
   gcc.diff \
-  getopt.diff \
   gfortran-msvc.cc \
   libgfortran-dllinit.c \
   libgfortran-msvcinit.c \
--- a/src/build-msvctools/Makefile	Fri Nov 29 18:46:40 2013 -0500
+++ b/src/build-msvctools/Makefile	Fri Nov 29 18:46:45 2013 -0500
@@ -5,9 +5,8 @@
 	clg++.exe \
 	clgfortran.exe \
 	dirent.h \
-	dirent.lib \
 	getopt.h \
-	getopt.lib \
+	posixcompat.lib \
 	inttypes.h \
 	lt-postproc \
 	ranlib-msvc \
@@ -83,23 +82,17 @@
 		-D_ttelldir=_wtelldir \
 		-c dirent.c -Fo$@
 
-dirent.lib: dirent.obj wdirent.obj
-	lib -out:$@ $^
+getopt.h:
+	$(WGET) -O $@ 'http://sourceforge.net/p/mingw-w64/code/HEAD/tree/trunk/mingw-w64-headers/crt/getopt.h?format=raw'
+	$(SED) -i -e 's,^.*crtdefs\.h.*$$,/*&*/,' $@
 
-getopt.h:
-	$(WGET) -O $@ 'http://sourceforge.net/p/mingw/mingw-org-wsl/ci/master/tree/include/getopt.h?format=raw'
-	$(SED) -i -e 's/__MINGW_NOTHROW//g' \
-		-e 's,^.*_mingw\.h.*$$,/*&*/,' \
-		getopt.h
-
-getopt.c: getopt.diff
-	$(WGET) -O $@ 'http://sourceforge.net/p/mingw/mingw-org-wsl/ci/master/tree/src/libcrt/misc/getopt.c?format=raw'
-	$(PATCH) -p0 < getopt.diff
+getopt.c:
+	$(WGET) -O $@ 'http://sourceforge.net/p/mingw-w64/code/HEAD/tree/trunk/mingw-w64-crt/misc/getopt.c?format=raw'
 
 getopt.obj: getopt.c getopt.h
 	cl -nologo -O2 -MD -I. -c $< -Fo$@
 
-getopt.lib: getopt.obj
+posixcompat.lib: dirent.obj wdirent.obj getopt.obj
 	lib -out:$@ $^
 
 compat/mingwcompat.lib:
@@ -183,8 +176,7 @@
 	$(INSTALL) getopt.h $(DESTDIR)/include
 	$(INSTALL) math/msvcmath.h $(DESTDIR)/include/math.h
 	$(INSTALL) -d $(DESTDIR)/lib
-	$(INSTALL) dirent.lib $(DESTDIR)/lib
-	$(INSTALL) getopt.lib $(DESTDIR)/lib
+	$(INSTALL) posixcompat.lib $(DESTDIR)/lib
 	$(INSTALL) compat/mingwcompat.lib $(DESTDIR)/lib
 	$(INSTALL) math/msvcmath.lib $(DESTDIR)/lib
 	$(INSTALL) gfortran-msvc.lib $(DESTDIR)/lib
--- a/src/build-msvctools/cc-msvc.cc	Fri Nov 29 18:46:40 2013 -0500
+++ b/src/build-msvctools/cc-msvc.cc	Fri Nov 29 18:46:45 2013 -0500
@@ -857,8 +857,8 @@
 
 	if (exeoutput && default_libs)
 	{
-		cllinkopt += " dirent.lib msvcmath.lib shell32.lib advapi32.lib user32.lib kernel32.lib";
-		linkopt += " dirent.lib msvcmath.lib shell32.lib advapi32.lib user32.lib kernel32.lib";
+		cllinkopt += " posixcompat.lib msvcmath.lib shell32.lib advapi32.lib user32.lib kernel32.lib";
+		linkopt += " posixcompat.lib msvcmath.lib shell32.lib advapi32.lib user32.lib kernel32.lib";
 	}
 
 	string opts;
--- a/src/build-msvctools/getopt.diff	Fri Nov 29 18:46:40 2013 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
---- getopt.c	2010-01-14 21:38:46 +0000
-+++ getopt-new.c	2010-01-14 21:37:14 +0000
-@@ -47,6 +47,10 @@
- # define PROGNAME  *argv
- #endif
- 
-+#ifdef _MSC_VER
-+# define __inline__ __inline
-+#endif
-+
- /* Initialise the public variables. */
- 
- int optind = 1;				/* index for first non-option arg     */
-@@ -463,7 +467,7 @@
-     /*
-      * we use `this_arg' to store these temporarily.
-      */
--    CHAR *this_arg[optspan];
-+    CHAR **this_arg = (CHAR**) malloc (sizeof(CHAR*) * optspan);
-     /*
-      * we cannot manipulate `argv' directly, since the `getopt'
-      * API prototypes it as `read-only'; this cast to `arglist'
-@@ -493,6 +497,8 @@
-     /* adjust `optbase', to account for the relocated option.
-      */
-     optbase += optspan;
-+
-+    free(this_arg);
-   }
- 
-   else
-@@ -578,9 +584,12 @@
- 	 * specified for the `getopt_long' APIs.
- 	 */
- 	va_list refptr;
-+	struct option *longopts;
-+	int *optindex;
-+	
- 	va_start( refptr, optstring );
--	struct option *longopts = va_arg( refptr, struct option * );
--	int *optindex = va_arg( refptr, int * );
-+	longopts = va_arg( refptr, struct option * );
-+	optindex = va_arg( refptr, int * );
- 	va_end( refptr );
- 
- 	/* ensuring that `optarg' does not inherit any junk, from parsing
--- a/src/build-msvctools/unistd.h	Fri Nov 29 18:46:40 2013 -0500
+++ b/src/build-msvctools/unistd.h	Fri Nov 29 18:46:45 2013 -0500
@@ -6,6 +6,7 @@
 #include <direct.h>
 #include <process.h>
 #include <io.h>
+#include <getopt.h>
 
 #ifndef PATH_MAX
 # define PATH_MAX 260