summaryrefslogtreecommitdiff
path: root/tests/Makefile
blob: 239e9f60934148af8c1c69e872abf2764bce2271 (plain)
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
CC = gcc
CFLAGS	= 
INCLUDES = -I.
LDFLAGS = -L$(BUILDDIR)/cgreen/build-c/src
LDLIBS = -lcgreen
UNITOBJ = $(BUILDDIR)/testserial/unitobj
DEPDIR = $(BUILDDIR)/testserial/unit.d
UNITEXE = $(BUILDDIR)/testserial/unitexe
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td
EXT = 
UNAME := $(shell uname)
ifneq (, $(findstring mingw, $(UNAME)))
	EXT += exe
endif
ifneq (, $(findstring cygwin, $(UNAME)))
	EXT += exe
endif
	
SRC = $(wildcard *.c)
EXE = $(patsubst %.c, $(UNITEXE)/%$(EXT), $(SRC))
$(shell mkdir -p $(DEPDIR) >/dev/null)

test: $(EXE)
	@for f in $^; do \
	echo "++++++++++++++++++"; \
	echo "Running unit tests"; \
	echo $$(basename $$f); \
	echo "++++++++++++++++++"; \
	echo ""; \
	$$f || exit 1; \
	echo ""; \
	echo "******************"; \
	echo ""; \
	done

$(UNITEXE)/%$(EXT): $(UNITOBJ)/%.o
	mkdir -p $(UNITEXE)
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)

$(UNITOBJ)/%.o : %.c
$(UNITOBJ)/%.o: %.c $(DEPDIR)/%.d
	mkdir -p $(UNITOBJ)
	$(CC) $(CFLAGS) $(DEPFLAGS) -c $< -o $@
	mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d
	
$(DEPDIR)/%.d: ;
.PRECIOUS: $(DEPDIR)/%.d

-include $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRC).c))