Sample Video Frame

Created by Zed A. Shaw Updated 2024-02-17 04:54:36

Exercise 45: A Simple TCP/IP Client

I'm going to use the RingBuffer to create a very simplistic network testing tool called netclient. To do this, I have to add some stuff to the Makefile to handle little programs in the bin/ directory.

Augment the Makefile

First, add a variable for the programs just like the unit test's TESTS and TEST_SRC variables:

PROGRAMS_SRC=$(wildcard bin/*.c)
PROGRAMS=$(patsubst %.c,%,$(PROGRAMS_SRC))

Then, you want to add the PROGRAMS to the all target:

all: $(TARGET) $(SO_TARGET) tests $(PROGRAMS)

Then, add PROGRAMS to the rm line in the clean target:

rm -rf build $(OBJECTS) $(TESTS) $(PROGRAMS)

Finally, you just need a target at the end to build them all:


With these changes, you can drop simple .c files into bin, and make will build them and link them to the library just like unit tests do.

Previous Lesson Next Lesson

Register for Learn C the Hard Way

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.