#
#  Makefile.in
#
#  Written by Jari Ruusu, February 18 2007
#
#  Copyright 2002-2007 by Jari Ruusu.
#  Redistribution of this file is permitted under the GNU Public License.
#

CC = @CC@ @CFLAGS@ @DEFS@ -D_GNU_SOURCE=1 -D_FILE_OFFSET_BITS=64
LINK = @CC@ @LDFLAGS@
prefix = @prefix@
exec_prefix = @exec_prefix@
@SET_MAKE@

aespipe: aespipe.o aes.o md5.o sha512.o rmd160.o
	$(LINK) -o aespipe aespipe.o aes.o md5.o sha512.o rmd160.o @LIBS@
x86 i586: aespipe.o aes-x86.o md5-x86.o sha512.o rmd160.o
	$(LINK) -o aespipe aespipe.o aes-x86.o md5-x86.o sha512.o rmd160.o @LIBS@
amd64: aespipe.o aes-amd64.o md5-amd64.o sha512.o rmd160.o
	$(LINK) -o aespipe aespipe.o aes-amd64.o md5-amd64.o sha512.o rmd160.o @LIBS@
aespipe.o: aespipe.c aes.h md5.h sha512.h rmd160.h
	$(CC) -o aespipe.o -c aespipe.c
aes.o: aes.c aes.h
	$(CC) -DCONFIGURE_DETECTS_BYTE_ORDER=1 -DDATA_ALWAYS_ALIGNED=1 -o aes.o -c aes.c
aes-x86.o: aes-x86.S aes.h
	$(CC) -o aes-x86.o -c aes-x86.S
aes-amd64.o: aes-amd64.S aes.h
	$(CC) -o aes-amd64.o -c aes-amd64.S
md5.o: md5.c md5.h
	$(CC) -o md5.o -c md5.c
md5-x86.o: md5-x86.S md5.h
	$(CC) -o md5-x86.o -c md5-x86.S
md5-amd64.o: md5-amd64.S md5.h
	$(CC) -o md5-amd64.o -c md5-amd64.S
sha512.o: sha512.c sha512.h
	$(CC) -o sha512.o -c sha512.c
rmd160.o: rmd160.c rmd160.h
	$(CC) -o rmd160.o -c rmd160.c

clean:
	rm -f *.o aespipe test-file[12345] config.log config.status configure.lineno
	rm -f -r test-dir1 autom4te.cache
distclean: clean
	rm -f Makefile

install:
	mkdir -p @bindir@
	rm -f @bindir@/aespipe
	cp aespipe @bindir@/aespipe
	mkdir -p @mandir@/man1
	rm -f @mandir@/man1/aespipe.1
	cp aespipe.1 @mandir@/man1/aespipe.1

