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

Fix mingw build #610

Merged
merged 2 commits into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
obj-*
*.user*
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ if (STLINK_HAVE_SYS_MMAN_H)
add_definitions(-DSTLINK_HAVE_SYS_MMAN_H)
endif()

CHECK_INCLUDE_FILE(unistd.h STLINK_HAVE_UNISTD_H)
if (STLINK_HAVE_UNISTD_H)
add_definitions(-DSTLINK_HAVE_UNISTD_H)
endif()

if (CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Debug")
endif()
Expand Down Expand Up @@ -73,10 +78,10 @@ include_directories(include)
include_directories(${PROJECT_BINARY_DIR}/include)
include_directories(src/mingw)
if (MSVC)
include_directories(src/win32)
include_directories(src/getopt)
# Use string.h rather than strings.h and disable annoying warnings
add_definitions(-DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS /wd4710)
include_directories(src/win32)
include_directories(src/getopt)
# Use string.h rather than strings.h and disable annoying warnings
add_definitions(-DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS /wd4710)
endif ()

###
Expand Down
4 changes: 2 additions & 2 deletions src/mingw/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ char *win32_strsep (char **stringp, const char *delim)
/* NOTREACHED */
}

#ifdef STLINK_HAVE_SYS_MMAN_H
void usleep(DWORD waitTime)
{
#ifdef _MSC_VER
if (waitTime >= 1000)
{
// Don't do long busy-waits.
Expand All @@ -290,7 +290,6 @@ void usleep(DWORD waitTime)
CloseHandle(timer);
return;
}
#endif
LARGE_INTEGER perf_cnt, start, now;

QueryPerformanceFrequency(&perf_cnt);
Expand All @@ -300,6 +299,7 @@ void usleep(DWORD waitTime)
QueryPerformanceCounter((LARGE_INTEGER*) &now);
} while ((now.QuadPart - start.QuadPart) / (float)perf_cnt.QuadPart * 1000 * 1000 < waitTime);
}
#endif

#endif

Expand Down
6 changes: 5 additions & 1 deletion src/mingw/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

#include <io.h>
#include <WinSock2.h>
#if defined(_MSC_VER)
#pragma comment(lib, "ws2_32.lib")
#endif
#include <unistd.h>

#if defined(_MSC_VER)
Expand Down Expand Up @@ -69,7 +71,9 @@ char *win32_strsep(char **stringp, const char *delim);
ssize_t win32_read_socket(SOCKET fd, void *buf, int n);
ssize_t win32_write_socket(SOCKET fd, void *buf, int n);

#ifdef STLINK_HAVE_SYS_MMAN_H
static inline void sleep(unsigned ms) { Sleep(ms); }
void usleep(DWORD waitTime);

#endif

#endif //defined(__MINGW32__) || defined(_MSC_VER)
2 changes: 1 addition & 1 deletion src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <sys/time.h>
#endif
#include <sys/types.h>
#if defined(_MSC_VER)
#include <mingw.h>
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4200 4255 4668 4820)
#include <libusb.h>
Expand Down