2016-03-24  Juan Manuel Guerrero <juan.guerrero@gmx.de>

	These are specific changes required for the use with the DJGPP ports
	of gcc 3.4.6, gcc 4.N.N and gcc 5.N.N.


	* watt/bin/djgpp.mak:  For gcc 5.N.N and higher versions add `-fgnu89-inline'
	to the CFLAGS to ensure that always traditional GNU extern inline semantics
	are used even if ISO C99 semantics have been specified.  ISO C99 semantics
	is always the default for gcc 5.N.N and higher versions.
	* watt/src/makefile.all:  For gcc 5.N.N and higher versions add `-fgnu89-inline'
	to the CFLAGS to ensure that always traditional GNU extern inline semantics
	are used even if ISO C99 semantics have been specified.  ISO C99 semantics
	is always the default for gcc 5.N.N and higher versions.
	* watt/src/tests/makefile.all:  For gcc 5.N.N and higher versions add
	`-fgnu89-inline' to the CFLAGS to ensure that always traditional GNU
	extern inline semantics are used even if ISO C99 semantics have been
	specified.  ISO C99 semantics is always the default for gcc 5.N.N and
	higher versions.


2016-03-20  Juan Manuel Guerrero <juan.guerrero@gmx.de>

	* watt/src/tests/makefile.all:  For DJGPP do not build neither
	swap.$(EXE) nor timeit_test.$(EXE).


2016-03-20  Juan Manuel Guerrero <juan.guerrero@gmx.de>

	* watt/src/tests/timeit.h:  Include cdefs.h to provide definition of
	GCC_INLINE.


2016-02-06  Juan Manuel Guerrero <juan.guerrero@gmx.de>

	* watt/src/cpumodel.h:  Solve for warning:
	    warning: implicit declaration of function `_w32_get_rdtsc2'
	for watt library compiled with DJGPP ports of gcc 3.4.6 and gcc 4.8.4
	using -O0 flag.  !defined(__NO_INLINE__) must be removed so that the
	definition of get_rdtsc2 is always available no matter what optimization
	level is used.  It is also necessary define or undefine W32_GCC_INLINE
	depending on the optimization level used.

	* watt/src/tests/cpu.c (print_misc_regs) [DOSX]:  DJGPP does neither
	provide SelReadable nor SelWritable.  Thus make print_misc_regs a no-op
	for DJGPP.

	* watt/src/misc.c (get_ss_limit):  Solve for warning:
	    warning: 'stack_limit' defined but not used [-Wunused-variable]
	Do not define for DJGPP.
	(main):  Solve for warning:
	    warning: 'strat' may be used uninitialized in this function [-Wmaybe-uninitialized]
	Set it.

	* watt/src/pcarp.c:  Solve for warning:
	    warning: 'num_okay' defined but not used [-Wunused-variable]
	    warning: 'num_fail' defined but not used [-Wunused-variable]
	Do not define for DJGPP.

	* watt/src/tests/fsext.c (main):  Solve for warning:
	    warning: ordered comparison of pointer with integer zero [-Wextra]
	Compare return value of fgets against NULL and not against less than 0.
	[__DJGPP__]:  Solve for warning:
	    warning: unused variable 'linger' [-Wunused-variable]
	Do not define for DJGPP.

	* watt/src/tests/cpu.c [COMPILING_PCDBUG_C]:  If not compiling for the
	library, provide the following prototypes: Cx86model, i486model,
	i586model, i686model, AMDmodel and cpu_get_model.  For DJGPP do not
	compile this functions because they are already provided by the library.

	* watt/src/tests/ttime2.c (main):  Solve for warning:
	    warning: 'lastsec' may be used uninitialized in this function [-Wmaybe-uninitialized]
	Solve for warning:
	    warning: pointer targets in passing argument 2 of '_bios_timeofday' differ in signedness [-Wpointer-sign]








