diff --git a/.gitignore b/.gitignore index e64aea5e..3158f9c3 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ INSTALL aclocal.m4 ar-lib compile -config.* +config.h configure depcomp install-sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c921e36..afebfe88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/cmake/config_posix.h.cmake b/cmake/config.h.in similarity index 68% rename from cmake/config_posix.h.cmake rename to cmake/config.h.in index ec4579fa..3f38835f 100644 --- a/cmake/config_posix.h.cmake +++ b/cmake/config.h.in @@ -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@ @@ -15,5 +14,9 @@ #cmakedefine _XOPEN_SOURCE @_XOPEN_SOURCE@ #cmakedefine SYSCONFDIR "@SYSCONFDIR@" -#endif /* !__CONFIG_POSIX_H__ */ +#if defined(__MINGW32__) && __MINGW64_VERSION_MAJOR < 3 +#include +#define ENOTSUP WSAEOPNOTSUPP +#endif +#endif /* !__CONFIG_H__ */ diff --git a/cmake/config_windows.h.cmake b/cmake/config_windows.h.cmake deleted file mode 100644 index f5d49751..00000000 --- a/cmake/config_windows.h.cmake +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * Copyright (C) 2011 Glenn Ergeerts. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see - */ - -#ifndef __CONFIG_WINDOWS_H__ -#define __CONFIG_WINDOWS_H__ - -#cmakedefine WITH_DEBUG - -#include - -#define htole32(x) (x) -#define le32toh(x) (x) -#define le16toh(x) (x) -#define htobe16(x) htons(x) -#define be16toh(x) ntohs(x) - -#define ENOTSUP WSAEOPNOTSUPP - -#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@" -#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" -#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" -#cmakedefine _XOPEN_SOURCE @_XOPEN_SOURCE@ -#cmakedefine SYSCONFDIR "@SYSCONFDIR@" - -#endif /* !__CONFIG_WINDOWS_H__ */ diff --git a/examples/felica-read-ndef.c b/examples/felica-read-ndef.c index 442a6003..bae1a9be 100644 --- a/examples/felica-read-ndef.c +++ b/examples/felica-read-ndef.c @@ -7,18 +7,6 @@ #include #include -#if defined(HAVE_SYS_ENDIAN_H) - #include -#endif - -#if defined(HAVE_ENDIAN_H) - #include -#endif - -#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H) - #include -#endif - #include #include diff --git a/libfreefare/freefare_internal.h b/libfreefare/freefare_internal.h index 26910ed1..56ff20bb 100644 --- a/libfreefare/freefare_internal.h +++ b/libfreefare/freefare_internal.h @@ -6,6 +6,7 @@ #endif #include +#include /* * Endienness macros @@ -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 #endif -#if !defined(le16toh) && defined(letoh16) - #define le16toh(x) letoh16(x) - #define be16toh(x) betoh16(x) +#if defined(HAVE_ENDIAN_H) + #include #endif -#if !defined(le32toh) && defined(HAVE_COREFOUNDATION_COREFOUNDATION_H) +#if !defined(HAVE_ENDIAN_H) && !defined(HAVE_SYS_ENDIAN_H) && defined(_WIN32) +#ifdef _WIN32 + #include + + #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 #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 #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)) diff --git a/libfreefare/mifare_classic.c b/libfreefare/mifare_classic.c index 6181db45..3e99f673 100644 --- a/libfreefare/mifare_classic.c +++ b/libfreefare/mifare_classic.c @@ -23,26 +23,6 @@ #include "config.h" #endif -#if defined(HAVE_SYS_TYPES_H) - #include -#endif - -#if defined(HAVE_SYS_ENDIAN_H) - #include -#endif - -#if defined(HAVE_ENDIAN_H) - #include -#endif - -#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H) - #include -#endif - -#if defined(HAVE_BYTESWAP_H) - #include -#endif - #include #include #include diff --git a/libfreefare/mifare_desfire.c b/libfreefare/mifare_desfire.c index 86fd63de..03f37454 100644 --- a/libfreefare/mifare_desfire.c +++ b/libfreefare/mifare_desfire.c @@ -16,26 +16,6 @@ #include "config.h" #endif -#if defined(HAVE_SYS_TYPES_H) - #include -#endif - -#if defined(HAVE_SYS_ENDIAN_H) - #include -#endif - -#if defined(HAVE_ENDIAN_H) - #include -#endif - -#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H) - #include -#endif - -#if defined(HAVE_BYTESWAP_H) - #include -#endif - #include #include #include diff --git a/libfreefare/mifare_desfire_aid.c b/libfreefare/mifare_desfire_aid.c index 19793f0f..5114d9c2 100644 --- a/libfreefare/mifare_desfire_aid.c +++ b/libfreefare/mifare_desfire_aid.c @@ -11,26 +11,6 @@ #include "config.h" #endif -#if defined(HAVE_SYS_TYPES_H) - #include -#endif - -#if defined(HAVE_SYS_ENDIAN_H) - #include -#endif - -#if defined(HAVE_ENDIAN_H) - #include -#endif - -#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H) - #include -#endif - -#if defined(HAVE_BYTESWAP_H) - #include -#endif - #include #include #include diff --git a/libfreefare/mifare_desfire_crypto.c b/libfreefare/mifare_desfire_crypto.c index b9a3c713..79f74f54 100644 --- a/libfreefare/mifare_desfire_crypto.c +++ b/libfreefare/mifare_desfire_crypto.c @@ -11,26 +11,6 @@ #include "config.h" #endif -#if defined(HAVE_SYS_TYPES_H) - #include -#endif - -#if defined(HAVE_SYS_ENDIAN_H) - #include -#endif - -#if defined(HAVE_ENDIAN_H) - #include -#endif - -#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H) - #include -#endif - -#if defined(HAVE_BYTESWAP_H) - #include -#endif - #if defined(HAVE_SYS_TYPES_H) #include diff --git a/libfreefare/tlv.c b/libfreefare/tlv.c index 2641c4d5..bd0eb99c 100644 --- a/libfreefare/tlv.c +++ b/libfreefare/tlv.c @@ -11,26 +11,6 @@ #include "config.h" #endif -#if defined(HAVE_SYS_TYPES_H) - #include -#endif - -#if defined(HAVE_SYS_ENDIAN_H) - #include -#endif - -#if defined(HAVE_ENDIAN_H) - #include -#endif - -#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H) - #include -#endif - -#if defined(HAVE_BYTESWAP_H) - #include -#endif - #include #include #include