makefile.shared 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # MAKEFILE for linux GCC
  2. #
  3. # This makefile produces a shared object.
  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. INSTALL_CMD := install
  25. UNINSTALL_CMD := rm -f
  26. NAME := libtomcrypt
  27. PIC := -fPIC
  28. SHARED := $(PIC)
  29. ifeq ($(UNAME), Darwin)
  30. NO_UNDEFINED := -Wl,-undefined,error
  31. SHARED += -dynamiclib
  32. else
  33. NO_UNDEFIED := -Wl,--no-undefined
  34. SHARED += -shared
  35. endif
  36. ifeq ($(PLATFORM), Darwin)
  37. TARGET := $(NAME).dylib
  38. else ifeq ($(OS), Windows_NT)
  39. TARGET := $(NAME).dll
  40. else
  41. TARGET := $(NAME).so
  42. endif
  43. #Output filenames for various targets.
  44. ifndef LIBNAME
  45. LIBNAME = $(TARGET).$(VERSION_LT)
  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. .PHONY: check install install_bins uninstall
  67. .bin/.tag: bin.in
  68. mkdir -p .bin
  69. touch $@
  70. #ciphers come in two flavours... enc+dec and enc
  71. src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
  72. $(CC) $(LTC_CFLAGS) $(PIC) $(CPPFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
  73. src/ciphers/aes/aes_enc_desc.o: src/ciphers/aes/aes_desc.c
  74. $(CC) $(LTC_CFLAGS) $(PIC) $(CPPFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes_desc.c -o src/ciphers/aes/aes_enc_desc.o
  75. .c.o:
  76. $(CC) $(LTC_CFLAGS) $(PIC) $(CPPFLAGS) -o $@ -c $<
  77. $(LIBNAME): $(OBJECTS)
  78. $(CC) $(LTC_LDFLAGS) $(OBJECTS) $(EXTRALIBS) $(SHARED) -Wl,-soname,$(TARGET).$(VERSION_MAJOR) $(NO_UNDEFINED) -o $@
  79. $(TARGET).$(VERSION_MAJOR) $(TARGET): $(LIBNAME)
  80. ln -sf $< $@
  81. .bin/$(TEST): $(TARGET).$(VERSION_MAJOR) $(TARGET) $(TOBJECTS) .bin/.tag
  82. $(CC) $(LTC_LDFLAGS) $(TOBJECTS) -L. -ltomcrypt $(EXTRALIBS) $(NO_UNDEFINED) -o $@
  83. test: $(call print-help,test,Builds the library and the 'test' application to run all self-tests) .bin/$(TEST)
  84. $(INSTALL_CMD) -m 755 bin.in $@
  85. # build the demos from a template
  86. define DEMO_template
  87. .bin/$(1): demos/$(1).o $$(TARGET).$$(VERSION_MAJOR) $$(TARGET) .bin/.tag
  88. $$(CC) $$(LTC_LDFLAGS) $$< -L. -ltomcrypt $$(EXTRALIBS) $(NO_UNDEFINED) -o $$@
  89. $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) .bin/$(1)
  90. $$(INSTALL_CMD) -m 755 bin.in $(1)
  91. endef
  92. $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
  93. install: $(call print-help,install,Installs the library + headers + pkg-config file) .common_install
  94. ln -sf $(LIBNAME) $(DESTDIR)/$(LIBPATH)/$(TARGET).$(VERSION_MAJOR)
  95. ln -sf $(LIBNAME) $(DESTDIR)/$(LIBPATH)/$(TARGET)
  96. sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION_PC),' -e 's,^libdir=.*,libdir=$(LIBPATH),' \
  97. -e 's,^includedir=.*,includedir=$(INCPATH),' \
  98. -e 's,@PKG_CONFIG_LIBS@,$(LTC_PKG_CONFIG_LIBS),' \
  99. -e 's,@PKG_CONFIG_CFLAGS@,$(LTC_PKG_CONFIG_CFLAGS),' libtomcrypt.pc.in > libtomcrypt.pc
  100. $(INSTALL_CMD) -p -d $(DESTDIR)$(LIBPATH)/pkgconfig
  101. $(INSTALL_CMD) -p -m 644 libtomcrypt.pc $(DESTDIR)$(LIBPATH)/pkgconfig/
  102. install_bins: $(call print-help,install_bins,Installs the useful demos ($(USEFUL_DEMOS))) $(USEFUL_DEMOS) $(DESTDIR)$(BINPATH)
  103. $(INSTALL_CMD) -p -m 775 $(foreach demo, $(strip $(USEFUL_DEMOS)),.bin/$(demo)) $(DESTDIR)$(BINPATH)
  104. uninstall: $(call print-help,uninstall,Uninstalls the library + headers + pkg-config file) .common_uninstall
  105. $(UNINSTALL_CMD) $(DESTDIR)/$(LIBPATH)/$(TARGET).$(VERSION_MAJOR)
  106. $(UNINSTALL_CMD) $(DESTDIR)/$(LIBPATH)/$(TARGET)
  107. $(UNINSTALL_CMD) $(DESTDIR)$(LIBPATH)/pkgconfig/libtomcrypt.pc