[PATCH v2 6/8] Refactor devices build

Ladislav Michl <[email protected]> Tue, 4 Dec 2018 22:26:44 +0100
Newsgroups gmane.linux.drivers.gnokii
Message-ID <20181204212644.GG10937@lenoch>
Remove #ifdefs from device drivers and compile them only when
selected. Once there, move device detection code in configure.ac
to live in one place.
---
 CHANGES:
 -v2: rebase on previous changes

 common/device.c                               |   8 +-
 common/devices/Makefile.am                    |  57 ++++-----
 common/devices/bluetooth.c                    |  31 -----
 common/devices/dku2libusb.c                   |  42 +------
 common/devices/irda.c                         |  27 -----
 common/devices/osxbluetooth.m                 |   8 +-
 common/devices/socketphonet.c                 |  38 +-----
 common/devices/tcp.c                          |  53 +-------
 common/devices/tekram.c                       |   1 -
 common/devices/unixbluetooth.c                |  19 +--
 common/devices/unixirda.c                     |  10 +-
 common/devices/winbluetooth.c                 |  10 +-
 common/devices/winirda.c                      |   7 +-
 configure.ac                                  | 114 +++++++++++-------
 .../devices/{unixbluetooth.h =3D> bluetooth.h}  |  37 +++++-
 include/devices/dku2libusb.h                  |  37 +++++-
 include/devices/irda.h                        |  32 +++++
 include/devices/socketphonet.h                |  32 +++++
 include/devices/tcp.h                         |  32 +++++
 include/devices/unixirda.h                    |  15 ---
 20 files changed, 287 insertions(+), 323 deletions(-)
 delete mode 100644 common/devices/bluetooth.c
 delete mode 100644 common/devices/irda.c
 rename include/devices/{unixbluetooth.h =3D> bluetooth.h} (53%)
 delete mode 100644 include/devices/unixirda.h

diff --git a/common/device.c b/common/device.c
index 68257955..7b6a901c 100644
--- a/common/device.c
+++ b/common/device.c
@@ -20,12 +20,12 @@
 #include "gnokii-internal.h"
 #include "device.h"
 #include "devices/irda.h"
-#include "devices/unixbluetooth.h"
-#include "devices/tcp.h"
-#include "devices/serial.h"
-#include "devices/tekram.h"
+#include "devices/bluetooth.h"
 #include "devices/dku2libusb.h"
+#include "devices/serial.h"
 #include "devices/socketphonet.h"
+#include "devices/tcp.h"
+#include "devices/tekram.h"
 =

 #include <errno.h>
 #include <sys/wait.h>
diff --git a/common/devices/Makefile.am b/common/devices/Makefile.am
index 860762e4..592c2b9d 100644
--- a/common/devices/Makefile.am
+++ b/common/devices/Makefile.am
@@ -1,34 +1,38 @@
 noinst_LTLIBRARIES =3D libDEVICES.la
 =

-WIN32_FILES =3D \
-	winserial.c \
-	winirda.c \
-	winbluetooth.c
-
-UNIX_FILES =3D \
-	unixserial.c \
-	unixirda.c \
-	tcp.c \
-	socketphonet.c
-
-if FOR_MAC
-UNIX_SPECIFIC_FILES =3D osxbluetooth.m
-else
-UNIX_SPECIFIC_FILES =3D unixbluetooth.c
+gnokii_devices	=3D tekram.c
+if LIBUSB
+gnokii_devices	+=3D dku2libusb.c
+endif
+if !WIN32
+gnokii_devices	+=3D tcp.c
+endif
+if SOCKETPHONET
+gnokii_devices	+=3D socketphonet.c
+endif
+if OSXBLUETOOTH
+gnokii_devices	+=3D osxbluetooth.m
+endif
+if UNIXBLUETOOTH
+gnokii_devices	+=3D unixbluetooth.c
+endif
+if UNIXIRDA
+gnokii_devices	+=3D unixirda.c
+endif
+if !WIN32
+gnokii_devices	+=3D unixserial.c
+endif
+if WINBLUETOOTH
+gnokii_devices	+=3D winbluetooth.c
+endif
+if WINIRDA
+gnokii_devices	+=3D winirda.c
 endif
-
 if WIN32
-PLATFORM_FILES =3D $(WIN32_FILES)
-else
-PLATFORM_FILES =3D $(UNIX_FILES) $(UNIX_SPECIFIC_FILES)
+gnokii_devices	+=3D winserial.c
 endif
 =

-libDEVICES_la_SOURCES =3D \
-	$(PLATFORM_FILES) \
-	tekram.c \
-	irda.c \
-	dku2libusb.c \
-	bluetooth.c
+libDEVICES_la_SOURCES =3D $(gnokii_devices)
 =

 libDEVICES_la_CFLAGS =3D		\
 	-I$(top_srcdir)/include
@@ -37,6 +41,3 @@ libDEVICES_la_LIBADD =3D		\
 	$(USB_LIBS)		\
 	$(BLUETOOTH_LIBS)	\
 	$(TCP_LIBS)
