Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

introduce modular build system #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
*.so
*.a
*.o
*.o.d
*~
tests/heavy
tests/shutdown
tests/thrdtest
58 changes: 34 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,51 @@
CFLAGS = -D_REENTRANT -Wall -pedantic -Isrc
LDLIBS = -lpthread
CFLAGS := -D_REENTRANT -Wall -pedantic -Isrc
CFLAGS += -fPIC
LDFLAGS = -lpthread

LIBNAME = libthreadpool
SHARED_SUFFIX = .so
STATIC_SUFFIX = .a

ifdef DEBUG
CFLAGS += -g
LDFLAGS += -g
endif

TARGETS = tests/thrdtest tests/heavy tests/shutdown \
libthreadpool.so libthreadpool.a
SHARED = $(LIBNAME)$(SHARED_SUFFIX)
STATIC = $(LIBNAME)$(STATIC_SUFFIX)

TARGETS = $(SHARED) $(STATIC)

all: $(TARGETS)

tests/shutdown: tests/shutdown.o src/threadpool.o
tests/thrdtest: tests/thrdtest.o src/threadpool.o
tests/heavy: tests/heavy.o src/threadpool.o
src/threadpool.o: src/threadpool.c src/threadpool.h
tests/thrdtest.o: tests/thrdtest.c src/threadpool.h
tests/heavy.o: tests/heavy.c src/threadpool.h
OBJS := \
src/threadpool.o

# Short-hand aliases
shared: libthreadpool.so
static: libthreadpool.a
deps := $(OBJS:%.o=%.o.d)
src/%.o: src/%.c
$(CC) $(CFLAGS) -o $@ -MMD -MF $@.d -c $<
tests/%: tests/%.c $(OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

libthreadpool.so: src/threadpool.c src/threadpool.h
$(CC) -shared -fPIC ${CFLAGS} -o $@ $< ${LDLIBS}
TESTS =
TESTS += tests/shutdown
TESTS += tests/thrdtest
TESTS += tests/heavy

src/libthreadpool.o: src/threadpool.c src/threadpool.h
$(CC) -c -fPIC ${CFLAGS} -o $@ $<
$(LIBNAME)$(SHARED_SUFFIX): $(OBJS)
$(CC) -shared -o $@ $< ${LDLIBS}

libthreadpool.a: src/libthreadpool.o
ar rcs $@ $^
$(LIBNAME)$(STATIC_SUFFIX): $(OBJS)
$(AR) rcs $@ $^

clean:
rm -f $(TARGETS) *~ */*~ */*.o
rm -f $(TARGETS) *~ */*~ $(OBJS) $(deps)

test: $(TARGETS)
./tests/shutdown
./tests/thrdtest
./tests/heavy
test: check
check: $(TESTS)
@for test in $^ ; \
do \
echo "Execute $$test..." ; $$test && echo "OK!\n" ; \
done

-include $(deps)