btrfs-progs: library-test: update test to build outside of topdir
authorDavid Sterba <dsterba@suse.com>
Mon, 13 Mar 2017 16:01:28 +0000 (17:01 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 16 Mar 2017 16:02:44 +0000 (17:02 +0100)
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 <dsterba@suse.com>
Makefile

index 12f6db7..b6a49e0 100644 (file)
--- 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.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: 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.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