11# MAKEFILE for linux GCC
22#
3- # This makefile produces a shared object and requires libtool to be installed .
3+ # This makefile produces a shared object.
44#
55# Thanks to Zed Shaw for helping debug this on BSD/OSX.
66# Tom St Denis
@@ -24,69 +24,87 @@ PLATFORM := $(shell uname | sed -e 's/_.*//')
2424# Linux (on all Linux distros)
2525# Darwin (on macOS, OS X)
2626
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
27+ ifneq ($(findstring $(PLATFORM),Linux CYGWIN MINGW32 MINGW64 MSYS),)
28+ NO_UNDEFINED := -Wl,--no-undefined
3929endif
4030
41- ifneq ($(findstring $(PLATFORM),CYGWIN MINGW32 MINGW64 MSYS),)
42- NO_UNDEFINED:=-no-undefined
43- endif
31+ INSTALL_CMD := install
32+ UNINSTALL_CMD := rm -f
33+
34+ NAME := libtomcrypt
35+ PIC := -fPIC
4436
45- LTCOMPILE = $(TGTLIBTOOL) --mode=compile --tag=CC $(CC)
46- INSTALL_CMD = $(TGTLIBTOOL) --mode=install install
47- UNINSTALL_CMD = $(TGTLIBTOOL) --mode=uninstall rm
37+ ifeq ($(PLATFORM), Darwin)
38+ SHARED += -dynamiclib
39+ TARGET := $(NAME).dylib
40+ else ifeq ($(OS), Windows_NT)
41+ SHARED += -shared
42+ TARGET := $(NAME).dll
43+ else
44+ SHARED += -shared
45+ TARGET := $(NAME).so
46+ endif
4847
4948#Output filenames for various targets.
5049ifndef LIBNAME
51- LIBNAME=libtomcrypt.la
50+ LIBNAME = $(TARGET).$(VERSION_LT)
5251endif
5352
54-
5553include makefile_include.mk
5654
55+ .PHONY: check install install_bins uninstall
56+
57+ .bin/.tag: bin.in
58+ mkdir -p .bin
59+ touch $@
5760
5861#ciphers come in two flavours... enc+dec and enc
5962src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
60- $(LTCOMPILE ) $(LTC_CFLAGS) $(CPPFLAGS ) $(LTC_LDFLAGS ) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
63+ $(CC ) $(LTC_CFLAGS) $(PIC ) $(CPPFLAGS ) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
6164
6265.c.o:
63- $(LTCOMPILE) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -o $@ -c $<
64-
65- LOBJECTS = $(OBJECTS:.o=.lo)
66+ $(CC) $(LTC_CFLAGS) $(PIC) $(CPPFLAGS) -o $@ -c $<
6667
6768$(LIBNAME): $(OBJECTS)
68- $(TGTLIBTOOL) --mode=link --tag=CC $(CC) $(LTC_LDFLAGS) $(LOBJECTS) $(EXTRALIBS) -o $@ -rpath $(LIBPATH) -version-info $(VERSION_LT) $(NO_UNDEFINED)
69+ $(CC) $(LTC_LDFLAGS) $(OBJECTS) $(EXTRALIBS) $(SHARED) -Wl,-soname,$(TARGET).$(VERSION_MAJOR) $(NO_UNDEFINED) -o $@
70+
71+ $(TARGET).$(VERSION_MAJOR): $(LIBNAME)
72+ ln -sf $< $@
6973
70- test: $(call print-help,test,Builds the library and the 'test' application to run all self-tests) $(LIBNAME) $(TOBJECTS)
71- $(TGTLIBTOOL) --mode=link --tag=CC $(CC) $(LTC_LDFLAGS) -o $(TEST) $(TOBJECTS) $(LIBNAME) $(EXTRALIBS)
74+ $(TARGET): $(LIBNAME)
75+ ln -sf $< $@
76+
77+ .bin/$(TEST): $(TARGET).$(VERSION_MAJOR) $(TARGET) $(TOBJECTS) .bin/.tag
78+ $(CC) $(LTC_LDFLAGS) $(TOBJECTS) -L. -ltomcrypt $(EXTRALIBS) $(NO_UNDEFINED) -o $@
79+
80+ test: $(call print-help,test,Builds the library and the 'test' application to run all self-tests) .bin/$(TEST)
81+ $(INSTALL_CMD) -m 755 bin.in $@
7282
7383# build the demos from a template
7484define DEMO_template
75- $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1).o $$(LIBNAME)
76- $$(TGTLIBTOOL) --mode=link --tag=CC $$(CC) $$(LTC_LDFLAGS) $$^ $$(EXTRALIBS) -o $(1)
85+ .bin/$(1): demos/$(1).o $$(TARGET).$$(VERSION_MAJOR) $$(TARGET) .bin/.tag
86+ $$(CC) $$(LTC_LDFLAGS) $$< -L. -ltomcrypt $$(EXTRALIBS) $(NO_UNDEFINED) -o $$@
87+
88+ $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) .bin/$(1)
89+ $$(INSTALL_CMD) -m 755 bin.in $(1)
7790endef
7891
7992$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
8093
8194install: $(call print-help,install,Installs the library + headers + pkg-config file) .common_install
95+ ln -sf $(LIBNAME) $(DESTDIR)/$(LIBPATH)/$(TARGET).$(VERSION_MAJOR)
96+ ln -sf $(LIBNAME) $(DESTDIR)/$(LIBPATH)/$(TARGET)
8297 sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION_PC),' libtomcrypt.pc.in > libtomcrypt.pc
83- install -p -d $(DESTDIR)$(LIBPATH)/pkgconfig
84- install -p -m 644 libtomcrypt.pc $(DESTDIR)$(LIBPATH)/pkgconfig/
98+ $(INSTALL_CMD) -p -d $(DESTDIR)$(LIBPATH)/pkgconfig
99+ $(INSTALL_CMD) -p -m 644 libtomcrypt.pc $(DESTDIR)$(LIBPATH)/pkgconfig/
85100
86- install_bins: $(call print-help,install_bins,Installs the useful demos ($(USEFUL_DEMOS))) .common_install_bins
101+ install_bins: $(call print-help,install_bins,Installs the useful demos ($(USEFUL_DEMOS))) $(USEFUL_DEMOS) $(DESTDIR)$(BINPATH)
102+ $(INSTALL_CMD) -p -m 775 $(foreach demo, $(strip $(USEFUL_DEMOS)),.bin/$(demo)) $(DESTDIR)$(BINPATH)
87103
88104uninstall: $(call print-help,uninstall,Uninstalls the library + headers + pkg-config file) .common_uninstall
89- rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtomcrypt.pc
105+ $(UNINSTALL_CMD) $(DESTDIR)/$(LIBPATH)/$(TARGET).$(VERSION_MAJOR)
106+ $(UNINSTALL_CMD) $(DESTDIR)/$(LIBPATH)/$(TARGET)
107+ $(UNINSTALL_CMD) $(DESTDIR)$(LIBPATH)/pkgconfig/libtomcrypt.pc
90108
91109# ref: $Format:%D$
92110# git commit: $Format:%H$
0 commit comments