makefile_include.mk 4.1 KB

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