MinGW build: Fix sleep() substitution

MinGW does not natively support the POSIX sleep() function so we have
had an override that was a part of the GR_PWIN32 macro and included in
the generated config.h file.  When compiling for Windows on POSIX using
MinGW, Autotools will detect sleep() and set HAVE_SLEEP which prevented
the substitution from being included in the source.  Adding a test for
_WIN32 (set by MinGW's gcc) then caused a warning from src/network.c on
POSIX about winsock2.h needing to be included before windows.h.  As
config.h needed to be included first, the solution to break out the
substitution that includes windows.h into its own file.  This patch
provides that solution and allows the code to compile cleanly on POSIX,
using MinGW on both POSIX and Windows, and on Cygwin.
Hamlib-3.0
Nate Bargmann 2013-07-29 12:38:22 -05:00
rodzic 977e92315e
commit 1fd85febee
9 zmienionych plików z 130 dodań i 16 usunięć

Wyświetl plik

@ -49,6 +49,20 @@
#include "register.h"
#include "num_stdio.h"
/* HAVE_SSLEEP is defined when Windows Sleep is found
* HAVE_SLEEP is defined when POSIX sleep is found
* _WIN32 is defined when compiling with MinGW
*
* When cross-compiling from POSIX to Windows using MinGW, HAVE_SLEEP
* will often be defined by configure although it is not supported by
* MinGW. So substitute the sleep definition below in such a case and
* when compiling on Windows using MinGW where HAVE_SLEEP will be
* undefined.
*/
#if defined(HAVE_SSLEEP) && (!defined(HAVE_SLEEP) || defined(_WIN32))
#include "hl_sleep.h"
#endif
// ---------------------------------------------------------------------------
// ADAT INCLUDES
// ---------------------------------------------------------------------------

Wyświetl plik

@ -1,4 +1,4 @@
noinst_HEADERS = config.h bandplan.h num_stdio.h
noinst_HEADERS = config.h bandplan.h num_stdio.h hl_sleep.h
nobase_include_HEADERS = hamlib/rig.h hamlib/riglist.h hamlib/rig_dll.h \
hamlib/rotator.h hamlib/rotlist.h hamlib/rigclass.h hamlib/rotclass.h

37
include/hl_sleep.h 100644
Wyświetl plik

@ -0,0 +1,37 @@
/*
* Hamlib Interface - Replacement sleep() declaration for Windows
* Copyright (C) 2013 The Hamlib Group
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/* Define missing sleep() prototype */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef HAVE_WINBASE_H
#include <windows.h>
#include <winbase.h>
#endif
/* TODO: what about SleepEx? */
static inline unsigned int sleep(unsigned int nb_sec) { Sleep(nb_sec*1000); return 0; }
#ifdef __cplusplus
}
#endif

Wyświetl plik

