summarylogtreecommitdiffstats
path: root/gcc-djgpp.diff
blob: d2d8d835dbb0240364687bf67152fee4c4746126 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c
index 4a75b590911..651affd8eca 100644
--- a/gcc/ada/adaint.c
+++ b/gcc/ada/adaint.c
@@ -249,6 +249,12 @@ char __gnat_dir_separator = DIR_SEPARATOR;
 
 char __gnat_path_separator = PATH_SEPARATOR;
 
+#ifdef __DJGPP__
+int __gnat_is_djgpp = 1;
+#else
+int __gnat_is_djgpp = 0;
+#endif
+
 /* The GNAT_LIBRARY_TEMPLATE contains a list of expressions that define
    the base filenames that libraries specified with -lsomelib options
    may have. This is used by GNATMAKE to check whether an executable
@@ -555,7 +561,11 @@ __gnat_try_lock (char *dir, char *file)
 int
 __gnat_get_maximum_file_name_length (void)
 {
+#if defined (__DJGPP__)
+  return (_use_lfn(".")) ? -1 : 8;
+#else
   return -1;
+#endif
 }
 
 /* Return nonzero if file names are case sensitive.  */
diff --git a/gcc/ada/gcc-interface/Make-lang.in b/gcc/ada/gcc-interface/Make-lang.in
index de23b1410f2..aae7158b881 100644
--- a/gcc/ada/gcc-interface/Make-lang.in
+++ b/gcc/ada/gcc-interface/Make-lang.in
@@ -1061,7 +1061,7 @@ ada/generated/gnatvsn.ads: ada/gnatvsn.ads BASE-VER ada/GNAT_DATE
 	s=`cat $(srcdir)/BASE-VER | sed -e "s/\([0-9]*\)\.\([0-9]*\)\..*/-\1\2/g"`; \
 	d=`if test -f $(srcdir)/ada/GNAT_DATE; then \
            cat $(srcdir)/ada/GNAT_DATE; else date +%Y%m%d; fi`; \
-	cat $< | sed -e "/Version/s/(\([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\).*)/($$d$$s)/g" >$@
+	cat $< | sed -e "/Version/s/(\([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\).*)/($$d$$s)/g" | tr -d \\\015 >$@
 
 ada/gnatvsn.o : ada/gnatvsn.adb ada/generated/gnatvsn.ads
 	$(CC) -c $(ALL_ADAFLAGS) -Iada/generated -I../ada/generated $(ADA_INCLUDES) $< $(ADA_OUTPUT_OPTION)
diff --git a/gcc/ada/libgnarl/s-taprop__dummy.adb b/gcc/ada/libgnarl/s-taprop__dummy.adb
index bd6387d821c..0cb49e3f553 100644
--- a/gcc/ada/libgnarl/s-taprop__dummy.adb
+++ b/gcc/ada/libgnarl/s-taprop__dummy.adb
@@ -41,7 +41,7 @@ pragma Polling (Off);
 package body System.Task_Primitives.Operations is
 
    use System.Tasking;
-   use System.Parameters;
+--   use System.Parameters;
 
    pragma Warnings (Off);
    --  Turn off warnings since so many unreferenced parameters
diff --git a/gcc/ada/libgnat/s-os_lib.adb b/gcc/ada/libgnat/s-os_lib.adb
index 7efddf710c6..680d6020e60 100644
--- a/gcc/ada/libgnat/s-os_lib.adb
+++ b/gcc/ada/libgnat/s-os_lib.adb
@@ -71,7 +71,7 @@ package body System.OS_Lib is
 
    --  The following are used by Create_Temp_File
 
-   First_Temp_File_Name : constant String := "GNAT-TEMP-000000.TMP";
+   First_Temp_File_Name : constant String := "GA000000.TMP";
    --  Used to initialize Current_Temp_File_Name and Temp_File_Name_Last_Digit
 
    Current_Temp_File_Name : String := First_Temp_File_Name;
