Merge pull request #672 from libtom/some-fixes
[libtomcrypt.git] / makefile.shared
blob310840c99ef847a27b2c69df71bd7d3bf3797060
1 # MAKEFILE for linux GCC
3 # This makefile produces a shared object and requires libtool to be installed.
5 # Thanks to Zed Shaw for helping debug this on BSD/OSX.
6 # Tom St Denis
8 #  (GNU make only)
10 ### USAGE:
12 # CFLAGS="-DUSE_LTM -DLTM_DESC -I/path/to/libtommath" make -f makefile.shared all EXTRALIBS=/path/to/libtommath/libtommath.a
13 # ./test
14 # make -f makefile.shared PREFIX=/opt/libtom install
17 PLATFORM := $(shell uname | sed -e 's/_.*//')
18 ### Observed uname outputs:
19 # MINGW32_NT-6.2          (on MSYS/MINGW old)
20 # MINGW64_NT-10.0-14393   (on MSYS new)
21 # MSYS_NT-10.0-19042      (on MSYS2)
22 # CYGWIN_NT-10.0          (on Cygwin 64bit)
23 # CYGWIN_NT-6.2-WOW64     (on Cygwin 32bit)
24 # Linux                   (on all Linux distros)
25 # Darwin                  (on macOS, OS X)
27 ifeq ($(LIBTOOL),rlibtool)
28   TGTLIBTOOL:=slibtool-shared
29 else
30   ifndef LIBTOOL
31     ifeq ($(PLATFORM), Darwin)
32       TGTLIBTOOL:=glibtool
33     else
34       TGTLIBTOOL:=libtool
35     endif
36   else
37     TGTLIBTOOL=$(LIBTOOL)
38   endif
39 endif
41 ifneq ($(findstring $(PLATFORM),CYGWIN MINGW32 MINGW64 MSYS),)
42   NO_UNDEFINED:=-no-undefined
43 endif
45 LTCOMPILE = $(TGTLIBTOOL) --mode=compile --tag=CC $(CC)
46 INSTALL_CMD = $(TGTLIBTOOL) --mode=install install
47 UNINSTALL_CMD = $(TGTLIBTOOL) --mode=uninstall rm
49 #Output filenames for various targets.
50 ifndef LIBNAME
51    LIBNAME=libtomcrypt.la
52 endif
55 include makefile_include.mk
57 ifneq ($(findstring -DLTM_DESC,$(LTC_CFLAGS)),)
58 LTC_MPI_PROVIDERS_CFLAGS += -DLTM_DESC
59 LTC_MPI_PROVIDERS_LIBS += -ltommath
60 endif
61 ifneq ($(findstring -DTFM_DESC,$(LTC_CFLAGS)),)
62 LTC_MPI_PROVIDERS_CFLAGS += -DTFM_DESC
63 LTC_MPI_PROVIDERS_LIBS += -ltfm
64 endif
65 ifneq ($(findstring -DGMP_DESC,$(LTC_CFLAGS)),)
66 LTC_MPI_PROVIDERS_CFLAGS += -DGMP_DESC
67 LTC_MPI_PROVIDERS_LIBS += -lgmp
68 endif
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         $(LTCOMPILE) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -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         $(LTCOMPILE) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes_desc.c -o src/ciphers/aes/aes_enc_desc.o
76 .c.o:
77         $(LTCOMPILE) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -o $@ -c $<
79 LOBJECTS = $(OBJECTS:.o=.lo)
81 $(LIBNAME): $(OBJECTS)
82         $(TGTLIBTOOL) --mode=link --tag=CC $(CC) $(LTC_LDFLAGS) $(LOBJECTS) $(EXTRALIBS) -o $@ -rpath $(LIBPATH) -version-info $(VERSION_LT) $(NO_UNDEFINED)
84 test: $(call print-help,test,Builds the library and the 'test' application to run all self-tests) $(LIBNAME) $(TOBJECTS)
85         $(TGTLIBTOOL) --mode=link --tag=CC $(CC) $(LTC_LDFLAGS) -o $(TEST) $(TOBJECTS) $(LIBNAME) $(EXTRALIBS)
87 # build the demos from a template
88 define DEMO_template
89 $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1).o $$(LIBNAME)
90         $$(TGTLIBTOOL) --mode=link --tag=CC $$(CC) $$(LTC_LDFLAGS) $$^ $$(EXTRALIBS) -o $(1)
91 endef
93 $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
95 install: $(call print-help,install,Installs the library + headers + pkg-config file) .common_install
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,@MPI_PROVIDERS_LIBS@,$(LTC_MPI_PROVIDERS_LIBS),' \
99                 -e 's,@MPI_PROVIDERS_CFLAGS@,$(LTC_MPI_PROVIDERS_CFLAGS),' libtomcrypt.pc.in > libtomcrypt.pc
100         install -p -d $(DESTDIR)$(LIBPATH)/pkgconfig
101         install -p -m 644 libtomcrypt.pc $(DESTDIR)$(LIBPATH)/pkgconfig/
103 install_bins: $(call print-help,install_bins,Installs the useful demos ($(USEFUL_DEMOS))) .common_install_bins
105 uninstall: $(call print-help,uninstall,Uninstalls the library + headers + pkg-config file) .common_uninstall
106         rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtomcrypt.pc
108 # ref:         $Format:%D$
109 # git commit:  $Format:%H$
110 # commit time: $Format:%ai$