@ -56,7 +56,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([
#include <windows.h>
#include <winbase.h>
], [ Sleep(0); ])],
[AC_DEFINE(HAVE_SSLEEP,1,[Define to 1 if you have win32 Sleep])
[AC_DEFINE(HAVE_SSLEEP,1,[Define to 1 if you have Windows Sleep])
AC_MSG_RESULT(yes)],
AC_MSG_RESULT(no)
)
@ -73,6 +73,7 @@ int getopt (int argc, char * const argv[], const char * optstring);
extern char * optarg;
extern int optind, opterr, optopt;
#endif
#ifndef HAVE_GETOPT_LONG
struct option;
int getopt_long (int argc, char * const argv[], const char * optstring,
@ -83,16 +84,6 @@ int getopt_long (int argc, char * const argv[], const char * optstring,
int usleep(unsigned long usec); /* SUSv2 */
#endif
#if defined(HAVE_SSLEEP) && !defined(HAVE_SLEEP)
#ifdef HAVE_WINBASE_H
#include <windows.h>
#include <winbase.h>
#endif
/* TODO: what about SleepEx? */
/* static inline unsigned int sleep (unsigned int nb_sec) { Sleep(nb_sec*1000); return 0; } */
#define sleep(seconds) Sleep((seconds)*1000)
#endif
#ifndef HAVE_GETTIMEOFDAY
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>

Wyświetl plik

@ -36,6 +36,20 @@
#include "misc.h"
#include "num_stdio.h"
/* HAVE_SSLEEP is defined when Windows Sleep is found
* HAVE_SLEEP is defined when POSIX sleep is found
* _WIN32 is defined when compiling with MinGW
*
* When cross-compiling from POSIX to Windows using MinGW, HAVE_SLEEP
* will often be defined by configure although it is not supported by
* MinGW. So substitute the sleep definition below in such a case and
* when compiling on Windows using MinGW where HAVE_SLEEP will be
* undefined.
*/
#if defined(HAVE_SSLEEP) && (!defined(HAVE_SLEEP) || defined(_WIN32))
#include "hl_sleep.h"
#endif
struct tt585_priv_data {
unsigned char status_data[30];
struct timeval status_tv;

Wyświetl plik

@ -33,12 +33,26 @@
#include <math.h>
#include <hamlib/rig.h>
#include <serial.h>
#include <misc.h>
#include <cal.h>
#include "serial.h"
#include "misc.h"
#include "cal.h"
#include "tt550.h"
/* HAVE_SSLEEP is defined when Windows Sleep is found
* HAVE_SLEEP is defined when POSIX sleep is found
* _WIN32 is defined when compiling with MinGW
*
* When cross-compiling from POSIX to Windows using MinGW, HAVE_SLEEP
* will often be defined by configure although it is not supported by
* MinGW. So substitute the sleep definition below in such a case and
* when compiling on Windows using MinGW where HAVE_SLEEP will be
* undefined.
*/
#if defined(HAVE_SSLEEP) && (!defined(HAVE_SLEEP) || defined(_WIN32))
#include "hl_sleep.h"
#endif
/*
* Filter table for 550 reciver support

Wyświetl plik

@ -8,6 +8,21 @@
#include <stdlib.h>
#include <hamlib/rig.h>
/* HAVE_SSLEEP is defined when Windows Sleep is found
* HAVE_SLEEP is defined when POSIX sleep is found
* _WIN32 is defined when compiling with MinGW
*
* When cross-compiling from POSIX to Windows using MinGW, HAVE_SLEEP
* will often be defined by configure although it is not supported by
* MinGW. So substitute the sleep definition below in such a case and
* when compiling on Windows using MinGW where HAVE_SLEEP will be
* undefined.
*/
#if defined(HAVE_SSLEEP) && (!defined(HAVE_SLEEP) || defined(_WIN32))
#include "hl_sleep.h"
#endif
#define SERIAL_PORT "/dev/ttyS0"
int main (int argc, char *argv[])

Wyświetl plik

@ -8,6 +8,21 @@
#include <stdlib.h>
#include <hamlib/rig.h>
/* HAVE_SSLEEP is defined when Windows Sleep is found
* HAVE_SLEEP is defined when POSIX sleep is found
* _WIN32 is defined when compiling with MinGW
*
* When cross-compiling from POSIX to Windows using MinGW, HAVE_SLEEP
* will often be defined by configure although it is not supported by
* MinGW. So substitute the sleep definition below in such a case and
* when compiling on Windows using MinGW where HAVE_SLEEP will be
* undefined.
*/
#if defined(HAVE_SSLEEP) && (!defined(HAVE_SLEEP) || defined(_WIN32))
#include "hl_sleep.h"
#endif
#define SERIAL_PORT "/dev/ttyS0"
int myfreq_event(RIG *rig, vfo_t vfo, freq_t freq, rig_ptr_t arg)

Wyświetl plik

@ -43,12 +43,26 @@
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include "hamlib/rig.h"
#include <hamlib/rig.h>
#include "serial.h"
#include "misc.h"
#include "yaesu.h"
#include "ft757gx.h"
/* HAVE_SSLEEP is defined when Windows Sleep is found
* HAVE_SLEEP is defined when POSIX sleep is found
* _WIN32 is defined when compiling with MinGW
*
* When cross-compiling from POSIX to Windows using MinGW, HAVE_SLEEP
* will often be defined by configure although it is not supported by
* MinGW. So substitute the sleep definition below in such a case and
* when compiling on Windows using MinGW where HAVE_SLEEP will be
* undefined.
*/
#if defined(HAVE_SSLEEP) && (!defined(HAVE_SLEEP) || defined(_WIN32))
#include "hl_sleep.h"
#endif
/* Private helper function prototypes */
static int ft757_get_update_data(RIG *rig);