-
-EXTRA_DIST =3D $(WIN32_FILES) $(UNIX_FILES) $(UNIX_SPECIFIC_FILES)
-
diff --git a/common/devices/bluetooth.c b/common/devices/bluetooth.c
deleted file mode 100644
index dccf448b..00000000
--- a/common/devices/bluetooth.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
-
-  G N O K I I
-
-  A Linux/Unix toolset and driver for the mobile phones.
-
-  This file is part of gnokii.
-
-  Copyright (C) 2002       Marcel Holtmann <[email protected]>
-  Copyright (C) 2003       BORBELY Zoltan
-  Copyright (C) 2004       Pawel Kot, Phil Ashby
-
-  Fake definitions for the bluetooth handling functions.
-
-*/
-
-#include "config.h"
-#include "compat.h"
-#include "misc.h"
-#include "gnokii.h"
-#include "devices/unixbluetooth.h"
-
-#ifndef HAVE_BLUETOOTH
-
-int bluetooth_open(const char *addr, uint8_t channel, struct gn_statemachi=
ne *state) { return -1; }
-int bluetooth_close(int fd, struct gn_statemachine *state) { return -1; }
-int bluetooth_write(int fd, const __ptr_t bytes, int size, struct gn_state=
machine *state) { return -1; }
-int bluetooth_read(int fd, __ptr_t bytes, int size, struct gn_statemachine=
 *state) { return -1; }
-int bluetooth_select(int fd, struct timeval *timeout, struct gn_statemachi=
ne *state) { return -1; }
-
-#endif /* HAVE_BLUETOOTH */
diff --git a/common/devices/dku2libusb.c b/common/devices/dku2libusb.c
index f219c39b..77d2af54 100644
--- a/common/devices/dku2libusb.c
+++ b/common/devices/dku2libusb.c
@@ -14,46 +14,14 @@
 =

 */
 =

-#include "config.h"
-#include "compat.h"
-#include "misc.h"
-#include "gnokii.h"
-#include "devices/dku2libusb.h"
-
-#ifndef HAVE_LIBUSB
-int fbusdku2usb_open(struct gn_statemachine *state)
-{
-	return -1;
-}
-
-int fbusdku2usb_close(struct gn_statemachine *state)
-{
-	return -1;
-}
-
-int fbusdku2usb_write(const __ptr_t bytes, int size, struct gn_statemachin=
e *state)
-{
-	return -1;
-}
-
-int fbusdku2usb_read(__ptr_t bytes, int size, struct gn_statemachine *stat=
e)
-{
-	return -1;
-}
-
-int fbusdku2usb_select(struct timeval *timeout, struct gn_statemachine *st=
ate)
-{
-	return -1;
-}
-
-#else
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <string.h>
 =

+#include "devices/dku2libusb.h"
+
 #define	DEVINSTANCE(s) (*((fbus_usb_interface **)(&(s)->device.device_inst=
ance)))
 =

 /*
@@ -388,7 +356,7 @@ static int usbfbus_connect_request(struct gn_statemachi=
ne *state)
 	return 1;
 =

 err3:
-	usb_release_interface(DEVINSTANCE(state)->interface->dev_data, DEVINSTANC=
E(state)->interface->data_interface);	=

+	usb_release_interface(DEVINSTANCE(state)->interface->dev_data, DEVINSTANC=
E(state)->interface->data_interface);
 err2:
 	usb_release_interface(DEVINSTANCE(state)->interface->dev_data, DEVINSTANC=
E(state)->interface->control_interface);
 err1:
@@ -420,7 +388,7 @@ static int usbfbus_disconnect_request(struct gn_statema=
chine *state)
 	ret =3D usb_close(DEVINSTANCE(state)->interface->dev_data);
 	if (ret < 0)
 		dprintf("Can't close data interface %d\n", ret);
-	return ret;	=

+	return ret;
 }
 =

 int fbusdku2usb_open(struct gn_statemachine *state)
@@ -459,5 +427,3 @@ int fbusdku2usb_select(struct timeval *timeout, struct =
gn_statemachine *state)
 {
 	return 1;
 }
-
-#endif
diff --git a/common/devices/irda.c b/common/devices/irda.c
deleted file mode 100644
index 2674c2db..00000000
--- a/common/devices/irda.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- *
- * G N O K I I
- *
- * A Linux/Unix toolset and driver for the mobile phones.
- *
- * Copyright (C) 1999-2000  Hugh Blemings & Pavel Jan=EDk ml.
- * Copyright (C) 2000-2001  Marcel Holtmann <[email protected]>
- * Copyright (C) 2004       Phil Ashby
- *
- * Fake definitions for irda handling functions.
- */
-
-#include "config.h"
-#include "compat.h"
-#include "misc.h"
-#include "gnokii.h"
-
-#ifndef HAVE_IRDA
-
-int irda_open(struct gn_statemachine *state) { return -1; }
-int irda_close(int fd, struct gn_statemachine *state) { return -1; }
-int irda_write(int fd, const __ptr_t bytes, int size, struct gn_statemachi=
ne *state) { return -1; }
-int irda_read(int fd, __ptr_t bytes, int size, struct gn_statemachine *sta=
te) { return -1; }
-int irda_select(int fd, struct timeval *timeout, struct gn_statemachine *s=
tate) { return -1; }
-
-#endif /* HAVE_IRDA */
diff --git a/common/devices/osxbluetooth.m b/common/devices/osxbluetooth.m
index 6216cc5c..1fc11295 100644
--- a/common/devices/osxbluetooth.m
+++ b/common/devices/osxbluetooth.m
@@ -10,14 +10,10 @@
 =

 */
 =

-#include "config.h"
-
-#ifdef HAVE_BLUETOOTH_MACOSX
-
 #include <IOBluetooth/objc/IOBluetoothRFCOMMChannel.h>
 #include <IOBluetooth/objc/IOBluetoothDevice.h>
 =

