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,34 +24,34 @@ 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
27+ INSTALL_CMD := install
28+ UNINSTALL_CMD := rm -f
29+
30+ NAME := libtomcrypt
31+ PIC := -fPIC
32+ SHARED := $(PIC)
33+
34+ ifeq ($(UNAME), Darwin)
35+ NO_UNDEFINED := -Wl,-undefined,error
36+ SHARED += -dynamiclib
2937else
30- ifndef LIBTOOL
31- ifeq ($(PLATFORM), Darwin)
32- TGTLIBTOOL:=glibtool
33- else
34- TGTLIBTOOL:=libtool
35- endif
36- else
37- TGTLIBTOOL=$(LIBTOOL)
38- endif
38+ NO_UNDEFIED := -Wl,--no-undefined
39+ SHARED += -shared
3940endif
4041
41- ifneq ($(findstring $(PLATFORM),CYGWIN MINGW32 MINGW64 MSYS),)
42- NO_UNDEFINED:=-no-undefined
42+ ifeq ($(PLATFORM), Darwin)
43+ TARGET := $(NAME).dylib
44+ else ifeq ($(OS), Windows_NT)
45+ TARGET := $(NAME).dll
46+ else
47+ TARGET := $(NAME).so
4348endif
4449
45- LTCOMPILE = $(TGTLIBTOOL) --mode=compile --tag=CC $(CC)
46- INSTALL_CMD = $(TGTLIBTOOL) --mode=install install
47- UNINSTALL_CMD = $(TGTLIBTOOL) --mode=uninstall rm
48-
4950#Output filenames for various targets.
5051ifndef LIBNAME
51- LIBNAME=libtomcrypt.la
52+ LIBNAME = $(TARGET).$(VERSION_LT)
5253endif
5354
54-
5555include makefile_include.mk
5656
5757ifneq ($(findstring -DLTM_DESC,$(LTC_CFLAGS)),)
@@ -74,40 +74,58 @@ endif
7474LTC_PKG_CONFIG_CFLAGS += $(PKG_CONFIG_CFLAGS)
7575LTC_PKG_CONFIG_LIBS += $(PKG_CONFIG_LIBS)
7676
77+ .PHONY: check install install_bins uninstall
78+
79+ .bin/.tag: bin.in
80+ mkdir -p .bin
81+ touch $@
82+
7783#ciphers come in two flavours... enc+dec and enc
7884src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
79- $(LTCOMPILE ) $(LTC_CFLAGS) $(CPPFLAGS ) $(LTC_LDFLAGS ) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
85+ $(CC ) $(LTC_CFLAGS) $(PIC ) $(CPPFLAGS ) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
8086src/ciphers/aes/aes_enc_desc.o: src/ciphers/aes/aes_desc.c
81- $(LTCOMPILE ) $(LTC_CFLAGS) $(CPPFLAGS ) $(LTC_LDFLAGS ) -DENCRYPT_ONLY -c src/ciphers/aes/aes_desc.c -o src/ciphers/aes/aes_enc_desc.o
87+ $(CC ) $(LTC_CFLAGS) $(PIC ) $(CPPFLAGS ) -DENCRYPT_ONLY -c src/ciphers/aes/aes_desc.c -o src/ciphers/aes/aes_enc_desc.o
8288
8389.c.o:
84- $(LTCOMPILE) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -o $@ -c $<
85-
86- LOBJECTS = $(OBJECTS:.o=.lo)
90+ $(CC) $(LTC_CFLAGS) $(PIC) $(CPPFLAGS) -o $@ -c $<
8791
8892$(LIBNAME): $(OBJECTS)
89- $(TGTLIBTOOL) --mode=link --tag=CC $(CC) $(LTC_LDFLAGS) $(LOBJECTS) $(EXTRALIBS) -o $@ -rpath $(LIBPATH) -version-info $(VERSION_LT) $(NO_UNDEFINED)
93+ $(CC) $(LTC_LDFLAGS) $(OBJECTS) $(EXTRALIBS) $(SHARED) -Wl,-soname,$(TARGET).$(VERSION_MAJOR) $(NO_UNDEFINED) -o $@
94+
95+ $(TARGET).$(VERSION_MAJOR) $(TARGET): $(LIBNAME)
96+ ln -sf $< $@
9097
91- test: $(call print-help,test,Builds the library and the 'test' application to run all self-tests) $(LIBNAME) $(TOBJECTS)
92- $(TGTLIBTOOL) --mode=link --tag=CC $(CC) $(LTC_LDFLAGS) -o $(TEST) $(TOBJECTS) $(LIBNAME) $(EXTRALIBS)
98+ .bin/$(TEST): $(TARGET).$(VERSION_MAJOR) $(TARGET) $(TOBJECTS) .bin/.tag
99+ $(CC) $(LTC_LDFLAGS) $(TOBJECTS) -L. -ltomcrypt $(EXTRALIBS) $(NO_UNDEFINED) -o $@
100+
101+ test: $(call print-help,test,Builds the library and the 'test' application to run all self-tests) .bin/$(TEST)
102+ $(INSTALL_CMD) -m 755 bin.in $@
93103
94104# build the demos from a template
95105define DEMO_template
96- $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1).o $$(LIBNAME)
97- $$(TGTLIBTOOL) --mode=link --tag=CC $$(CC) $$(LTC_LDFLAGS) $$^ $$(EXTRALIBS) -o $$@
106+ .bin/$(1): demos/$(1).o $$(TARGET).$$(VERSION_MAJOR) $$(TARGET) .bin/.tag
107+ $$(CC) $$(LTC_LDFLAGS) $$< -L. -ltomcrypt $$(EXTRALIBS) $(NO_UNDEFINED) -o $$@
108+
109+ $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) .bin/$(1)
110+ $$(INSTALL_CMD) -m 755 bin.in $(1)
98111endef
99112
100113$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
101114
102115install: $(call print-help,install,Installs the library + headers + pkg-config file) .common_install
116+ ln -sf $(LIBNAME) $(DESTDIR)/$(LIBPATH)/$(TARGET).$(VERSION_MAJOR)
117+ ln -sf $(LIBNAME) $(DESTDIR)/$(LIBPATH)/$(TARGET)
103118 sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION_PC),' -e 's,^libdir=.*,libdir=$(LIBPATH),' \
104119 -e 's,^includedir=.*,includedir=$(INCPATH),' \
105120 -e 's,@PKG_CONFIG_LIBS@,$(LTC_PKG_CONFIG_LIBS),' \
106121 -e 's,@PKG_CONFIG_CFLAGS@,$(LTC_PKG_CONFIG_CFLAGS),' libtomcrypt.pc.in > libtomcrypt.pc
107- install -p -d $(DESTDIR)$(LIBPATH)/pkgconfig
108- install -p -m 644 libtomcrypt.pc $(DESTDIR)$(LIBPATH)/pkgconfig/
122+ $(INSTALL_CMD) -p -d $(DESTDIR)$(LIBPATH)/pkgconfig
123+ $(INSTALL_CMD) -p -m 644 libtomcrypt.pc $(DESTDIR)$(LIBPATH)/pkgconfig/
109124
110- install_bins: $(call print-help,install_bins,Installs the useful demos ($(USEFUL_DEMOS))) .common_install_bins
125+ install_bins: $(call print-help,install_bins,Installs the useful demos ($(USEFUL_DEMOS))) $(USEFUL_DEMOS) $(DESTDIR)$(BINPATH)
126+ $(INSTALL_CMD) -p -m 775 $(foreach demo, $(strip $(USEFUL_DEMOS)),.bin/$(demo)) $(DESTDIR)$(BINPATH)
111127
112128uninstall: $(call print-help,uninstall,Uninstalls the library + headers + pkg-config file) .common_uninstall
113- rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtomcrypt.pc
129+ $(UNINSTALL_CMD) $(DESTDIR)/$(LIBPATH)/$(TARGET).$(VERSION_MAJOR)
130+ $(UNINSTALL_CMD) $(DESTDIR)/$(LIBPATH)/$(TARGET)
131+ $(UNINSTALL_CMD) $(DESTDIR)$(LIBPATH)/pkgconfig/libtomcrypt.pc
0 commit comments