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,85 @@ 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
36+ SHARED := $(PIC)
4437
45- LTCOMPILE = $(TGTLIBTOOL) --mode=compile --tag=CC $(CC)
46- INSTALL_CMD = $(TGTLIBTOOL) --mode=install install
47- UNINSTALL_CMD = $(TGTLIBTOOL) --mode=uninstall rm
38+ ifeq ($(PLATFORM), Darwin)
39+ SHARED += -dynamiclib
40+ TARGET := $(NAME).dylib
41+ else ifeq ($(OS), Windows_NT)
42+ SHARED += -shared
43+ TARGET := $(NAME).dll
44+ else
45+ SHARED += -shared
46+ TARGET := $(NAME).so
47+ endif
4848
4949#Output filenames for various targets.
5050ifndef LIBNAME
51- LIBNAME=libtomcrypt.la
51+ LIBNAME = $(TARGET).$(VERSION_LT)
5252endif
5353
54-
5554include makefile_include.mk
5655
56+ .PHONY: check install install_bins uninstall
57+
58+ .bin/.tag: bin.in
59+ mkdir -p .bin
60+ touch $@
5761
5862#ciphers come in two flavours... enc+dec and enc
5963src/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
64+ $(CC ) $(LTC_CFLAGS) $(PIC ) $(CPPFLAGS ) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
6165
6266.c.o:
63- $(LTCOMPILE) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -o $@ -c $<
64-
65- LOBJECTS = $(OBJECTS:.o=.lo)
67+ $(CC) $(LTC_CFLAGS) $(PIC) $(CPPFLAGS) -o $@ -c $<
6668
6769$(LIBNAME): $(OBJECTS)
68- $(TGTLIBTOOL) --mode=link --tag=CC $(CC) $(LTC_LDFLAGS) $(LOBJECTS) $(EXTRALIBS) -o $@ -rpath $(LIBPATH) -version-info $(VERSION_LT) $(NO_UNDEFINED)
70+ $(CC) $(LTC_LDFLAGS) $(OBJECTS) $(EXTRALIBS) $(SHARED) -Wl,-soname,$(TARGET).$(VERSION_MAJOR) $(NO_UNDEFINED) -o $@
71+
72+ $(TARGET).$(VERSION_MAJOR) $(TARGET): $(LIBNAME)
73+ ln -sf $< $@
6974
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)
75+ .bin/$(TEST): $(TARGET).$(VERSION_MAJOR) $(TARGET) $(TOBJECTS) .bin/.tag
76+ $(CC) $(LTC_LDFLAGS) $(TOBJECTS) -L. -ltomcrypt $(EXTRALIBS) $(NO_UNDEFINED) -o $@
77+
78+ test: $(call print-help,test,Builds the library and the 'test' application to run all self-tests) .bin/$(TEST)
79+ $(INSTALL_CMD) -m 755 bin.in $@
7280
7381# build the demos from a template
7482define 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)
83+ .bin/$(1): demos/$(1).o $$(TARGET).$$(VERSION_MAJOR) $$(TARGET) .bin/.tag
84+ $$(CC) $$(LTC_LDFLAGS) $$< -L. -ltomcrypt $$(EXTRALIBS) $(NO_UNDEFINED) -o $$@
85+
86+ $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) .bin/$(1)
87+ $$(INSTALL_CMD) -m 755 bin.in $(1)
7788endef
7889
7990$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
8091
8192install: $(call print-help,install,Installs the library + headers + pkg-config file) .common_install
93+ ln -sf $(LIBNAME) $(DESTDIR)/$(LIBPATH)/$(TARGET).$(VERSION_MAJOR)
94+ ln -sf $(LIBNAME) $(DESTDIR)/$(LIBPATH)/$(TARGET)
8295 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/
96+ $(INSTALL_CMD) -p -d $(DESTDIR)$(LIBPATH)/pkgconfig
97+ $(INSTALL_CMD) -p -m 644 libtomcrypt.pc $(DESTDIR)$(LIBPATH)/pkgconfig/
8598
86- install_bins: $(call print-help,install_bins,Installs the useful demos ($(USEFUL_DEMOS))) .common_install_bins
99+ install_bins: $(call print-help,install_bins,Installs the useful demos ($(USEFUL_DEMOS))) $(USEFUL_DEMOS) $(DESTDIR)$(BINPATH)
100+ $(INSTALL_CMD) -p -m 775 $(foreach demo, $(strip $(USEFUL_DEMOS)),.bin/$(demo)) $(DESTDIR)$(BINPATH)
87101
88102uninstall: $(call print-help,uninstall,Uninstalls the library + headers + pkg-config file) .common_uninstall
89- rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtomcrypt.pc
103+ $(UNINSTALL_CMD) $(DESTDIR)/$(LIBPATH)/$(TARGET).$(VERSION_MAJOR)
104+ $(UNINSTALL_CMD) $(DESTDIR)/$(LIBPATH)/$(TARGET)
105+ $(UNINSTALL_CMD) $(DESTDIR)$(LIBPATH)/pkgconfig/libtomcrypt.pc
90106
91107# ref: $Format:%D$
92108# git commit: $Format:%H$
0 commit comments