Skip to content

Commit 8ebf6b6

Browse files
committed
Added Windows support
1 parent 7247109 commit 8ebf6b6

File tree

12 files changed

+305
-100
lines changed

12 files changed

+305
-100
lines changed

Makefile

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,20 @@ else
3939
LIMESDR ?= no
4040
endif
4141

42-
UNAME := $(shell uname)
42+
ifeq ($(OS),Windows_NT)
43+
DETECTED_OS := Windows
44+
else
45+
DETECTED_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
46+
endif
4347

44-
ifeq ($(UNAME), Linux)
45-
CPPFLAGS += -D_DEFAULT_SOURCE
48+
ifeq ($(DETECTED_OS), Linux)
4649
LIBS += -lrt
4750
LIBS_USB += -lusb-1.0
4851
LIBS_CURSES := -lncurses
4952
CPUFEATURES ?= yes
5053
endif
5154

52-
ifeq ($(UNAME), Darwin)
55+
ifeq ($(DETECTED_OS), Darwin)
5356
ifneq ($(shell sw_vers -productVersion | egrep '^10\.([0-9]|1[01])\.'),) # Mac OS X ver <= 10.11
5457
CPPFLAGS += -DMISSING_GETTIME
5558
COMPAT += compat/clock_gettime/clock_gettime.o
@@ -61,29 +64,37 @@ ifeq ($(UNAME), Darwin)
6164
CPUFEATURES ?= yes
6265
endif
6366

64-
ifeq ($(UNAME), OpenBSD)
67+
ifeq ($(DETECTED_OS), OpenBSD)
6568
CPPFLAGS += -DMISSING_NANOSLEEP
6669
COMPAT += compat/clock_nanosleep/clock_nanosleep.o
6770
LIBS_USB += -lusb-1.0
6871
LIBS_CURSES := -lncurses
72+
CPUFEATURES ?= yes
6973
endif
7074

71-
ifeq ($(UNAME), FreeBSD)
72-
CPPFLAGS += -D_DEFAULT_SOURCE
75+
ifeq ($(DETECTED_OS), FreeBSD)
7376
LIBS += -lrt
7477
LIBS_USB += -lusb
7578
LIBS_CURSES := -lncurses
7679
endif
7780

78-
ifeq ($(UNAME), NetBSD)
79-
CFLAGS += -D_DEFAULT_SOURCE
81+
ifeq ($(DETECTED_OS), NetBSD)
8082
LIBS += -lrt
8183
LIBS_USB += -lusb-1.0
8284
LIBS_CURSES := -lcurses
8385
endif
8486

85-
CPUFEATURES ?= no
87+
ifeq ($(DETECTED_OS), Windows)
88+
# TODO: Perhaps copy the DLL files to the output folder if the OS is Windows?
89+
CPPFLAGS += -DMISSING_TIME_R_FUNCS -DMISSING_CURSES_H_NCURSES -D_USE_MATH_DEFINES
90+
LIBS += -lws2_32 -lsystre
91+
LIBS_USB += -lusb-1.0
92+
LIBS_CURSES := -lncurses
93+
CPUFEATURES ?= yes
94+
endif
8695

96+
97+
CPUFEATURES ?= no
8798
ifeq ($(CPUFEATURES),yes)
8899
include Makefile.cpufeatures
89100
CPPFLAGS += -DENABLE_CPUFEATURES -Icpu_features/include
@@ -202,7 +213,9 @@ starch-benchmark: cpu.o dsp/helpers/tables.o $(CPUFEATURES_OBJS) $(STARCH_OBJS)
202213
$(CC) -g -o $@ $^ $(LDFLAGS) $(LIBS)
203214

