From 28a4d48d7223258606823ecc7dd9d08ffb614cbc Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Wed, 5 Oct 2016 17:20:29 +0800 Subject: [PATCH 1/2] modularize build system --- Makefile | 58 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 2a05679..fc5c6c2 100644 --- a/Makefile +++ b/Makefile @@ -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) From e288ee45fadb7b370fd62f08cc6daadc938d80b9 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Wed, 5 Oct 2016 17:21:18 +0800 Subject: [PATCH 2/2] update .gitignore to reflect build system changes --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index ab803f2..7015ae6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ *.so *.a *.o +*.o.d *~ +tests/heavy +tests/shutdown +tests/thrdtest