Minor changes

This commit is contained in:
Loic Guegan 2023-07-14 20:08:36 +02:00
parent e0440fc811
commit 5f4d586aca
7 changed files with 35 additions and 21 deletions

View file

@ -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:

2
config.mk Normal file
View file

@ -0,0 +1,2 @@
PUBLISHER_PORT=5556
PUBLISHER_ADDR=localhost

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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)
{

10
src/utils.h Normal file
View file

@ -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