204215
clean:
205-
rm -f *.o oneoff/*.o compat/clock_gettime/*.o compat/clock_nanosleep/*.o cpu_features/src/*.o dsp/generated/*.o dsp/helpers/*.o $(CPUFEATURES_OBJS) dump1090 view1090 faup1090 cprtests crctests oneoff/convert_benchmark oneoff/decode_comm_b oneoff/dsp_error_measurement oneoff/uc8_capture_stats starch-benchmark
216+
rm -f dump1090 view1090 faup1090 cprtests crctests oneoff/convert_benchmark oneoff/decode_comm_b oneoff/dsp_error_measurement oneoff/uc8_capture_stats starch-benchmark
217+
find . -type f -name '*.o' -exec rm {} +
218+
find . -type f -name '*.exe' -exec rm {} +
206219

207220
test: cprtests
208221
./cprtests

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,28 @@ libhackrf.
7474
``make LIMESDR=no`` will disable LimeSDR support and remove the dependency on
7575
libLimeSuite.
7676

77+
## Building on MSYS2
78+
79+
Install PothosSDR on the default location and install MSYS2.
80+
#### Building with MinGW-w64
81+
```
82+
$ pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-ncurses mingw-w64-x86_64-libsystre mingw-w64-x86_64-libusb
83+
$ alias make=mingw32-make
84+
$ PKG_CONFIG_PATH="/c/PothosSDR/lib/pkgconfig:$PKG_CONFIG_PATH" make -j$(nproc)
85+
```
86+
#### Building with Clang
87+
```
88+
$ pacman -S mingw-w64-clang-x86_64-toolchain mingw-w64-clang-x86_64-ncurses mingw-w64-clang-x86_64-libsystre mingw-w64-clang-x86_64-libusb
89+
$ alias make=mingw32-make
90+
$ PKG_CONFIG_PATH="/c/PothosSDR/lib/pkgconfig:$PKG_CONFIG_PATH" make -j$(nproc)
91+
```
92+
#### Building with MinGW-w64/UCRT
93+
```
94+
$ pacman -S mingw-w64-ucrt-x86_64-toolchain mingw-w64-ucrt-x86_64-ncurses mingw-w64-ucrt-x86_64-libsystre mingw-w64-ucrt-x86_64-libgnurx
95+
$ alias make=mingw32-make
96+
$ PKG_CONFIG_PATH="/c/PothosSDR/lib/pkgconfig:$PKG_CONFIG_PATH" make -j$(nproc)
97+
```
98+
7799
## Building on OSX
78100

79101
Minimal testing on Mojave 10.14.6, YMMV.

anet.c

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,29 @@
5151
* POSSIBILITY OF SUCH DAMAGE.
5252
*/
5353

54+
#ifdef _WIN32
55+
# include <winsock2.h>
56+
# include <ws2def.h>
57+
# include <ws2tcpip.h>
58+
# include <Windows.h>
59+
# define socklen_t int
60+
# define sockaddr_storage sockaddr
61+
# define p_setsockopt_optval_t const char*
62+
#else
63+
# include <sys/socket.h>
64+
# include <sys/un.h>
65+
# include <netinet/in.h>
66+
# include <netinet/tcp.h>
67+
# include <arpa/inet.h>
68+
# include <unistd.h>
69+
# include <netdb.h>
70+
# define p_setsockopt_optval_t void*
71+
#endif
5472
#include <sys/types.h>
55-
#include <sys/socket.h>
5673
#include <sys/stat.h>
57-
#include <sys/un.h>
58-
#include <netinet/in.h>
59-
#include <netinet/tcp.h>
60-
#include <arpa/inet.h>
61-
#include <unistd.h>
6274
#include <fcntl.h>
6375
#include <string.h>
64-
#include <netdb.h>
76+
6577
#include <errno.h>
6678
#include <stdarg.h>
6779
#include <stdio.h>
@@ -80,6 +92,7 @@ static void anetSetError(char *err, const char *fmt, ...)
8092

