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 compilation issues on Windows #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ INSTALL
aclocal.m4
ar-lib
compile
config.*
config.h
configure
depcomp
install-sh
Expand Down
23 changes: 7 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,23 @@ add_definitions("-std=c99")
find_package(LIBNFC REQUIRED)
find_package(OpenSSL REQUIRED)

include(CheckIncludeFiles)
check_include_files("sys/endian.h" HAVE_SYS_ENDIAN_H)
check_include_files("endian.h" HAVE_ENDIAN_H)
check_include_files("byteswap.h" HAVE_BYTESWAP_H)
check_include_files("CoreFoundation/CoreFoundation.h" HAVE_COREFOUNDATION_COREFOUNDATION_H)
IF(WIN32)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config_windows.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/include/config.h)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/contrib/win32)
find_library(WINSOCK_LIB libws2_32.a)
find_library(WINSOCK_LIB ws2_32)
set(LIBS ${LIBS} ${WINSOCK_LIB})
ELSE(WIN32)
include(CheckIncludeFiles)
check_include_files("sys/endian.h" HAVE_SYS_ENDIAN_H)
check_include_files("endian.h" HAVE_ENDIAN_H)
check_include_files("byteswap.h" HAVE_BYTESWAP_H)
check_include_files("CoreFoundation/CoreFoundation.h" HAVE_COREFOUNDATION_COREFOUNDATION_H)
set(_XOPEN_SOURCE 600)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config_posix.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/include/config.h)
ENDIF(WIN32)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/config.h)

include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/)
add_definitions("-DHAVE_CONFIG_H")

