From 766b989269b5ad7a994cb46841699e14f9544a22 Mon Sep 17 00:00:00 2001
From: Florian Pose <fp@igh-essen.com>
Date: Tue, 7 Aug 2007 07:54:51 +0000
Subject: [PATCH] Added --enable-dummy; renamed EC_DBG_IF to EC_DEBUG_IF,
 ENABLE_DEBUG_IF conditional.

---
 configure.ac      | 38 +++++++++++++++++++++++++++++++-------
 dummy/Kbuild      | 10 +++++-----
 dummy/Makefile.am |  4 +++-
 master/Kbuild     |  2 +-
 master/device.c   | 12 ++++++------
 master/device.h   |  4 ++--
 6 files changed, 48 insertions(+), 22 deletions(-)

diff --git a/configure.ac b/configure.ac
index dc750642..41e4a928 100644
--- a/configure.ac
+++ b/configure.ac
@@ -346,25 +346,48 @@ fi
 # Debug interface
 #------------------------------------------------------------------------------
 
-AC_ARG_ENABLE([dbg-if],
-    AS_HELP_STRING([--enable-dbg-if],
+AC_ARG_ENABLE([debug-if],
+    AS_HELP_STRING([--enable-debug-if],
                    [Create a debug interface for each master @<:@NO@:>@]),
     [
         case "${enableval}" in
             yes) dbg=1
-                AC_DEFINE([EC_DBG_IF], [1], [Debug interfaces enabled])
                 ;;
             no) dbg=0
                 ;;
-            *) AC_MSG_ERROR([Invalid value for --enable-dbg-if])
+            *) AC_MSG_ERROR([Invalid value for --enable-debug-if])
                 ;;
         esac
     ],
     [dbg=0]
 )
 
-AM_CONDITIONAL(EC_DBG_IF, test "x$dbg" = "x1")
-AC_SUBST([EC_DBG_IF],${dbg})
+if test "x${dbg}" = "x1"; then
+    AC_DEFINE([EC_DEBUG_IF], [1], [Debug interfaces enabled])
+fi
+AM_CONDITIONAL(ENABLE_DEBUG_IF, test "x$dbg" = "x1")
+
+#------------------------------------------------------------------------------
+# Dummy master module
+#------------------------------------------------------------------------------
+
+AC_ARG_ENABLE([dummy],
+    AS_HELP_STRING([--enable-dummy],
+                   [Build the dummy master module @<:@NO@:>@]),
+    [
+        case "${enableval}" in
+            yes) dummy=1
+                ;;
+            no) dummy=0
+                ;;
+            *) AC_MSG_ERROR([Invalid value for --enable-dummy])
+                ;;
+        esac
+    ],
+    [dummy=0]
+)
+
+AM_CONDITIONAL(ENABLE_DUMMY, test "x$dummy" = "x1")
 
 #------------------------------------------------------------------------------
 
@@ -374,7 +397,7 @@ echo configure: creating config.kbuild...
 
 cat > config.kbuild <<EOF
 # config.kbuild - created by configure
-EC_DBG_IF := ${dbg}
+EC_DEBUG_IF := ${dbg}
 EC_ENABLE_8139TOO := ${enable8139too}
 EC_8139TOO_KERNEL := ${kernel8139too}
 EC_ENABLE_E100 := ${enablee100}
@@ -385,6 +408,7 @@ EC_ENABLE_E1000 := ${enablee1000}
 EC_E1000_KERNEL := ${kernele1000}
 EC_RTAI_DIR := "${rtaidir}"
 EC_MSR_DIR := "${msrdir}"
+EC_DUMMY := ${dummy}
 EOF
 
 #------------------------------------------------------------------------------
diff --git a/dummy/Kbuild b/dummy/Kbuild
index 0504f33f..620e2e5b 100644
--- a/dummy/Kbuild
+++ b/dummy/Kbuild
@@ -33,16 +33,16 @@
 
 include $(src)/../config.kbuild
 
-obj-m := ec_dummy.o
-
-ec_dummy-objs := module.o master.o slave.o domain.o
-
 REV := $(shell if test -s $(src)/../svnrevision; then \
 		cat $(src)/../svnrevision; \
 	else \
 		svnversion $(src) 2>/dev/null || echo "unknown"; \
 	fi)
 
-CFLAGS_dummy.o := -DSVNREV=$(REV)
+ifeq ($(EC_DUMMY),1)
+    obj-m := ec_dummy.o
+	ec_dummy-objs := module.o master.o slave.o domain.o
+	CFLAGS_dummy.o := -DSVNREV=$(REV)
+endif
 
 #------------------------------------------------------------------------------