diff -aprNU7 watt.orig/bin/djgpp.mak watt/bin/djgpp.mak
--- watt.orig/bin/djgpp.mak	2016-03-25 15:48:26 +0100
+++ watt/bin/djgpp.mak	2016-03-25 15:47:32 +0100
@@ -48,14 +48,21 @@ else
   WATTLIB = ../lib/libwatt.a
   EXTRAS  = tiny.c
 endif
 
 CC      = gcc
 CFLAGS += -Wall -W -Wno-sign-compare -g -O2 -I$(INC_DIR) #-s # strip symbols from .exe
 
+ifeq ($(filter 2 3 4,$(word 3, $(shell true | $(CC) -E -dD -x c - | grep 'define\ *__GNUC__'))),)
+# We have gcc >= 5.x and we must ensure that always traditional
+# GNU extern inline semantics are used (aka -fgnu89-inline) even
+# if ISO C99 semantics have been specified.
+CFLAGS += -fgnu89-inline
+endif
+
 ifeq ($(USE_EXCEPT),1)
   CFLAGS += -DUSE_EXCEPT
   EXTRAS += d:/prog/mw/except/lib/libexc.a
 endif
 
 #
 # Change '-o' to '-e' for gcc 4.3 (?) or older.
diff -aprNU7 watt.orig/src/cpumodel.h watt/src/cpumodel.h
--- watt.orig/src/cpumodel.h	2015-10-04 08:15:44 +0200
+++ watt/src/cpumodel.h	2016-03-25 15:47:32 +0100
@@ -148,15 +148,15 @@ extern CONST char  DATA_DECL x86_vendor_
   #pragma alias (_w32_asm_ffs,     "_w32_asm_ffs")
   #pragma alias (_w32_Get_CR4,     "_w32_Get_CR4")
   #pragma alias (_w32_SelWritable, "_w32_SelWritable")
   #pragma alias (_w32_SelReadable, "_w32_SelReadable")
 #endif
 
 
-#if defined(__GNUC__) && defined(__i386__) && !defined(__NO_INLINE__)
+#if defined(__GNUC__) && defined(__i386__)
   /*
    * Call this only if x86_have_cpuid == TRUE.
    */
   W32_GCC_INLINE void get_cpuid (DWORD  val, DWORD *eax,
                                  DWORD *ebx, DWORD *ecx,
                                  DWORD *edx)
   {
diff -aprNU7 watt.orig/src/makefile.all watt/src/makefile.all
--- watt.orig/src/makefile.all	2015-11-26 20:38:10 +0100
+++ watt/src/makefile.all	2016-03-25 15:47:32 +0100
@@ -152,14 +152,20 @@ PKT_STUB = pkt_stub.h
 
 @ifdef DJGPP
 
 CC     = gcc
 CFLAGS = -O2 -g -I. -I../inc -W -Wall -Wno-strict-aliasing -DWATT32_BUILD \
        # -fno-strength-reduce -ffast-math \
        # -ffunction-sections -fomit-frame-pointer -gcoff
+ifeq ($(filter 2 3 4,$(word 3, $(shell true | $(CC) -E -dD -x c - | grep 'define\ *__GNUC__'))),)
+# We have gcc >= 5.x and we must ensure that always traditional
+# GNU extern inline semantics are used (aka -fgnu89-inline) even
+# if ISO C99 semantics have been specified.
+CFLAGS += -fgnu89-inline
+endif
 
 AS     = as
 AR     = ar rs
 AFLAGS = # --gdwarf2
 TARGET = ../lib/libwatt.a
 OBJDIR = djgpp
 
diff -aprNU7 watt.orig/src/misc.c watt/src/misc.c
--- watt.orig/src/misc.c	2015-11-25 11:45:54 +0100
+++ watt/src/misc.c	2016-03-25 15:47:32 +0100
@@ -1232,15 +1232,17 @@ DWORD get_ss_limit (void)
   }
 
   #define GetCurrentFiber() _w32_GetCurrentFiber()
   #define GetFiberData()    (*(void**) (ULONG_PTR) _w32_GetCurrentFiber() )
 
 #else
   THREAD_LOCAL static UINT_PTR stack_bottom = 0;