@@ -2257,9 +2257,10 @@ package body System.OS_Lib is
       --    * Check the drive letter
       --    * Remove all double-quotes
 
-      if On_Windows then
+      if On_Windows
+        and then Is_Djgpp = 0
+      then
          --  Replace all '/' by '\'
-
          for Index in 1 .. End_Path loop
             if Path_Buffer (Index) = '/' then
                Path_Buffer (Index) := Directory_Separator;
diff --git a/gcc/ada/libgnat/s-os_lib.ads b/gcc/ada/libgnat/s-os_lib.ads
index 8b21aa7de70..58b81351ff4 100644
--- a/gcc/ada/libgnat/s-os_lib.ads
+++ b/gcc/ada/libgnat/s-os_lib.ads
@@ -1082,9 +1082,12 @@ package System.OS_Lib is
    Path_Separator : constant Character;
    --  The character to separate paths in an environment variable value
 
+   Is_Djgpp : constant Integer;
+
 private
    pragma Import (C, Path_Separator, "__gnat_path_separator");
    pragma Import (C, Directory_Separator, "__gnat_dir_separator");
+   pragma Import (C, Is_Djgpp, "__gnat_is_djgpp");
    pragma Import (C, Current_Time, "__gnat_current_time");
    pragma Import (C, Current_Process_Id, "__gnat_current_process_id");
 
diff --git a/gcc/collect2.c b/gcc/collect2.c
index eb84f84639b..ba7291f293b 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -1235,21 +1235,30 @@ main (int argc, char **argv)
   *ld1++ = *ld2++ = ld_file_name;
 
   /* Make temp file names.  */
+
+#ifdef __DJGPP__
+#define CDTOR_C_NAME ".ctc"
+#define CDTOR_O_NAME ".cto"
+#else
+#define CDTOR_C_NAME ".cdtor.c"
+#define CDTOR_O_NAME ".cdtor.o"
+#endif
+
   if (save_temps)
     {
       c_file = (char *) xmalloc (strlen (output_file)
-				  + sizeof (".cdtor.c") + 1);
+				  + sizeof (CDTOR_C_NAME) + 1);
       strcpy (c_file, output_file);
-      strcat (c_file, ".cdtor.c");
+      strcat (c_file, CDTOR_C_NAME);
       o_file = (char *) xmalloc (strlen (output_file)
-				  + sizeof (".cdtor.o") + 1);
+				  + sizeof (CDTOR_O_NAME) + 1);
       strcpy (o_file, output_file);
-      strcat (o_file, ".cdtor.o");
+      strcat (o_file, CDTOR_O_NAME);
     }
   else
     {
-      c_file = make_temp_file (".cdtor.c");
-      o_file = make_temp_file (".cdtor.o");
+      c_file = make_temp_file (CDTOR_C_NAME);
+      o_file = make_temp_file (CDTOR_O_NAME);
     }
 #ifdef COLLECT_EXPORT_LIST
   export_file = make_temp_file (".x");
diff --git a/gcc/config/i386/xm-djgpp.h b/gcc/config/i386/xm-djgpp.h
index 8cb8bc6939c..6e152a69bfc 100644
--- a/gcc/config/i386/xm-djgpp.h
+++ b/gcc/config/i386/xm-djgpp.h
@@ -30,6 +30,8 @@ along with GCC; see the file COPYING3.  If not see
 #undef NATIVE_SYSTEM_HEADER_DIR
 #define NATIVE_SYSTEM_HEADER_DIR "/dev/env/DJDIR/include/"
 
+//#undef PREFIX_INCLUDE_DIR
+
 /* Search for as.exe and ld.exe in DJGPP's binary directory.  */
 #undef MD_EXEC_PREFIX
 #define MD_EXEC_PREFIX "/dev/env/DJDIR/bin/"
