common: Move debug and userpref code into libinternalcommon
diff --git a/common/Makefile.am b/common/Makefile.am
index dfa6852..664e13b 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -8,7 +8,9 @@
 libinternalcommon_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined
 libinternalcommon_la_SOURCES = \
 		       socket.c socket.h \
-		       thread.c thread.h
+		       thread.c thread.h \
+		       debug.c debug.h \
+		       userpref.c userpref.h
 
 if WIN32
 libinternalcommon_la_LIBADD += -lole32
diff --git a/src/debug.c b/common/debug.c
similarity index 100%
rename from src/debug.c
rename to common/debug.c
diff --git a/src/debug.h b/common/debug.h
similarity index 100%
rename from src/debug.h
rename to common/debug.h
diff --git a/src/userpref.c b/common/userpref.c
similarity index 100%
rename from src/userpref.c
rename to common/userpref.c
diff --git a/src/userpref.h b/common/userpref.h
similarity index 100%
rename from src/userpref.h
rename to common/userpref.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 66be29f..7024ead 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = -I$(top_srcdir)/include
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)
 
 AM_CFLAGS = $(GLOBAL_CFLAGS) $(libusbmuxd_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libplist_CFLAGS) $(LFS_CFLAGS) $(openssl_CFLAGS)
 AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS) $(libplist_LIBS) $(libusbmuxd_LIBS) $(libgcrypt_LIBS) ${libpthread_LIBS} $(openssl_LIBS)
@@ -7,8 +7,6 @@
 libimobiledevice_la_LIBADD = $(top_srcdir)/common/libinternalcommon.la
 libimobiledevice_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LIBIMOBILEDEVICE_SO_VERSION) -no-undefined
 libimobiledevice_la_SOURCES = idevice.c idevice.h \
-		       debug.c debug.h\
-		       userpref.c userpref.h\
 		       service.c service.h\
 		       property_list_service.c property_list_service.h\
 		       device_link_service.c device_link_service.h\
diff --git a/src/afc.c b/src/afc.c
index f8ca27c..7b4a396 100644
--- a/src/afc.c
+++ b/src/afc.c
@@ -29,7 +29,7 @@
 
 #include "afc.h"
 #include "idevice.h"
-#include "debug.h"
+#include "common/debug.h"
 #include "endianness.h"
 
 /** The maximum size an AFC data packet can be */
diff --git a/src/device_link_service.c b/src/device_link_service.c
index 2608b9f..e9ca5f6 100644
--- a/src/device_link_service.c
+++ b/src/device_link_service.c
@@ -22,7 +22,7 @@
 #include <stdlib.h>
 #include "device_link_service.h"
 #include "property_list_service.h"