-#include "devices/unixbluetooth.h"
+#include "devices/bluetooth.h"
 =

 static NSMutableDictionary *queues;
 static int next_fd =3D 1;
@@ -179,5 +175,3 @@ int bluetooth_close(int fd, struct gn_statemachine *sta=
te)
     [queues removeObjectForKey:@(fd)];
     return 1;
 }
-
-#endif
diff --git a/common/devices/socketphonet.c b/common/devices/socketphonet.c
index 12bed8b2..1e119939 100644
--- a/common/devices/socketphonet.c
+++ b/common/devices/socketphonet.c
@@ -15,49 +15,17 @@
 =

 */
 =

-#include "config.h"
-#include "compat.h" /* for __ptr_t definition */
-#include "gnokii.h"
-
-#ifndef HAVE_SOCKETPHONET
-
-int socketphonet_close(struct gn_statemachine *state)
-{
-	return -1;
-}
-
-int socketphonet_open(const char *iface, int with_async, struct gn_statema=
chine *state)
-{
-	return -1;
-}
-
-size_t socketphonet_read(int fd, __ptr_t buf, size_t nbytes, struct gn_sta=
temachine *state)
-{
-	return -1;
-}
-
-size_t socketphonet_write(int fd, const __ptr_t buf, size_t n, struct gn_s=
tatemachine *state)
-{
-	return -1;
-}
-
-int socketphonet_select(int fd, struct timeval *timeout, struct gn_statema=
chine *state)
-{
-	return -1;
-}
-
-#else
-
 /* System header files */
 #include <sys/socket.h>
 #include <linux/phonet.h>
 =

 /* Various header files */
+#include "config.h"
 #include "compat.h"
 #include "links/fbus-common.h"
 #include "links/fbus-phonet.h"
-#include "device.h"
 #include "devices/serial.h"
