summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-07-14 20:08:36 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2023-07-14 20:08:36 +0200
commit5f4d586aca4b5e802e2d18d527ee0b0a4e2f884c (patch)
treee39c303230a5a09d48377f7074f0857bc85cf837
parente0440fc811bafd9c72b5c85b4d3d59dd8c629027 (diff)
Minor changes
-rw-r--r--Makefile15
-rw-r--r--config.mk2
-rw-r--r--src/client/Makefile7
-rw-r--r--src/client/main.c8
-rw-r--r--src/publisher/Makefile7
-rw-r--r--src/publisher/main.c7
-rw-r--r--src/utils.h10
7 files changed, 35 insertions, 21 deletions
diff --git a/Makefile b/Makefile
index 9606e51..9739ea0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,18 +1,19 @@
-PUBLISHER_PORT=5556
+CONF=$(PWD)/config.mk
+include $(CONF)
CC="gcc"
CFLAGS=
all: publisher client
publisher:
- echo "Building publisher..."
- CFLAGS+=-DPUBLISHER_PORT=$(PUBLISHER_PORT) \
- $(MAKE) -C src/publisher/ CC=$(CC) OUT=$(PWD)
+ @echo "---------- Building publisher..."
+ CFLAGS=$(CFLAGS) \
+ $(MAKE) -C src/publisher/ CC=$(CC) OUT=$(PWD) CONF=$(CONF)
client:
- echo "Building client..."
- CFLAGS+=-DPUBLISHER_PORT=$(PUBLISHER_PORT) \
- $(MAKE) -C src/client/ CC=$(CC) OUT=$(PWD)
+ @echo "---------- Building client..."
+ CFLAGS=$(CFLAGS) \
+ $(MAKE) -C src/client/ CC=$(CC) OUT=$(PWD) CONF=$(CONF)
clean:
diff --git a/config.mk b/config.mk
new file mode 100644
index 0000000..29fdf7c
--- /dev/null
+++ b/config.mk
@@ -0,0 +1,2 @@
+PUBLISHER_PORT=5556
+PUBLISHER_ADDR=localhost \ No newline at end of file
diff --git a/src/client/Makefile b/src/client/Makefile
index 0ae633e..1afa44c 100644
--- a/src/client/Makefile
+++ b/src/client/Makefile
@@ -1,8 +1,13 @@
+include $(CONF)
EXEC=client
CFLAGS+=-lzmq
+DEFINES=\
+-DPUBLISHER_PORT=$(PUBLISHER_PORT) \
+-DPUBLISHER_ADDR=$(PUBLISHER_ADDR)
+
all: main.c
- $(CC) $^ -o $(OUT)/$(EXEC) $(CFLAGS)
+ $(CC) $^ -o $(OUT)/$(EXEC) $(CFLAGS) $(DEFINES)
clean:
rm -f $(OUT)/$(EXEC)
diff --git a/src/client/main.c b/src/client/main.c
index e7ff4a5..e4b3498 100644
--- a/src/client/main.c
+++ b/src/client/main.c
@@ -6,12 +6,8 @@
#include <time.h>
#include <string.h>
-#define STR(symbol) #symbol
-#define STRINGIFY(symbol) STR(symbol)
+#include "../utils.h"
-#ifndef PUBLISHER_PORT
-#error PUBLISHER_PORT macro undefined
-#endif
int main (int argc, char *argv [])
{
@@ -19,7 +15,7 @@ int main (int argc, char *argv [])
printf ("Collecting updates from weather server...\n");
void *context = zmq_ctx_new ();
void *subscriber = zmq_socket (context, ZMQ_SUB);
- int rc = zmq_connect (subscriber, "tcp://localhost:"STRINGIFY(PUBLISHER_PORT));
+ int rc = zmq_connect (subscriber, "tcp://"STRINGIFY(PUBLISHER_ADDR)":"STRINGIFY(PUBLISHER_PORT));
assert (rc == 0);
// Subscribe to zipcode, default is NYC, 10001
diff --git a/src/publisher/Makefile b/src/publisher/Makefile
index 57eccb9..49bf5ea 100644
--- a/src/publisher/Makefile
+++ b/src/publisher/Makefile
@@ -1,8 +1,13 @@
+include $(CONF)
EXEC=publisher
CFLAGS+=-lzmq
+DEFINES=\
+-DPUBLISHER_PORT=$(PUBLISHER_PORT) \
+-DPUBLISHER_ADDR=$(PUBLISHER_ADDR)
+
all: main.c
- $(CC) $^ -o $(OUT)/$(EXEC) $(CFLAGS)
+ $(CC) $^ -o $(OUT)/$(EXEC) $(CFLAGS) $(DEFINES)
clean:
rm -f $(OUT)/$(EXEC)
diff --git a/src/publisher/main.c b/src/publisher/main.c
index 817d79f..001df66 100644
--- a/src/publisher/main.c
+++ b/src/publisher/main.c
@@ -6,12 +6,7 @@
#include <assert.h>
#include <time.h>
-#define STR(symbol) #symbol
-#define STRINGIFY(symbol) STR(symbol)
-
-#ifndef PUBLISHER_PORT
-#error PUBLISHER_PORT macro undefined
-#endif
+#include "../utils.h"
int main (void)
{
diff --git a/src/utils.h b/src/utils.h
new file mode 100644
index 0000000..4761b04
--- /dev/null
+++ b/src/utils.h
@@ -0,0 +1,10 @@
+#define STR(symbol) #symbol
+#define STRINGIFY(symbol) STR(symbol)
+
+#ifndef PUBLISHER_PORT
+#error PUBLISHER_PORT undefined
+#endif
+
+#ifndef PUBLISHER_ADDR
+#error PUBLISHER_ADDR undefined
+#endif