Lay foundation for unit test build framework.

GNU Make double colon rules, rule ;-)

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2015-08-22 21:59:52 +02:00
parent b7a8042c87
commit 2ea2357b62
3 changed files with 41 additions and 44 deletions
+3 -23
View File
@@ -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 <rules.mk>
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 -)
+3 -21
View File
@@ -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
+35
View File
@@ -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