-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathMakefile
168 lines (145 loc) · 4.57 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# This Makefile ensures that the build is made out of source in a
# subdirectory called 'build' If it doesn't exist, it is created.
#
# This Makefile also contains delegation of the most common make commands
#
# If you have cmake installed you should be able to do:
#
# make
# make test
# make install
# make package
#
# That should build Cgreen in the build directory, run some tests,
# install it locally and generate a distributable package.
ifndef VERBOSE
MAKEFLAGS += --no-print-directory
endif
.PHONY:all
all: build-it
.PHONY:debug
debug:
cmake -DCMAKE_BUILD_TYPE:string=Debug -S . -B build
$(MAKE) -C build
.PHONY:test
test: build-it
cd build; ctest
.PHONY:clean
clean: build/Makefile
$(MAKE) -C build clean
.PHONY:package
package: build/Makefile
$(MAKE) -C build package
.PHONY:install
install: build
ifeq ($(OS),Msys)
# Thanks to https://stackoverflow.com/a/46027426/204658
$(MAKE) -C build install DESTDIR=/
else
$(MAKE) -C build install
endif
# This is kind of a hack to get a quicker and clearer feedback when
# developing Cgreen by allowing 'make unit'. Must be updated when new
# test libraries or output comparisons are added.
# Find out if 'uname -o' works, if it does - use it, otherwise use 'uname -s'
UNAMEOEXISTS=$(shell uname -o &>/dev/null; echo $$?)
ifeq ($(UNAMEOEXISTS),0)
OS=$(shell uname -o)
else
OS=$(shell uname -s)
endif
# Set prefix and suffix for shared libraries depending on platform
ifeq ($(OS),Darwin)
LDPATH=DYLD_LIBRARY_PATH=$(PWD)/build/src
PREFIX=lib
SUFFIX=.dylib
else ifeq ($(OS),Cygwin)
LDPATH=PATH=$(PWD)/build/src:"$$PATH"
PREFIX=cyg
SUFFIX=.dll
else ifeq ($(OS),Msys)
# This is for Msys "proper"
# TODO: handle Msys/Mingw32/64
LDPATH=PATH=$(PWD)/build/src:"$$PATH"
PREFIX=msys-
SUFFIX=.dll
else
LDPATH=LD_LIBRARY_PATH=$(PWD)/build/src
PREFIX=lib
SUFFIX=.so
endif
# Here are
#
# 1. tests linked into a library that we run as is
# 2. tests linked into a library that we run and compare its normalized output to expected output
# TODO: the diff_tools scripts determine prefix and extension by themselves
# Would be better if those were arguments, since we do it here anyway
# These "diff tools" also normalize the output using replacements
DIFF_TOOL=../../tools/cgreen_runner_output_diff
XML_DIFF_TOOL=../../tools/cgreen_xml_output_diff
DIFF_TOOL_ARGUMENTS = $(1)_tests \
../../tests \
$(1)_tests.expected
.PHONY: unit
unit: build-it
cd build ; \
$(LDPATH) tools/cgreen-runner -c `find tests -name $(PREFIX)cgreen_c_tests$(SUFFIX)` ; \
r=$$((r + $$?)) ; \
$(LDPATH) tools/cgreen-runner -c `find tests -name $(PREFIX)cgreen_cpp_tests$(SUFFIX)` ; \
r=$$((r + $$?)) ; \
$(LDPATH) tools/cgreen-runner -c `find tools -name $(PREFIX)cgreen_runner_tests$(SUFFIX)` ; \
r=$$((r + $$?)) ; \
cd tests ; \
$(LDPATH) $(XML_DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,xml_output) ; \
r=$$((r + $$?)) ; \
$(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,assertion_messages) ; \
r=$$((r + $$?)) ; \
$(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,mock_messages) ; \
r=$$((r + $$?)) ; \
$(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,constraint_messages) ; \
r=$$((r + $$?)) ; \
$(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,custom_constraint_messages) ; \
r=$$((r + $$?)) ; \
$(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,ignore_messages) ; \
r=$$((r + $$?)) ; \
$(LDPATH) CGREEN_PER_TEST_TIMEOUT=1 $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,failure_messages) ; \
r=$$((r + $$?)) ; \
exit $$r
.PHONY: doc
doc: build
cmake -DCGREEN_WITH_HTML_DOCS:bool=TRUE -S . -B build
cmake --build build
cmake -DCGREEN_WITH_HTML_DOCS:bool=False -S . -B build
echo open $(PWD)/build/doc/cgreen-guide-en.html
pdf: build
cmake -DCGREEN_WITH_PDF_DOCS:bool=TRUE -S . -B build
cmake --build build
cmake -DCGREEN_WITH_PDF_DOCS:bool=FALSE -S . -B build
echo open $(PWD)/build/doc/cgreen-guide-en.pdf
chunked: doc
asciidoctor-chunker build/doc/cgreen-guide-en.html -o docs
echo open $(PWD)/docs/index.html
.PHONY:valgrind
valgrind: build-it
@echo -n "Running all tests under Valgrind "
@> valgrind.log
@for lib in `ls build/tests/$(PREFIX)*_tests$(SUFFIX)` ; \
do \
echo -n "." ; \
LD_LIBRARY_PATH=build/src valgrind --leak-check=full build/tools/cgreen-runner $$lib >> valgrind.log 2>&1 ; \
done
@echo
grep --with-filename --line-number " lost: " valgrind.log | grep -v " 0 bytes" ; \
if [ $$? -eq 1 ] ; then echo "Nothing lost" ; fi
############# Internal
build build/Makefile:
ifeq ($(OS),Darwin)
cmake -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -S . -B build
#cmake -S . -B build
else
cmake -S . -B build
endif
.PHONY:build-it
build-it: build
$(MAKE) -C build
.SILENT: