makefile.shared 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # MAKEFILE for linux GCC
  2. #
  3. # This makefile produces a shared object and requires libtool to be installed.
  4. #
  5. # Thanks to Zed Shaw for helping debug this on BSD/OSX.
  6. # Tom St Denis
  7. #
  8. # (GNU make only)
  9. ### USAGE:
  10. #
  11. # CFLAGS="-DUSE_LTM -DLTM_DESC -I/path/to/libtommath" make -f makefile.shared all EXTRALIBS=/path/to/libtommath/libtommath.a
  12. # ./test
  13. # make -f makefile.shared PREFIX=/opt/libtom install
  14. #
  15. PLATFORM := $(shell uname | sed -e 's/_.*//')
  16. ### Observed uname outputs:
  17. # MINGW32_NT-6.2 (on MSYS/MINGW old)
  18. # MINGW64_NT-10.0-14393 (on MSYS new)
  19. # MSYS_NT-10.0-19042 (on MSYS2)
  20. # CYGWIN_NT-10.0 (on Cygwin 64bit)
  21. # CYGWIN_NT-6.2-WOW64 (on Cygwin 32bit)
  22. # Linux (on all Linux distros)
  23. # Darwin (on macOS, OS X)
  24. ifeq ($(LIBTOOL),rlibtool)
  25. TGTLIBTOOL:=slibtool-shared
  26. else
  27. ifndef LIBTOOL
  28. ifeq ($(PLATFORM), Darwin)
  29. TGTLIBTOOL:=glibtool
  30. else
  31. TGTLIBTOOL:=libtool
  32. endif
  33. else
  34. TGTLIBTOOL=$(LIBTOOL)
  35. endif
  36. endif
  37. ifneq ($(findstring $(PLATFORM),CYGWIN MINGW32 MINGW64 MSYS),)
  38. NO_UNDEFINED:=-no-undefined
  39. endif
  40. LTCOMPILE = $(TGTLIBTOOL) --mode=compile --tag=CC $(CC)
  41. INSTALL_CMD = $(TGTLIBTOOL) --mode=install install
  42. UNINSTALL_CMD = $(TGTLIBTOOL) --mode=uninstall rm
  43. #Output filenames for various targets.
  44. ifndef LIBNAME
  45. LIBNAME=libtomcrypt.la
  46. endif
  47. include makefile_include.mk
  48. ifneq ($(findstring -DLTM_DESC,$(LTC_CFLAGS)),)
  49. LTC_PKG_CONFIG_CFLAGS += -DLTM_DESC
  50. LTC_PKG_CONFIG_LIBS += -ltommath
  51. endif
  52. ifneq ($(findstring -DTFM_DESC,$(LTC_CFLAGS)),)
  53. LTC_PKG_CONFIG_CFLAGS += -DTFM_DESC
  54. LTC_PKG_CONFIG_LIBS += -ltfm
  55. endif
  56. ifneq ($(findstring -DGMP_DESC,$(LTC_CFLAGS)),)
  57. LTC_PKG_CONFIG_CFLAGS += -DGMP_DESC
  58. LTC_PKG_CONFIG_LIBS += -lgmp
  59. endif
  60. ifneq ($(findstring -DLTC_PTHREAD,$(LTC_CFLAGS)),)
  61. LTC_PKG_CONFIG_CFLAGS += -DLTC_PTHREAD
  62. endif
  63. # set PKG_CONFIG_CFLAGS and PKG_CONFIG_LIBS to what your environment requires
  64. LTC_PKG_CONFIG_CFLAGS += $(PKG_CONFIG_CFLAGS)
  65. LTC_PKG_CONFIG_LIBS += $(PKG_CONFIG_LIBS)
  66. #ciphers come in two flavours... enc+dec and enc
  67. src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
  68. $(LTCOMPILE) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
  69. src/ciphers/aes/aes_enc_desc.o: src/ciphers/aes/aes_desc.c
  70. $(LTCOMPILE) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes_desc.c -o src/ciphers/aes/aes_enc_desc.o
  71. .c.o:
  72. $(LTCOMPILE) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -o $@ -c $<
  73. LOBJECTS = $(OBJECTS:.o=.lo)
  74. $(LIBNAME): $(OBJECTS)
  75. $(TGTLIBTOOL) --mode=link --tag=CC $(CC) $(LTC_LDFLAGS) $(LOBJECTS) $(EXTRALIBS) -o $@ -rpath $(LIBPATH) -version-info $(VERSION_LT) $(NO_UNDEFINED)
  76. test: $(call print-help,test,Builds the library and the 'test' application to run all self-tests) $(LIBNAME) $(TOBJECTS)
  77. $(TGTLIBTOOL) --mode=link --tag=CC $(CC) $(LTC_LDFLAGS) -o $(TEST) $(TOBJECTS) $(LIBNAME) $(EXTRALIBS)
  78. # build the demos from a template
  79. define DEMO_template
  80. $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1).o $$(LIBNAME)
  81. $$(TGTLIBTOOL) --mode=link --tag=CC $$(CC) $$(LTC_LDFLAGS) $$^ $$(EXTRALIBS) -o $$@
  82. endef
  83. $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
  84. install: $(call print-help,install,Installs the library + headers + pkg-config file) .common_install
  85. sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION_PC),' -e 's,^libdir=.*,libdir=$(LIBPATH),' \
  86. -e 's,^includedir=.*,includedir=$(INCPATH),' \
  87. -e 's,@PKG_CONFIG_LIBS@,$(LTC_PKG_CONFIG_LIBS),' \
  88. -e 's,@PKG_CONFIG_CFLAGS@,$(LTC_PKG_CONFIG_CFLAGS),' libtomcrypt.pc.in > libtomcrypt.pc
  89. install -p -d $(DESTDIR)$(LIBPATH)/pkgconfig
  90. install -p -m 644 libtomcrypt.pc $(DESTDIR)$(LIBPATH)/pkgconfig/
  91. install_bins: $(call print-help,install_bins,Installs the useful demos ($(USEFUL_DEMOS))) .common_install_bins
  92. uninstall: $(call print-help,uninstall,Uninstalls the library + headers + pkg-config file) .common_uninstall
  93. rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtomcrypt.pc