makefile.unix facelift

This commit is contained in:
Karel Miko 2017-05-02 20:54:41 +02:00 committed by Steffen Jaeckel
parent bf45ea66e5
commit bb4a051e40

View File

@ -1,44 +1,46 @@
# MAKEFILE for bsd make # MAKEFILE that is intended to be compatible with any kind of make (GNU make, BDS make , ...)
# #
# Tom St Denis # Please do not use here neither any special make syntax nor any unusual tools/utilities!
# Compiler and Linker Names ### USAGE:
CC=cc #
LD=ld # make -f makefile.unix all
# ./test
# make -f makefile.unix install
#
#OR:
#
# make -f makefile.unix CFLAGS="-O3 -DUSE_LTM -DLTM_DESC -I/path/to/libtommath" EXTRALIBS=/path/to/libtommath/libtommath.a all
# ./test
# make -f makefile.unix DESTDIR=/opt/libtom install
#
# Archiver [makes .a files] #The following can be overridden from command line e.g. "make -f makefile.unix CC=gcc ARFLAGS=rcs"
AR=ar CC ?= cc
ARFLAGS=r LD ?= ld
AR ?= ar
ARFLAGS ?= r
RANLIB ?= ranlib
CFLAGS ?= -O2 -DUSE_LTM -DLTM_DESC -I../libtommath
EXTRALIBS ?= ../libtommath/libtommath.a
DESTDIR ?= /usr/local
# Compilation flags. Note the += does not write over the user's CFLAGS! #Compilation flags
CFLAGS = -c -I./testprof/ -I./src/headers/ -DLTC_SOURCE -O2 ${CFLAGS_OPTS} -o $@ LTC_CFLAGS = $(CFLAGS) -Isrc/headers -Itestprof -DLTC_SOURCE
LTC_LDFLAGS = $(LDFLAGS) $(EXTRALIBS)
VERSION=1.17
VERSION_MAJ=1
VERSION_MIN=17
LIBNAME=libtomcrypt.a #Libraries to be created
LIBTEST=libtomcrypt_prof.a LIBMAIN_S =libtomcrypt.a
LIBTEST_S=$(LIBTEST) LIBTEST_S =libtomcrypt_prof.a
LIBMAIN_D =libtomcrypt.so.0.0.$(VERSION_MAJ)$(VERSION_MIN)
#The following will be symlinks to $(LIBMAIN_D)
LIBMAIN_L1=libtomcrypt.so.0
LIBMAIN_L2=libtomcrypt.so
HASH=hashsum # List of objects to compile (all goes to libtomcrypt.a)
CRYPT=encrypt
SMALL=small
PROF=x86_prof
TV=tv_gen
TIMING=timing
TEST=test
#LIBPATH-The directory for libtomcrypt to be installed to.
#INCPATH-The directory to install the header files for libtomcrypt.
#DATAPATH-The directory to install the pdf docs.
LIBPATH=/usr/local/lib
INCPATH=/usr/local/include
DATAPATH=/usr/local/share/doc/libtomcrypt/pdf
#Who do we install as?
USER=root
GROUP=wheel
#List of objects to compile.
#START_INS
OBJECTS=src/ciphers/aes/aes.o src/ciphers/aes/aes_enc.o src/ciphers/anubis.o src/ciphers/blowfish.o \ OBJECTS=src/ciphers/aes/aes.o src/ciphers/aes/aes_enc.o src/ciphers/anubis.o src/ciphers/blowfish.o \
src/ciphers/camellia.o src/ciphers/cast5.o src/ciphers/des.o src/ciphers/kasumi.o src/ciphers/khazad.o \ src/ciphers/camellia.o src/ciphers/cast5.o src/ciphers/des.o src/ciphers/kasumi.o src/ciphers/khazad.o \
src/ciphers/kseed.o src/ciphers/multi2.o src/ciphers/noekeon.o src/ciphers/rc2.o src/ciphers/rc5.o \ src/ciphers/kseed.o src/ciphers/multi2.o src/ciphers/noekeon.o src/ciphers/rc2.o src/ciphers/rc5.o \
@ -190,36 +192,35 @@ src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_setup.o src/stream
src/stream/rc4/rc4.o src/stream/rc4/rc4_test.o src/stream/sober128/sober128.o \ src/stream/rc4/rc4.o src/stream/rc4/rc4_test.o src/stream/sober128/sober128.o \
src/stream/sober128/sober128_test.o src/stream/sober128/sober128_test.o
# List of test objects to compile (all goes to libtomcrypt_prof.a)
TOBJECTS=testprof/base64_test.o testprof/cipher_hash_test.o testprof/der_tests.o testprof/dh_test.o \
testprof/dsa_test.o testprof/ecc_test.o testprof/file_test.o testprof/katja_test.o testprof/mac_test.o \
testprof/misc_test.o testprof/modes_test.o testprof/multi_test.o testprof/no_prng.o \
testprof/pkcs_1_eme_test.o testprof/pkcs_1_emsa_test.o testprof/pkcs_1_oaep_test.o \
testprof/pkcs_1_pss_test.o testprof/pkcs_1_test.o testprof/rotate_test.o testprof/rsa_test.o \
testprof/store_test.o testprof/test_driver.o testprof/x86_prof.o
# The following headers will be installed by "make install"
HEADERS=src/headers/tomcrypt.h src/headers/tomcrypt_argchk.h src/headers/tomcrypt_cfg.h \ HEADERS=src/headers/tomcrypt.h src/headers/tomcrypt_argchk.h src/headers/tomcrypt_cfg.h \
src/headers/tomcrypt_cipher.h src/headers/tomcrypt_custom.h src/headers/tomcrypt_hash.h \ src/headers/tomcrypt_cipher.h src/headers/tomcrypt_custom.h src/headers/tomcrypt_hash.h \
src/headers/tomcrypt_mac.h src/headers/tomcrypt_macros.h src/headers/tomcrypt_math.h \ src/headers/tomcrypt_mac.h src/headers/tomcrypt_macros.h src/headers/tomcrypt_math.h \
src/headers/tomcrypt_misc.h src/headers/tomcrypt_pk.h src/headers/tomcrypt_pkcs.h \ src/headers/tomcrypt_misc.h src/headers/tomcrypt_pk.h src/headers/tomcrypt_pkcs.h \
src/headers/tomcrypt_prng.h testprof/tomcrypt_test.h src/headers/tomcrypt_prng.h
#END_INS #this is necessary for compatibility with BSD make (namely on OpenBSD)
.SUFFIXES: .o .c
TESTOBJECTS=demos/test.o .c.o:
HASHOBJECTS=demos/hashsum.o $(CC) $(LTC_CFLAGS) -c $< -o $@
CRYPTOBJECTS=demos/encrypt.o
SMALLOBJECTS=demos/small.o
TVS=demos/tv_gen.o
TIMINGS=demos/timing.o
TESTS=demos/test.o
#Files left over from making the crypt.pdf. #The default rule for make builds the libtomcrypt.a library (static)
LEFTOVERS=*.dvi *.log *.aux *.toc *.idx *.ilg *.ind *.out default: $(LIBMAIN_S)
#Compressed filenames #SPECIAL: AES come in two flavours... enc+dec and enc-only
COMPRESSED=crypt-$(VERSION).tar.bz2 crypt-$(VERSION).zip
#The default rule for make builds the libtomcrypt library.
default:library
#ciphers come in two flavours... enc+dec and enc
src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
$(CC) $(CFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o $(CC) $(LTC_CFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
#These are the rules to make certain object files. #SPECIAL: these are the rules to make certain object files
src/ciphers/aes/aes.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c src/ciphers/aes/aes.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
src/ciphers/twofish/twofish.o: src/ciphers/twofish/twofish.c src/ciphers/twofish/twofish_tab.c src/ciphers/twofish/twofish.o: src/ciphers/twofish/twofish.c src/ciphers/twofish/twofish_tab.c
src/hashes/whirl/whirl.o: src/hashes/whirl/whirl.c src/hashes/whirl/whirltab.c src/hashes/whirl/whirl.o: src/hashes/whirl/whirl.c src/hashes/whirl/whirltab.c
@ -228,56 +229,64 @@ src/hashes/sha2/sha512_224.o: src/hashes/sha2/sha512.c src/hashes/sha2/sha512_22
src/hashes/sha2/sha512_256.o: src/hashes/sha2/sha512.c src/hashes/sha2/sha512_256.c src/hashes/sha2/sha512_256.o: src/hashes/sha2/sha512.c src/hashes/sha2/sha512_256.c
src/hashes/sha2/sha256.o: src/hashes/sha2/sha256.c src/hashes/sha2/sha224.c src/hashes/sha2/sha256.o: src/hashes/sha2/sha256.c src/hashes/sha2/sha224.c
#This rule makes the libtomcrypt library. #Dependencies on *.h
library: $(LIBNAME) $(OBJECTS): $(HEADERS)
$(TOBJECTS): $(HEADERS) testprof/tomcrypt_test.h
.PHONY: testprof/$(LIBTEST) #Create libtomcrypt_prof.a
testprof/$(LIBTEST): $(LIBTEST_S): $(TOBJECTS)
cd testprof ; CFLAGS="$(CFLAGS)" LIBTEST_S=$(LIBTEST_S) CC="$(CC)" LD="$(LD)" AR="$(AR)" RANLIB="$(RANLIB)" $(MAKE) $(AR) $(ARFLAGS) $@ $(TOBJECTS)
$(RANLIB) $@
$(LIBNAME): $(OBJECTS) #Create libtomcrypt.a
$(LIBMAIN_S): $(OBJECTS)
$(AR) $(ARFLAGS) $@ $(OBJECTS) $(AR) $(ARFLAGS) $@ $(OBJECTS)
$(RANLIB) $@ $(RANLIB) $@
#This rule makes the hash program included with libtomcrypt #Create libtomcrypt.so
hashsum: library $(HASHOBJECTS) $(LIBMAIN_D): $(OBJECTS)
$(CC) $(HASHOBJECTS) $(LIBNAME) $(EXTRALIBS) -o $(HASH) $(WARN) $(CC) -shared -Wl,-soname=$(LIBMAIN_L1) $(OBJECTS) $(LTC_LDFLAGS) -o $@
#makes the crypt program #Demo tools/utilities
crypt: library $(CRYPTOBJECTS) hashsum: demos/hashsum.o $(LIBMAIN_S)
$(CC) $(CRYPTOBJECTS) $(LIBNAME) $(EXTRALIBS) -o $(CRYPT) $(WARN) $(CC) $< $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
crypt: demos/crypt.o $(LIBMAIN_S)
$(CC) $< $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
small: demos/small.o $(LIBMAIN_S)
$(CC) $< $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
tv_gen: demos/tv_gen.o $(LIBMAIN_S)
$(CC) $< $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
#makes the small program #Tests + timing tests
small: library $(SMALLOBJECTS) timing: demos/timing.o $(LIBTEST_S) $(LIBMAIN_S)
$(CC) $(SMALLOBJECTS) $(LIBNAME) $(EXTRALIBS) -o $(SMALL) $(WARN) $(CC) $< $(LIBTEST_S) $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
@echo "NOTICE: start the timing tests by: ./timing"
tv_gen: library $(TVS) test: demos/test.o $(LIBMAIN_S) $(LIBTEST_S)
$(CC) $(LDFLAGS) $(TVS) $(LIBNAME) $(EXTRALIBS) -o $(TV) $(CC) $< $(LIBTEST_S) $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
@echo "NOTICE: start the tests by: ./test"
timing: library testprof/$(LIBTEST) $(TIMINGS) all: $(LIBMAIN_S) $(LIBMAIN_D) $(LIBTEST_S) hashsum crypt small tv_gen timing test
$(CC) $(LDFLAGS) $(TIMINGS) testprof/$(LIBTEST) $(LIBNAME) $(EXTRALIBS) -o $(TIMING)
.PHONY: test #NOTE: as this makefile works also on cygwin, thus we need to delete *.exe
test: library testprof/$(LIBTEST) $(TESTS) clean:
$(CC) $(LDFLAGS) $(TESTS) testprof/$(LIBTEST) $(LIBNAME) $(EXTRALIBS) -o $(TEST) -@rm -f $(OBJECTS)
-@rm -f $(LIBMAIN_S) $(LIBMAIN_D) $(LIBTEST_S)
-@rm -f testprof/*.o demos/*.o lib*.so lib*.so.*
-@rm -f test tv_gen hashsum crypt small timing
-@rm -f test.exe tv_gen.exe hashsum.exe crypt.exe small.exe timing.exe
all_test: test tv_gen hashsum crypt small timing install_static: $(LIBMAIN_S) $(HEADERS)
@mkdir -p $(DESTDIR)/include $(DESTDIR)/lib/pkgconfig
@cp $(LIBMAIN_S) $(DESTDIR)/lib/
@cp $(HEADERS) $(DESTDIR)/include/
@sed -e 's,^prefix=.*,prefix=$(DESTDIR),' -e 's,^Version:.*,Version: $(VERSION),' libtomcrypt.pc.in > $(DESTDIR)/lib/pkgconfig/libtomcrypt.pc
#This rule installs the library and the header files. This must be run install_dynamic: $(LIBMAIN_D) $(HEADERS)
#as root in order to have a high enough permission to write to the correct @mkdir -p $(DESTDIR)/include $(DESTDIR)/lib/pkgconfig
#directories and to set the owner and group to root. @cp $(LIBMAIN_D) $(DESTDIR)/lib/
install: library @cp $(HEADERS) $(DESTDIR)/include/
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH) @ln -sf $(LIBMAIN_D) $(DESTDIR)/lib/$(LIBMAIN_L1)
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH) @ln -sf $(LIBMAIN_D) $(DESTDIR)/lib/$(LIBMAIN_L2)
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(DATAPATH) @sed -e 's,^prefix=.*,prefix=$(DESTDIR),' -e 's,^Version:.*,Version: $(VERSION),' libtomcrypt.pc.in > $(DESTDIR)/lib/pkgconfig/libtomcrypt.pc
install -g $(GROUP) -o $(USER) $(LIBNAME) $(DESTDIR)$(LIBPATH)
install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH)
install_test: testprof/$(LIBTEST) install: install_static install_dynamic
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH)
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH)
install -g $(GROUP) -o $(USER) testprof/$(LIBTEST) $(DESTDIR)$(LIBPATH)
# $Source$
# $Revision$
# $Date$