8193
int anetNonBlock(char *err, int fd)
8294
{
95+
#if !defined(_WIN32)
8396
int flags;
8497

8598
/* Set the socket nonblocking.
@@ -93,14 +106,21 @@ int anetNonBlock(char *err, int fd)
93106
anetSetError(err, "fcntl(F_SETFL,O_NONBLOCK): %s", strerror(errno));
94107
return ANET_ERR;
95108
}
96-
109+
#else
110+
u_long mode = 1; // 1 to enable non-blocking socket
111+
int errorCode = ioctlsocket(fd, FIONBIO, &mode);
112+
if (errorCode != 0) {
113+
anetSetError(err, "ioctlsocket(FIONBIO): %d", errorCode);
114+
return ANET_ERR;
115+
}
116+
#endif
97117
return ANET_OK;
98118
}
99119

100120
int anetTcpNoDelay(char *err, int fd)
101121
{
102122
int yes = 1;
103-
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void*)&yes, sizeof(yes)) == -1)
123+
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (p_setsockopt_optval_t)&yes, sizeof(yes)) == -1)
104124
{
105125
anetSetError(err, "setsockopt TCP_NODELAY: %s", strerror(errno));
106126
return ANET_ERR;
@@ -110,7 +130,7 @@ int anetTcpNoDelay(char *err, int fd)
110130

111131
int anetSetSendBuffer(char *err, int fd, int buffsize)
112132
{
113-
if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void*)&buffsize, sizeof(buffsize)) == -1)
133+
if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (p_setsockopt_optval_t)&buffsize, sizeof(buffsize)) == -1)
114134
{
115135
anetSetError(err, "setsockopt SO_SNDBUF: %s", strerror(errno));
116136
return ANET_ERR;
@@ -121,7 +141,7 @@ int anetSetSendBuffer(char *err, int fd, int buffsize)
121141
int anetTcpKeepAlive(char *err, int fd)
122142
{
123143
int yes = 1;
124-
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&yes, sizeof(yes)) == -1) {
144+
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (p_setsockopt_optval_t)&yes, sizeof(yes)) == -1) {
125145
anetSetError(err, "setsockopt SO_KEEPALIVE: %s", strerror(errno));
126146
return ANET_ERR;
127147
}
@@ -138,7 +158,7 @@ static int anetCreateSocket(char *err, int domain)
138158

139159
/* Make sure connection-intensive things like the redis benckmark
140160
* will be able to close/open sockets a zillion of times */
141-
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&on, sizeof(on)) == -1) {
161+
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (p_setsockopt_optval_t)&on, sizeof(on)) == -1) {
142162
anetSetError(err, "setsockopt SO_REUSEADDR: %s", strerror(errno));
143163
return ANET_ERR;
144164
}
@@ -239,7 +259,7 @@ int anetWrite(int fd, char *buf, int count)
239259
static int anetListen(char *err, int s, struct sockaddr *sa, socklen_t len) {
240260
if (sa->sa_family == AF_INET6) {
241261
int on = 1;
242-
setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on));
262+
setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (p_setsockopt_optval_t)&on, sizeof(on));
243263
}
244264

