From 50f9a2eafaf01fb53e17baa91bbc54ecb996c6de Mon Sep 17 00:00:00 2001
From: "Wesley W. Terpstra" <w.terpstra@gsi.de>
Date: Fri, 25 Oct 2013 16:33:16 +0200
Subject: [PATCH] w1-tools: remove dependency on duplicated code

---
 dev/w1-eeprom.c       | 10 +++++++++-
 dev/w1-hw.c           |  2 +-
 dev/w1.c              | 14 ++++++++++++--
 tools/Makefile        |  9 +++------
 tools/wrpc-w1-read.c  |  2 +-
 tools/wrpc-w1-write.c |  2 +-
 6 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/dev/w1-eeprom.c b/dev/w1-eeprom.c
index ae55021..e453e5f 100644
--- a/dev/w1-eeprom.c
+++ b/dev/w1-eeprom.c
@@ -4,9 +4,14 @@
  */
 #include <stdlib.h>
 #include <string.h>
+#include <w1.h>
+
+#ifndef EXTERNAL_W1
 #include <wrc.h>
 #include <shell.h>
-#include <w1.h>
+#else
+#include <unistd.h>
+#endif
 
 #define LSB_ADDR(X) ((X) & 0xFF)
 #define MSB_ADDR(X) (((X) & 0xFF00)>>8)
@@ -138,6 +143,7 @@ int w1_write_eeprom_bus(struct w1_bus *bus,
 	return -1;
 }
 
+#ifndef EXTERNAL_W1
 #define BLEN 32
 
 /* A shell command, for testing write: "w1w <offset> <byte> [<byte> ...]" */
@@ -190,3 +196,5 @@ DEFINE_WRC_COMMAND(w1r) = {
 	.name = "w1r",
 	.exec = cmd_w1_r,
 };
+
+#endif
diff --git a/dev/w1-hw.c b/dev/w1-hw.c
index 5bf645a..b4cca26 100644
--- a/dev/w1-hw.c
+++ b/dev/w1-hw.c
@@ -6,9 +6,9 @@
  *
  * Released according to the GNU GPL, version 2 or any later version.
  */
-#include <wrc.h>
 #include <string.h>
 #include <w1.h>
+#include <board.h>
 #include <hw/sockit_owm_regs.h>
 
 static inline uint32_t __wait_cycle(void *base)
diff --git a/dev/w1.c b/dev/w1.c
index b7d0fd9..ccea416 100644
--- a/dev/w1.c
+++ b/dev/w1.c
@@ -2,11 +2,17 @@
  * Onewire generic interface
  * Alessandro Rubini, 2013 GNU GPL2 or later
  */
-#include <wrc.h>
 #include <string.h>
-#include <shell.h>
 #include <w1.h>
 
+#ifndef EXTERNAL_W1
+#include <wrc.h>
+#include <shell.h>
+#else
+#include <unistd.h>
+#define pp_printf(...) do {} while (0)
+#endif
+
 static const struct w1_ops *ops = &wrpc_w1_ops; /* local shorter name */
 
 void w1_write_byte(struct w1_bus *bus, int byte)
@@ -146,6 +152,8 @@ void w1_match_rom(struct w1_dev *dev)
 	}
 }
 
+#ifndef EXTERNAL_W1
+
 /* A shell command, for checking */
 static int cmd_w1(const char *args[])
 {
@@ -171,3 +179,5 @@ DEFINE_WRC_COMMAND(w1) = {
 	.name = "w1",
 	.exec = cmd_w1,
 };
+
+#endif
diff --git a/tools/Makefile b/tools/Makefile
index fb3c54a..9b908cb 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -1,4 +1,4 @@
-CFLAGS = -Wall -ggdb
+CFLAGS = -Wall -ggdb -DEXTERNAL_W1 -I../include
 LDFLAGS = -lutil
 ALL    = genraminit genramvhd genrammif wrpc-uart-sw
 ALL   += wrpc-w1-read wrpc-w1-write
@@ -18,14 +18,11 @@ all:	$(ALL)
 %:	%.c
 	$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
 
-wrpc-w1-read: wrpc-w1-read.c w1-host/libw1.a
+wrpc-w1-read: wrpc-w1-read.c ../dev/w1.c ../dev/w1-eeprom.c ../dev/w1-hw.c
 	$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
 
-wrpc-w1-write: wrpc-w1-write.c w1-host/libw1.a
+wrpc-w1-write: wrpc-w1-write.c ../dev/w1.c ../dev/w1-eeprom.c ../dev/w1-hw.c
 	$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
-w1-host/libw1.a:
-	$(MAKE) -C w1-host
 
 clean:
 	rm -f $(ALL) *.o *~
-	$(MAKE) -C w1-host clean
diff --git a/tools/wrpc-w1-read.c b/tools/wrpc-w1-read.c
index 05dbbb1..8624f48 100644
--- a/tools/wrpc-w1-read.c
+++ b/tools/wrpc-w1-read.c
@@ -20,7 +20,7 @@
 #include <sys/stat.h>
 #include <sys/mman.h>
 
-#include "w1-host/w1.h"
+#include <w1.h>
 
 #define SPEC_W1_OFFSET 0x20600 /* from "sdb" on the shell, current gateware */
 
diff --git a/tools/wrpc-w1-write.c b/tools/wrpc-w1-write.c
index 5c9a783..9f789c3 100644
--- a/tools/wrpc-w1-write.c
+++ b/tools/wrpc-w1-write.c
@@ -20,7 +20,7 @@
 #include <sys/stat.h>
 #include <sys/mman.h>
 
-#include "w1-host/w1.h"
+#include <w1.h>
 
 #define SPEC_W1_OFFSET 0x20600 /* from "sdb" on the shell, current gateware */
 
-- 
GitLab