Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Windows support #146

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added Windows support
  • Loading branch information
snake-4 committed Aug 5, 2021
commit 8ebf6b63bd6b0b83baf120d486c4b47c8321d52f
35 changes: 24 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,20 @@ else
LIMESDR ?= no
endif

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

ifeq ($(UNAME), Linux)
CPPFLAGS += -D_DEFAULT_SOURCE
ifeq ($(DETECTED_OS), Linux)
LIBS += -lrt
LIBS_USB += -lusb-1.0
LIBS_CURSES := -lncurses
CPUFEATURES ?= yes
endif

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

ifeq ($(UNAME), OpenBSD)
ifeq ($(DETECTED_OS), OpenBSD)
CPPFLAGS += -DMISSING_NANOSLEEP
COMPAT += compat/clock_nanosleep/clock_nanosleep.o
LIBS_USB += -lusb-1.0
LIBS_CURSES := -lncurses
CPUFEATURES ?= yes
endif

ifeq ($(UNAME), FreeBSD)
CPPFLAGS += -D_DEFAULT_SOURCE
ifeq ($(DETECTED_OS), FreeBSD)
LIBS += -lrt
LIBS_USB += -lusb
LIBS_CURSES := -lncurses
endif

ifeq ($(UNAME), NetBSD)
CFLAGS += -D_DEFAULT_SOURCE
ifeq ($(DETECTED_OS), NetBSD)
LIBS += -lrt
LIBS_USB += -lusb-1.0
LIBS_CURSES := -lcurses
endif

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


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

clean:
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
rm -f dump1090 view1090 faup1090 cprtests crctests oneoff/convert_benchmark oneoff/decode_comm_b oneoff/dsp_error_measurement oneoff/uc8_capture_stats starch-benchmark
find . -type f -name '*.o' -exec rm {} +
find . -type f -name '*.exe' -exec rm {} +

test: cprtests
./cprtests
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ libhackrf.
``make LIMESDR=no`` will disable LimeSDR support and remove the dependency on
libLimeSuite.

## Building on MSYS2

Install PothosSDR on the default location and install MSYS2.
#### Building with MinGW-w64
```
$ pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-ncurses mingw-w64-x86_64-libsystre mingw-w64-x86_64-libusb
$ alias make=mingw32-make
$ PKG_CONFIG_PATH="/c/PothosSDR/lib/pkgconfig:$PKG_CONFIG_PATH" make -j$(nproc)
```
#### Building with Clang
```
$ 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
$ alias make=mingw32-make
$ PKG_CONFIG_PATH="/c/PothosSDR/lib/pkgconfig:$PKG_CONFIG_PATH" make -j$(nproc)
```
#### Building with MinGW-w64/UCRT
```
$ 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
$ alias make=mingw32-make
$ PKG_CONFIG_PATH="/c/PothosSDR/lib/pkgconfig:$PKG_CONFIG_PATH" make -j$(nproc)
```

## Building on OSX

Minimal testing on Mojave 10.14.6, YMMV.
Expand Down
46 changes: 33 additions & 13 deletions anet.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,29 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifdef _WIN32
# include <winsock2.h>
# include <ws2def.h>
# include <ws2tcpip.h>
# include <Windows.h>
# define socklen_t int
# define sockaddr_storage sockaddr
# define p_setsockopt_optval_t const char*
#else
# include <sys/socket.h>
# include <sys/un.h>
# include <netinet/in.h>
# include <netinet/tcp.h>
# include <arpa/inet.h>
# include <unistd.h>
# include <netdb.h>
# define p_setsockopt_optval_t void*
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <netdb.h>

#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
Expand All @@ -80,6 +92,7 @@ static void anetSetError(char *err, const char *fmt, ...)

