-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.am
248 lines (219 loc) · 7.34 KB
/
Makefile.am
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# General syntax:
# {WHERE}_{PRIMARY} = targets...
# {WHERE}:
# "bin": $(bindir) for executables, default $(prefix)/bin
# "lib": $(libdir) for libraries, default $(prefix)/lib
# "noinst" = not installed
# "check" = for "make check"
# {PRIMARY}: the type of file
# PROGRAMS = executable binary files
# SCRIPTS = executable scripts
# DATA = data files
# some variables
# AM_CPPFLAGS: default C preprocessor flags
# AM_CFLAGS: default C compiler flags
# AM_CXXFLAGS: default C++ compiler flags
# AM_LIBS: libraries
# NOTE for using pkg-config:
# suppose we have in our configure.ac:
# PKG_CHECK_MODULES([DEPS], [list-of-libs...])
# then we do:
# AM_CFLAGS = $(DEPS_CFLAGS)
# AM_LIBS = $(DEPS_LIBS)
# target specific variables
# {TARGET}_{SPECIFICS} = ...
# good specifics:
# SOURCES: list of source files
# LDADD: extra objects for program
# CPPFLAGS: this target's C preprocessor flags
# handling libraries:
# 1. DO NOT FORGET to add LT_INIT to configure.ac
#
# lib_LTLIBRARIES = libwhine-1.la
# libwhine_1_la_SOURCES = src/whine.c src/whine.h
# libwhine_1_la_LDFLAGS = -version-info 1:0:0
# include_HEADERS = src/whine.h
#
# if library is used by a program:
# hello_LDADD = $(lib_LTLIBRARIES)
#
# define custom targets for check
# like running tests and linterss
# check-local: <TARGETS>
# $(MAKE) $(AM_MAKEFLAGS) ...
#
# define pkgconfig destination
# pkgconfiglibdir = $(libdir)/pkgconfig
# pkgconfiglib_DATA = autotools-unittest.pc
# check building of libraries (like test)
# check_LTLIBRARIES = \
# lib/gmock/libgmock.la \
# lib/gmock/libgmock_main.la
# check building of binaries
# check_PROGRAMS = test/sample_test
#############################################
# change macro directory to ./m4
ACLOCAL_AMFLAGS = -I m4 --install
# some extra files which are not source files
EXTRA_DIST = \
autogen.sh \
whine.pc \
CPPLINT.cfg \
pkg/postinst.sh \
pkg/postrm.sh \
pkg/preinst.sh \
pkg/prerm.sh
# define root as include dir
AM_CPPFLAGS = -I$(top_srcdir)/src
# set flags to be later used
AM_CFLAGS =
AM_LDFLAGS =
# include glib as dependency
AM_CFLAGS += $(GLIB_CFLAGS)
AM_LDFLAGS += $(GLIB_LIBS)
# check code style via cpplint
.PHONY: lint
if HAVE_CPPLINT
lint:
find $(top_srcdir)/src -type f -name "*.cc" -or -name "*.c" -or -name "*.cpp" -or -name "*.cu" -or -name "*.cuh" -or -name "*.h" -or -name "*.hpp" | xargs $(CPPLINT) --counting=detailed
endif
# run pre-built tests
.PHONY: check-test
check-test: test/whine/whine_test
test/whine/whine_test
# run unit tests
.PHONY: unittest
unittest:
$(MAKE) $(AM_MAKEFLAGS) clean
$(MAKE) $(AM_MAKEFLAGS) check-test
#-fprofile-arcs -ftest-coverage
# sanitizer specs
.PHONY: sanity-leak sanity-address sanity-undefined sanity-thread sanity-memory
sanity-leak:
if HAVE_LEAK_SANITIZER
$(MAKE) $(AM_MAKEFLAGS) clean
$(MAKE) $(AM_MAKEFLAGS) CFLAGS="$(CFLAGS) -fsanitize=leak -O0" CXXFLAGS="$(CXXFLAGS) -fsanitize=leak" check-test
endif
sanity-address:
if HAVE_ADDRESS_SANITIZER
$(MAKE) $(AM_MAKEFLAGS) clean
$(MAKE) $(AM_MAKEFLAGS) CFLAGS="$(CFLAGS) -fsanitize=address -O0" CXXFLAGS="$(CXXFLAGS) -fsanitize=address" check-test
endif
sanity-undefined:
if HAVE_UNDEFINED_SANITIZER
$(MAKE) $(AM_MAKEFLAGS) clean
$(MAKE) $(AM_MAKEFLAGS) CFLAGS="$(CFLAGS) -fsanitize=undefined -O0" CXXFLAGS="$(CXXFLAGS) -fsanitize=undefined" check-test
endif
sanity-thread:
if HAVE_THREAD_SANITIZER
$(MAKE) $(AM_MAKEFLAGS) clean
$(MAKE) $(AM_MAKEFLAGS) CFLAGS="$(CFLAGS) -fsanitize=thread -O0" CXXFLAGS="$(CXXFLAGS) -fsanitize=thread" LDFLAGS="$(LDFLAGS) -shared" check-test
endif
sanity-memory:
if HAVE_MEMORY_SANITIZER
$(MAKE) $(AM_MAKEFLAGS) clean
$(MAKE) $(AM_MAKEFLAGS) CFLAGS="$(CFLAGS) -fsanitize=memory -O0" CXXFLAGS="$(CXXFLAGS) -fsanitize=memory" check-test
endif
# run all sanitizers
.PHONY: sanity
sanity: | sanity-leak sanity-address sanity-undefined sanity-thread sanity-memory
# run code coverage
# notable outputs
# Summary coverage rate:
# lines......: 40.0% (2 of 5 lines)
# functions..: 50.0% (1 of 2 functions)
# branches...: no data found
# Overall coverage rate:
# lines......: 40.0% (2 of 5 lines)
# functions..: 50.0% (1 of 2 functions)
.PHONY: coverage
coverage:
$(MAKE) $(AM_MAKEFLAGS) clean
$(MAKE) $(AM_MAKEFLAGS) \
CFLAGS="$(CFLAGS) $(COVERAGE_CFLAGS) $(COVERAGE_OPTFLAGS)" \
CXXFLAGS="$(CXXFLAGS) $(COVERAGE_CXXFLAGS) $(COVERAGE_OPTFLAGS)" \
LDFLAGS="$(LDFLAGS) $(COVERAGE_LDFLAGS)" \
LIBS="$(LIBS) $(COVERAGE_LIBS)" \
check-test
$(LCOV) --capture \
--directory "$(top_builddir)/src" \
--base-directory "$(abspath $(top_builddir))" \
--output-file $(top_builddir)/coverage.info \
--gcov-tool "$(GCOV)" \
--compat-libtool --checksum
$(LCOV) \
--extract $(top_builddir)/coverage.info "$(abspath $(top_srcdir))/src/*" \
--gcov-tool $(GCOV) \
--output-file $(top_builddir)/coverage.info
$(GENHTML) \
--prefix "$(abspath $(top_srcdir))" \
--output-directory $(top_builddir)/coverage \
--title $(PACKAGE_NAME) \
--legend --show-details \
$(GENHTML_OPTIONS) \
$(top_builddir)/coverage.info
clean-coverage:
find $(top_builddir) -name *.gcda -exec rm -f {} +
find $(top_builddir) -name *.gcno -exec rm -f {} +
find $(top_builddir) -name *.gcov -exec rm -f {} +
rm -f $(top_builddir)/coverage.info
rm -rfv $(top_builddir)/coverage
# debian packaging
if HAVE_DEBIAN_PACKAGING
deb:
$(MAKE) $(AM_MAKEFLAGS) dist-gzip
rm -rf $(distdir)
GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar)
$(MKDIR_P) $(distdir)/_build/DEBIAN
install_base=`$(am__cd) $(distdir)/_build && pwd` \
&& $(am__cd) $(distdir) \
&& ./configure $(AM_CONFIGURE_FLAGS) --prefix="$$install_base" \
&& $(MAKE) $(AM_MAKEFLAGS) \
&& $(MAKE) $(AM_MAKEFLAGS) install
cat pkg/preinst.sh | $(SED) "s/__VERSION__/${VERSION}/g" > $(distdir)/_build/DEBIAN/preinst
cat pkg/prerm.sh | $(SED) "s/__VERSION__/${VERSION}/g" > $(distdir)/_build/DEBIAN/prerm
cat pkg/postinst.sh | $(SED) "s/__VERSION__/${VERSION}/g" > $(distdir)/_build/DEBIAN/postinst
cat pkg/postrm.sh | $(SED) "s/__VERSION__/${VERSION}/g" > $(distdir)/_build/DEBIAN/postrm
chmod +x $(distdir)/_build/DEBIAN/preinst
chmod +x $(distdir)/_build/DEBIAN/postinst
chmod +x $(distdir)/_build/DEBIAN/prerm
chmod +x $(distdir)/_build/DEBIAN/postrm
arch=`echo $(host_cpu) | $(SED) "s/x86_64/amd64/g"` && \
name=`echo $(PACKAGE_NAME) | $(SED) "s/_/-/g"` && \
cat pkg/debian.in | \
$(SED) "s/__VERSION__/${VERSION}/g" | \
$(SED) "s/__NAME__/$$name/g" | \
$(SED) "s/__ARCHITECTURE__/$$arch/g" \
> $(distdir)/_build/DEBIAN/control
$(DPKG_DEB) --build $(distdir)/_build
$(am__mv) $(distdir)/_build.deb $(distdir).deb
cp $(distdir).deb $(PACKAGE).deb
endif
# define extensions to "make check"
check-local: | check-test
# define extensions to "make clean"
clean-local: | clean-coverage
# define whine library
lib_LTLIBRARIES = libwhine-1.la
libwhine_1_la_SOURCES = \
src/whine/whine.c \
src/whine/whine.h
libwhine_1_la_LDFLAGS = -version-info 1:0:0
include_HEADERS = \
src/whine/whine.h \
config.h
# define test for whine library
check_PROGRAMS = test/whine/whine_test
test_whine_whine_test_SOURCES = test/whine/whine_test.c
test_whine_whine_test_LDADD = $(lib_LTLIBRARIES)
# define pkgconfig
pkgconfiglibdir = $(libdir)/pkgconfig
pkgconfiglib_DATA = whine.pc
# Lists programs to be installed
# in "bin" directory
bin_PROGRAMS = hello
# list source files required to
# generate target "hello"
hello_SOURCES = src/hello.c
# hello uses our whine lib!
hello_LDADD = $(lib_LTLIBRARIES)