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,82 @@ 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
5756
5857#ciphers come in two flavours... enc+dec and enc
5958src/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
59+ $(CC ) $(LTC_CFLAGS) $(PIC ) $(CPPFLAGS) $(LTC_LDFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
6160
6261.c.o:
63- $(LTCOMPILE) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -o $@ -c $<
64-
65- LOBJECTS = $(OBJECTS:.o=.lo)
62+ $(CC) $(LTC_CFLAGS) $(PIC) $(CPPFLAGS) $(LTC_LDFLAGS) -o $@ -c $<
6663
6764$(LIBNAME): $(OBJECTS)
68- $(TGTLIBTOOL) --mode=link --tag=CC $(CC) $(LTC_LDFLAGS) $(LOBJECTS) $(EXTRALIBS) -o $@ -rpath $(LIBPATH) -version-info $(VERSION_LT) $(NO_UNDEFINED)
65+ $(CC) $(LTC_LDFLAGS) $(OBJECTS) $(EXTRALIBS) $(SHARED) -Wl,-soname,$(TARGET).$(VERSION_MAJOR) $(NO_UNDEFINED) -o $@
66+ ln -sf $(LIBNAME) $(TARGET).$(VERSION_MAJOR)
67+ ln -sf $(LIBNAME) $(TARGET)
6968
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)
69+ tests/$(TEST): $(LIBNAME) $(TOBJECTS)
70+ $(CC) $(LTC_LDFLAGS) $(TOBJECTS) -L. -ltomcrypt $(EXTRALIBS) $(NO_UNDEFINED) -o $@
71+
72+ test: $(call print-help,test,Builds the library and the 'test' application to run all self-tests) tests/$(TEST) bin.in
73+ sed -e 's|@EXE@|tests/$@|' bin.in >
[email protected] 74+ $(INSTALL_CMD) -m 755
[email protected] $@
75+ 7276
7377# build the demos from a template
7478define 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)
79+ demos/$(1): demos/$(1).o $$(LIBNAME)
80+ $$(CC) $$(LTC_LDFLAGS) $$< -L. -ltomcrypt $$(EXTRALIBS) -o $$@
81+
82+ $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1) bin.in
83+ sed -e 's|@EXE@|demos/$(1)|' bin.in > $(1).out
84+ $$(INSTALL_CMD) -m 755 $(1).out $(1)
85+ @rm -f $(1).out
7786endef
7887
7988$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
8089
8190install: $(call print-help,install,Installs the library + headers + pkg-config file) .common_install
91+ ln -sf $(LIBNAME) $(DESTDIR)/$(LIBPATH)/$(TARGET).$(VERSION_MAJOR)
92+ ln -sf $(LIBNAME) $(DESTDIR)/$(LIBPATH)/$(TARGET)
8293 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/
94+ $(INSTALL_CMD) -p -d $(DESTDIR)$(LIBPATH)/pkgconfig
95+ $(INSTALL_CMD) -p -m 644 libtomcrypt.pc $(DESTDIR)$(LIBPATH)/pkgconfig/
8596
8697install_bins: $(call print-help,install_bins,Installs the useful demos ($(USEFUL_DEMOS))) .common_install_bins
8798
8899uninstall: $(call print-help,uninstall,Uninstalls the library + headers + pkg-config file) .common_uninstall
89- rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtomcrypt.pc
100+ $(UNINSTALL_CMD) $(DESTDIR)/$(LIBPATH)/$(TARGET).$(VERSION_MAJOR)
101+ $(UNINSTALL_CMD) $(DESTDIR)/$(LIBPATH)/$(TARGET)
102+ $(UNINSTALL_CMD) $(DESTDIR)$(LIBPATH)/pkgconfig/libtomcrypt.pc
90103
91104# ref: $Format:%D$
92105# git commit: $Format:%H$
0 commit comments