3 ## Purpose: Makefile for imath library and associated tools
4 ## Author: M. J. Fromberger
6 ## Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
8 ## Permission is hereby granted, free of charge, to any person obtaining a copy
9 ## of this software and associated documentation files (the "Software"), to
10 ## deal in the Software without restriction, including without limitation the
11 ## rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 ## sell copies of the Software, and to permit persons to whom the Software is
13 ## furnished to do so, subject to the following conditions:
15 ## The above copyright notice and this permission notice shall be included in
16 ## all copies or substantial portions of the Software.
18 ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 ## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 ## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 ## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 # --- begin configuration section ---
29 ## Generic settings for systems with GCC (default)
30 ## To build with debugging, add DEBUG=Y on the "make" command line.
31 ifeq ($(origin CC
),default
)
34 CFLAGS
+=-pedantic
-Wall
-Werror
-Wextra
-Wno-unused-parameter \
35 -I.
-std
=c99
$(DFLAGS
$(DEBUG
))
36 CSFLAGS
=$(CFLAGS
) -fPIC
39 # These are needed to build the GMP compatibility tests.
42 DFLAGS
=-O3
-funroll-loops
-finline-functions
46 # --- end of configuration section ---
48 TARGETS
=bintest bug-swap imtest imtimer rtest
49 HDRS
=imath.h imrat.h iprime.h imdrover.h rsamath.h gmp_compat.h
50 SRCS
=$(HDRS
:.h
=.c
) $(TARGETS
:=.c
)
52 OTHER
=LICENSE ChangeLog Makefile doc.md doc.md.in \
53 tools
/findthreshold.py tools
/mkdoc.py .dockerignore
54 VPATH
+= examples tests
55 EXAMPLES
=basecvt findprime imcalc input pi randprime rounding rsakey
57 .PHONY
: all test clean distclean
64 $(CC
) $(CSFLAGS
) -o
$@
-c
$<
66 all: objs examples
test
70 check: test gmp-compat-test
71 @ echo
"Completed running imath and gmp-compat unit tests"
73 test: imtest pi bug-swap doc.md
75 @ echo
"Running tests, you should not see any 'FAILED' lines here."
76 @ echo
"If you do, please see doc.txt for how to report a bug."
78 (cd tests
&& .
/test.sh
)
80 gmp-compat-test
: libimath.so
81 @ echo
"Running gmp-compat unit tests"
82 @ echo
"Printing progress after every 100,000 tests"
83 make
-C tests
/gmp-compat-test TESTS
="-p 100000 random.tests"
89 "$(shell docker build -f tests/linux/Dockerfile -q .)" ; \
92 $(EXAMPLES
):%: imath.o imrat.o iprime.o
%.o
93 $(CC
) $(CFLAGS
) -o
$@
$^
$(LIBS
)
95 $(TARGETS
):%: imath.o
%.o
96 $(CC
) $(CFLAGS
) -o
$@
$^
$(LIBS
)
100 libimath.so
: imath.so imrat.so gmp_compat.so
101 $(CC
) $(CFLAGS
) -shared
-o
$@
$^
103 imtest
: imtest.o imath.o imrat.o imdrover.o iprime.o
105 rtest
: rtest.o imath.o rsamath.o
107 # Requires clang-format: https://clang.llvm.org/docs/ClangFormat.html
109 @ echo
"Formatting C source files and headers ..."
110 find .
-type f
-name
'*.h' -o
-name
'*.c' -print0 | \
111 xargs
-0 clang-format
--style
=Google
-i
113 # Requires yapf: pip install yapf
115 @ echo
"Formatting Python source files ..."
116 find .
-type f
-name
'*.py' -print0 | \
117 xargs
-0 yapf
--style
=pep8
-i
119 # Format source files.
120 format
: format-c format-py
122 # Generate documentation from header comments.
123 # This rule depends on the header files to ensure the docs get updated when the
125 doc.md
: doc.md.in imath.h imrat.h tools
/mkdoc.py
129 rm -f
*.o
*.so
*.pyc
*~ core gmon.out tests
/*~ tests
/gmon.out examples
/*~
130 make
-C tests
/gmp-compat-test
clean
131 rm -f
$(TARGETS
) $(EXAMPLES
)