tests:
	dd if=/dev/zero of=test-file1 bs=1024 count=33
	echo 09876543210987654321 >test-file4
	./aespipe -p 3 -e AES128 <test-file1 >test-file3 3<test-file4
	echo 12345678901234567890 >test-file4
	$(MAKE) test-part2 CT=AES128 HF=sha256 ITER=0  GK= MD=7c1cfd4fdd0d7cc847dd0942a2d48e48 MD5WORK=test-part@MD5WORKPART@
	$(MAKE) test-part2 CT=AES192 HF=sha384 ITER=0  GK= MD=51c91bcc04ee2a4ca00310b519b3228c MD5WORK=test-part@MD5WORKPART@
	$(MAKE) test-part2 CT=AES256 HF=sha512 ITER=0  GK= MD=1bf92ee337b653cdb32838047dec00fc MD5WORK=test-part@MD5WORKPART@
	$(MAKE) test-part2 CT=AES256 HF=rmd160 ITER=0  GK= MD=c85eb59da18876ae71ebd838675c6ef4 MD5WORK=test-part@MD5WORKPART@
	$(MAKE) test-part2 CT=AES256 HF=sha512 ITER=10 GK= MD=dadad48a6d3d9b9914199626ed7b710c MD5WORK=test-part@MD5WORKPART@
	@GPGWORKPART@mkdir test-dir1
	@GPGWORKPART@$(MAKE) test-part2 CT=AES128 HF=sha256 ITER=0 GK="-K gpgkey1.asc -G test-dir1" MD=fa5c9a84bc8f6257830c3cbe60294c69 MD5WORK=test-part@MD5WORKPART@
	@GPGWORKPART@$(MAKE) test-part2 CT=AES192 HF=sha384 ITER=0 GK="-K gpgkey1.asc -G test-dir1" MD=ddec9544a36100156aef353ec2bf9740 MD5WORK=test-part@MD5WORKPART@
	@GPGWORKPART@$(MAKE) test-part2 CT=AES256 HF=sha512 ITER=0 GK="-K gpgkey1.asc -G test-dir1" MD=cb38b603f96f0deac1891d423983d69c MD5WORK=test-part@MD5WORKPART@
	@GPGWORKPART@$(MAKE) test-part2 CT=AES128 HF=sha256 ITER=0 GK="-K gpgkey2.asc -G test-dir1" MD=f9825b79873f5c439ae9371c1a929a6c MD5WORK=test-part@MD5WORKPART@
	@GPGWORKPART@$(MAKE) test-part2 CT=AES192 HF=sha384 ITER=0 GK="-K gpgkey2.asc -G test-dir1" MD=489991b779213f60219f09c575c08247 MD5WORK=test-part@MD5WORKPART@
	@GPGWORKPART@$(MAKE) test-part2 CT=AES256 HF=sha512 ITER=0 GK="-K gpgkey2.asc -G test-dir1" MD=2a1d0d3fce83fbe5f3edcca95fbab3b7 MD5WORK=test-part@MD5WORKPART@
	@GPGWORKPART@$(MAKE) test-part2 CT=AES128 HF=sha256 ITER=0 GK="-K gpgkey3.asc -G test-dir1" MD=fabe7422f534820838dfd4571ba14ade MD5WORK=test-part@MD5WORKPART@
	@GPGWORKPART@$(MAKE) test-part2 CT=AES192 HF=sha384 ITER=0 GK="-K gpgkey3.asc -G test-dir1" MD=3eadc976525f9df7e18d56676ec730c8 MD5WORK=test-part@MD5WORKPART@
	@GPGWORKPART@$(MAKE) test-part2 CT=AES256 HF=sha512 ITER=0 GK="-K gpgkey3.asc -G test-dir1" MD=3be488a60dd77bcab9fbeba4a428c3d5 MD5WORK=test-part@MD5WORKPART@
	echo 1234567890123456789012345678901 >test-file4
	$(MAKE) test-part2 CT=AES HF=unhashed1 ITER=0 GK= MD=293b09053055af7ca5235dc6a5bc0b74 MD5WORK=test-part@MD5WORKPART@
	echo 12345678901234567890123456789012 >test-file4
	$(MAKE) test-part2 CT=AES HF=unhashed1 ITER=0 GK= MD=6b157917570250ef4370bf9acae49279 MD5WORK=test-part@MD5WORKPART@
	echo 123456789012345678901234567890123456789012 >test-file4
	$(MAKE) test-part2 CT=AES HF=unhashed1 ITER=0 GK= MD=6b157917570250ef4370bf9acae49279 MD5WORK=test-part@MD5WORKPART@
	echo 1234567890123456789012345678901234567890123 >test-file4
	$(MAKE) test-part2 CT=AES HF=unhashed1 ITER=0 GK= MD=e12fd55fbae9fc0e03517593e253e239 MD5WORK=test-part@MD5WORKPART@
	rm -f -r test-file[12345] test-dir1
	@echo "*** Test results ok ***"
test-part2:
	./aespipe -p 3 -e $(CT) -H $(HF) -C $(ITER) $(GK) <test-file3 >test-file1 3<test-file4
	$(MAKE) $(MD5WORK)
	cmp test-file2 test-file5
	./aespipe -d -P test-file4 -e $(CT) -H $(HF) -C $(ITER) $(GK) <test-file1 >test-file2
	cmp test-file3 test-file2
test-part3:
	md5sum test-file1 >test-file2
	echo "$(MD)  test-file1" >test-file5
test-part4:
	md5 test-file1 >test-file2
	echo "MD5 (test-file1) = $(MD)" >test-file5
test-part5:
	echo "NO MD5 TEST" >test-file2
	echo "NO MD5 TEST" >test-file5

.PHONY: aespipe x86 i586 amd64 clean distclean install tests test-part2 test-part3 test-part4 test-part5
