From f3ec118ab764927895b429001561a1b96458574a Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 13 Mar 2017 17:01:28 +0100 Subject: [PATCH] btrfs-progs: library-test: update test to build outside of topdir We need to build outside of the topdir so we can use the "btrfs/" prefix for includes and not accidentally include other files. Make magic is simple: - build dependencies inside TOPDIR - build inside temporary directory, link back to TOPDIR - library-test.o not built anymore obviously Signed-off-by: David Sterba --- Makefile | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 12f6db79..b6a49e0b 100644 --- a/Makefile +++ b/Makefile @@ -446,17 +446,25 @@ test-ioctl: ioctl-test ioctl-test-32 ioctl-test-64 $(Q)./ioctl-test-32 > ioctl-test-32.log $(Q)./ioctl-test-64 > ioctl-test-64.log -library-test: library-test.o messages.o $(libs_shared) - @echo " [LD] $@" - $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -Wl,-rpath=$(TOPDIR) -lbtrfs - @echo " [TEST] $@" - $(Q)./$@ +library-test: library-test.c messages.o $(libs_shared) + @echo " [TEST PREP] $@"$(eval TMPD=$(shell mktemp -d)) + $(Q)mkdir -p $(TMPD)/include/btrfs && \ + cp $(libbtrfs_headers) $(TMPD)/include/btrfs && \ + cd $(TMPD) && $(CC) -I$(TMPD)/include -o $@ $(addprefix $(TOPDIR)/,$^) -Wl,-rpath=$(TOPDIR) -lbtrfs + @echo " [TEST RUN] $@" + $(Q)cd $(TMPD) && ./$@ + @echo " [TEST CLEAN] $@" + $(Q)$(RM) -rf -- $(TMPD) -library-test.static: library-test.static.o messages.static.o $(libs_static) - @echo " [LD] $@" - $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $^ $(STATIC_LDFLAGS) $(libs_static) $(STATIC_LIBS) - @echo " [TEST] $@" - $(Q)./$@ +library-test.static: library-test.c messages.static.o $(libs_static) + @echo " [TEST PREP] $@"$(eval TMPD=$(shell mktemp -d)) + $(Q)mkdir -p $(TMPD)/include/btrfs && \ + cp $(libbtrfs_headers) $(TMPD)/include/btrfs && \ + cd $(TMPD) && $(CC) -I$(TMPD)/include -o $@ $(addprefix $(TOPDIR)/,$^) $(STATIC_LDFLAGS) $(STATIC_LIBS) + @echo " [TEST RUN] $@" + $(Q)cd $(TMPD) && ./$@ + @echo " [TEST CLEAN] $@" + $(Q)$(RM) -rf -- $(TMPD) test-build: test-build-pre test-build-real