ifeq ($(origin CC),default)
CC=gcc
endif
CFLAGS+=-pedantic -Wall -Werror -Wextra -Wno-unused-parameter \
-I. -std=c99 $(DFLAGS$(DEBUG))
CSFLAGS=$(CFLAGS) -fPIC
export CC CFLAGS
DFLAGS=-O3 -funroll-loops -finline-functions
DFLAGSN=$(DFLAGS)
DFLAGSY=-g -DDEBUG=1
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)
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-test:
if which docker ; \
then \
docker run --rm -it \
"$(shell docker build -f tests/linux/Dockerfile -q .)" ; \
fi
$(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
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
format-py:
@ echo "Formatting Python source files ..."
find . -type f -name '*.py' -print0 | \
xargs -0 yapf --style=pep8 -i
format: format-c format-py
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 tests/*~ tests/gmon.out examples/*~
make -C tests/gmp-compat-test clean
rm -f $(TARGETS) $(EXAMPLES)