1# 2# Include makefile for libtommath 3# 4 5#version of library 6VERSION=1.2.0 7VERSION_PC=1.2.0 8VERSION_SO=3:0:2 9 10PLATFORM := $(shell uname | sed -e 's/_.*//') 11 12# default make target 13default: ${LIBNAME} 14 15# Compiler and Linker Names 16ifndef CROSS_COMPILE 17 CROSS_COMPILE= 18endif 19 20# We only need to go through this dance of determining the right compiler if we're using 21# cross compilation, otherwise $(CC) is fine as-is. 22ifneq (,$(CROSS_COMPILE)) 23ifeq ($(origin CC),default) 24CSTR := "\#ifdef __clang__\nCLANG\n\#endif\n" 25ifeq ($(PLATFORM),FreeBSD) 26 # XXX: FreeBSD needs extra escaping for some reason 27 CSTR := $$$(CSTR) 28endif 29ifneq (,$(shell echo $(CSTR) | $(CC) -E - | grep CLANG)) 30 CC := $(CROSS_COMPILE)clang 31else 32 CC := $(CROSS_COMPILE)gcc 33endif # Clang 34endif # cc is Make's default 35endif # CROSS_COMPILE non-empty 36 37# Dropbear passes these down 38#LD=$(CROSS_COMPILE)ld 39#AR=$(CROSS_COMPILE)ar 40#RANLIB=$(CROSS_COMPILE)ranlib 41 42ifndef MAKE 43# BSDs refer to GNU Make as gmake 44ifneq (,$(findstring $(PLATFORM),FreeBSD OpenBSD DragonFly NetBSD)) 45 MAKE=gmake 46else 47 MAKE=make 48endif 49endif 50 51LTM_CFLAGS += -I./ -Wall -Wsign-compare -Wextra -Wshadow 52 53# renamed for Dropbear to avoid clash with oss-fuzz $SANITIZER var 54ifdef LTM_SANITIZER 55LTM_CFLAGS += -fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=float-divide-by-zero 56endif 57 58ifndef NO_ADDTL_WARNINGS 59# additional warnings 60LTM_CFLAGS += -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align 61LTM_CFLAGS += -Wstrict-prototypes -Wpointer-arith 62endif 63 64ifdef CONV_WARNINGS 65LTM_CFLAGS += -std=c89 -Wconversion -Wsign-conversion 66ifeq ($(CONV_WARNINGS), strict) 67LTM_CFLAGS += -DMP_USE_ENUMS -Wc++-compat 68endif 69else 70LTM_CFLAGS += -Wsystem-headers 71endif 72 73ifdef COMPILE_DEBUG 74#debug 75LTM_CFLAGS += -g3 76endif 77 78ifdef COMPILE_SIZE 79#for size 80LTM_CFLAGS += -Os 81else 82 83ifndef IGNORE_SPEED 84#for speed 85LTM_CFLAGS += -O3 -funroll-loops 86 87#x86 optimizations [should be valid for any GCC install though] 88LTM_CFLAGS += -fomit-frame-pointer 89endif 90 91endif # COMPILE_SIZE 92 93ifneq ($(findstring clang,$(CC)),) 94LTM_CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header 95endif 96ifneq ($(findstring mingw,$(CC)),) 97LTM_CFLAGS += -Wno-shadow 98endif 99ifeq ($(PLATFORM), Darwin) 100LTM_CFLAGS += -Wno-nullability-completeness 101endif 102ifeq ($(PLATFORM), CYGWIN) 103LIBTOOLFLAGS += -no-undefined 104endif 105 106# add in the standard FLAGS 107LTM_CFLAGS += $(CFLAGS) 108LTM_LFLAGS += $(LFLAGS) 109LTM_LDFLAGS += $(LDFLAGS) 110LTM_LIBTOOLFLAGS += $(LIBTOOLFLAGS) 111 112 113ifeq ($(PLATFORM),FreeBSD) 114 _ARCH := $(shell sysctl -b hw.machine_arch) 115else 116 _ARCH := $(shell uname -m) 117endif 118 119# adjust coverage set 120ifneq ($(filter $(_ARCH), i386 i686 x86_64 amd64 ia64),) 121 COVERAGE = test_standalone timing 122 COVERAGE_APP = ./test && ./timing 123else 124 COVERAGE = test_standalone 125 COVERAGE_APP = ./test 126endif 127 128HEADERS_PUB=tommath.h 129HEADERS=tommath_private.h tommath_class.h tommath_superclass.h tommath_cutoffs.h $(HEADERS_PUB) 130 131#LIBPATH The directory for libtommath to be installed to. 132#INCPATH The directory to install the header files for libtommath. 133#DATAPATH The directory to install the pdf docs. 134DESTDIR ?= 135PREFIX ?= /usr/local 136LIBPATH ?= $(PREFIX)/lib 137INCPATH ?= $(PREFIX)/include 138DATAPATH ?= $(PREFIX)/share/doc/libtommath/pdf 139 140#make the code coverage of the library 141# 142coverage: LTM_CFLAGS += -fprofile-arcs -ftest-coverage -DTIMING_NO_LOGS 143coverage: LTM_LFLAGS += -lgcov 144coverage: LTM_LDFLAGS += -lgcov 145 146coverage: $(COVERAGE) 147 $(COVERAGE_APP) 148 149lcov: coverage 150 rm -f coverage.info 151 lcov --capture --no-external --no-recursion $(LCOV_ARGS) --output-file coverage.info -q 152 genhtml coverage.info --output-directory coverage -q 153 154# target that removes all coverage output 155cleancov-clean: 156 rm -f `find . -type f -name "*.info" | xargs` 157 rm -rf coverage/ 158 159# cleans everything - coverage output and standard 'clean' 160cleancov: cleancov-clean clean 161 162clean: 163 rm -f *.gcda *.gcno *.gcov *.bat *.o *.a *.obj *.lib *.exe *.dll etclib/*.o \ 164 demo/*.o test timing mtest_opponent mtest/mtest mtest/mtest.exe tuning_list \ 165 *.s mpi.c *.da *.dyn *.dpi tommath.tex `find . -type f | grep [~] | xargs` *.lo *.la 166 rm -rf .libs/ demo/.libs 167