-
Notifications
You must be signed in to change notification settings - Fork 20
/
Makefile
140 lines (113 loc) · 4.37 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
##
## Name: Makefile
## Purpose: Makefile for imath library and associated tools
## Author: M. J. Fromberger
##
## Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to
## deal in the Software without restriction, including without limitation the
## rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
## sell copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in
## all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
## IN THE SOFTWARE.
##
# --- begin configuration section ---
## Generic settings for systems with GCC (default)
## To build with debugging, add DEBUG=Y on the "make" command line.
ifeq ($(origin CC),default)
CC=gcc
endif
CFLAGS+=-pedantic -Wall -Werror -Wextra -Wno-unused-parameter \
-I. -std=c99 $(DFLAGS$(DEBUG))
CSFLAGS=$(CFLAGS) -fPIC
#LIBS=
# These are needed to build the GMP compatibility tests.
export CC CFLAGS
DFLAGS=-O3 -funroll-loops -finline-functions
DFLAGSN=$(DFLAGS)
DFLAGSY=-g -DDEBUG=1
# --- end of configuration section ---
TARGETS=bintest bug-swap imtest imtimer rtest
HDRS=imath.h imrat.h iprime.h imdrover.h rsamath.h gmp_compat.h
SRCS=$(HDRS:.h=.c) $(TARGETS:=.c)
OBJS=$(SRCS:.c=.o)
OTHER=LICENSE ChangeLog Makefile doc.md doc.md.in \
tools/findthreshold.py tools/mkdoc.py .dockerignore
VPATH += examples tests
EXAMPLES=basecvt findprime imcalc input pi randprime rounding rsakey
.PHONY: all test clean distclean
.SUFFIXES: .so .md
.c.o:
$(CC) $(CFLAGS) -c $<
.c.so:
$(CC) $(CSFLAGS) -o $@ -c $<
all: objs examples test
objs: $(OBJS)
# N.B.: With a stock installation of Python 2 on macOS, this test may fail
# because SIP may block its attempt to load the shared library. If you see
# this error on macOS:
#
# Reason: unsafe use of relative rpath libimath.so
# in imath_test.so with restricted binary
#
# try the Homebrew version of Python 2: brew install python@2
#
check: test gmp-compat-test
@ echo "Completed running imath and gmp-compat unit tests"
test: imtest pi bug-swap doc.md
@ echo ""
@ echo "Running tests, you should not see any 'FAILED' lines here."
@ echo "If you do, please see doc.txt for how to report a bug."
@ echo ""
(cd tests && ./test.sh)
gmp-compat-test: libimath.so
@ echo "Running gmp-compat unit tests"
@ echo "Printing progress after every 100,000 tests"
make -C tests/gmp-compat-test TESTS="-p 100000 random.tests"
docker-image: clean
docker build -t imath/test-runner -f tests/linux/Dockerfile .
docker-test: docker-image
docker run --rm -it imath/test-runner:latest
$(EXAMPLES):%: imath.o imrat.o iprime.o %.o
$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
$(TARGETS):%: imath.o %.o
$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
examples: $(EXAMPLES)
libimath.so: imath.so imrat.so gmp_compat.so
$(CC) $(CFLAGS) -shared -o $@ $^
imtest: imtest.o imath.o imrat.o imdrover.o iprime.o
rtest: rtest.o imath.o rsamath.o
# Requires clang-format: https://clang.llvm.org/docs/ClangFormat.html
format-c:
@ echo "Formatting C source files and headers ..."
find . -type f -name '*.h' -o -name '*.c' -print0 | \
xargs -0 clang-format --style=Google -i
# Requires yapf: pip install yapf
format-py:
@ echo "Formatting Python source files ..."
find . -type f -name '*.py' -print0 | \
xargs -0 yapf --style=pep8 -i
# Format source files.
format: format-c format-py
# Generate documentation from header comments.
# This rule depends on the header files to ensure the docs get updated when the
# headers change.
doc.md: doc.md.in imath.h imrat.h tools/mkdoc.py
tools/mkdoc.py $< $@
clean distclean:
rm -f -- *.o *.so *.pyc *~ core gmon.out examples/*~
rm -f -- tests/*~ tests/gmon.out
make -C tests/gmp-compat-test clean
rm -f $(TARGETS) $(EXAMPLES)