-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
54 lines (43 loc) · 2.5 KB
/
Makefile
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
ifneq (,$(findstring mingw,$(CC)))
BINEXT:=.exe
else
BINEXT:=.bin
endif
UNITTEST_SOURCES_NOSDL=$(sort $(wildcard ./implementation/test_*_nosdl.c))
UNITTEST_SOURCES=$(sort $(wildcard ./implementation/test_*.c))
UNITTEST_SOURCES_WITHSDL=$(sort $(filter-out $(UNITTEST_SOURCES), $(UNITTEST_SOURCES_NOSDL)))
UNITTEST_BASENAMES=$(sort $(patsubst %.c, %, $(UNITTEST_SOURCES)))
UNITTEST_BASENAMES_NOSDL=$(sort $(patsubst %.c, %, $(UNITTEST_SOURCES_NOSDL)))
UNITTEST_BASENAMES_WITHSDL=$(sort $(patsubst %.c, %, $(UNITTEST_SOURCES_WITHSDL)))
HEADERS=$(sort $(filter-out ./include/spew3dweb.h ./implementation/testmain.h ./implementation/spew3dweb_prefix_all.h,$(wildcard ./include/*.h) $(wildcard ./implementation/*.h)))
SOURCES=$(sort $(filter-out $(UNITTEST_SOURCES), $(wildcard ./implementation/*.c)))
TESTPROG=$(sort $(patsubst %.c, %$(BINEXT), $(wildcard ./examples/example_*.c ./implementation/test_*.c)))
all: amalgamate build-tests
amalgamate: update-vendor-if-needed
echo "#ifdef SPEW3DWEB_IMPLEMENTATION" > .spew3d_ifdef
echo "" >> .spew3d_ifdef
echo "#endif // SPEW3DWEB_IMPLEMENTATION" > .spew3d_ifndef
echo "" >> .spew3d_ifndef
cat implementation/spew3dweb_prefix_all.h $(HEADERS) $(SOURCES) > include/spew3dweb.h
rm -f .spew3d_ifdef
rm -f .spew3d_ifndef
reset-deps:
git submodule foreach --recursive git reset --hard && git submodule foreach --recursive git clean -xfd && git submodule update --init
cd vendor/Spew3D/ && $(MAKE) reset-deps && $(MAKE) clean
build-tests:
cd examples && $(MAKE) clean && $(MAKE) CC="$(CC)"
test: amalgamate build-tests unittests
cd examples && valgrind ./example_markdown_basic.bin
update-vendor-if-needed:
@if [ ! -e "vendor/Spew3D/include/spew3d.h" ]; then $(MAKE) update-vendor; fi
update-vendor:
@if [ ! -e "vendor/Spew3D/AUTHORS.md" ]; then git submodule update --init; fi
cd vendor/Spew3D/ && make amalgamate
unittests:
echo "TESTS: $(UNITTEST_SOURCES) | $(UNITTEST_BASENAMES)"
for x in $(UNITTEST_BASENAMES_WITHSDL); do $(CC) -g -O0 $(CFLAGS) -Iinclude/ -I./vendor/Spew3D/include/ $(CXXFLAGS) -pthread -o ./$$x$(BINEXT) ./$$x.c -lSDL2 -lcheck -lrt -lm $(LDFLAGS) || { exit 1; }; done
for x in $(UNITTEST_BASENAMES_NOSDL); do $(CC) -g -O0 $(CFLAGS) -Iinclude/ -I./vendor/Spew3D/include/ $(CXXFLAGS) -pthread -o ./$$x$(BINEXT) ./$$x.c -lcheck -lrt -lm $(LDFLAGS) || { exit 1; }; done
for x in $(UNITTEST_BASENAMES); do echo ">>> TEST RUN: $$x"; CK_FORK=no valgrind --track-origins=yes --leak-check=full ./$$x$(BINEXT) || { exit 1; }; done
clean:
rm -f $(TESTPROG)
rm -f ./include/spew3dweb.h