makefile 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. # MAKEFILE for linux GCC
  2. #
  3. # Tom St Denis
  4. # Modified by Clay Culver
  5. #
  6. # (GNU make only)
  7. ifeq ($V,0)
  8. silent_echo= > /dev/null
  9. else
  10. silent_echo=
  11. endif
  12. ifeq ($V,1)
  13. silent=
  14. silent_stdout=
  15. silent_stderr=
  16. else
  17. silent=@
  18. silent_stdout= > /dev/null
  19. silent_stderr= 2> /dev/null
  20. endif
  21. PLATFORM := $(shell uname | sed -e 's/_.*//')
  22. # ranlib tools
  23. ifndef RANLIB
  24. RANLIB:=$(CROSS_COMPILE)ranlib
  25. endif
  26. INSTALL_CMD = install
  27. UNINSTALL_CMD = rm
  28. #Output filenames for various targets.
  29. ifndef LIBNAME
  30. LIBNAME=libtomcrypt.a
  31. endif
  32. include makefile_include.mk
  33. ifeq ($(COVERAGE),1)
  34. all_test: LIB_PRE = -Wl,--whole-archive
  35. all_test: LIB_POST = -Wl,--no-whole-archive
  36. LTC_CFLAGS += -fprofile-arcs -ftest-coverage
  37. LTC_EXTRALIBS += -lgcov
  38. endif
  39. LTC_EXTRALIBS += $(EXTRALIBS)
  40. #AES comes in two flavours... enc+dec and enc
  41. src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
  42. ifneq ($V,1)
  43. @echo " * ${CC} $@" ${silent_echo}
  44. endif
  45. ${silent} ${CC} ${LTC_CFLAGS} -DENCRYPT_ONLY -c $< -o $@
  46. src/ciphers/aes/aes_enc_desc.o: src/ciphers/aes/aes_desc.c
  47. ifneq ($V,1)
  48. @echo " * ${CC} $@" ${silent_echo}
  49. endif
  50. ${silent} ${CC} ${LTC_CFLAGS} -DENCRYPT_ONLY -c $< -o $@
  51. .c.o:
  52. ifneq ($V,1)
  53. @echo " * ${CC} $@" ${silent_echo}
  54. endif
  55. ${silent} ${CC} ${LTC_CFLAGS} -c $< -o $@
  56. $(LIBNAME): $(OBJECTS)
  57. ifneq ($V,1)
  58. @echo " * ${AR} $@" ${silent_echo}
  59. endif
  60. ${silent} $(AR) $(ARFLAGS) $@ $(OBJECTS)
  61. ifneq ($V,1)
  62. @echo " * ${RANLIB} $@" ${silent_echo}
  63. endif
  64. ${silent} $(RANLIB) $@
  65. test: $(call print-help,test,Builds the library and the 'test' application to run all self-tests) $(LIBNAME) $(TOBJECTS)
  66. ifneq ($V,1)
  67. @echo " * ${CC} $@" ${silent_echo}
  68. endif
  69. ${silent} $(CC) $(LTC_LDFLAGS) $(TOBJECTS) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(LTC_EXTRALIBS) -o $(TEST)
  70. # build the demos from a template
  71. define DEMO_template
  72. $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1).o $$(LIBNAME)
  73. ifneq ($V,1)
  74. @echo " * $${CC} $$@" ${silent_echo}
  75. endif
  76. $${silent} $$(CC) $$(LTC_LDFLAGS) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(LTC_EXTRALIBS) -o $$@
  77. endef
  78. $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
  79. #This rule installs the library and the header files. This must be run
  80. #as root in order to have a high enough permission to write to the correct
  81. #directories and to set the owner and group to root.
  82. install: $(call print-help,install,Installs the library and headers) .common_install
  83. install_bins: $(call print-help,install_bins,Installs the useful demos ($(USEFUL_DEMOS))) .common_install_bins
  84. uninstall: $(call print-help,uninstall,Uninstalls the library and headers) .common_uninstall
  85. profile:
  86. LTC_CFLAGS="$(LTC_CFLAGS) -fprofile-generate" $(MAKE) timing EXTRALIBS="$(LTC_EXTRALIBS) -lgcov"
  87. ./timing
  88. rm -f timing `find . -type f | grep [.][ao] | xargs`
  89. LTC_CFLAGS="$(LTC_CFLAGS) -fprofile-use" $(MAKE) timing EXTRALIBS="$(LTC_EXTRALIBS) -lgcov"
  90. # target that pre-processes all coverage data
  91. lcov-single-create:
  92. lcov --capture --no-external --directory src -q --output-file coverage_std.info
  93. # target that removes all coverage output
  94. cleancov-clean:
  95. rm -f `find . -type f -name "*.info" | xargs`
  96. rm -rf coverage/
  97. # merges all coverage_*.info files into coverage.info
  98. coverage.info:
  99. lcov `find -name 'coverage_*.info' -exec echo -n " -a {}" \;` -o coverage.info
  100. # generates html output from all coverage_*.info files
  101. lcov-html: coverage.info
  102. genhtml coverage.info --output-directory coverage -q
  103. # combines all necessary steps to create the coverage from a single testrun with e.g.
  104. # CFLAGS="-DUSE_LTM -DLTM_DESC -I../libtommath" EXTRALIBS="../libtommath/libtommath.a" make coverage -j9
  105. lcov-single:
  106. $(MAKE) cleancov-clean
  107. $(MAKE) lcov-single-create
  108. $(MAKE) coverage.info
  109. #make the code coverage of the library
  110. coverage: LTC_CFLAGS += -fprofile-arcs -ftest-coverage
  111. coverage: LTC_EXTRALIBS += -lgcov
  112. coverage: LIB_PRE = -Wl,--whole-archive
  113. coverage: LIB_POST = -Wl,--no-whole-archive
  114. coverage: $(call print-help,coverage,Create code-coverage of the library - but better use coverage.sh) test
  115. ./test
  116. # cleans everything - coverage output and standard 'clean'
  117. cleancov: cleancov-clean clean
  118. ifndef AMALGAM
  119. AMALGAM_FILTER_OUT = src/ciphers/aes/aes_enc.c src/ciphers/aes/aes_enc_desc.c
  120. TAB_SOURCES = src/ciphers/aes/aes_tab.c src/ciphers/safer/safer_tab.c src/hashes/whirl/whirltab.c src/stream/sober128/sober128tab.c
  121. SOURCES = $(filter-out $(AMALGAM_FILTER_OUT),$(OBJECTS:.o=.c))
  122. pre_gen/tomcrypt_amalgam.c: $(TAB_SOURCES) $(SOURCES)
  123. mkdir -p pre_gen
  124. printf "/*\n * This file has been auto-generated, do not edit!\n */\n\n" > $@
  125. printf "#define LTC_AES_TAB_C\n" >> $@
  126. printf "#define LTC_SAFER_TAB_C\n" >> $@
  127. printf "#define LTC_SOBER128TAB_C\n" >> $@
  128. printf "#define LTC_WHIRLTAB_C\n\n" >> $@
  129. printf "#include \"tomcrypt_private.h\"\n\n" >> $@
  130. cat $^ >> $@
  131. pre_gen: pre_gen/tomcrypt_amalgam.c
  132. .PHONY: pre_gen/tomcrypt_amalgam.c
  133. endif