@@ -107,6 +109,11 @@ along with GCC; see the file COPYING3.  If not see
       (PATH) = xstrdup (fixed_path);		\
     }
 
+/* Rename libstdc++ to libstdcxx as the first name is not valid for DOS */
+#define LIBSTDCXX "stdcxx"
+#define LIBSTDCXX_PROFILE "stdcxx"
+#define LIBSTDCXX_STATIC "stdcxx"
+
 #undef MAX_OFILE_ALIGNMENT
 #define MAX_OFILE_ALIGNMENT 128
 
diff --git a/gcc/gcov-tool.c b/gcc/gcov-tool.c
index 5bb1ccac6be..161da5caed3 100644
--- a/gcc/gcov-tool.c
+++ b/gcc/gcov-tool.c
@@ -56,11 +56,18 @@ static bool verbose;
 
 /* Remove file NAME if it has a gcda suffix. */
 
+#ifdef __DJGPP__
+static int
+unlink_gcda_file (const char *name,
+                  struct stat *status ATTRIBUTE_UNUSED,
+                  int type ATTRIBUTE_UNUSED)
+#else
 static int
 unlink_gcda_file (const char *name,
                   const struct stat *status ATTRIBUTE_UNUSED,
                   int type ATTRIBUTE_UNUSED,
                   struct FTW *ftwbuf ATTRIBUTE_UNUSED)
+#endif
 {
   int ret = 0;
   int len = strlen (name);
@@ -82,7 +89,11 @@ static int
 unlink_profile_dir (const char *path ATTRIBUTE_UNUSED)
 {
 #if HAVE_FTW_H
+#ifdef __DJGPP__
+    return ftw(path, unlink_gcda_file, 64);
+#else
     return nftw(path, unlink_gcda_file, 64, FTW_DEPTH | FTW_PHYS);
+#endif
 #else
     return -1;
 #endif
diff --git a/gcc/ginclude/float.h b/gcc/ginclude/float.h
index 4767d7b9dfb..15e83f703a4 100644
--- a/gcc/ginclude/float.h
+++ b/gcc/ginclude/float.h
@@ -25,6 +25,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
  * ISO C Standard:  5.2.4.2.2  Characteristics of floating types <float.h>
  */
 
+#ifdef __DJGPP__
+#include_next <float.h>
+#endif
+
 #ifndef _FLOAT_H___
 #define _FLOAT_H___
 
diff --git a/include/libiberty.h b/include/libiberty.h
index 57476135026..276cc7a4981 100644
--- a/include/libiberty.h
+++ b/include/libiberty.h
@@ -108,6 +108,7 @@ extern int countargv (char * const *);
 #if defined (__GNU_LIBRARY__ ) || defined (__linux__) \
  || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__NetBSD__) \
  || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (__MINGW32__) \
+ || defined (__DJGPP__) \
  || defined (__DragonFly__) || defined (HAVE_DECL_BASENAME) 
 extern char *basename (const char *) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_NONNULL(1);
 #else
diff --git a/libcpp/files.c b/libcpp/files.c
index b0ac22be6ba..0ad0403c050 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -740,6 +740,10 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file, location_t loc)
     cpp_error_at (pfile, CPP_DL_WARNING, loc,
 	       "%s is shorter than expected", file->path);
 
+/* For DOS we should handle DOS EOF character (0x1A, ^Z). It is
+   only done if it is really the last character of the file  */
+  if (total>0 && buf[total-1]==0x1A) total--;
+
   file->buffer = _cpp_convert_input (pfile,
 				     CPP_OPTION (pfile, input_charset),
 				     buf, size + 16, total,
diff --git a/libcpp/lex.c b/libcpp/lex.c
index eedfcbb3146..fab1e12c9d2 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -502,6 +502,13 @@ init_vectorized_lexer (void)
   search_line_fast_type impl = search_line_acc_char;
   int minimum = 0;
 
+// [FIXME][DJGPP] Using SSE here causes preprocessor to randomly
+// [FIXME][DJGPP] fail when run under Windows 10 32 bit (and maybe
+// [FIXME][DJGPP] some other systems (I have observed similar
+// [FIXME][DJGPP] behavior earlier with DJGPP v2.03p2 under Windows
+// [FIXME][DJGPP] Vista
+#ifndef __DJGPP__
+
 #if defined(__SSE4_2__)
   minimum = 3;
 #elif defined(__SSE2__)
@@ -528,6 +535,8 @@ init_vectorized_lexer (void)
 	impl = search_line_mmx;
     }
 
