xref: /llvm-project/polly/lib/External/isl/imath/Makefile (revision 658eb9e14264d48888ade0e3daf0b648f76c3f0e)
1##
2## Name:     Makefile
3## Purpose:  Makefile for imath library and associated tools
4## Author:   M. J. Fromberger
5##
6## Copyright (C) 2002-2008 Michael J. Fromberger, All Rights Reserved.
7##
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:
14##
15## The above copyright notice and this permission notice shall be included in
16## all copies or substantial portions of the Software.
17##
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
24## IN THE SOFTWARE.
25##
26
27# --- begin configuration section ---
28
29## Generic settings for systems with GCC (default)
30## To build with debugging, add DEBUG=Y on the "make" command line.
31ifeq ($(origin CC),default)
32CC=gcc
33endif
34CFLAGS+=-pedantic -Wall -Werror -Wextra -Wno-unused-parameter \
35	-I. -std=c99 $(DFLAGS$(DEBUG))
36CSFLAGS=$(CFLAGS) -fPIC
37#LIBS=
38
39# These are needed to build the GMP compatibility tests.
40export CC CFLAGS
41
42DFLAGS=-O3 -funroll-loops -finline-functions
43DFLAGSN=$(DFLAGS)
44DFLAGSY=-g -DDEBUG=1
45
46# --- end of configuration section ---
47
48TARGETS=bintest bug-swap imtest imtimer rtest
49HDRS=imath.h imrat.h iprime.h imdrover.h rsamath.h gmp_compat.h
50SRCS=$(HDRS:.h=.c) $(TARGETS:=.c)
51OBJS=$(SRCS:.c=.o)
52OTHER=LICENSE ChangeLog Makefile doc.md doc.md.in \
53	tools/findthreshold.py tools/mkdoc.py .dockerignore
54VPATH += examples tests
55EXAMPLES=basecvt findprime imcalc input pi randprime rounding rsakey
56
57.PHONY: all test clean distclean
58.SUFFIXES: .so .md
59
60.c.o:
61	$(CC) $(CFLAGS) -c $<
62
63.c.so:
64	$(CC) $(CSFLAGS) -o $@ -c $<
65
66all: objs examples test
67
68objs: $(OBJS)
69
70check: test gmp-compat-test
71	@ echo "Completed running imath and gmp-compat unit tests"
72
73test: imtest pi bug-swap doc.md
74	@ echo ""
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."
77	@ echo ""
78	(cd tests && ./test.sh)
79
80gmp-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"
84
85docker-test:
86	if which docker ; \
87	then \
88		docker run --rm -it \
89		"$(shell docker build -f tests/linux/Dockerfile -q .)" ; \
90	fi
91
92$(EXAMPLES):%: imath.o imrat.o iprime.o %.o
93	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
94
95$(TARGETS):%: imath.o %.o
96	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
97
98examples: $(EXAMPLES)
99
100libimath.so: imath.so imrat.so gmp_compat.so
101	$(CC) $(CFLAGS) -shared -o $@ $^
102
103imtest: imtest.o imath.o imrat.o imdrover.o iprime.o
104
105rtest: rtest.o imath.o rsamath.o
106
107# Requires clang-format: https://clang.llvm.org/docs/ClangFormat.html
108format-c:
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
112
113# Requires yapf: pip install yapf
114format-py:
115	@ echo "Formatting Python source files ..."
116	find . -type f -name '*.py' -print0 | \
117		xargs -0 yapf --style=pep8 -i
118
119# Format source files.
120format: format-c format-py
121
122# Generate documentation from header comments.
123# This rule depends on the header files to ensure the docs get updated when the
124# headers change.
125doc.md: doc.md.in imath.h imrat.h tools/mkdoc.py
126	tools/mkdoc.py $< $@
127
128clean distclean:
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)
132