-#include "debug.h"
+#include "common/debug.h"
 
 /**
  * Internally used function to extract the message string from a DL* message
diff --git a/src/diagnostics_relay.c b/src/diagnostics_relay.c
index 506b901..6069169 100644
--- a/src/diagnostics_relay.c
+++ b/src/diagnostics_relay.c
@@ -22,7 +22,7 @@
 #include <stdlib.h>
 #include "diagnostics_relay.h"
 #include "property_list_service.h"
-#include "debug.h"
+#include "common/debug.h"
 
 #define RESULT_SUCCESS 0
 #define RESULT_FAILURE 1
diff --git a/src/file_relay.c b/src/file_relay.c
index b1adb4f..2b45d70 100644
--- a/src/file_relay.c
+++ b/src/file_relay.c
@@ -22,7 +22,7 @@
 #include <stdlib.h>
 #include "file_relay.h"
 #include "property_list_service.h"
-#include "debug.h"
+#include "common/debug.h"
 
 /**
  * Connects to the file_relay service on the specified device.
diff --git a/src/heartbeat.c b/src/heartbeat.c
index cee852e..b33f236 100644
--- a/src/heartbeat.c
+++ b/src/heartbeat.c
@@ -28,7 +28,7 @@
 
 #include "heartbeat.h"
 #include "lockdown.h"
-#include "debug.h"
+#include "common/debug.h"
 
 /**
  * Convert a property_list_service_error_t value to a heartbeat_error_t value.
diff --git a/src/house_arrest.c b/src/house_arrest.c
index 5dfd1b6..4eaf5e3 100644
--- a/src/house_arrest.c
+++ b/src/house_arrest.c
@@ -27,7 +27,7 @@
 #include "house_arrest.h"
 #include "property_list_service.h"
 #include "afc.h"
-#include "debug.h"
+#include "common/debug.h"
 
 /**
  * Convert a property_list_service_error_t value to a house_arrest_error_t
diff --git a/src/idevice.c b/src/idevice.c
index 1dd6c0f..f0d89df 100644
--- a/src/idevice.c
+++ b/src/idevice.c
@@ -35,8 +35,8 @@
 #include <gnutls/gnutls.h>
 #endif
 #include "idevice.h"
-#include "userpref.h"
-#include "debug.h"
+#include "common/userpref.h"
+#include "common/debug.h"
 
 #ifdef HAVE_OPENSSL
 static int openssl_init_done = 0;
diff --git a/src/idevice.h b/src/idevice.h
index 0833090..0fdcdfe 100644
--- a/src/idevice.h
+++ b/src/idevice.h
@@ -33,7 +33,7 @@
 #include <gnutls/x509.h>
 #endif
 
-#include "userpref.h"
+#include "common/userpref.h"
 
 #include "libimobiledevice/libimobiledevice.h"
 
diff --git a/src/installation_proxy.c b/src/installation_proxy.c
index b1dfeb4..3e2726e 100644
--- a/src/installation_proxy.c
+++ b/src/installation_proxy.c
@@ -26,7 +26,7 @@
 
 #include "installation_proxy.h"
 #include "property_list_service.h"
-#include "debug.h"
+#include "common/debug.h"
 
 struct instproxy_status_data {
 	instproxy_client_t client;
diff --git a/src/lockdown.c b/src/lockdown.c
index f78a78d..1319e5d 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -43,8 +43,8 @@
 #include "property_list_service.h"
 #include "lockdown.h"
 #include "idevice.h"
-#include "debug.h"
-#include "userpref.h"
+#include "common/debug.h"
+#include "common/userpref.h"
 #include "asprintf.h"
 
 #define RESULT_SUCCESS 0
diff --git a/src/lockdown.h b/src/lockdown.h
index 59b1659..30ebc15 100644
--- a/src/lockdown.h
+++ b/src/lockdown.h
@@ -22,7 +22,7 @@
 #ifndef __LOCKDOWND_H
 #define __LOCKDOWND_H
 
-#include "userpref.h"
+#include "common/userpref.h"
 
 #include "libimobiledevice/lockdown.h"
 #include "property_list_service.h"
diff --git a/src/misagent.c b/src/misagent.c
index 1bc4519..331fc6c 100644
--- a/src/misagent.c
+++ b/src/misagent.c
@@ -27,7 +27,7 @@
 
 #include "misagent.h"
 #include "property_list_service.h"
-#include "debug.h"
+#include "common/debug.h"
 
 /**
  * Convert a property_list_service_error_t value to a misagent_error_t
diff --git a/src/mobile_image_mounter.c b/src/mobile_image_mounter.c
index 209e367..f2e423a 100644
--- a/src/mobile_image_mounter.c
+++ b/src/mobile_image_mounter.c
@@ -26,7 +26,7 @@
 
 #include "mobile_image_mounter.h"
 #include "property_list_service.h"
-#include "debug.h"
+#include "common/debug.h"
 
 /**
  * Locks a mobile_image_mounter client, used for thread safety.
diff --git a/src/mobilebackup.c b/src/mobilebackup.c
index aae4b06..6382b94 100644
--- a/src/mobilebackup.c
+++ b/src/mobilebackup.c
@@ -25,7 +25,7 @@
 
 #include "mobilebackup.h"
 #include "device_link_service.h"
-#include "debug.h"
+#include "common/debug.h"
 
 #define MBACKUP_VERSION_INT1 100
 #define MBACKUP_VERSION_INT2 0
diff --git a/src/mobilebackup2.c b/src/mobilebackup2.c
index 6356376..c1159e1 100644
--- a/src/mobilebackup2.c
+++ b/src/mobilebackup2.c
@@ -25,7 +25,7 @@
 
 #include "mobilebackup2.h"
 #include "device_link_service.h"
-#include "debug.h"
+#include "common/debug.h"
 
 #define MBACKUP2_VERSION_INT1 300
 #define MBACKUP2_VERSION_INT2 0
diff --git a/src/mobilesync.c b/src/mobilesync.c
index af70ea4..0e98709 100644
--- a/src/mobilesync.c
+++ b/src/mobilesync.c
@@ -30,7 +30,7 @@
 
 #include "mobilesync.h"
 #include "device_link_service.h"
-#include "debug.h"
+#include "common/debug.h"
 
 #define MSYNC_VERSION_INT1 300
 #define MSYNC_VERSION_INT2 100
diff --git a/src/notification_proxy.c b/src/notification_proxy.c
index 291c257..410a519 100644
--- a/src/notification_proxy.c
+++ b/src/notification_proxy.c
@@ -26,7 +26,7 @@
 
 #include "notification_proxy.h"
 #include "property_list_service.h"
-#include "debug.h"
+#include "common/debug.h"
 
 #ifdef WIN32
 #define sleep(x) Sleep(x*1000)
diff --git a/src/property_list_service.c b/src/property_list_service.c
index 941f37e..f1c3f86 100644
--- a/src/property_list_service.c
+++ b/src/property_list_service.c
@@ -25,7 +25,7 @@
 #include <string.h>
 
 #include "property_list_service.h"
-#include "debug.h"
+#include "common/debug.h"
 #include "endianness.h"
 
 /**
diff --git a/src/restore.c b/src/restore.c
index 1b2ff78..85009e4 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -27,7 +27,7 @@
 #include "property_list_service.h"
 #include "restore.h"
 #include "idevice.h"
-#include "debug.h"
+#include "common/debug.h"
 
 #define RESULT_SUCCESS 0
 #define RESULT_FAILURE 1
diff --git a/src/sbservices.c b/src/sbservices.c
index 1cd17db..dde8b9d 100644
--- a/src/sbservices.c
+++ b/src/sbservices.c
@@ -26,7 +26,7 @@
 
 #include "sbservices.h"
 #include "property_list_service.h"
-#include "debug.h"
+#include "common/debug.h"
 
 /**
  * Locks an sbservices client, used for thread safety.
diff --git a/src/screenshotr.c b/src/screenshotr.c
index b538232..2e16032 100644
--- a/src/screenshotr.c
+++ b/src/screenshotr.c
@@ -25,7 +25,7 @@
 
 #include "screenshotr.h"
 #include "device_link_service.h"
-#include "debug.h"
+#include "common/debug.h"
 
 #define SCREENSHOTR_VERSION_INT1 300
 #define SCREENSHOTR_VERSION_INT2 0
diff --git a/src/service.c b/src/service.c
index abd1696..5bc7aea 100644
--- a/src/service.c
+++ b/src/service.c
@@ -26,7 +26,7 @@
 
 #include "service.h"
 #include "idevice.h"
-#include "debug.h"
+#include "common/debug.h"
 
 /**
  * Convert an idevice_error_t value to an service_error_t value.
diff --git a/src/webinspector.c b/src/webinspector.c
index aef6d6f..d7c86d0 100644
--- a/src/webinspector.c
+++ b/src/webinspector.c
@@ -28,7 +28,7 @@
 
 #include "webinspector.h"
 #include "lockdown.h"
-#include "debug.h"
+#include "common/debug.h"
 
 /**
  * Convert a property_list_service_error_t value to a webinspector_error_t value.
diff --git a/tools/Makefile.am b/tools/Makefile.am
index e668592..fe9b1fa 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -11,9 +11,9 @@
 ideviceinfo_LDADD = ../src/libimobiledevice.la
 
 idevicepair_SOURCES = idevicepair.c
-idevicepair_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/src
+idevicepair_CFLAGS = $(AM_CFLAGS)
 idevicepair_LDFLAGS = $(AM_LDFLAGS)
-idevicepair_LDADD = ../src/libimobiledevice.la
+idevicepair_LDADD = $(top_srcdir)/common/libinternalcommon.la ../src/libimobiledevice.la
 
 idevicesyslog_SOURCES = idevicesyslog.c
 idevicesyslog_CFLAGS = $(AM_CFLAGS)
diff --git a/tools/idevicepair.c b/tools/idevicepair.c
index dddb6ee..d634d5f 100644
--- a/tools/idevicepair.c
+++ b/tools/idevicepair.c
@@ -23,7 +23,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <getopt.h>
-#include "userpref.h"
+#include "common/userpref.h"
 
 #include <libimobiledevice/libimobiledevice.h>
 #include <libimobiledevice/lockdown.h>