int anetNonBlock(char *err, int fd)
{
#if !defined(_WIN32)
int flags;

/* Set the socket nonblocking.
Expand All @@ -93,14 +106,21 @@ int anetNonBlock(char *err, int fd)
anetSetError(err, "fcntl(F_SETFL,O_NONBLOCK): %s", strerror(errno));
return ANET_ERR;
}

#else
u_long mode = 1; // 1 to enable non-blocking socket
int errorCode = ioctlsocket(fd, FIONBIO, &mode);
if (errorCode != 0) {
anetSetError(err, "ioctlsocket(FIONBIO): %d", errorCode);
return ANET_ERR;
}
#endif
return ANET_OK;
}

int anetTcpNoDelay(char *err, int fd)
{
int yes = 1;
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void*)&yes, sizeof(yes)) == -1)
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (p_setsockopt_optval_t)&yes, sizeof(yes)) == -1)
{
anetSetError(err, "setsockopt TCP_NODELAY: %s", strerror(errno));
return ANET_ERR;
Expand All @@ -110,7 +130,7 @@ int anetTcpNoDelay(char *err, int fd)

int anetSetSendBuffer(char *err, int fd, int buffsize)
{
if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void*)&buffsize, sizeof(buffsize)) == -1)
if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (p_setsockopt_optval_t)&buffsize, sizeof(buffsize)) == -1)
{
anetSetError(err, "setsockopt SO_SNDBUF: %s", strerror(errno));
return ANET_ERR;
Expand All @@ -121,7 +141,7 @@ int anetSetSendBuffer(char *err, int fd, int buffsize)
int anetTcpKeepAlive(char *err, int fd)
{
int yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&yes, sizeof(yes)) == -1) {
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (p_setsockopt_optval_t)&yes, sizeof(yes)) == -1) {
anetSetError(err, "setsockopt SO_KEEPALIVE: %s", strerror(errno));
return ANET_ERR;
}
Expand All @@ -138,7 +158,7 @@ static int anetCreateSocket(char *err, int domain)

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

if (bind(s,sa,len) == -1) {
Expand Down
29 changes: 7 additions & 22 deletions compat/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,18 @@
* Platform-specific bits
*/

#if defined(__APPLE__)

/*
* Mach endian conversion
*/
# include <libkern/OSByteOrder.h>
# define bswap_16 OSSwapInt16
# define bswap_32 OSSwapInt32
# define bswap_64 OSSwapInt64
# include <machine/endian.h>
# define le16toh(x) OSSwapLittleToHostInt16(x)
# define le32toh(x) OSSwapLittleToHostInt32(x)
# define le64toh(x) OSSwapLittleToHostInt64(x)

#elif defined(__FreeBSD__)
#include <sys/endian.h>

#else // other platforms

# include <endian.h>

#endif
#include "endian.h"

/* clock_* and time-related types */

#include <time.h>

//MSVC/MinGW has no _r time functions
#ifdef MISSING_TIME_R_FUNCS
# define localtime_r(T,Tm) (localtime_s(Tm,T) ? NULL : Tm)
# define gmtime_r(T,Tm) (gmtime_s(Tm,T) ? NULL : Tm)
#endif

#if defined(CLOCK_REALTIME)
# define HAVE_CLOCKID_T
#endif
Expand Down
115 changes: 115 additions & 0 deletions compat/endian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// "License": Public Domain
// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like.
// In case there are jurisdictions that don't support putting things in the public domain you can also consider it to
// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it
// an example on how to get the endian conversion functions on different platforms.

#ifndef PORTABLE_ENDIAN_H__
#define PORTABLE_ENDIAN_H__

#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)

# define __WINDOWS__

#endif

#if defined(__linux__) || defined(__CYGWIN__)

# include <endian.h>

#elif defined(__APPLE__)

# include <libkern/OSByteOrder.h>

# define htobe16(x) OSSwapHostToBigInt16(x)
# define htole16(x) OSSwapHostToLittleInt16(x)
# define be16toh(x) OSSwapBigToHostInt16(x)
# define le16toh(x) OSSwapLittleToHostInt16(x)

# define htobe32(x) OSSwapHostToBigInt32(x)
# define htole32(x) OSSwapHostToLittleInt32(x)
# define be32toh(x) OSSwapBigToHostInt32(x)
# define le32toh(x) OSSwapLittleToHostInt32(x)

# define htobe64(x) OSSwapHostToBigInt64(x)
# define htole64(x) OSSwapHostToLittleInt64(x)
# define be64toh(x) OSSwapBigToHostInt64(x)
# define le64toh(x) OSSwapLittleToHostInt64(x)

# define __BYTE_ORDER BYTE_ORDER
# define __BIG_ENDIAN BIG_ENDIAN
# define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN

#elif defined(__OpenBSD__)

# include <sys/endian.h>

#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)

# include <sys/endian.h>

# define be16toh(x) betoh16(x)
# define le16toh(x) letoh16(x)

# define be32toh(x) betoh32(x)
# define le32toh(x) letoh32(x)

# define be64toh(x) betoh64(x)
# define le64toh(x) letoh64(x)

#elif defined(__WINDOWS__)

# if BYTE_ORDER == LITTLE_ENDIAN

# define htobe16(x) __builtin_bswap16(x)
# define htole16(x) (x)
# define be16toh(x) __builtin_bswap16(x)
# define le16toh(x) (x)

# define htobe32(x) __builtin_bswap32(x)
# define htole32(x) (x)
# define be32toh(x) __builtin_bswap32(x)
# define le32toh(x) (x)

# define htobe64(x) __builtin_bswap64(x)
# define htole64(x) (x)
# define be64toh(x) __builtin_bswap64(x)
# define le64toh(x) (x)

# elif BYTE_ORDER == BIG_ENDIAN

/* that would be xbox 360 */
# define htobe16(x) (x)
# define htole16(x) __builtin_bswap16(x)
# define be16toh(x) (x)
# define le16toh(x) __builtin_bswap16(x)

# define htobe32(x) (x)
# define htole32(x) __builtin_bswap32(x)
# define be32toh(x) (x)
# define le32toh(x) __builtin_bswap32(x)

# define htobe64(x) (x)
# define htole64(x) __builtin_bswap64(x)
# define be64toh(x) (x)
# define le64toh(x) __builtin_bswap64(x)

# else

# error byte order not supported

# endif

# define __BYTE_ORDER BYTE_ORDER
# define __BIG_ENDIAN BIG_ENDIAN
# define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN

#else

# error platform not supported

#endif

#endif
1 change: 1 addition & 0 deletions dump1090.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ int main(int argc, char **argv) {
}
}

modesDeInitNet();
interactiveCleanup();

// Write final stats
Expand Down
Loading