diff --git a/CMakeLists.txt b/CMakeLists.txt
index a3cb9bf..0d32205 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,12 +9,23 @@ find_package(LIBNFC REQUIRED)
find_package(OpenSSL REQUIRED)
IF(WIN32)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config_windows.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config.h)
+ 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)
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)
+include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/)
+add_definitions("-DHAVE_CONFIG_H")
+
if(MINGW)
# force MinGW-w64 in 32bit mode
add_definitions("-m32")
diff --git a/cmake/config_posix.h.cmake b/cmake/config_posix.h.cmake
new file mode 100644
index 0000000..470acea
--- /dev/null
+++ b/cmake/config_posix.h.cmake
@@ -0,0 +1,13 @@
+
+#ifndef __CONFIG_POSIX_H__
+#define __CONFIG_POSIX_H__
+
+#cmakedefine _XOPEN_SOURCE @_XOPEN_SOURCE@
+
+#cmakedefine HAVE_SYS_ENDIAN_H @_HAVE_SYS_ENDIAN_H@
+#cmakedefine HAVE_ENDIAN_H @_HAVE_ENDIAN_H@
+#cmakedefine HAVE_BYTESWAP_H @_HAVE_BYTESWAP_H@
+#cmakedefine HAVE_COREFOUNDATION_COREFOUNDATION_H @_HAVE_COREFOUNDATION_COREFOUNDATION_H@
+
+#endif /* !__CONFIG_POSIX_H__ */
+
diff --git a/cmake/modules/FindLIBNFC.cmake b/cmake/modules/FindLIBNFC.cmake
index f2b1b75..0c5d6ac 100644
--- a/cmake/modules/FindLIBNFC.cmake
+++ b/cmake/modules/FindLIBNFC.cmake
@@ -9,7 +9,7 @@ message("libnfc install dir: " ${LIBNFC_INSTALL_DIR})
find_path(LIBNFC_INCLUDE_DIRS NAMES nfc/nfc.h PATHS ${LIBNFC_INSTALL_DIR}/include)
message("libnfc include dir found: " ${LIBNFC_INCLUDE_DIRS})
-find_library(LIBNFC_LIBRARIES libnfc PATHS ${LIBNFC_INSTALL_DIR}/lib)
+find_library(LIBNFC_LIBRARIES nfc PATHS ${LIBNFC_INSTALL_DIR}/lib)
message("libnfc library found: " ${LIBNFC_LIBRARIES})
INCLUDE(FindPackageHandleStandardArgs)
diff --git a/examples/felica-read-ndef.c b/examples/felica-read-ndef.c
index 60a9593..6415780 100644
--- a/examples/felica-read-ndef.c
+++ b/examples/felica-read-ndef.c
@@ -15,7 +15,9 @@
* along with this program. If not, see
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#include
#include
diff --git a/examples/mifare-classic-format.c b/examples/mifare-classic-format.c
index bfd0059..7b785ee 100644
--- a/examples/mifare-classic-format.c
+++ b/examples/mifare-classic-format.c
@@ -16,7 +16,9 @@
* along with this program. If not, see
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#include
#include
diff --git a/examples/mifare-classic-read-ndef.c b/examples/mifare-classic-read-ndef.c
index 3c8b4ff..deb297a 100644
--- a/examples/mifare-classic-read-ndef.c
+++ b/examples/mifare-classic-read-ndef.c
@@ -30,7 +30,9 @@
* Document Identifier 130410
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#include
#include
diff --git a/examples/mifare-classic-write-ndef.c b/examples/mifare-classic-write-ndef.c
index 2a9e483..3e11cae 100644
--- a/examples/mifare-classic-write-ndef.c
+++ b/examples/mifare-classic-write-ndef.c
@@ -15,7 +15,9 @@
* along with this program. If not, see
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#include
#include
diff --git a/examples/mifare-desfire-create-ndef.c b/examples/mifare-desfire-create-ndef.c
index 32ceb22..0709534 100644
--- a/examples/mifare-desfire-create-ndef.c
+++ b/examples/mifare-desfire-create-ndef.c
@@ -15,7 +15,9 @@
* along with this program. If not, see
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#include
#include
diff --git a/examples/mifare-desfire-ev1-configure-ats.c b/examples/mifare-desfire-ev1-configure-ats.c
index 08d374c..daf0e01 100644
--- a/examples/mifare-desfire-ev1-configure-ats.c
+++ b/examples/mifare-desfire-ev1-configure-ats.c
@@ -15,7 +15,9 @@
* along with this program. If not, see
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#include
#include
diff --git a/examples/mifare-desfire-ev1-configure-default-key.c b/examples/mifare-desfire-ev1-configure-default-key.c
index 7c5423b..063fb05 100644
--- a/examples/mifare-desfire-ev1-configure-default-key.c
+++ b/examples/mifare-desfire-ev1-configure-default-key.c
@@ -15,7 +15,9 @@
* along with this program. If not, see
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#include
#include
diff --git a/examples/mifare-desfire-ev1-configure-random-uid.c b/examples/mifare-desfire-ev1-configure-random-uid.c
index 05c90fe..fd54972 100644
--- a/examples/mifare-desfire-ev1-configure-random-uid.c
+++ b/examples/mifare-desfire-ev1-configure-random-uid.c
@@ -15,7 +15,9 @@
* along with this program. If not, see
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#include
#include
diff --git a/examples/mifare-desfire-format.c b/examples/mifare-desfire-format.c
index e8342d3..adb73f9 100644
--- a/examples/mifare-desfire-format.c
+++ b/examples/mifare-desfire-format.c
@@ -15,7 +15,9 @@
* along with this program. If not, see
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#include
#include
diff --git a/examples/mifare-desfire-read-ndef.c b/examples/mifare-desfire-read-ndef.c
index c17cf6b..17c04f5 100644
--- a/examples/mifare-desfire-read-ndef.c
+++ b/examples/mifare-desfire-read-ndef.c
@@ -15,7 +15,9 @@
* along with this program. If not, see
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#include
#include
diff --git a/examples/mifare-desfire-write-ndef.c b/examples/mifare-desfire-write-ndef.c
index 71a960e..9a471e9 100644
--- a/examples/mifare-desfire-write-ndef.c
+++ b/examples/mifare-desfire-write-ndef.c
@@ -15,7 +15,9 @@
* along with this program. If not, see
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#include
#include
diff --git a/libfreefare/felica.c b/libfreefare/felica.c
index 40b8f47..6a69cce 100644
--- a/libfreefare/felica.c
+++ b/libfreefare/felica.c
@@ -24,7 +24,9 @@
* No. M624-E01-20
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#include
#include
diff --git a/libfreefare/freefare.c b/libfreefare/freefare.c
index 40fe1e5..9a64fe6 100644
--- a/libfreefare/freefare.c
+++ b/libfreefare/freefare.c
@@ -15,7 +15,9 @@
* along with this program. If not, see
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#include
#include
diff --git a/libfreefare/freefare_internal.h b/libfreefare/freefare_internal.h
index f7f8568..11e11cd 100644
--- a/libfreefare/freefare_internal.h
+++ b/libfreefare/freefare_internal.h
@@ -18,7 +18,9 @@
#ifndef __FREEFARE_INTERNAL_H__
#define __FREEFARE_INTERNAL_H__
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#include
diff --git a/libfreefare/mad.c b/libfreefare/mad.c
index 5d3e2c7..a469193 100644
--- a/libfreefare/mad.c
+++ b/libfreefare/mad.c
@@ -27,7 +27,10 @@
* Storing NFC Forum data in Mifare Standard 1k/4k
* Rev. 1.1 - 21 August 2007
*/
-#include "config.h"
+
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#include
diff --git a/libfreefare/mifare_application.c b/libfreefare/mifare_application.c
index 4d0d261..3ad6ed2 100644
--- a/libfreefare/mifare_application.c
+++ b/libfreefare/mifare_application.c
@@ -21,7 +21,10 @@
*
* /dev/brain
*/
-#include "config.h"
+
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#include
#include
diff --git a/libfreefare/mifare_classic.c b/libfreefare/mifare_classic.c
index 18014a5..918d174 100644
--- a/libfreefare/mifare_classic.c
+++ b/libfreefare/mifare_classic.c
@@ -36,7 +36,9 @@
* Rev. 1.1 — 21 August 2007
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#if defined(HAVE_SYS_TYPES_H)
# include
diff --git a/libfreefare/mifare_desfire.c b/libfreefare/mifare_desfire.c
index 4be12ac..76698a5 100644
--- a/libfreefare/mifare_desfire.c
+++ b/libfreefare/mifare_desfire.c
@@ -29,7 +29,9 @@
* http://ridrix.wordpress.com/2009/09/19/mifare-desfire-communication-example/
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#if defined(HAVE_SYS_TYPES_H)
# include
diff --git a/libfreefare/mifare_desfire_aid.c b/libfreefare/mifare_desfire_aid.c
index 59f4dd6..f8d7806 100644
--- a/libfreefare/mifare_desfire_aid.c
+++ b/libfreefare/mifare_desfire_aid.c
@@ -24,7 +24,9 @@
* http://www.scnf.org.uk/smartstore/LASSeO%20docs/DESFIRE%20Specification%20V1%200.pdf
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#if defined(HAVE_SYS_TYPES_H)
# include
diff --git a/libfreefare/mifare_desfire_crypto.c b/libfreefare/mifare_desfire_crypto.c
index 9a6dd9c..f42898a 100644
--- a/libfreefare/mifare_desfire_crypto.c
+++ b/libfreefare/mifare_desfire_crypto.c
@@ -24,7 +24,9 @@
* May 2005
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#if defined(HAVE_SYS_TYPES_H)
# include
diff --git a/libfreefare/mifare_ultralight.c b/libfreefare/mifare_ultralight.c
index 2afb212..4ceeb41 100644
--- a/libfreefare/mifare_ultralight.c
+++ b/libfreefare/mifare_ultralight.c
@@ -26,7 +26,9 @@
* March 2003
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#if defined(HAVE_SYS_TYPES_H)
# include
diff --git a/libfreefare/tlv.c b/libfreefare/tlv.c
index 054eefa..e3bcaad 100644
--- a/libfreefare/tlv.c
+++ b/libfreefare/tlv.c
@@ -24,7 +24,9 @@
* 2007-07-09
*/
-#include "config.h"
+#if defined(HAVE_CONFIG_H)
+# include "config.h"
+#endif
#if defined(HAVE_SYS_TYPES_H)
# include