Debian Codegraph @

Makefile

raw symbols SCIP
1 # This Makefile ensures that the build is made out of source in a
2 # subdirectory called 'build' If it doesn't exist, it is created.
3 #
4 # This Makefile also contains delegation of the most common make commands
5 #
6 # If you have cmake installed you should be able to do:
7 #
8 # make
9 # make test
10 # make install
11 # make package
12 #
13 # That should build Cgreen in the build directory, run some tests,
14 # install it locally and generate a distributable package.
15
16 ifndef VERBOSE
17 MAKEFLAGS += --no-print-directory
18 endif
19
20 .PHONY:all
21 all: build-it
22
23 .PHONY:debug
24 debug:
25 cmake -DCMAKE_BUILD_TYPE:string=Debug -S . -B build
26 $(MAKE) -C build
27
28 .PHONY:test
29 test: build-it
30 cd build; ctest
31
32 .PHONY:clean
33 clean: build/Makefile
34 $(MAKE) -C build clean
35
36 .PHONY:package
37 package: build/Makefile
38 $(MAKE) -C build package
39
40 # Bump the version consistently across CMakeLists.txt, the public header and
41 # debian/control. Pick the level you want, or set it explicitly:
42 # make bump VERSION=1.7.0
43 # make bump-patch | bump-minor | bump-major
44 # Nothing is committed or tagged -- review the diff, then commit and tag.
45 .PHONY:bump bump-patch bump-minor bump-major
46 bump:
47 @test -n "$(VERSION)" || { echo "Usage: make bump VERSION=X.Y.Z (or bump-patch/bump-minor/bump-major)"; exit 1; }
48 @tools/bump-version.sh $(VERSION)
49
50 bump-patch:
51 @tools/bump-version.sh --patch
52
53 bump-minor:
54 @tools/bump-version.sh --minor
55
56 bump-major:
57 @tools/bump-version.sh --major
58
59 .PHONY:install
60 install: build
61 ifeq ($(OS),Msys)
62 # Thanks to https://stackoverflow.com/a/46027426/204658
63 $(MAKE) -C build install DESTDIR=/
64 else
65 $(MAKE) -C build install
66 endif
67
68 # This is kind of a hack to get a quicker and clearer feedback when
69 # developing Cgreen by allowing 'make unit'. Must be updated when new
70 # test libraries or output comparisons are added.
71
72 # Find out if 'uname -o' works, if it does - use it, otherwise use 'uname -s'
73 UNAMEOEXISTS=$(shell uname -o &>/dev/null; echo $$?)
74 ifeq ($(UNAMEOEXISTS),0)
75 OS=$(shell uname -o)
76 else
77 OS=$(shell uname -s)
78 endif
79
80 # Set prefix and suffix for shared libraries depending on platform
81 ifeq ($(OS),Darwin)
82 LDPATH=DYLD_LIBRARY_PATH=$(PWD)/build/src
83 PREFIX=lib
84 SUFFIX=.dylib
85 else ifeq ($(OS),Cygwin)
86 LDPATH=PATH=$(PWD)/build/src:"$$PATH"
87 PREFIX=cyg
88 SUFFIX=.dll
89 else ifeq ($(OS),Msys)
90 # This is for Msys "proper"
91 # TODO: handle Msys/Mingw32/64
92 LDPATH=PATH=$(PWD)/build/src:"$$PATH"
93 PREFIX=msys-
94 SUFFIX=.dll
95 else
96 LDPATH=LD_LIBRARY_PATH=$(PWD)/build/src
97 PREFIX=lib
98 SUFFIX=.so
99 endif
100
101 # Here are
102 #
103 # 1. tests linked into a library that we run as is
104 # 2. tests linked into a library that we run and compare its normalized output to expected output
105
106 # TODO: the diff_tools scripts determine prefix and extension by themselves
107 # Would be better if those were arguments, since we do it here anyway
108
109 # These "diff tools" also normalize the output using replacements
110 DIFF_TOOL=../../tools/cgreen_runner_output_diff
111 XML_DIFF_TOOL=../../tools/cgreen_xml_output_diff
112 DIFF_TOOL_ARGUMENTS = $(1)_tests \
113 ../../tests \
114 $(1)_tests.expected
115
116 .PHONY: unit
117 unit: build-it
118 cd build ; \
119 $(LDPATH) tools/cgreen-runner -c `find tests -name $(PREFIX)cgreen_c_tests$(SUFFIX)` ; \
120 r=$$((r + $$?)) ; \
121 $(LDPATH) tools/cgreen-runner -c `find tests -name $(PREFIX)cgreen_cpp_tests$(SUFFIX)` ; \
122 r=$$((r + $$?)) ; \
123 $(LDPATH) tools/cgreen-runner -c `find tools -name $(PREFIX)cgreen_runner_tests$(SUFFIX)` ; \
124 r=$$((r + $$?)) ; \
125 cd tests ; \
126 $(LDPATH) $(XML_DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,xml_output) ; \
127 r=$$((r + $$?)) ; \
128 $(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,assertion_messages) ; \
129 r=$$((r + $$?)) ; \
130 $(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,mock_messages) ; \
131 r=$$((r + $$?)) ; \
132 $(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,constraint_messages) ; \
133 r=$$((r + $$?)) ; \
134 $(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,custom_constraint_messages) ; \
135 r=$$((r + $$?)) ; \
136 $(LDPATH) $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,ignore_messages) ; \
137 r=$$((r + $$?)) ; \
138 $(LDPATH) CGREEN_PER_TEST_TIMEOUT=1 $(DIFF_TOOL) $(call DIFF_TOOL_ARGUMENTS,failure_messages) ; \
139 r=$$((r + $$?)) ; \
140 exit $$r
141
142 .PHONY: doc
143 doc: build
144 cmake -DCGREEN_WITH_HTML_DOCS:bool=TRUE -S . -B build
145 cmake --build build
146 cmake -DCGREEN_WITH_HTML_DOCS:bool=False -S . -B build
147 echo open $(PWD)/build/doc/cgreen-guide-en.html
148
149 pdf: build
150 cmake -DCGREEN_WITH_PDF_DOCS:bool=TRUE -S . -B build
151 cmake --build build
152 cmake -DCGREEN_WITH_PDF_DOCS:bool=FALSE -S . -B build
153 echo open $(PWD)/build/doc/cgreen-guide-en.pdf
154
155 chunked: doc
156 asciidoctor-chunker build/doc/cgreen-guide-en.html -o docs
157 echo open $(PWD)/docs/index.html
158
159 .PHONY:valgrind
160 valgrind: build-it
161 @echo -n "Running all tests under Valgrind "
162 @> valgrind.log
163 @for lib in `ls build/tests/$(PREFIX)*_tests$(SUFFIX)` ; \
164 do \
165 echo -n "." ; \
166 LD_LIBRARY_PATH=build/src valgrind --leak-check=full build/tools/cgreen-runner $$lib >> valgrind.log 2>&1 ; \
167 done
168 @echo
169 grep --with-filename --line-number " lost: " valgrind.log | grep -v " 0 bytes" ; \
170 if [ $$? -eq 1 ] ; then echo "Nothing lost" ; fi
171
172
173
174 ############# Internal
175 build build/Makefile:
176 ifeq ($(OS),Darwin)
177 # cmake -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -S . -B build
178 cmake -S . -B build
179 else
180 cmake -S . -B build
181 endif
182
183 .PHONY:build-it
184 build-it: build
185 $(MAKE) -C build
186
187 .SILENT: