forked from north-numerical-computing/cpfloat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
361 lines (263 loc) · 9.3 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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# SPDX-FileCopyrightText: 2020 Massimiliano Fasi and Mantas Mikaitis
# SPDX-License-Identifier: LGPL-2.1-or-later
ROOTDIR=$(shell pwd)
DEPSDIR=$(ROOTDIR)/deps/
SRCDIR=$(ROOTDIR)/src/
DOCDIR=$(ROOTDIR)/docs/
MEXDIR=$(ROOTDIR)/mex/
EXAMPLEDIR=$(ROOTDIR)/examples/
TESTDIR=$(ROOTDIR)/test/
UTILDIR=$(ROOTDIR)/util/
BINDIR=$(ROOTDIR)/bin/
BUILDDIR=$(ROOTDIR)/build/
PREFIX?=/usr/local/
LIBDIR=$(BUILDDIR)lib/
INCDIR=$(BUILDDIR)include/
DATDIR=$(ROOTDIR)/datfiles/
PCG_HEADER=$(DEPSDIR)pcg-c/include/pcg_variants.h
SHELL:=/bin/sh
CP:=cp
MKDIR:=mkdir
MV:=mv
RM:=rm -f
CHECKMK:=checkmk
CC:=gcc
CCOV:=gcov
DOXYGEN:=doxygen
SPHINXBUILD:=sphinx-build
GIT:=git
MATLAB:=$(shell which matlab) -nodesktop -nosplash
MEXEXT:=$(shell which mexext)
OCTAVE:=octave
WFLAGS=-Wall -Wextra -pedantic
ARCHFLAGS=-march=native
CFLAGS=$(WFLAGS) $(ARCHFLAGS) -std=gnu99 -I $(SRCDIR) \
-I $(PREFIX)include -L $(PREFIX)lib
COPTIM=-O3
CCOVFLAGS=-Og -g --coverage
CLIBS=-lm -fopenmp
CHECKLIBS=-lcheck -lpthread -lsubunit
PCG_INCLUDE=-include $(PCG_HEADER)
PCG_LIB=-L $(DEPSDIR)pcg-c/src -lpcg_random
PCG_FLAGS=$(PCG_INCLUDE) $(PCG_LIB)
.PRECIOUS: %.o
.PHONY: all
all: autotune lib mexmat mexoct
init(%):
$(GIT) submodule update --init deps/$%
$(DEPSDIR)pcg-c/src/libpcg_random.a: init(pcg-c)
cd $(DEPSDIR)pcg-c; make
.PHONY: libpcg
libpcg: $(DEPSDIR)pcg-c/src/libpcg_random.a
$(ROOTDIR)%:
$(MKDIR) -p $@
$(BINDIR)cpfloat_autotune: $(SRCDIR)cpfloat_autotune.c $(BINDIR) libpcg
$(CC) $(CFLAGS) $(COPTIM) -o $@ $< $(CLIBS) $(PCG_FLAGS)
.PHONY: autotune
autotune: $(BINDIR)cpfloat_autotune
$<
$(MV) cpfloat_threshold_*.h $(SRCDIR)
install: lib
$(CP) $(INCDIR) $(PREFIX)include/
$(CP) $(LIBDIR) $(PREFIX)lib/
lib: autotune $(INCDIR)cpfloat_definitions.h $(INCDIR)cpfloat_docmacros.h \
$(INCDIR)cpfloat.h \
$(INCDIR)cpfloat_threshold_binary32.h \
$(INCDIR)cpfloat_threshold_binary64.h \
$(LIBDIR)libcpfloat.so $(LIBDIR)libcpfloat.a
HEADERS=$(INCDIR)cpfloat_definitions.h $(INCDIR)cpfloat_docmacros.h \
$(INCDIR)cpfloat_threshold_binary32.h $(INCDIR)cpfloat_threshold_binary64.h
$(HEADERS):$(INCDIR)cpfloat_%.h:$(SRCDIR)cpfloat_%.h $(INCDIR)
$(CP) $< $@
$(BUILDDIR)cpfloat.tmp: $(SRCDIR)cpfloat_binary32.h $(SRCDIR)cpfloat_binary64.h
sed '/CPFLOAT_BINARY\|^#include "cpfloat_\(doc\|def\)/d' \
$(SRCDIR)cpfloat_binary32.h > $(BUILDDIR)cpfloat.tmp
sed '/CPFLOAT_BINARY\|^#include "cpfloat_\(doc\|def\)/d' \
$(SRCDIR)cpfloat_binary64.h >> $(BUILDDIR)cpfloat.tmp
sed 's/static inline //g' $(BUILDDIR)cpfloat.tmp > $(BUILDDIR)cpfloat.tmpfinal
$(MV) $(BUILDDIR)cpfloat.tmpfinal $(BUILDDIR)cpfloat.tmp
$(BUILDDIR)cpfloat_template.c: $(SRCDIR)cpfloat_template.h
sed 's/static inline//g' $< > $@
$(BUILDDIR)cpfloat.c: $(BUILDDIR)cpfloat.tmp $(BUILDDIR)cpfloat_template.c
printf "#include \"cpfloat_docmacros.h\"\n\
#include \"cpfloat_definitions.h\"\n" > $@
sed 's/template.h/template.c/' $(BUILDDIR)cpfloat.tmp >> $@
$(INCDIR)cpfloat.h: $(BUILDDIR)cpfloat.tmp $(BUILDDIR) $(INCDIR)
sed '/^\/\*\* @/,/^\/\*\* @/d' $< > $(BUILDDIR)cpfloat-h.tmp
sed '/^ \*\|\/\*/d' $(BUILDDIR)cpfloat-h.tmp > $(BUILDDIR)cpfloat-h.tmpfinal
$(MV) $(BUILDDIR)cpfloat-h.tmpfinal $(BUILDDIR)cpfloat-h.tmp
printf "/* SPDX-FileCopyrightText: 2020 Massimiliano Fasi and Mantas Mikaitis */\n\
/* SPDX-License-Identifier: LGPL-2.1-or-later */\n\
\n\
/**\n\
* @file cpfloat.h\n\
* @brief CPFloat header file.\n\
*/\n\
\n\
#ifndef _CPFLOAT_\n\
#define _CPFLOAT_\n\
\n\
#include \"cpfloat_docmacros.h\"\n\
#include \"cpfloat_definitions.h\"\n\
\n" > $@
cat $(BUILDDIR)cpfloat-h.tmp >> $@
printf "#endif /* #ifndef _CPFLOAT_ */" >> $@
HEADER_DEPS=$(INCDIR)cpfloat_threshold_binary32.h \
$(INCDIR)cpfloat_threshold_binary64.h \
$(DEPSDIR)pcg-c/include/pcg_variants.h
$(BUILDDIR)cpfloat-shared.o: $(BUILDDIR)cpfloat.c $(HEADER_DEPS)
$(CC) $(CFLAGS) $(COPTIM) -fPIC -c $< $(PCG_INCLUDE) -o $@
$(BUILDDIR)cpfloat-static.o: $(BUILDDIR)cpfloat.c $(HEADER_DEPS)
$(CC) $(CFLAGS) $(COPTIM) -c $< $(PCG_INCLUDE) -o $@
LIBPCG_OBJ=$(DEPSDIR)pcg-c/src/pcg-global-32.o \
$(DEPSDIR)pcg-c/src/pcg-advance-64.o \
$(DEPSDIR)pcg-c/src/pcg-global-64.o \
$(DEPSDIR)pcg-c/src/pcg-advance-128.o
$(LIBDIR)libcpfloat.so: $(BUILDDIR)cpfloat-shared.o libpcg $(LIBDIR)
$(CC) -shared -o $@ $< $(LIBPCG_OBJ) $(CLIBS) $(PCG_LIB)
$(LIBDIR)libcpfloat.a: $(BUILDDIR)cpfloat-static.o libpcg $(LIBDIR)
ar -cr $@ $< $(LIBPCG_OBJ)
MEXEXTENSION:=`$(MEXEXT)`
.PHONY: mexmat
mexmat: $(BINDIR)cpfloat.m $(BINDIR)cpfloat.$(MEXEXTENSION)
.PHONY: mexoct
mexoct: $(BINDIR)cpfloat.m $(BINDIR)cpfloat.mex
$(BINDIR)cpfloat.m: $(MEXDIR)cpfloat.m $(BINDIR)
$(CP) $< $@
MEXSTRING="cd $(MEXDIR); \
retval = cpfloat_compile('cpfloatdir', '$(SRCDIR)', \
'pcgpath', '$(DEPSDIR)pcg-c/', \
'compilerpath', '$(CC)'); \
if retval \
rehash(); \
cpfloat_autotune('cpfloatdir', '$(SRCDIR)'); \
cpfloat_compile('cpfloatdir', '$(SRCDIR)', \
'pcgpath', '$(DEPSDIR)pcg-c/', \
'compilerpath', '$(CC)'); \
end; \
exit;"
MEXEXTENSION:=`$(MEXEXT)`
$(BINDIR)cpfloat.$(MEXEXTENSION): $(MEXDIR)cpfloat.c libpcg $(BINDIR)
$(MATLAB) -r $(MEXSTRING)
$(MV) $(MEXDIR)cpfloat.$(MEXEXTENSION) $@
$(BINDIR)cpfloat.mex: $(MEXDIR)cpfloat.c libpcg $(BINDIR)
$(OCTAVE) --eval $(MEXSTRING)
$(MV) $(MEXDIR)cpfloat.mex $@
.PHONY: test
test: ctest libtest mtest otest
$(TESTDIR)cpfloat_test.c: $(TESTDIR)cpfloat_test.ts
$(CHECKMK) clean_mode=1 $< > $@
$(BINDIR)cpfloat_test: $(TESTDIR)cpfloat_test.c libpcg $(BINDIR)
$(CC) $(CFLAGS) $(COPTIM) -fsanitize=undefined -o $@ $< \
$(CHECKLIBS) $(CLIBS) $(PCG_FLAGS)
.PHONY: ctest
ctest: $(BINDIR)cpfloat_test
$<
$(MV) cpfloat_test.log $(TESTDIR)
$(TESTDIR)libcpfloat_test.c: $(TESTDIR)cpfloat_test.c
sed '/#include "cpfloat_binary32.h"/d' $< > $@
sed 's/#include "cpfloat_binary64.h"/#include "cpfloat.h"/g' $@ > cpfloath.temp
$(MV) cpfloath.temp $@
$(BINDIR)libcpfloat_static_test: $(TESTDIR)libcpfloat_test.c lib
$(CC) $(CFLAGS) $(COPTIM) -fsanitize=undefined -static -o $@ $< \
-I$(INCDIR) -L$(LIBDIR) -lcpfloat $(CHECKLIBS)
$(BINDIR)libcpfloat_shared_test: $(TESTDIR)libcpfloat_test.c lib
$(CC) $(CFLAGS) $(COPTIM) -fsanitize=undefined -o $@ $< \
-I$(INCDIR) -L$(LIBDIR) -lcpfloat $(CHECKLIBS) -lm
.PHONY: libtest
libtest: libtest-shared libtest-static
.PHONY: libtest-shared
libtest-shared: $(BINDIR)libcpfloat_shared_test
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(LIBDIR); $<
$(MV) cpfloat_test.log $(TESTDIR)libcpfloat_dinamic_test.log
.PHONY: libtest-static
libtest-static: $(BINDIR)libcpfloat_static_test
$<
$(MV) cpfloat_test.log $(TESTDIR)libcpfloat_static_test.log
.PHONY: mtest
mtest: MTESTSTRING="addpath('$(DEPSDIR)float_params'); \
addpath('$(BINDIR)'); \
cd $(TESTDIR); \
cpfloat_test; \
exit;"
mtest: $(BINDIR)cpfloat.$(MEXEXTENSION) $(BINDIR)cpfloat.m init(float_params)
$(MATLAB) -r $(MTESTSTRING)
.PHONY: otest
otest: OTESTSTRING="pkglist=pkg('list'); \
no_fenv=true; \
for i=1:length(pkglist); \
if strcmp(pkglist{i}.name, 'fenv'); \
no_fenv = false; \
break; \
end; \
end; \
if no_fenv; \
pkg install -forge fenv; \
end; \
pkg load fenv; \
addpath('$(DEPSDIR)float_params'); \
addpath('$(BINDIR)'); \
cd $(TESTDIR); \
cpfloat_test; \
exit;"
otest: $(BINDIR)cpfloat.mex $(BINDIR)cpfloat.m init(float_params)
$(OCTAVE) --eval $(OTESTSTRING)
.PHONY: docs
docs: $(DOCDIR)html
$(DOCDIR)Doxyfile:
$(DOXYGEN) -g $(DOCDIR)Doxyfile
$(DOCDIR)xml: $(DOCDIR)Doxyfile $(DOCDIR)Doxyfile-project
$(DOXYGEN) $(DOCDIR)Doxyfile-project
$(DOCDIR)html: $(DOCDIR)xml
$(SPHINXBUILD) -M html "$(DOCDIR)source" "$(DOCDIR)"
.PHONY: coverage
coverage: $(TESTDIR)cpfloat_test.c libpcg
$(CC) $(CFLAGS) $(CCOVFLAGS) -o $(TESTDIR)cpfloat_test $< \
$(CHECKLIBS) $(CLIBS) $(PCG_FLAGS)
$(TESTDIR)cpfloat_test
$(CP) $(TESTDIR)cpfloat_test.c .
$(CCOV) cpfloat_test.c
.PHONY: example
example: $(BINDIR)example_manuscript
$(BINDIR)example_manuscript: $(EXAMPLEDIR)example_manuscript.c libpcg $(BINDIR)
$(CC) $(CFLAGS) $(COPTIM) -o $@ $< $(CLIBS) $(PCG_FLAGS)
.PHONY: cleanall
cleanall: clean cleanlib cleandeps cleantest cleancoverage cleandocs
.PHONY: clean
clean:
$(RM) $(BINDIR)*
.PHONY: cleanlib
cleanlib:
$(RM) -r $(BUILDDIR)*
.PHONY: cleandeps
cleandep:
cd $(DEPSDIR)pcg-c; make clean
.PHONY: cleantest
cleantest:
$(RM) $(TESTDIR)cpfloat_test $(TESTDIR)*.c $(TESTDIR)*.log
.PHONY: cleancoverage
cleancoverage:
$(RM) cpfloat_test.c cpfloat_test.log *.gcno *.gcda *.gcov
.PHONY: cleandocs
cleandocs:
$(RM) -r $(DOCDIR)Doxyfile $(DOCDIR)xml
$(RM) -r $(DOCDIR)html $(DOCDIR)source/cpfloat
license.spdx:
$(UTILDIR)generate_spdx.sh > $@
# CPFloat - Custom Precision Floating-point numbers.
#
# Copyright 2020 Massimiliano Fasi and Mantas Mikaitis
#
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this library; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA