Fix Makefile to correctly handle 'make -j4 test' If we have more than one test build running we cannot use the same file for each test case; instead we need to use a per-test path so there aren't any collisions. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
diff --git a/Makefile b/Makefile
index bbd29af..2cb057e 100644
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ all:: $(GIT_LIB)
clean:
rm -f $(GIT_LIB)
rm -f src/*.o
- rm -f tests/*.o tests/*.exe
+ rm -f tests/*.o tests/*.exe tests/*.toc
rm -f include/git/config.h
rm -rf apidocs
@@ -50,22 +50,36 @@ $(GIT_LIB): $(OBJS)
rm -f $(LIB)
$(AR) cr $(GIT_LIB) $(OBJS)
-T_HDR = tests/test_lib.h
-T_LIB = tests/test_lib.o
-T_MAIN_C = tests/test_main.c
-T_MAIN_O = tests/test_main.o
+T_HDR = tests/test_lib.h
+T_LIB = tests/test_lib.o
+T_MAIN_C = tests/test_main.c
-$(T_LIB): tests/test_lib.h $(HDRS)
-$(TEST_EXE): $(T_LIB) $(T_HDR) $(T_MAIN_C) $(HDRS) $(GIT_LIB)
+$(T_LIB): $(T_HDR) $(HDRS)
+$(TEST_OBJ): $(T_HDR) $(HDRS)
-tests/%.exe: tests/%.o
- grep BEGIN_TEST $(patsubst %.o,%.c,$<) >tests/test_contents
- $(CC) $(CFLAGS) -Iinclude -c $(T_MAIN_C) -o $(T_MAIN_O)
- $(CC) -o $@ $(T_MAIN_O) $< $(T_LIB) -L. -lgit2
- rm -f $(T_MAIN_O) tests/test_contents
+$(patsubst %.exe,%.toc,$(TEST_EXE)): tests/%.toc: tests/%.c
+ grep BEGIN_TEST $< >$@+
+ mv $@+ $@
-$(TEST_RUN): $(TEST_EXE)
- $<
+$(TEST_OBJ): tests/%.o: tests/%.c
+ $(CC) -Iinclude $(CFLAGS) -c $< -o $@
+
+$(patsubst %.exe,%_main.o,$(TEST_EXE)): tests/%_main.o: $(HDRS)
+$(patsubst %.exe,%_main.o,$(TEST_EXE)): tests/%_main.o: $(T_MAIN_C)
+$(patsubst %.exe,%_main.o,$(TEST_EXE)): tests/%_main.o: tests/%.toc
+ $(CC) -Iinclude -I. '-DTEST_TOC="$<"' \
+ -c $(T_MAIN_C) \
+ -o $@
+
+$(TEST_EXE): tests/%.exe: $(T_LIB) $(GIT_LIB)
+$(TEST_EXE): tests/%.exe: tests/%.o tests/%_main.o
+ $(CC) -o $@ \
+ $(patsubst %.exe,%_main.o,$@) \
+ $(patsubst %.exe,%.o,$@) \
+ $(T_LIB) -L. -lgit2
+
+$(TEST_RUN): tests/%.run: tests/%.exe
+ @$<
.PHONY: all
.PHONY: clean
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 0000000..690624b
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1 @@
+*.toc
diff --git a/tests/test_main.c b/tests/test_main.c
index a870abd..6267cbc 100644
--- a/tests/test_main.c
+++ b/tests/test_main.c
@@ -27,13 +27,13 @@
#undef BEGIN_TEST
#define BEGIN_TEST(name) extern void testfunc__##name(void);
-#include "test_contents"
+#include TEST_TOC
int main(int argc, char **argv)
{
#undef BEGIN_TEST
#define BEGIN_TEST(name) testfunc__##name();
-#include "test_contents"
+#include TEST_TOC
return 0;
}