Imported Upstream version 3.0
[debian/gnuradio] / config / gr_pwin32.m4
1 # Check for (mingw)win32 POSIX replacements.             -*- Autoconf -*-
2
3 # Copyright 2003,2004,2005 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
11
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING.  If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
21
22
23 AC_DEFUN([GR_PWIN32],
24 [
25 AC_REQUIRE([AC_HEADER_TIME])
26 AC_CHECK_HEADERS([sys/types.h fcntl.h io.h])
27 AC_CHECK_HEADERS([windows.h])
28 AC_CHECK_HEADERS([winioctl.h winbase.h], [], [], [
29         #if HAVE_WINDOWS_H
30         #include <windows.h>
31         #endif
32 ])
33
34 AC_CHECK_FUNCS([getopt usleep gettimeofday nanosleep rand srand random srandom sleep sigaction])
35 AC_CHECK_TYPES([struct timezone, struct timespec, ssize_t],[],[],[
36      #if HAVE_SYS_TYPES_H
37      # include <sys/types.h>
38      #endif
39      #if TIME_WITH_SYS_TIME
40      # include <sys/time.h>
41      # include <time.h>
42      #else
43      # if HAVE_SYS_TIME_H
44      #  include <sys/time.h>
45      # else
46      #  include <time.h>
47      # endif
48      #endif
49 ])
50
51 dnl Checks for replacements
52 AC_REPLACE_FUNCS([getopt usleep gettimeofday])
53
54
55 AC_MSG_CHECKING(for Sleep)
56 AC_TRY_LINK([   #include <windows.h>
57                 #include <winbase.h>
58                 ], [ Sleep(0); ],
59                 [AC_DEFINE(HAVE_SSLEEP,1,[Define to 1 if you have win32 Sleep])
60                 AC_MSG_RESULT(yes)],
61                 AC_MSG_RESULT(no)
62                 )
63
64 dnl Under Win32, mkdir prototype in io.h has only one arg
65 AC_MSG_CHECKING(whether mkdir accepts only one arg)
66 AC_TRY_COMPILE([#include <sys/types.h>
67        #include <sys/stat.h>
68        #include <fcntl.h>], [
69        mkdir("")
70  ], [ AC_MSG_RESULT(yes)
71      AC_DEFINE(MKDIR_TAKES_ONE_ARG,[],[Define if mkdir accepts only one arg]) ],
72  [ AC_MSG_RESULT(no)
73  ])
74
75 AH_BOTTOM(
76 [
77 /* Define missing prototypes, implemented in replacement lib */
78 #ifdef  __cplusplus
79 extern "C" {
80 #endif
81
82 #ifndef HAVE_GETOPT
83 int getopt (int argc, char * const argv[], const char * optstring);
84 extern char * optarg;
85 extern int optind, opterr, optopt;
86 #endif
87
88 #ifndef HAVE_USLEEP
89 int usleep(unsigned long usec); /* SUSv2 */
90 #endif
91
92 #ifndef HAVE_NANOSLEEP
93 #ifndef HAVE_STRUCT_TIMESPEC
94 #if HAVE_SYS_TYPES_H
95 # include <sys/types.h> /* need time_t */
96 #endif
97 struct timespec {
98         time_t  tv_sec;
99         long    tv_nsec;
100 };
101 #endif
102 static inline int nanosleep(const struct timespec *req, struct timespec *rem) { return usleep(req->tv_sec*1000000+req->tv_nsec/1000); }
103 #endif
104
105 #if defined(HAVE_SSLEEP) && !defined(HAVE_SLEEP)
106 #ifdef HAVE_WINBASE_H
107 #include <windows.h>
108 #include <winbase.h>
109 #endif
110 /* TODO: what about SleepEx? */
111 static inline unsigned int sleep (unsigned int nb_sec) { Sleep(nb_sec*1000); return 0; }
112 #endif
113
114 #ifndef HAVE_GETTIMEOFDAY
115 #ifdef HAVE_SYS_TIME_H
116 #include <sys/time.h>
117 #endif
118 #ifndef HAVE_STRUCT_TIMEZONE
119 struct timezone {
120         int  tz_minuteswest;
121         int  tz_dsttime;
122 };
123 #endif
124 int gettimeofday(struct timeval *tv, struct timezone *tz);
125 #endif
126
127 #if !defined(HAVE_RANDOM) && defined(HAVE_RAND)
128 #include <stdlib.h>
129 static inline long int random (void) { return rand(); }
130 #endif
131
132 #if !defined(HAVE_SRANDOM) && defined(HAVE_SRAND)
133 static inline void srandom (unsigned int seed) { srand(seed); }
134 #endif
135
136 #ifndef HAVE_SSIZE_T
137 typedef size_t ssize_t;
138 #endif
139
140 #ifdef  __cplusplus
141 }
142 #endif
143 ])
144
145
146 ])