From 2ea2357b620983abf520813ffe343a99bb7500be Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sat, 22 Aug 2015 21:59:49 +0200 Subject: [PATCH] Lay foundation for unit test build framework. GNU Make double colon rules, rule ;-) Signed-off-by: Joachim Nilsson --- Makefile | 26 +++----------------------- rsync.mk | 24 +++--------------------- rules.mk | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 44 deletions(-) diff --git a/Makefile b/Makefile index b7e126e..e423c78 100644 --- a/Makefile +++ b/Makefile @@ -19,10 +19,7 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -.PHONY: all install clean - -# Figure out root of library, unless used as submodule -ROOTDIR ?= $(shell pwd) +.PHONY: install test #VERSION = $(shell git tag -l | tail -1) VERSION ?= 1.0.0 @@ -42,17 +39,6 @@ CPPFLAGS += -D_GNU_SOURCE CPPFLAGS += -W -Wall ARFLAGS = crus -# Default to silent build, use V=1 to get verbose mode. -ifeq ($V,1) -Q = -PRINT = @true -MAKEFLAGS = -else -Q = @ -PRINT = @printf -MAKEFLAGS = --no-print-directory --silent -endif - DISTFILES = README LICENSE HEADERS = lite.h OBJS := chomp.o copyfile.o dir.o fexist.o fisdir.o fmode.o fsendfile.o @@ -78,8 +64,8 @@ incdir ?= $(prefix)/include #include include rules.mk -# Build rules -all: $(TARGET) +test: + $(MAKE) -f rsync.mk $(OBJS): Makefile @@ -130,12 +116,6 @@ strip: $(TARGET) check: clean $(Q)scan-build $(MAKE) all -clean: - -$(Q)$(RM) $(OBJS) $(DEPS) $(TARGET) $(SOLIB) $(STATICLIB) - -distclean: - -$(Q)$(RM) $(JUNK) unittest *.o *.a *.so* *.unittest - # When called from GNU configure and build system distdir: @git archive --format=tar HEAD | (cd $(distdir); tar xf -) diff --git a/rsync.mk b/rsync.mk index 8556c78..add8b15 100644 --- a/rsync.mk +++ b/rsync.mk @@ -1,22 +1,4 @@ -# Unittest makefile for rsync.c -.PHONY: clean - -SRC = rsync.c -OBJS = dir.o copyfile.o fexist.o fisdir.o fmode.o -UNIT = rsync.unittest -#CPPFLAGS = -DDEBUG -I../../.. -I../../include - -all: build run - -clean: - @rm -f $(OBJS) $(UNIT) - -# This rule also forces a cleanup of built objects to not leave any object files -# lingering in the tree to interfere with cross builds. -build: clean $(OBJS) - $(CC) $(CFLAGS) $(CPPFLAGS) -o $(UNIT) -DUNITTEST $(SRC) $(OBJS) - @rm -f $(OBJS) - -run: - @./$(UNIT) +OBJS = dir.o copyfile.o fexist.o fisdir.o fmode.o +TARGET = $(OBJS) rsync.test clean +include rules.mk diff --git a/rules.mk b/rules.mk index 0f77e63..f4df0c8 100644 --- a/rules.mk +++ b/rules.mk @@ -1,3 +1,23 @@ +.PHONY: all clean distclean + +# Figure out root of library, unless used as submodule +ROOTDIR ?= $(shell pwd) + +# Default to silent build, use V=1 to get verbose mode. +ifeq ($V,1) +Q = +PRINT = @true +REDIRECT = +MAKEFLAGS = +else +Q = @ +PRINT = @printf +REDIRECT = >/dev/null +MAKEFLAGS = --no-print-directory --silent +endif + +export ROOTDIR Q PRINT MAKEFLAGS + # Pretty printing and GCC -M for auto dep files %.o: %.c $(PRINT) " CC $(subst $(ROOTDIR)/,,$(shell pwd)/)$@\n" @@ -7,3 +27,18 @@ $(PRINT) " LINK $(subst $(ROOTDIR)/,,$(shell pwd)/)$@\n" $(Q)$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-Map,$@.map -o $@ $^ $(LDLIBS$(LDLIBS-$(@))) +%.test: %.c + $(PRINT) " TEST $(subst $(ROOTDIR)/,,$(shell pwd)/)$(@:.test=)\n" + $(Q)$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -DUNITTEST $< $(OBJS) + $(Q)@./$@ $(REDIRECT) + + +# Default build rules for both main and unit test makefiles +all:: $(TARGET) + +clean:: + -$(Q)$(RM) $(OBJS) $(DEPS) $(TARGET) $(SOLIB) $(STATICLIB) + +distclean:: + -$(Q)$(RM) $(JUNK) unittest *.o *.a *.so* *.unittest *.test +