245265
if (bind(s,sa,len) == -1) {

compat/compat.h

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,18 @@
55
* Platform-specific bits
66
*/
77

8-
#if defined(__APPLE__)
9-
10-
/*
11-
* Mach endian conversion
12-
*/
13-
# include <libkern/OSByteOrder.h>
14-
# define bswap_16 OSSwapInt16
15-
# define bswap_32 OSSwapInt32
16-
# define bswap_64 OSSwapInt64
17-
# include <machine/endian.h>
18-
# define le16toh(x) OSSwapLittleToHostInt16(x)
19-
# define le32toh(x) OSSwapLittleToHostInt32(x)
20-
# define le64toh(x) OSSwapLittleToHostInt64(x)
21-
22-
#elif defined(__FreeBSD__)
23-
#include <sys/endian.h>
24-
25-
#else // other platforms
26-
27-
# include <endian.h>
28-
29-
#endif
8+
#include "endian.h"
309

3110
/* clock_* and time-related types */
3211

3312
#include <time.h>
3413

14+
//MSVC/MinGW has no _r time functions
15+
#ifdef MISSING_TIME_R_FUNCS
16+
# define localtime_r(T,Tm) (localtime_s(Tm,T) ? NULL : Tm)
17+
# define gmtime_r(T,Tm) (gmtime_s(Tm,T) ? NULL : Tm)
18+
#endif
19+
3520
#if defined(CLOCK_REALTIME)
3621
# define HAVE_CLOCKID_T
3722
#endif

compat/endian.h

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// "License": Public Domain
2+
// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like.
3+
// In case there are jurisdictions that don't support putting things in the public domain you can also consider it to
4+
// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it
5+
// an example on how to get the endian conversion functions on different platforms.
6+
7+
#ifndef PORTABLE_ENDIAN_H__
8+
#define PORTABLE_ENDIAN_H__
9+
10+
#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
11+
12+
# define __WINDOWS__
13+
14+
#endif
15+
16+
#if defined(__linux__) || defined(__CYGWIN__)
17+
18+
# include <endian.h>
19+
20+
#elif defined(__APPLE__)
21+
22+
# include <libkern/OSByteOrder.h>
23+
24+
# define htobe16(x) OSSwapHostToBigInt16(x)
25+
# define htole16(x) OSSwapHostToLittleInt16(x)
26+
# define be16toh(x) OSSwapBigToHostInt16(x)
27+
# define le16toh(x) OSSwapLittleToHostInt16(x)
28+
29+
# define htobe32(x) OSSwapHostToBigInt32(x)
30+
# define htole32(x) OSSwapHostToLittleInt32(x)
31+
# define be32toh(x) OSSwapBigToHostInt32(x)
32+
# define le32toh(x) OSSwapLittleToHostInt32(x)
33+
34+
# define htobe64(x) OSSwapHostToBigInt64(x)
35+
# define htole64(x) OSSwapHostToLittleInt64(x)
36+
# define be64toh(x) OSSwapBigToHostInt64(x)
37+
# define le64toh(x) OSSwapLittleToHostInt64(x)
38+
39+
# define __BYTE_ORDER BYTE_ORDER
40+
# define __BIG_ENDIAN BIG_ENDIAN
41+
# define __LITTLE_ENDIAN LITTLE_ENDIAN
42+
# define __PDP_ENDIAN PDP_ENDIAN
43+
44+
#elif defined(__OpenBSD__)
45+
46+
# include <sys/endian.h>
47+
48+
#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
49+
50+
# include <sys/endian.h>
51+
52+
# define be16toh(x) betoh16(x)
53+
# define le16toh(x) letoh16(x)
54+
55+
# define be32toh(x) betoh32(x)
56+
# define le32toh(x) letoh32(x)
57+
58+
# define be64toh(x) betoh64(x)
59+
# define le64toh(x) letoh64(x)
60+
61+
#elif defined(__WINDOWS__)
62+
63+
# if BYTE_ORDER == LITTLE_ENDIAN
64+
65+
# define htobe16(x) __builtin_bswap16(x)
66+
# define htole16(x) (x)
67+
# define be16toh(x) __builtin_bswap16(x)
68+
# define le16toh(x) (x)
69+
70+
# define htobe32(x) __builtin_bswap32(x)
71+
# define htole32(x) (x)
72+
# define be32toh(x) __builtin_bswap32(x)
73+
# define le32toh(x) (x)
74+
75+
# define htobe64(x) __builtin_bswap64(x)
76+
# define htole64(x) (x)
77+
# define be64toh(x) __builtin_bswap64(x)
78+
# define le64toh(x) (x)
79+
80+
# elif BYTE_ORDER == BIG_ENDIAN
81+
82+
/* that would be xbox 360 */
83+
# define htobe16(x) (x)
84+
# define htole16(x) __builtin_bswap16(x)
85+
# define be16toh(x) (x)
86+
# define le16toh(x) __builtin_bswap16(x)
87+
88+
# define htobe32(x) (x)
89+
# define htole32(x) __builtin_bswap32(x)
90+
# define be32toh(x) (x)
91+
# define le32toh(x) __builtin_bswap32(x)
92+
93+
# define htobe64(x) (x)
94+
# define htole64(x) __builtin_bswap64(x)
95+
# define be64toh(x) (x)
96+
# define le64toh(x) __builtin_bswap64(x)
97+
98+
# else
99+
100+
# error byte order not supported
101+
102+
# endif
103+
104+
# define __BYTE_ORDER BYTE_ORDER
105+
# define __BIG_ENDIAN BIG_ENDIAN
106+
# define __LITTLE_ENDIAN LITTLE_ENDIAN
107+
# define __PDP_ENDIAN PDP_ENDIAN
108+
109+
#else
110+
111+
# error platform not supported
112+
113+
#endif
114+
115+
#endif

dump1090.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ int main(int argc, char **argv) {
920920
}
921921
}
922922

923+
modesDeInitNet();
923924
interactiveCleanup();
924925

925926
// Write final stats

0 commit comments

Comments
 (0)