--- grap_lex.ll~0	2014-08-25 01:55:34.000000000 +0300
+++ grap_lex.ll	2019-01-07 12:53:59.842332800 +0200
@@ -7,6 +7,17 @@
 #endif
 #ifdef STDC_HEADERS
 #include <string.h>
+#ifdef __MINGW32__
+extern "C" {
+  extern char *strdup (const char *);
+  extern int fileno (FILE *);
+}
+#define IS_ABSOLUTE(fn)							\
+  ((fn)[0] == '/' || (fn)[0] == '\\'					\
+   || ((fn)[0] && (fn)[1] == ':' && ((fn)[2] == '/' || (fn)[2] == '\\')))
+#else
+#define IS_ABSOLUTE(fn)	((fn)[0] == '/')
+#endif
 #include <ctype.h>
 #endif
 #if defined(STDC_HEADERS) | defined(HAVE_STDLIB_H)
@@ -790,7 +801,7 @@ bool include_file(string *s, bool rs /* 
             tokenpos = 0;
         }
 	if ( *s != "-" ) {
-            if ( (*s)[0] != '/' && usepath ) {
+            if ( !IS_ABSOLUTE(*s) && usepath ) {
                 // use path to look up relative path
                 for ( stringSequence::iterator i = path.begin();
                       i != path.end(); i++) {
@@ -802,6 +813,24 @@ bool include_file(string *s, bool rs /* 
             }
             else f = fopen(s->c_str(),"r");
 
+#ifdef __MINGW32__
+            if ( !f ) {
+	        // Maybe look for the basename of S along PATH.
+	        if (IS_ABSOLUTE(*s) && usepath && *s == DEFINES) {
+		    string::size_type p = s->rfind('/');
+		    if (p != string::npos) {
+			string *basefn = new string(s->substr(p));
+			for ( stringSequence::iterator i = path.begin();
+			      i != path.end(); i++) {
+			    string str = *(*i);
+
+			    str += *basefn;
+			    if ( ( f = fopen(str.c_str(),"r"))) break;
+			}
+		    }
+		}
+	    }
+#endif
             if ( !f ) {
                 cerr << "Can't open " << *s << " " << strerror(errno) << endl;
 		return 0;
--- grap_parse.cc~0	2014-08-25 01:50:08.000000000 +0300
+++ grap_parse.cc	2019-01-07 13:44:58.721291600 +0200
@@ -28,6 +28,10 @@ extern "C" {
 #include "grap_pic.h"
 #include "y.tab.h"
 
+#ifdef __MINGW32__
+static char * default_path(void);
+#endif
+
 extern doubleDictionary vars;
 extern stringSequence path; 
 extern graph *the_graph;
@@ -931,7 +935,11 @@ int main(int argc, char** argv) {
 		unaligned_default = 1;
 		break;
 	    case 'M':
+#ifdef __MINGW32__
+		pathstring = (pathstring + ";") + optarg;
+#else
 		pathstring = (pathstring + ":") + optarg;
+#endif
 		break;
 	    case 'c':
 		clip_default = false;
@@ -956,14 +964,29 @@ int main(int argc, char** argv) {
 		usage();
 		break;
 	}
+#ifdef __MINGW32__
+    if (pathstring.length() > 0)
+	pathstring += ";";
+    pathstring += default_path();
+    pathstring += (pathstring.length() > 0) ? ";." : ".";
+#else
     pathstring += (pathstring.length() > 0) ? ":." : ".";
+#endif
 
     // Convert the colon separated file path into a sequence
     while (pathstring.length()) {
+#ifdef __MINGW32__
+	string::size_type p = pathstring.find(';');
+#else
 	string::size_type p = pathstring.find(':');
+#endif
 	string *s;
 
+#ifdef __MINGW32__
+	if ( pathstring[p] == ';' ) {
+#else
 	if ( pathstring[p] == ':' ) {
+#endif
 	    if ( p != 0 ) {
 		s = new string(pathstring.substr(0,p));
 		pathstring.erase(0,p+1);
@@ -999,3 +1022,28 @@ int main(int argc, char** argv) {
     path.erase(path.begin(),path.end());
     
 }
+
+#ifdef __MINGW32__
+
+extern "C" {
+  unsigned long __stdcall GetModuleFileNameA(void *, char *, unsigned long);
+};
+
+static char * default_path(void) {
+      static char dir_name[260], *p;
+
+      if (!GetModuleFileNameA(NULL, dir_name, 260)
+	  || (p = strrchr (dir_name, '\\')) == NULL)
+	  strcpy(dir_name, "./");
+      else {
+	  p[1] = '\0';
+	  for ( p = dir_name; *p; p++ ) {
+	      if (*p == '\\')
+		  *p = '/';
+	  }
+      }
+      // Assume the executable is in .../bin
+      strcat(dir_name, "../share/grap");
+      return dir_name;
+}
+#endif
--- grap.yy~0	2014-08-25 01:58:06.000000000 +0300
+++ grap.yy	2019-01-10 13:12:12.407643200 +0200
@@ -25,6 +25,12 @@
 #include <unistd.h>
 #endif
 
+#include <time.h>
+
+#ifdef __MINGW32__
+char * strptime(const char*, const char*, struct tm*);
+#endif
+
 #include "grap.h"
 #include "grap_data.h"
 #include "grap_draw.h"
@@ -1285,3 +1291,23 @@ void_function:
  	    { if ( $1 >=0 && $1 < NVF1 ) jtvf1[$1]($3); }
 ;
 %%
+
+#ifdef __MINGW32__
+// From http://stackoverflow.com/questions/321849/strptime-equivalent-on-windows#3137634
+// Note: This needs GCC 5.1 or later to work.
+#include <time.h>
+#include <iomanip>
+#include <sstream>
+
+char * strptime(const char* str, const char* fmt, struct tm* tm) {
+  //  C++ standard std::get_time is defined such that its format
+  //  parameters are the exact same as strptime.
+  std::istringstream input(str);
+  input.imbue(std::locale(""));
+  input >> std::get_time(tm, fmt);
+  if (input.fail()) {
+    return nullptr;
+  }
+  return (char*)(str + input.tellg());
+}
+#endif