if(MINGW AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
# force MinGW-w64 in 32bit mode
add_definitions("-m32")
add_definitions("-DNOCRYPT")
set(CMAKE_SHARED_LINKER_FLAGS -m32)
set(CMAKE_EXE_LINKER_FLAGS -m32)
endif(MINGW)

message("CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS})
message("CMAKE_SHARED_LINKER_FLAGS: " ${CMAKE_SHARED_LINKER_FLAGS})

Expand Down
13 changes: 8 additions & 5 deletions cmake/config_posix.h.cmake → cmake/config.h.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#ifndef __CONFIG_H__
#define __CONFIG_H__

#ifndef __CONFIG_POSIX_H__
#define __CONFIG_POSIX_H__

#cmakedefine _XOPEN_SOURCE @_XOPEN_SOURCE@
#cmakedefine WITH_DEBUG

#cmakedefine HAVE_SYS_ENDIAN_H @_HAVE_SYS_ENDIAN_H@
#cmakedefine HAVE_ENDIAN_H @_HAVE_ENDIAN_H@
Expand All @@ -15,5 +14,9 @@
#cmakedefine _XOPEN_SOURCE @_XOPEN_SOURCE@
#cmakedefine SYSCONFDIR "@SYSCONFDIR@"

#endif /* !__CONFIG_POSIX_H__ */
#if defined(__MINGW32__) && __MINGW64_VERSION_MAJOR < 3
#include <winerror.h>
#define ENOTSUP WSAEOPNOTSUPP
#endif

#endif /* !__CONFIG_H__ */
39 changes: 0 additions & 39 deletions cmake/config_windows.h.cmake

This file was deleted.

12 changes: 0 additions & 12 deletions examples/felica-read-ndef.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@
#include <stdlib.h>
#include <unistd.h>

#if defined(HAVE_SYS_ENDIAN_H)
#include <sys/endian.h>
#endif

#if defined(HAVE_ENDIAN_H)
#include <endian.h>
#endif

#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H)
#include <CoreFoundation/CoreFoundation.h>
#endif

#include <nfc/nfc.h>

#include <freefare.h>
Expand Down
65 changes: 42 additions & 23 deletions libfreefare/freefare_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#endif

#include <openssl/des.h>
#include <sys/types.h>

/*
* Endienness macros
Expand All @@ -24,57 +25,75 @@
* dealt with).
*/

#if !defined(le32toh) && defined(letoh32)
#define le32toh(x) letoh32(x)
#define be32toh(x) betoh32(x)
#if defined(HAVE_SYS_ENDIAN_H)
#include <sys/endian.h>
#endif

#if !defined(le16toh) && defined(letoh16)
#define le16toh(x) letoh16(x)
#define be16toh(x) betoh16(x)
#if defined(HAVE_ENDIAN_H)
#include <endian.h>
#endif

#if !defined(le32toh) && defined(HAVE_COREFOUNDATION_COREFOUNDATION_H)
#if !defined(HAVE_ENDIAN_H) && !defined(HAVE_SYS_ENDIAN_H) && defined(_WIN32)
#ifdef _WIN32
#include <winsock2.h>

#define be32toh(x) ntohl(x)
#define htobe32(x) ntohl(x)
#define le32toh(x) (x)
#define htole32(x) (x)
#define be16toh(x) ntohs(x)
#define htobe16(x) htons(x)
#define le16toh(x) (x)
#define htole16(x) (x)
#elif defined(HAVE_COREFOUNDATION_COREFOUNDATION_H)
#include <CoreFoundation/CoreFoundation.h>
#define be32toh(x) CFSwapInt32BigToHost(x)
#define htobe32(x) CFSwapInt32HostToBig(x)
#define le32toh(x) CFSwapInt32LittleToHost(x)
#define htole32(x) CFSwapInt32HostToLittle(x)
#endif

#if !defined(le16toh) && defined(HAVE_COREFOUNDATION_COREFOUNDATION_H)
#define be16toh(x) CFSwapInt16BigToHost(x)
#define htobe16(x) CFSwapInt16HostToBig(x)
#define le16toh(x) CFSwapInt16LittleToHost(x)
#define htole16(x) CFSwapInt16HostToLittle(x)
#endif

#if !defined(le32toh) && defined(bswap_32)
#elif defined(HAVE_BYTESWAP_H)
#include <byteswap.h>
#if BYTE_ORDER == LITTLE_ENDIAN
#define be32toh(x) bswap_32(x)
#define htobe32(x) bswap_32(x)
#define le32toh(x) (x)
#define htole32(x) (x)
#else
#define be32toh(x) (x)
#define htobe32(x) (x)
#define le32toh(x) bswap_32(x)
#define htole32(x) bswap_32(x)
#endif
#endif

#if !defined(htole16) && defined(bswap_16)
#if BYTE_ORDER == LITTLE_ENDIAN
#define be16toh(x) (bswap_16(x))
#define htobe16(x) (bswap_16(x))
#define htole16(x) (x)
#define le16toh(x) (x)
#else
#define be32toh(x) (x)
#define htobe32(x) (x)
#define le32toh(x) bswap_32(x)
#define htole32(x) bswap_32(x)
#define be16toh(x) (x)
#define htobe16(x) (x)
#define htole16(x) (bswap_16(x))
#define le16toh(x) (bswap_16(x))
#endif
#endif
#endif

#if !defined(le32toh) && defined(letoh32)
#define le32toh(x) letoh32(x)
#endif

#if !defined(be32toh) && defined(betoh32)
#define be32toh(x) betoh32(x)
#endif

#if !defined(le16toh) && defined(letoh16)
#define le16toh(x) letoh16(x)
#endif

#if !defined(be16toh) && defined(betoh16)
#define be16toh(x) betoh16(x)
#endif

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
Expand Down
20 changes: 0 additions & 20 deletions libfreefare/mifare_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,6 @@
#include "config.h"
#endif

#if defined(HAVE_SYS_TYPES_H)
#include <sys/types.h>
#endif

#if defined(HAVE_SYS_ENDIAN_H)
#include <sys/endian.h>
#endif

#if defined(HAVE_ENDIAN_H)
#include <endian.h>
#endif

#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H)
#include <CoreFoundation/CoreFoundation.h>
#endif

#if defined(HAVE_BYTESWAP_H)
#include <byteswap.h>
#endif

#include <errno.h>
#include <stdlib.h>
#include <string.h>
Expand Down
20 changes: 0 additions & 20 deletions libfreefare/mifare_desfire.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,6 @@
#include "config.h"
#endif

#if defined(HAVE_SYS_TYPES_H)
#include <sys/types.h>
#endif

#if defined(HAVE_SYS_ENDIAN_H)
#include <sys/endian.h>
#endif

#if defined(HAVE_ENDIAN_H)
#include <endian.h>
#endif

#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H)
#include <CoreFoundation/CoreFoundation.h>
#endif

#if defined(HAVE_BYTESWAP_H)
#include <byteswap.h>
#endif

#include <errno.h>
#include <stdlib.h>
#include <string.h>
Expand Down
20 changes: 0 additions & 20 deletions libfreefare/mifare_desfire_aid.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,6 @@
#include "config.h"
#endif

#if defined(HAVE_SYS_TYPES_H)
#include <sys/types.h>
#endif

#if defined(HAVE_SYS_ENDIAN_H)
#include <sys/endian.h>
#endif

#if defined(HAVE_ENDIAN_H)
#include <endian.h>
#endif

#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H)
#include <CoreFoundation/CoreFoundation.h>
#endif

#if defined(HAVE_BYTESWAP_H)
#include <byteswap.h>
#endif

#include <errno.h>
#include <stdlib.h>
#include <string.h>
Expand Down
20 changes: 0 additions & 20 deletions libfreefare/mifare_desfire_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,6 @@
#include "config.h"
#endif

#if defined(HAVE_SYS_TYPES_H)
#include <sys/types.h>
#endif

#if defined(HAVE_SYS_ENDIAN_H)
#include <sys/endian.h>
#endif

#if defined(HAVE_ENDIAN_H)
#include <endian.h>
#endif

#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H)
#include <CoreFoundation/CoreFoundation.h>
#endif

#if defined(HAVE_BYTESWAP_H)
#include <byteswap.h>
#endif


#if defined(HAVE_SYS_TYPES_H)
#include <sys/types.h>
Expand Down
20 changes: 0 additions & 20 deletions libfreefare/tlv.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,6 @@
#include "config.h"
#endif

#if defined(HAVE_SYS_TYPES_H)
#include <sys/types.h>
#endif

#if defined(HAVE_SYS_ENDIAN_H)
#include <sys/endian.h>
#endif

#if defined(HAVE_ENDIAN_H)
#include <endian.h>
#endif

#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H)
#include <CoreFoundation/CoreFoundation.h>
#endif

#if defined(HAVE_BYTESWAP_H)
#include <byteswap.h>
#endif

#include <stdlib.h>
#include <string.h>
#include <stdint.h>
Expand Down