diff --git a/dummy/Makefile.am b/dummy/Makefile.am
index 6db8c0db..e71451b0 100644
--- a/dummy/Makefile.am
+++ b/dummy/Makefile.am
@@ -39,11 +39,13 @@ EXTRA_DIST = \
     domain.c
 
 modules:
-	$(MAKE) -C "$(LINUX_SOURCE_DIR)" M="@abs_top_srcdir@" modules
+	$(MAKE) -C "@abs_top_srcdir@" modules
 
 modules_install:
 	mkdir -p $(DESTDIR)$(LINUX_MOD_PATH)
+if ENABLE_DUMMY
 	cp $(srcdir)/ec_dummy.ko $(DESTDIR)$(LINUX_MOD_PATH)
+endif
 
 clean-local:
 	$(MAKE) -C "$(LINUX_SOURCE_DIR)" M="@abs_srcdir@" clean
diff --git a/master/Kbuild b/master/Kbuild
index 93692bb7..8c50d05f 100644
--- a/master/Kbuild
+++ b/master/Kbuild
@@ -39,7 +39,7 @@ ec_master-objs := module.o master.o device.o pdo.o sync.o fmmu.o slave.o \
     datagram.o domain.o mailbox.o canopen.o ethernet.o fsm_sii.o fsm_change.o \
     fsm_coe.o fsm_mapping.o fsm_slave.o fsm_master.o xmldev.o
 
-ifeq ($(EC_DBG_IF),1)
+ifeq ($(ENABLE_DEBUG_IF),1)
 	ec_master-objs += debug.o
 endif
 
diff --git a/master/device.c b/master/device.c
index 7c7c4c1d..47fa8c03 100644
--- a/master/device.c
+++ b/master/device.c
@@ -59,7 +59,7 @@ int ec_device_init(ec_device_t *device, /**< EtherCAT device */
 {
     device->master = master;
 
-#ifdef EC_DBG_IF
+#ifdef EC_DEBUG_IF
     if (ec_debug_init(&device->dbg)) {
         EC_ERR("Failed to init debug device!\n");
         goto out_return;
@@ -68,7 +68,7 @@ int ec_device_init(ec_device_t *device, /**< EtherCAT device */
 
     if (!(device->tx_skb = dev_alloc_skb(ETH_FRAME_LEN))) {
         EC_ERR("Error allocating device socket buffer!\n");
-#ifdef EC_DBG_IF
+#ifdef EC_DEBUG_IF
         goto out_debug;
 #else
         goto out_return;
@@ -84,7 +84,7 @@ int ec_device_init(ec_device_t *device, /**< EtherCAT device */
     ec_device_detach(device); // resets remaining fields
     return 0;
 
-#ifdef EC_DBG_IF
+#ifdef EC_DEBUG_IF
  out_debug:
     ec_debug_clear(&device->dbg);
 #endif
@@ -102,7 +102,7 @@ void ec_device_clear(ec_device_t *device /**< EtherCAT device */)
 {
     if (device->open) ec_device_close(device);
     dev_kfree_skb(device->tx_skb);
-#ifdef EC_DBG_IF
+#ifdef EC_DEBUG_IF
     ec_debug_clear(&device->dbg);
 #endif
 }
@@ -234,7 +234,7 @@ void ec_device_send(ec_device_t *device, /**< EtherCAT device */
         ec_print_data(device->tx_skb->data + ETH_HLEN, size);
     }
 
-#ifdef EC_DBG_IF
+#ifdef EC_DEBUG_IF
     ec_debug_send(&device->dbg, device->tx_skb->data, ETH_HLEN + size);
 #endif
 
@@ -283,7 +283,7 @@ void ecdev_receive(ec_device_t *device, /**< EtherCAT device */
                            data + ETH_HLEN, size - ETH_HLEN);
     }
 
-#ifdef EC_DBG_IF
+#ifdef EC_DEBUG_IF
     ec_debug_send(&device->dbg, data, size);
 #endif
 
diff --git a/master/device.h b/master/device.h
index 08a5b529..77b03eec 100644
--- a/master/device.h
+++ b/master/device.h
@@ -47,7 +47,7 @@
 #include "../devices/ecdev.h"
 #include "globals.h"
 
-#ifdef EC_DBG_IF
+#ifdef EC_DEBUG_IF
 #include "debug.h"
 #endif
 
@@ -73,7 +73,7 @@ struct ec_device
     unsigned long jiffies_poll; /**< jiffies of last poll */
     unsigned int tx_count; /**< number of frames sent */
     unsigned int rx_count; /**< number of frames received */
-#ifdef EC_DBG_IF
+#ifdef EC_DEBUG_IF
     ec_debug_t dbg; /**< debug device */
 #endif
 };
-- 
GitLab