+#endif // __DJGPP__
+
   search_line_fast = impl;
 }
 
diff --git a/libcpp/macro.c b/libcpp/macro.c
index 30d3686451c..57d4de1e993 100644
--- a/libcpp/macro.c
+++ b/libcpp/macro.c
@@ -516,17 +516,22 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node,
 	      && pfile->cb.get_source_date_epoch != NULL)
 	    pfile->source_date_epoch = pfile->cb.get_source_date_epoch (pfile);
 
-	  if (pfile->source_date_epoch >= (time_t) 0)
-	    tb = gmtime (&pfile->source_date_epoch);
-	  else
-	    {
-	      /* (time_t) -1 is a legitimate value for "number of seconds
-		 since the Epoch", so we have to do a little dance to
-		 distinguish that from a genuine error.  */
-	      errno = 0;
-	      tt = time (NULL);
-	      if (tt != (time_t)-1 || errno == 0)
-		tb = localtime (&tt);
+          switch (pfile->source_date_epoch)
+            {
+               default:
+                   tb = gmtime (&pfile->source_date_epoch);
+                   break;
+
+               case (time_t) -1:
+               case (time_t) -2:
+	           /* (time_t) -1 is a legitimate value for "number of seconds
+		      since the Epoch", so we have to do a little dance to
+		      distinguish that from a genuine error.  */
+	           errno = 0;
+	           tt = time (NULL);
+	           if (tt != (time_t)-1 || errno == 0)
+		       tb = localtime (&tt);
+                   break;
 	    }
 
 	  if (tb)
diff --git a/libffi/src/x86/sysv.S b/libffi/src/x86/sysv.S
index 78f245bda07..1ae18b248a7 100644
--- a/libffi/src/x86/sysv.S
+++ b/libffi/src/x86/sysv.S
@@ -822,7 +822,7 @@ ENDF(C(__x86.get_pc_thunk.dx))
 #ifdef __APPLE__
 .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
 EHFrame0:
-#elif defined(X86_WIN32)
+#elif defined(X86_WIN32) || defined(__DJGPP__)
 .section .eh_frame,"r"
 #elif defined(HAVE_AS_X86_64_UNWIND_SECTION_TYPE)
 .section .eh_frame,EH_FRAME_FLAGS,@unwind
diff --git a/libgcc/libgcov-util.c b/libgcc/libgcov-util.c
index ae0dd017204..08b04d292a2 100644
--- a/libgcc/libgcov-util.c
+++ b/libgcc/libgcov-util.c
@@ -391,7 +391,11 @@ read_gcda_file (const char *filename)
 
 static int
 ftw_read_file (const char *filename,
+#ifdef __DJGPP__
+               struct stat *status ATTRIBUTE_UNUSED,
+#else
                const struct stat *status ATTRIBUTE_UNUSED,
+#endif
                int type)
 {
   int filename_len;
diff --git a/libgfortran/intrinsics/chmod.c b/libgfortran/intrinsics/chmod.c
index 9bfe52439f3..d116e89adde 100644
--- a/libgfortran/intrinsics/chmod.c
+++ b/libgfortran/intrinsics/chmod.c
@@ -442,7 +442,7 @@ clause_done:
 	if ((ugo[2] || honor_umask) && !rwxXstugo[8])
 	  file_mode = (file_mode & ~(S_IROTH | S_IWOTH | S_IXOTH))
 		      | (new_mode & (S_IROTH | S_IWOTH | S_IXOTH));
-#ifndef __VXWORKS__
+#if !defined(__VXWORKS__) && !defined(__DJGPP__)
 	if (is_dir && rwxXstugo[5])
 	  file_mode |= S_ISVTX;
 	else if (!is_dir)
@@ -454,7 +454,7 @@ clause_done:
       {
 	/* Clear '-'.  */
 	file_mode &= ~new_mode;
-#if !defined( __MINGW32__) && !defined (__VXWORKS__)
+#if !defined( __MINGW32__) && !defined (__VXWORKS__) && !defined(__DJGPP__)
 	if (rwxXstugo[5] || !is_dir)
 	  file_mode &= ~S_ISVTX;
 #endif
@@ -462,7 +462,7 @@ clause_done:
     else if (set_mode == 3)
       {
 	file_mode |= new_mode;
-#if !defined (__MINGW32__) && !defined (__VXWORKS__)
+#if !defined (__MINGW32__) && !defined (__VXWORKS__) && !defined(__DJGPP__)
 	if (rwxXstugo[5] && is_dir)
 	  file_mode |= S_ISVTX;
 	else if (!is_dir)
diff --git a/libgfortran/intrinsics/execute_command_line.c b/libgfortran/intrinsics/execute_command_line.c
index 1a471632172..5956fbfd7bd 100644
--- a/libgfortran/intrinsics/execute_command_line.c
+++ b/libgfortran/intrinsics/execute_command_line.c
@@ -65,7 +65,7 @@ set_cmdstat (int *cmdstat, int value)
 }
 
 
-#if defined(HAVE_WAITPID) && defined(HAVE_SIGACTION)
+#if defined(HAVE_WAITPID) && defined(HAVE_SIGACTION) && !defined(__DJGPP__)
 static void
 sigchld_handler (int signum __attribute__((unused)))
 {
@@ -85,7 +85,7 @@ execute_command_line (const char *command, bool wait, int *exitstat,
   /* Flush all I/O units before executing the command.  */
   flush_all_units();
 
-#if defined(HAVE_POSIX_SPAWN) || defined(HAVE_FORK)
+#if (defined(HAVE_POSIX_SPAWN) || defined(HAVE_FORK)) && !defined(__DJGPP__)
   if (!wait)
     {
       /* Asynchronous execution.  */
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c
index 42792976c4b..3418a4af1e9 100644
--- a/libgfortran/io/unix.c
+++ b/libgfortran/io/unix.c
@@ -221,6 +221,9 @@ typedef struct
 }
 unix_stream;
 
+#ifdef __DJGPP__
+#include <io.h>
+#endif
 
 /* fix_fd()-- Given a file descriptor, make sure it is not one of the
    standard descriptors, returning a non-standard descriptor.  If the
@@ -1222,8 +1225,13 @@ tempfile_open (const char *tempdir, char **fname)
   char *template = xmalloc (tempdirlen + 23);
 
 #ifdef HAVE_MKSTEMP
+#ifdef __DJGPP__
+  /* Default filename is too long for DOS */
+  snprintf (template, tempdirlen + 23, "%s/gfXXXXXX", tempdir);
+#else
   snprintf (template, tempdirlen + 23, "%s%sgfortrantmpXXXXXX", 
 	    tempdir, slash);
+#endif
 
 #ifdef HAVE_UMASK
   /* Temporarily set the umask such that the file has 0600 permissions.  */
@@ -1589,6 +1597,13 @@ open_external (st_parameter_open *opp, unit_flags *flags)
     return NULL;
   fd = fix_fd (fd);
 
+#ifdef __DJGPP__
+  if (flags->form == FORM_UNFORMATTED)
+    {
+      setmode (fd, O_BINARY);
+    }
+#endif
+
   if (open_share (opp, fd, flags) < 0)
     return NULL;
 
diff --git a/libiberty/make-relative-prefix.c b/libiberty/make-relative-prefix.c
index ec0b0ee7494..1ed86db2a09 100644
--- a/libiberty/make-relative-prefix.c
+++ b/libiberty/make-relative-prefix.c
@@ -65,6 +65,7 @@ relative prefix can be found, return @code{NULL}.
 
 #include "ansidecl.h"
 #include "libiberty.h"
+#include "filenames.h"
 
 #ifndef R_OK
 #define R_OK 4
@@ -337,7 +338,7 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix,
     {
       for (i = 0; i < bin_num; i++)
 	{
-	  if (strcmp (prog_dirs[i], bin_dirs[i]) != 0)
+	  if (FILENAME_CMP (prog_dirs[i], bin_dirs[i]) != 0)
 	    break;
 	}
 
@@ -353,7 +354,7 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix,
   n = (prefix_num < bin_num) ? prefix_num : bin_num;
   for (common = 0; common < n; common++)
     {
-      if (strcmp (bin_dirs[common], prefix_dirs[common]) != 0)
+      if (FILENAME_CMP (bin_dirs[common], prefix_dirs[common]) != 0)
 	break;
     }
 
diff --git a/libiberty/make-temp-file.c b/libiberty/make-temp-file.c
index 2c66e35cc1f..f058c39dc3d 100644
--- a/libiberty/make-temp-file.c
+++ b/libiberty/make-temp-file.c
@@ -47,6 +47,7 @@ Boston, MA 02110-1301, USA.  */
 #endif
 
 #include "libiberty.h"
+#include "filenames.h"
 extern int mkstemps (char *, int);
 
 /* '/' works just fine on MS-DOS based systems.  */
@@ -142,7 +143,8 @@ choose_tmpdir (void)
       len = strlen (base);
       tmpdir = XNEWVEC (char, len + 2);
       strcpy (tmpdir, base);
-      tmpdir[len] = DIR_SEPARATOR;
+      if (len>0 && !IS_DIR_SEPARATOR(tmpdir[len-1]))
+          tmpdir[len] = DIR_SEPARATOR;
       tmpdir[len+1] = '\0';
       memoized_tmpdir = tmpdir;
 #else /* defined(_WIN32) && !defined(__CYGWIN__) */
diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c
index 3d49f339631..75f2ca4e2f4 100644
--- a/libiberty/simple-object-elf.c
+++ b/libiberty/simple-object-elf.c
@@ -1293,7 +1293,9 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
     }
   if (new_i - 1 >= SHN_LORESERVE)
     {
+#ifdef ENOTSUP
       *err = ENOTSUP;
+#endif
       return "Too many copied sections";
     }
   eow->shdrs = XNEWVEC (unsigned char, shdr_size * (new_i - 1));
diff --git a/libquadmath/printf/quadmath-printf.h b/libquadmath/printf/quadmath-printf.h
index 32ebcec928c..96498b7c408 100644
--- a/libquadmath/printf/quadmath-printf.h
+++ b/libquadmath/printf/quadmath-printf.h
@@ -29,7 +29,8 @@ Boston, MA 02110-1301, USA.  */
 #ifdef HAVE_CTYPE_H
 #include <ctype.h>
 #endif
-#ifdef HAVE_WCHAR_H
+#if defined(HAVE_WCHAR_H) && !defined(__DJGPP__)
+/* DJGPP wchar.h is not good enough */
 #include <wchar.h>
 #endif
 #ifdef HAVE_WCTYPE_H
@@ -44,7 +45,7 @@ Boston, MA 02110-1301, USA.  */
 #include "quadmath-imp.h"
 #include "gmp-impl.h"
 
-#ifdef HAVE_WCHAR_H
+#if defined(HAVE_WCHAR_H) && !defined(__DJGPP__)
 #define L_(x) L##x
 #else
 #define L_(x) x
diff --git a/libstdc++-v3/config/os/djgpp/error_constants.h b/libstdc++-v3/config/os/djgpp/error_constants.h
index 7b8810d62f1..9795a81aa70 100644
--- a/libstdc++-v3/config/os/djgpp/error_constants.h
+++ b/libstdc++-v3/config/os/djgpp/error_constants.h
@@ -33,6 +33,15 @@
 #include <bits/c++config.h>
 #include <cerrno>
 
+#ifndef EOPNOTSUPP
+// Use same value as in wat3222br6.zip file net/watt/sys/djgpp.err
+#define EOPNOTSUPP 52
+#endif
+
+#ifndef ENOTSUP
+#define ENOTSUP 101
+#endif
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -118,9 +127,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 //    not_connected = 				ENOTCONN,
       not_enough_memory = 			ENOMEM,
 
-#ifdef _GLIBCXX_HAVE_ENOTSUP
       not_supported = 				ENOTSUP,
-#endif
 
 #ifdef _GLIBCXX_HAVE_ECANCELED
       operation_canceled = 			ECANCELED,
@@ -128,7 +135,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 //    operation_in_progress = 			EINPROGRESS,
       operation_not_permitted = 		EPERM,
-//    operation_not_supported = 		EOPNOTSUPP,
+      operation_not_supported = 		EOPNOTSUPP,
 //    operation_would_block = 			EWOULDBLOCK,
 
 #ifdef _GLIBCXX_HAVE_EOWNERDEAD
diff --git a/libstdc++-v3/include/experimental/bits/fs_path.h b/libstdc++-v3/include/experimental/bits/fs_path.h
index 64089b432eb..f6b287d8d55 100644
--- a/libstdc++-v3/include/experimental/bits/fs_path.h
+++ b/libstdc++-v3/include/experimental/bits/fs_path.h
@@ -53,6 +53,11 @@
 # include <algorithm>
 #endif
 
+#if defined(__DJGPP__)
+# define _GLIBCXX_FILESYSTEM_IS_DJGPP 1
+# include <algorithm>
+#endif
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -493,6 +498,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
     {
 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
       return __ch == L'/' || __ch == preferred_separator;
+#elif defined(_GLIBCXX_FILESYSTEM_IS_DJGPP)
+      return __ch == '/' || __ch == '\\';
 #else
       return __ch == '/';
 #endif
@@ -874,6 +881,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
 #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
     std::replace(_M_pathname.begin(), _M_pathname.end(), L'/',
 		 preferred_separator);
+#elif defined(_GLIBCXX_FILESYSTEM_IS_DJGPP)
+    std::replace(_M_pathname.begin(), _M_pathname.end(), '\\',
+		 preferred_separator);
 #endif
     return *this;
   }
@@ -1075,7 +1085,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   inline bool
   path::is_absolute() const
   {
-#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
+#if defined(_GLIBCXX_FILESYSTEM_IS_WINDOWS) || defined(_GLIBCXX_FILESYSTEM_IS_DJGPP)
     return has_root_name() && has_root_directory();
 #else
     return has_root_directory();
diff --git a/libstdc++-v3/src/filesystem/path.cc b/libstdc++-v3/src/filesystem/path.cc
index edf7c67c01b..af343bcee28 100644
--- a/libstdc++-v3/src/filesystem/path.cc
+++ b/libstdc++-v3/src/filesystem/path.cc
@@ -408,8 +408,13 @@ path::_M_split_cmpts()
 	_M_add_root_dir(0);
       ++pos;
     }
-#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
+#if defined(_GLIBCXX_FILESYSTEM_IS_WINDOWS) \
+  || defined(_GLIBCXX_FILESYSTEM_IS_DJGPP)
+#ifdef __DJGPP__
+  else if (len > 1 && _M_pathname[1] == ':')
+#else
   else if (len > 1 && _M_pathname[1] == L':')
+#endif
     {
       // got disk designator
       if (len == 2)