+#include "devices/socketphonet.h"
 #include "gnokii-internal.h"
 =

 static struct sockaddr_pn addr =3D { .spn_family =3D AF_PHONET, .spn_dev =
=3D FBUS_DEVICE_PHONE };
@@ -159,5 +127,3 @@ int socketphonet_select(int fd, struct timeval *timeout=
, struct gn_statemachine
 {
 	return serial_select(fd, timeout, state);
 }
-
-#endif /* HAVE_SOCKETPHONET */
diff --git a/common/devices/tcp.c b/common/devices/tcp.c
index 619737aa..8a48d4e1 100644
--- a/common/devices/tcp.c
+++ b/common/devices/tcp.c
@@ -12,13 +12,6 @@
 =

 */
 =

-#include "config.h"
-#include "misc.h"
-#include "devices/tcp.h"
-#include "devices/serial.h"
-
-#ifndef WIN32
-
 #include <stdio.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
@@ -34,6 +27,12 @@
 #include <netdb.h>
 #include <termios.h>
 =

+#include "config.h"
+#include "misc.h"
+#include "devices/tcp.h"
+#include "devices/serial.h"
+
+
 #ifdef HAVE_SYS_FILE_H
 #  include <sys/file.h>
 #endif
@@ -50,8 +49,6 @@
 #  define O_NONBLOCK  0
 #endif
 =

-/* Open the serial port and store the settings. */
-
 static int tcp_open(const char *file)
 {
 	int fd;
@@ -148,16 +145,12 @@ int tcp_close(int fd, struct gn_statemachine *state)
 	return close(fd);
 }
 =

-/* Open a device with standard options.
- * Use value (-1) for "with_hw_handshake" if its specification is required=
 from the user
- */
 int tcp_opendevice(const char *file, int with_async, struct gn_statemachin=
e *state)
 {
 	int fd;
 	int retcode;
 =

 	/* Open device */
-
 	fd =3D tcp_open(file);
 =

 	if (fd < 0)
@@ -203,46 +196,12 @@ int tcp_select(int fd, struct timeval *timeout, struc=
t gn_statemachine *state)
 	return serial_select(fd, timeout, state);
 }
 =

-
-/* Read from serial device. */
-
 size_t tcp_read(int fd, __ptr_t buf, size_t nbytes, struct gn_statemachine=
 *state)
 {
 	return read(fd, buf, nbytes);
 }
 =

-/* Write to serial device. */
-
 size_t tcp_write(int fd, const __ptr_t buf, size_t n, struct gn_statemachi=
ne *state)
 {
 	return write(fd, buf, n);
 }
-
-#else /* WIN32 */
-
-int tcp_close(int fd, struct gn_statemachine *state)
-{
-	return -1;
-}
-
-int tcp_opendevice(const char *file, int with_async, struct gn_statemachin=
e *state)
-{
-	return -1;
-}
-
-size_t tcp_read(int fd, __ptr_t buf, size_t nbytes, struct gn_statemachine=
 *state)
-{
-	return -1;
-}
-
-size_t tcp_write(int fd, const __ptr_t buf, size_t n, struct gn_statemachi=
ne *state)
-{
-	return -1;
-}
-
-int tcp_select(int fd, struct timeval *timeout, struct gn_statemachine *st=
ate)
-{
-	return -1;
-}
-
-#endif /* WIN32 */
diff --git a/common/devices/tekram.c b/common/devices/tekram.c
index 51e5e8fb..bfb887ff 100644
--- a/common/devices/tekram.c
+++ b/common/devices/tekram.c
@@ -13,7 +13,6 @@
  */
 =

 #include "config.h"
-
 #include "misc.h"
 #include "gnokii.h"
 =

diff --git a/common/devices/unixbluetooth.c b/common/devices/unixbluetooth.c
index c9be96f9..2c195940 100644
--- a/common/devices/unixbluetooth.c
+++ b/common/devices/unixbluetooth.c
@@ -16,14 +16,6 @@
 =

 */
 =

-#include "config.h"
-#include "compat.h"
-#include "misc.h"
-#include "gnokii.h"
-#include "devices/unixbluetooth.h"
-
-#if defined(HAVE_BLUETOOTH_BLUEZ) || defined(HAVE_BLUETOOTH_NETGRAPH) || d=
efined(HAVE_BLUETOOTH_NETBT)
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
@@ -32,6 +24,9 @@
 #include <sys/time.h>
 #include <sys/socket.h>
 =

+#include "config.h"
+#include "devices/bluetooth.h"
+
 #ifdef HAVE_BLUETOOTH_NETGRAPH	/* FreeBSD / netgraph */
 =

 #include <bluetooth.h>
@@ -265,7 +260,7 @@ static int find_service_channel(bdaddr_t *adapter, bdad=
dr_t *device, int only_gn
 		case SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET:
 			if (channel =3D=3D -1)
 				break;
-			=

+
 			SDP_GET8(type, start);
 			switch (type) {
 				case SDP_DATA_STR8:
@@ -303,7 +298,7 @@ static int find_service_channel(bdaddr_t *adapter, bdad=
dr_t *device, int only_gn
 					break;
 				}
 			}
-			=

+
 			if (strstr(name, "Nokia PC Suite") !=3D NULL) {
 				channel =3D -1;
 				break;
@@ -509,7 +504,7 @@ int bluetooth_open(const char *addr, uint8_t channel, s=
truct gn_statemachine *st
 =

 	dprintf("Using channel: %d\n", channel);
 	raddr.rc_channel =3D channel;
-	=

+
 	if (connect(fd, (struct sockaddr *)&raddr, sizeof(raddr)) < 0) {
 		perror(_("Can't connect"));
 		close(fd);
@@ -549,5 +544,3 @@ int bluetooth_select(int fd, struct timeval *timeout, s=
truct gn_statemachine *st
 =

 	return select(fd + 1, &readfds, NULL, NULL, timeout);
 }
-
-#endif	/* HAVE_BLUETOOTH_BLUEZ || HAVE_BLUETOOTH_NETGRAPH || HAVE_BLUETOOT=
H_NETBT */
diff --git a/common/devices/unixirda.c b/common/devices/unixirda.c
index 0a175ed3..763946ed 100644
--- a/common/devices/unixirda.c
+++ b/common/devices/unixirda.c
@@ -13,12 +13,6 @@
  *
  */
 =

-#include "compat.h"
-#include "misc.h"
-#include "gnokii.h"
-
-#ifdef HAVE_IRDA
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
@@ -29,6 +23,8 @@
 #include <linux/types.h>
 #include <linux/irda.h>
 =

+#include "compat.h"
+#include "misc.h"
 #include "devices/irda.h"
 =

 #ifndef AF_IRDA
@@ -177,5 +173,3 @@ int irda_select(int fd, struct timeval *timeout, struct=
 gn_statemachine *state)
 =

 	return select(fd + 1, &readfds, NULL, NULL, timeout);
 }
-
-#endif /* HAVE_IRDA */
diff --git a/common/devices/winbluetooth.c b/common/devices/winbluetooth.c
index a898e2e6..7be40127 100644
--- a/common/devices/winbluetooth.c
+++ b/common/devices/winbluetooth.c
@@ -8,18 +8,14 @@
  *
  */
 =

-#include "config.h"
-
-#ifdef HAVE_BLUETOOTH
-
 #include <winsock2.h>
 #include <mmsystem.h>
 #include <ws2bth.h>
 #include <bluetoothapis.h>
 =

+#include "config.h"
 #include "compat.h"
-#include "gnokii.h"
-#include "misc.h"
+#include "devices/bluetooth.h"
 =

 /* QTTY by Davide Libenzi ( Terminal interface to Symbian QConsole )
  * Copyright (C) 2004  Davide Libenzi
@@ -109,5 +105,3 @@ int bluetooth_select(int fd, struct timeval *timeout, s=
truct gn_statemachine *st
 =

 	return select(0 /* ignored on Win32 */, &readfds, NULL, NULL, timeout);
 }
-
-#endif /* HAVE_BLUETOOTH */
diff --git a/common/devices/winirda.c b/common/devices/winirda.c
index 4bfed742..71018842 100644
--- a/common/devices/winirda.c
+++ b/common/devices/winirda.c
@@ -8,14 +8,11 @@
  *
  */
 =

-#include "config.h"
-
-#ifdef HAVE_IRDA
-
 #define WIN32_LEAN_AND_MEAN
 #include <winsock.h>
 #include <mmsystem.h>
 =

+#include "config.h"
 #include "compat.h"
 #include "misc.h"
 #include "devices/irda.h"
@@ -160,5 +157,3 @@ int irda_select(int fd, struct timeval *timeout, struct=
 gn_statemachine *state)
 =

 	return select(0 /* ignored on Win32 */, &readfds, NULL, NULL, timeout);
 }
-
-#endif /* HAVE_IRDA */
diff --git a/configure.ac b/configure.ac
index b2892d27..b427c393 100644
--- a/configure.ac
+++ b/configure.ac
@@ -356,6 +356,17 @@ AC_ARG_WITH(readline,
 AC_SUBST(TERMLIBS)
 AC_SUBST(TERMLDFLAGS)
 =

+dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D Defines location for gettext
+AC_ARG_WITH(gettext,
+	[  --with-gettext=3DDIR      specifies the base gettext],
+	[ if test x$withval =3D xyes; then
+		AC_MSG_WARN(Usage is: --with-gettext=3DDIR)
+	  else
+		CFLAGS=3D"$CFLAGS -I$withval"
+	  fi
+	]
+)
+
 dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D Check for libical
 AC_ARG_WITH(libical,
    [  --with-libical=3DDIR      specifies the base libical],
@@ -415,6 +426,15 @@ if test "$enable_libical" =3D "yes"; then
 	CFLAGS=3D"$OLD_CFLAGS"
 fi
 =

+dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D Checks for gethostbyname support
+AC_CHECK_FUNC(gethostbyname, ,
+	AC_CHECK_LIB(nsl, gethostbyname, TCP_LIBS=3D"-lnsl"
+		     AC_SUBST(TCP_LIBS)))
+dnl Haiku requires -lnetwork for socket functions
+AC_CHECK_FUNC(gethostbyname, ,
+	AC_CHECK_LIB(network, gethostbyname, TCP_LIBS=3D"-lnetwork"
+		     AC_SUBST(TCP_LIBS)))
+
 dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D Check for libusb
 USE_LIBUSB=3D"no"
 AC_ARG_ENABLE(libusb,
@@ -438,59 +458,25 @@ if test "$enable_libusb" =3D "yes"; then
 		]
 	)
 fi
+AM_CONDITIONAL([LIBUSB], [test $USE_LIBUSB =3D yes])
 =

-dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D Checks for Linux Phonet support
+dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D Phonet switch
 USE_SOCKETPHONET=3D"no"
 AC_ARG_ENABLE(phonet,
               AC_HELP_STRING([--disable-phonet],
                              [disable phonet support (default is autodetec=
ted)]
                             ),,
               [enable_phonet=3Dyes])
-if test "$enable_phonet" =3D "yes"; then
-	AC_CHECK_HEADER(linux/phonet.h,
-		[AC_DEFINE(HAVE_SOCKETPHONET, 1, [Whether Phonet is available])
-		 USE_SOCKETPHONET=3D"yes"],,
-		[#include <sys/socket.h>
-		 #include <linux/phonet.h>])
-fi
-
-dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D Checks for gethostbyname support
-AC_CHECK_FUNC(gethostbyname, ,
-	AC_CHECK_LIB(nsl, gethostbyname, TCP_LIBS=3D"-lnsl"
-		     AC_SUBST(TCP_LIBS)))
-dnl Haiku requires -lnetwork for socket functions
-AC_CHECK_FUNC(gethostbyname, ,
-	AC_CHECK_LIB(network, gethostbyname, TCP_LIBS=3D"-lnetwork"
-		     AC_SUBST(TCP_LIBS)))
 =

-dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D Checks for Linux IrDA support
+dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D IrDA switch
 USE_IRDA=3D"no"
 AC_ARG_ENABLE(irda,
               AC_HELP_STRING([--disable-irda],
                              [disable irda support (default is autodetecte=
d)]
                             ),,
               [enable_irda=3Dyes])
-if test "$enable_irda" =3D "yes"; then
-	AC_CHECK_HEADER(linux/irda.h,
-		[AC_DEFINE(HAVE_IRDA, 1, [Whether IrDA is available])
-		 USE_IRDA=3D"yes"],,
-		[#include <sys/socket.h>
-		 #include <sys/ioctl.h>
-		 #include <linux/types.h>])
-fi
-
-dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D Defines location for gettext
-AC_ARG_WITH(gettext,
-	[  --with-gettext=3DDIR      specifies the base gettext],
-	[ if test x$withval =3D xyes; then
-		AC_MSG_WARN(Usage is: --with-gettext=3DDIR)
-	  else
-		CFLAGS=3D"$CFLAGS -I$withval"
-	  fi
-	]
-)
 =

-dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D Checks for Bluetooth support
+dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D Bluetooth switch
 USE_BLUETOOTH=3D"no"
 AC_ARG_WITH(bluetooth,
 	[  --with-bluetooth=3DDIR    specifies the base libbluetooth],
@@ -509,8 +495,8 @@ AC_ARG_ENABLE(bluetooth,
               [enable_bluetooth=3Dyes])
 =

 case "$host_os" in
+dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D Checks for Linux devices
 linux*)
-dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D Checks for Linux Bluetooth support
 	if test "$enable_bluetooth" =3D "yes"; then
 		AC_MSG_NOTICE([checking for the Linux Bluetooth support])
 		AC_CACHE_CHECK(for the struct sockaddr_rc in <bluetooth/rfcomm.h>, ac_cv=
_have_sockaddr_rc,
@@ -524,13 +510,30 @@ dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D Checks for Linux Bluetooth support
 			AC_DEFINE(HAVE_BLUETOOTH, 1, [Whether Bluetooth is available])
 			AC_DEFINE(HAVE_BLUETOOTH_BLUEZ,[],[Compile on Linux])
 			USE_BLUETOOTH=3D"yes"
+			UNIX_BLUETOOTH=3D"true"
 			BLUETOOTH_LIBS=3D"-lbluetooth"
 			AC_SUBST(BLUETOOTH_LIBS)
 		fi
 	fi
+	if test "$enable_irda" =3D "yes"; then
+		AC_CHECK_HEADER(linux/irda.h,
+			[AC_DEFINE(HAVE_IRDA, 1, [Whether IrDA is available])
+			[USE_IRDA=3D"yes" UNIX_IRDA=3D"true"]],,
+			[#include <sys/socket.h>
+			 #include <sys/ioctl.h>
+			 #include <linux/types.h>])
+	fi
+	if test "$enable_phonet" =3D "yes"; then
+		AC_CHECK_HEADER(linux/phonet.h,
+			[AC_DEFINE(HAVE_SOCKETPHONET, 1, [Whether Phonet is available])
+			 USE_SOCKETPHONET=3D"yes"],,
+			[#include <sys/socket.h>
+			 #include <linux/phonet.h>])
+	fi
 	;;
-darwin*)
+
 dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D Checks for MacOSX Bluetooth support
+darwin*)
 	if test "$enable_bluetooth" =3D "yes"; then
 		AC_LANG_PUSH([Objective C])
 		AC_CHECK_HEADERS(IOBluetooth/objc/IOBluetoothRFCOMMChannel.h)
@@ -551,6 +554,7 @@ dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D Checks for MacOSX Bluetooth support
 			AC_DEFINE(HAVE_BLUETOOTH, 1, [Whether Bluetooth is available])
 			AC_DEFINE(HAVE_BLUETOOTH_MACOSX,[],[Compile on Darwin / Mac OSX])
 			USE_BLUETOOTH=3D"yes"
+			OSX_BLUETOOTH=3D"true"
 			BLUETOOTH_LIBS=3D"$PTHREAD_LIBS -Wl,-framework,CoreFoundation -Wl,-fram=
ework,IOBluetooth -Wl,-framework,Foundation"
 			AC_SUBST(BLUETOOTH_LIBS)
 		fi
@@ -572,6 +576,7 @@ freebsd)
 			AC_DEFINE(HAVE_BLUETOOTH, 1, [Whether Bluetooth is available])
 			AC_DEFINE(HAVE_BLUETOOTH_NETGRAPH, [], [Compile on FreeBSD])
 			USE_BLUETOOTH=3D"yes"
+			UNIX_BLUETOOTH=3D"true"
 			AC_CHECK_LIB(bluetooth, bt_aton,
 				[BLUETOOTH_LIBS=3D"-lbluetooth" ac_cv_have_bt_lib=3Dyes],
 				ac_cv_have_bt_lib=3Dno)
@@ -598,6 +603,7 @@ netbsd*)
 			AC_DEFINE(HAVE_BLUETOOTH, 1, [Whether Bluetooth is available])
 			AC_DEFINE(HAVE_BLUETOOTH_NETBT, [], [Compile on NetBSD])
 			USE_BLUETOOTH=3D"yes"
+			UNIX_BLUETOOTH=3D"true"
 			CFLAGS=3D"$CFLAGS -DCOMPAT_BLUEZ"
 			AC_CHECK_LIB(bluetooth, bt_aton,
 				[BLUETOOTH_LIBS=3D"-lbluetooth" ac_cv_have_bt_lib=3Dyes],
@@ -611,19 +617,37 @@ netbsd*)
 	fi
 	;;
 =

+dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D Checks for Windows devices
 cygwin32|cygwin|mingw32|mingw32msvc)
-	AC_CHECK_HEADER(af_irda.h, [AC_DEFINE(HAVE_IRDA, 1, [Whether IrDA is avai=
lable]) USE_IRDA=3D"yes" LIBS=3D"$LIBS -lwinmm"],, [#include <windows.h>])
-	AC_CHECK_HEADER(ws2bth.h, [AC_DEFINE(HAVE_BLUETOOTH, 1, [Whether Bluetoot=
h is available]) USE_BLUETOOTH=3D"yes"],, [#include <windows.h>])
+	if test "$enable_bluetooth" =3D "yes"; then
+		AC_CHECK_HEADER(ws2bth.h,
+				[AC_DEFINE(HAVE_BLUETOOTH, 1, [Whether Bluetooth is available]) USE_BL=
UETOOTH=3D"yes" WIN32_BLUETOOTH=3D"true"],,
+				[#include <windows.h>])
+	fi
+	if test "$enable_irda" =3D "yes"; then
+		AC_CHECK_HEADER(af_irda.h,
+				[AC_DEFINE(HAVE_IRDA, 1, [Whether IrDA is available]) USE_IRDA=3D"yes"=
 WIN32_IRDA=3D"true"],,
+				[#include <windows.h>])
+	fi
+	BLUETOOTH_LIBS=3D""
 	if test x"$USE_IRDA" =3D "xyes" -o x"$USE_BLUETOOTH" =3D "xyes"; then
-		LIBS=3D"$LIBS -lws2_32"
+		BLUETOOTH_LIBS=3D"-lws2_32"
+	fi
+	if test x"$USE_IRDA" =3D "xyes"; then
+		BLUETOOTH_LIBS=3D"$BLUETOOTH_LIBS -lwinmm"
 	fi
+	AC_SUBST(BLUETOOTH_LIBS)
 	WIN32=3D1
 	;;
-
 esac
 =

 AM_CONDITIONAL([WIN32], [test "x$WIN32" =3D "x1"])
-AM_CONDITIONAL([FOR_MAC], [test "x$FOR_MAC" =3D "x1"])
+AM_CONDITIONAL([SOCKETPHONET], [test "x$USE_SOCKETPHONET" =3D "xyes"])
+AM_CONDITIONAL([OSXBLUETOOTH], [test "x$OSX_BLUETOOTH" =3D "xtrue"])
+AM_CONDITIONAL([UNIXBLUETOOTH], [test "x$UNIX_BLUETOOTH" =3D "xtrue"])
+AM_CONDITIONAL([UNIXIRDA], [test "x$UNIX_IRDA" =3D "xtrue"])
+AM_CONDITIONAL([WINBLUETOOTH], [test "x$WIN32_BLUETOOTH" =3D "xtrue"])
+AM_CONDITIONAL([WINIRDA], [test "x$WIN32_IRDA" =3D "xtrue"])
 =

 dnl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D Checks for X base support
 =

diff --git a/include/devices/unixbluetooth.h b/include/devices/bluetooth.h
similarity index 53%
rename from include/devices/unixbluetooth.h
rename to include/devices/bluetooth.h
index 81cad19b..0e8cedd8 100644
--- a/include/devices/unixbluetooth.h
+++ b/include/devices/bluetooth.h
@@ -11,17 +11,48 @@
 =

 */
 =

-#ifndef _gnokii_unix_bluetooth_h
-#define _gnokii_unix_bluetooth_h
+#ifndef _gnokii_bluetooth_h
+#define _gnokii_bluetooth_h
 =

 #include "compat.h"
 #include "misc.h"
 #include "gnokii.h"
 =

+#ifdef HAVE_BLUETOOTH
+
 int bluetooth_open(const char *addr, uint8_t channel, struct gn_statemachi=
ne *state);
 int bluetooth_close(int fd, struct gn_statemachine *state);
 int bluetooth_write(int fd, const __ptr_t bytes, int size, struct gn_state=
machine *state);
 int bluetooth_read(int fd, __ptr_t bytes, int size, struct gn_statemachine=
 *state);
 int bluetooth_select(int fd, struct timeval *timeout, struct gn_statemachi=
ne *state);
 =

-#endif /* _gnokii_unix_bluetooth_h */
+#else
+
+int bluetooth_open(const char *addr, uint8_t channel, struct gn_statemachi=
ne *state)
+{
+	return -1;
+}
+
+int bluetooth_close(int fd, struct gn_statemachine *state)
+{
+	return -1;
+}
+
+int bluetooth_write(int fd, const __ptr_t bytes, int size, struct gn_state=
machine *state)
+{
+	return -1;
+}
+
+int bluetooth_read(int fd, __ptr_t bytes, int size, struct gn_statemachine=
 *state)
+{
+	return -1;
+}
+
+int bluetooth_select(int fd, struct timeval *timeout, struct gn_statemachi=
ne *state)
+{
+	return -1;
+}
+
+#endif
+
+#endif /* _gnokii_bluetooth_h */
diff --git a/include/devices/dku2libusb.h b/include/devices/dku2libusb.h
index be4d4ba4..8b099f8f 100644
--- a/include/devices/dku2libusb.h
+++ b/include/devices/dku2libusb.h
@@ -16,16 +16,14 @@
 #ifndef _gnokii_dku2libusb_h
 #define _gnokii_dku2libusb_h
 =

-#ifdef HAVE_LIBUSB
-#  include <usb.h>
-#endif
-
 #include "compat.h"
 #include "misc.h"
 #include "gnokii.h"
 =

 #ifdef HAVE_LIBUSB
 =

+#include <usb.h>
+
 /* Information about a USB DKU2 FBUS interface present on the system */
 struct fbus_usb_interface_transport {
 	struct fbus_usb_interface_transport *prev, *next;	/* Next and previous in=
terfaces in the list */
@@ -102,12 +100,39 @@ struct cdc_union_desc {
 #define USB_MAX_STRING_SIZE		256
 #define USB_FBUS_TIMEOUT		10000 /* 10 seconds */
 =

-#endif
-
 int fbusdku2usb_open(struct gn_statemachine *state);
 int fbusdku2usb_close(struct gn_statemachine *state);
 int fbusdku2usb_write(const __ptr_t bytes, int size, struct gn_statemachin=
e *state);
 int fbusdku2usb_read(__ptr_t bytes, int size, struct gn_statemachine *stat=
e);
 int fbusdku2usb_select(struct timeval *timeout, struct gn_statemachine *st=
ate);
 =

+#else
+
+int fbusdku2usb_open(struct gn_statemachine *state)
+{
+	return -1;
+}
+
+int fbusdku2usb_close(struct gn_statemachine *state)
+{
+	return -1;
+}
+
+int fbusdku2usb_write(const __ptr_t bytes, int size, struct gn_statemachin=
e *state)
+{
+	return -1;
+}
+
+int fbusdku2usb_read(__ptr_t bytes, int size, struct gn_statemachine *stat=
e)
+{
+	return -1;
+}
+
+int fbusdku2usb_select(struct timeval *timeout, struct gn_statemachine *st=
ate)
+{
+	return -1;
+}
+
+#endif
+
 #endif /* _gnokii_dku2libusb_h */
diff --git a/include/devices/irda.h b/include/devices/irda.h
index 819dd257..82191b1f 100644
--- a/include/devices/irda.h
+++ b/include/devices/irda.h
@@ -12,12 +12,44 @@
 #ifndef __gnokii_irda_h_
 #define __gnokii_irda_h_
 =

+#include "config.h"
 #include "gnokii.h"
 =

+#ifdef HAVE_IRDA
+
 int irda_open(struct gn_statemachine *state);
 int irda_close(int fd, struct gn_statemachine *state);
 int irda_write(int fd, const __ptr_t bytes, int size, struct gn_statemachi=
ne *state);
 int irda_read(int fd, __ptr_t bytes, int size, struct gn_statemachine *sta=
te);
 int irda_select(int fd, struct timeval *timeout, struct gn_statemachine *s=
tate);
 =

+#else
+
+int irda_open(struct gn_statemachine *state)
+{
+	return -1;
+}
+
+int irda_close(int fd, struct gn_statemachine *state)
+{
+	return -1;
+}
+
+int irda_write(int fd, const __ptr_t bytes, int size, struct gn_statemachi=
ne *state)
+{
+	return -1;
+}
+
+int irda_read(int fd, __ptr_t bytes, int size, struct gn_statemachine *sta=
te)
+{
+	return -1;
+}
+
+int irda_select(int fd, struct timeval *timeout, struct gn_statemachine *s=
tate)
+{
+	return -1;
+}
+
+#endif
+
 #endif /* __gnokii_irda_h_ */
diff --git a/include/devices/socketphonet.h b/include/devices/socketphonet.h
index 77550c6f..05a06f56 100644
--- a/include/devices/socketphonet.h
+++ b/include/devices/socketphonet.h
@@ -18,12 +18,44 @@
 #ifndef _gnokii_devices_linuxphonet_h
 #define _gnokii_devices_linuxphonet_h
 =

+#include "config.h"
 #include "gnokii.h"
 =

+#ifdef HAVE_SOCKETPHONET
+
 int socketphonet_close(struct gn_statemachine *state);
 int socketphonet_open(const char *iface, int with_async, struct gn_statema=
chine *state);
 size_t socketphonet_read(int fd, __ptr_t buf, size_t nbytes, struct gn_sta=
temachine *state);
 size_t socketphonet_write(int fd, const __ptr_t buf, size_t n, struct gn_s=
tatemachine *state);
 int socketphonet_select(int fd, struct timeval *timeout, struct gn_statema=
chine *state);
 =

+#else
+
+int socketphonet_close(struct gn_statemachine *state)
+{
+	return -1;
+}
+
+int socketphonet_open(const char *iface, int with_async, struct gn_statema=
chine *state)
+{
+	return -1;
+}
+
+size_t socketphonet_read(int fd, __ptr_t buf, size_t nbytes, struct gn_sta=
temachine *state)
+{
+	return -1;
+}
+
+size_t socketphonet_write(int fd, const __ptr_t buf, size_t n, struct gn_s=
tatemachine *state)
+{
+	return -1;
+}
+
+int socketphonet_select(int fd, struct timeval *timeout, struct gn_statema=
chine *state)
+{
+	return -1;
+}
+
+#endif
+
 #endif /* _gnokii_devices_linuxphonet_h */
diff --git a/include/devices/tcp.h b/include/devices/tcp.h
index 0e3786e7..77e96203 100644
--- a/include/devices/tcp.h
+++ b/include/devices/tcp.h
@@ -17,6 +17,8 @@
 #include "misc.h"
 #include "gnokii.h"
 =

+#ifndef WIN32
+
 int tcp_opendevice(const char *file, int with_async, struct gn_statemachin=
e *state);
 int tcp_close(int fd, struct gn_statemachine *state);
 =

@@ -25,4 +27,34 @@ size_t tcp_write(int fd, const __ptr_t buf, size_t n, st=
ruct gn_statemachine *st
 =

 int tcp_select(int fd, struct timeval *timeout, struct gn_statemachine *st=
ate);
 =

+#else
+
+int tcp_opendevice(const char *file, int with_async, struct gn_statemachin=
e *state)
+{
+	return -1;
+}
+
+int tcp_close(int fd, struct gn_statemachine *state)
+{
+	return -1;
+}
+
+
+size_t tcp_read(int fd, __ptr_t buf, size_t nbytes, struct gn_statemachine=
 *state)
+{
+	return -1;
+}
+
+size_t tcp_write(int fd, const __ptr_t buf, size_t n, struct gn_statemachi=
ne *state)
+{
+	return -1;
+}
+
+int tcp_select(int fd, struct timeval *timeout, struct gn_statemachine *st=
ate)
+{
+	return -1;
+}
+
+#endif
+
 #endif  /* __devices_tcp_h */
diff --git a/include/devices/unixirda.h b/include/devices/unixirda.h
deleted file mode 100644
index 19b07ef4..00000000
--- a/include/devices/unixirda.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- *
- * G N O K I I
- *
- * A Linux/Unix toolset and driver for the mobile phones.
- *
- * Copyright (C) 1999, 2000 Hugh Blemings & Pavel Jan=EDk ml.
- * Copyright (C) 2000-2001  Marcel Holtmann <[email protected]>
- *
- */
-
-#ifndef __unix_irda_h_
-#define __unix_irda_h_
-
-#endif
-- =

2.20.0.rc2