Makefile: move test related targets to a new tests/Makefile
[libgit2.git] / tests / Makefile
blob7ce510638eb4f25e6d74a788e941e27557831291
2 all::
4 LD = $(CC)
6 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo no')
8 CFLAGS = -g -O2 -Wall
9 LIBS = -L.. -lgit2 -lz
10 OS = unix
12 CRYPTO_LIB = -lcrypto
14 EXTRA_LIBS =
16 HDRS = $(wildcard ../src/*.h)
17 PUBLIC_HEADERS = $(wildcard ../src/git/*.h)
18 HDRS += $(PUBLIC_HEADERS)
20 TEST_OBJ = $(patsubst %.c,%.o,\
21 $(wildcard t[0-9][0-9][0-9][0-9]-*.c))
22 TEST_EXE = $(patsubst %.o,%.exe,$(TEST_OBJ))
23 TEST_RUN = $(patsubst %.exe,%.run,$(TEST_EXE))
25 ifndef NO_OPENSSL
26 EXTRA_LIBS += $(CRYPTO_LIB)
27 endif
29 BASIC_CFLAGS := -I../src
31 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS)
32 LIBS += $(EXTRA_LIBS)
34 all:: $(TEST_RUN)
36 clean:
37 rm -f *.o *.exe *.toc
38 rm -rf trash-*.exe
39 rm -f *~
41 test: $(TEST_RUN)
43 .c.o:
44 $(CC) $(ALL_CFLAGS) -c $< -o $@
46 T_HDR = test_lib.h test_helpers.h
47 T_LIB = test_lib.o test_helpers.o
48 T_MAIN_C = test_main.c
50 $(T_LIB): $(T_HDR) $(HDRS)
51 $(TEST_OBJ): $(T_HDR) $(HDRS)
53 $(patsubst %.exe,%.toc,$(TEST_EXE)): %.toc: %.c
54 grep BEGIN_TEST $< >$@+
55 mv $@+ $@
57 $(TEST_OBJ): %.o: %.c
58 $(CC) $(ALL_CFLAGS) -c $< -o $@
60 $(patsubst %.exe,%_main.o,$(TEST_EXE)): %_main.o: $(HDRS)
61 $(patsubst %.exe,%_main.o,$(TEST_EXE)): %_main.o: $(T_MAIN_C)
62 $(patsubst %.exe,%_main.o,$(TEST_EXE)): %_main.o: %.toc
63 $(CC) $(ALL_CFLAGS) '-DTEST_TOC="$<"' \
64 -c $(T_MAIN_C) \
65 -o $@
67 $(TEST_EXE): %.exe: $(T_LIB)
68 $(TEST_EXE): %.exe: %.o %_main.o
69 $(LD) -o $@ \
70 $(patsubst %.exe,%_main.o,$@) \
71 $(patsubst %.exe,%.o,$@) \
72 $(T_LIB) $(LIBS)
74 $(TEST_RUN): %.run: %.exe
75 @t=trash-$(<F) && \
76 mkdir $$t && \
77 if (cd $$t && ../$<); \
78 then rm -rf $$t; \
79 else rmdir $$t; exit 1; \
82 .PHONY: all
83 .PHONY: clean
84 .PHONY: test $(TEST_RUN)