+# ifndef __DJGPP__
   THREAD_LOCAL static UINT_PTR stack_limit  = 0;
+# endif
 #endif
 
 unsigned _get_frame_size (const char *x)
 {
   char y = 0;
   return (unsigned)(x - &y);
 }
@@ -1935,15 +1937,15 @@ void foo_40 (void) { puts ("I'm foo_40()
 void foo_50 (void) { puts ("I'm foo_50()"); }
 void foo_60 (void) { puts ("I'm foo_60()"); }
 void foo_70 (void) { puts ("I'm foo_70()"); }
 
 int main (void)
 {
 #if defined(__MSDOS__)
-  BYTE strat;
+  BYTE strat = 0;
 
   printf ("DOS memory allocation strategy: ");
   if (!get_mem_strat(&strat))
        puts ("failed");
   else printf ("0x%02X\n", strat);
 
   printf ("Setting \"low memory best fit\" ");
diff -aprNU7 watt.orig/src/pcarp.c watt/src/pcarp.c
--- watt.orig/src/pcarp.c	2015-06-28 17:18:32 +0200
+++ watt/src/pcarp.c	2016-03-25 15:47:32 +0100
@@ -2160,16 +2160,18 @@ DWORD _route_destin (DWORD ip)
 
 
 #if defined(TEST_PROG)
 
 #include "pcdns.h"
 #include "pcbuf.h"
 
+#ifndef __DJGPP__
 static int num_okay = 0;
 static int num_fail = 0;
+#endif
 
 #define TEST(func, args, expect) do {                                   \
                                    HIGH_TEXT();                         \
                                    (*_printf) ("%s() ", #func);         \
                                    NORM_TEXT();                         \
                                    if (func args == expect) {           \
                                      num_okay++;                        \
diff -aprNU7 watt.orig/src/tests/cpu.c watt/src/tests/cpu.c
--- watt.orig/src/tests/cpu.c	2015-10-06 12:38:50 +0200
+++ watt/src/tests/cpu.c	2016-03-25 15:47:32 +0100
@@ -31,20 +31,30 @@
 #if !defined(HAVE_UINT64)
 #error I need 64-bit integer support.
 #endif
 
 static char Cx86_step = 0;
 
 #if !defined(COMPILING_PCDBUG_C)
+const char *Cx86model (void);
+const char *i486model (unsigned int nr);
+const char *i586model (unsigned int nr);
+const char *i686model (unsigned int nr);
+const char *AMDmodel (void);
+const char *cpu_get_model (int type, int model);
+
   static char *Cx86_type[] = {
        "unknown", "1.3", "1.4", "1.5", "1.6", "2.4",
        "2.5", "2.6", "2.7 or 3.7", "4.2"
      };
 #endif
 
+/* Since these are already in libwatt.a
+ */
+#if defined(COMPILING_PCDBUG_C)
 const char *i486model (unsigned int nr)
 {
   static char *model[] = {
               "0", "DX", "SX", "DX/2", "4", "SX/2", "6",
               "DX/2-WB", "DX/4", "DX/4-WB", "10", "11", "12", "13",
               "Am5x86-WT", "Am5x86-WB"
             };
@@ -137,14 +147,15 @@ const char *i686model (unsigned int nr)
   static const char *model[] = {
                     "PPro A-step", "Pentium Pro"
                   };
   if (nr < DIM(model))
      return (model[nr]);
   return (NULL);
 }
+#endif
 
 struct cpu_model_info {
        int   x86;
        char *model_names[16];
      };
 
 static const struct cpu_model_info amd_models[] = {
@@ -158,14 +169,17 @@ static const struct cpu_model_info amd_m
       "K5 (PR-166)", "K5 (PR-200)", NULL, NULL,
       "K6 (166 - 266)", "K6 (166 - 300)", "K6-2 (200 - 450)",
       "K6-3D-Plus (200 - 450)", NULL, NULL, NULL, NULL, NULL, NULL
     }
   },
 };
 
+/* Since these are already in libwatt.a
+ */
+#if defined(COMPILING_PCDBUG_C)
 const char *AMDmodel (void)
 {
   char *p = NULL;
   int   i;
 
   if (x86_model < 16)
   {
@@ -225,14 +239,15 @@ const char *cpu_get_model (int type, int
   }
   if (p)
      return (p);
 
   sprintf (nbuf, "%d", model);
   return (nbuf);
 }
+#endif
 
 /* Do not compile this if this file is included from pcdbug.c.
  */
 #if !defined(COMPILING_PCDBUG_C)
 
 /*
  * A good CPU reference:
@@ -375,27 +390,29 @@ void print_cpuid_info (void)
   print_reg (ecx, "ECX");
   print_reg (edx, "EDX");
 }
 
 void print_misc_regs (void)
 {
 #if (DOSX)
+# if defined(__DJGPP__) && 0
   WORD cs = MY_CS();
   WORD ds = MY_DS();
   WORD es = MY_ES();
   WORD ss = MY_SS();
 
   printf ("CS       : Readable: %s, Writable: %s\n",
           SelReadable(cs) ? "Yes": "No", SelWritable(cs) ? "Yes": "No");
   printf ("DS       : Readable: %s, Writable: %s\n",
           SelReadable(ds) ? "Yes": "No", SelWritable(ds) ? "Yes": "No");
   printf ("ES       : Readable: %s, Writable: %s\n",
           SelReadable(es) ? "Yes": "No", SelWritable(es) ? "Yes": "No");
   printf ("SS       : Readable: %s, Writable: %s\n",
           SelReadable(ss) ? "Yes": "No", SelWritable(ss) ? "Yes": "No");
+# endif
 #endif
 }
 
 int main (void)
 {
   uint64 Hz;
 
diff -aprNU7 watt.orig/src/tests/fsext.c watt/src/tests/fsext.c
--- watt.orig/src/tests/fsext.c	2007-01-22 23:35:16 +0100
+++ watt/src/tests/fsext.c	2016-03-25 15:47:32 +0100
@@ -11,15 +11,17 @@
 #include <sys/socket.h>
 #include <arpa/inet.h>
 #include <tcp.h>
 
 int main (void)
 {
   struct sockaddr_in sin;
+#ifndef __DJGPP__
   struct linger      linger;
+#endif
   int    s, on = 1;
   FILE  *fil;
 
   dbug_init();
 
   if ((s = socket (AF_INET, SOCK_DGRAM, 0)) < 0)
   {
@@ -55,15 +57,15 @@ int main (void)
 
     gethostname (buf, sizeof(buf));
     if (fprintf(fil, "HELO %s\r\n", buf) < 0)
     {
       perror ("fprintf");
       break;
     }
-    if (fgets(msg,sizeof(msg),fil) < 0)
+    if (fgets(msg,sizeof(msg),fil) == NULL)
     {
       perror ("fgets");
       break;
     }
     fputs (msg, stderr);
   }
 
diff -aprNU7 watt.orig/src/tests/makefile.all watt/src/tests/makefile.all
--- watt.orig/src/tests/makefile.all	2015-09-29 17:15:16 +0200
+++ watt/src/tests/makefile.all	2016-03-25 15:47:32 +0100
@@ -49,18 +49,16 @@ PROGRAMS = bind.$(EXE)        \
            packet.$(EXE)      \
            pc_cbrk.$(EXE)     \
            pcarp.$(EXE)       \
            pcconfig.$(EXE)    \
            punycode.$(EXE)    \
            select.$(EXE)      \
            socktest.$(EXE)    \
-           swap.$(EXE)        \
            syslog.$(EXE)      \
            tftp.$(EXE)        \
-           timeit_test.$(EXE) \
            ttime.$(EXE)       \
            udp_srv.$(EXE)     \
            udp_test.$(EXE)    \
            wecho.$(EXE)
 
 ifeq ($(USE_IPV6),1)
   PROGRAMS += get_ai.$(EXE) get_ni.$(EXE) gethost6.$(EXE) presaddr.$(EXE)
@@ -68,36 +66,45 @@ endif
 
 @ifdef DJGPP WATCOM HIGHC BORLAND
   PROGRAMS += oldstuff.$(EXE) ttime2.$(EXE)
 @endif
 
 @ifdef DJGPP
   PROGRAMS += fsext.$(EXE)
+@else
+  PROGRAMS += swap.$(EXE) timeit_test.$(EXE)
 @endif
 
 VPATH = ..
 
 @ifdef IS_GCC
   CC      = gcc
   CFLAGS  = -O2 -g -W -Wall -Wno-strict-aliasing
   LDFLAGS = -Wl,--print-map,--sort-common
 
   define COMP_AND_LINK
     $(CC) $(CFLAGS) $(LDFLAGS) -o $(1) $(2) $(WATT_LIB) > $(1:.exe=.map)
-    # @echo
+    @echo
   endef
 @endif
 
 LIB_DIR = ../../lib
 
 CFLAGS += -DTEST_PROG -DWATT32 -DWATT32_STATIC -I.. -I../../inc
 
 @ifdef VISUALC
   CFLAGS += -nologo
   LDFLAGS = -nologo
+@elifdef DJGPP
+  ifeq ($(filter 2 3 4,$(word 3, $(shell true | $(CC) -E -dD -x c - | grep 'define\ *__GNUC__'))),)
+    # We have gcc >= 5.x and we must ensure that always traditional
+    # GNU extern inline semantics are used (aka -fgnu89-inline) even
+    # if ISO C99 semantics have been specified.
+    CFLAGS += -fgnu89-inline
+  endif
 @endif
 
 default: all
 
 @ifdef MINGW64 VISUALC CYGWIN64
   @ifdef WIN32
     #
diff -aprNU7 watt.orig/src/tests/timeit.h watt/src/tests/timeit.h
--- watt.orig/src/tests/timeit.h	2015-09-29 17:14:08 +0200
+++ watt/src/tests/timeit.h	2016-03-25 15:47:32 +0100
@@ -2,18 +2,19 @@
 #define __TIMEIT_H
 
 #include <stdio.h>
 #include <string.h>
 #include <signal.h>
 #include <setjmp.h>
 
+#include "sys/cdefs.h"
+
+
 #if defined(__GNUC__)
   #define uint64 unsigned long long
-  #define GCC_INLINE extern __inline__ __attribute__ ((__gnu_inline__))
-
 #elif defined(_MSC_VER)
   #define uint64 unsigned __int64
 #endif
 
 #if defined(__GNUC__) && defined(__i386__) && !defined(__NO_INLINE__)  /* -O0 */
   GCC_INLINE uint64 _get_rdtsc (void)
   {
diff -aprNU7 watt.orig/src/tests/ttime2.c watt/src/tests/ttime2.c
--- watt.orig/src/tests/ttime2.c	2016-01-02 19:15:34 +0100
+++ watt/src/tests/ttime2.c	2016-03-25 15:47:32 +0100
@@ -23,20 +23,22 @@ int BCDtoDecimal (int in)
   }
   return (result);
 }
 
 int main (void)
 {
   union REGS regs;
-  long  tick, lasttick = 0, key = 0;
-  int   dx, sec, lastsec;
+  long  key = 0;
+  int   dx, sec, lastsec = 0;
 
   printf ("Press Esc to quit...\n");
   do
   {
+    unsigned long tick, lasttick = 0;
+
     if (kbhit())
        key = getch();
 
     /* get BIOS timerticks through int 0x1A/0 */
     _bios_timeofday (_TIME_GETCLOCK, &tick);
 
     /* get RTC time through int 0x1A/2 */
