PKGDIR ?= ../..
L4DIR  ?= $(PKGDIR)/../../..

SYSTEMS     = $(SYSTEMS_PLAIN)
TARGET      = libmd.a libmd.so libmd.p.a
PC_FILENAME = libmd

SRC_C = md2.c md2hl.c md4.c md4hl.c md5.c md5hl.c rmd160.c \
        rmd160hl.c sha1.c sha1hl.c sha2.c sha224hl.c \
        sha256hl.c sha384hl.c sha512_256hl.c sha512hl.c

CONTRIB_INCDIR = libmd

CONTRIB_SRC_DIR = $(SRC_DIR)/../contrib/include

PRIVATE_INCDIR = $(SRC_DIR)

vpath %.c $(SRC_DIR)/../contrib/src

include $(L4DIR)/mk/lib.mk

AM_V_GEN = $(VERBOSE)

# from src/Makefile.am
md2hl.c: helper.c
	@$(GEN_MESSAGE)
	$(AM_V_GEN) $(SED) -e 's/hashinc/md2.h/g' -e 's/HASH/MD2/g' $^ > $@

md4hl.c: helper.c
	@$(GEN_MESSAGE)
	$(AM_V_GEN) $(SED) -e 's/hashinc/md4.h/g' -e 's/HASH/MD4/g' $^ > $@

md5hl.c: helper.c
	@$(GEN_MESSAGE)
	$(AM_V_GEN) $(SED) -e 's/hashinc/md5.h/g' -e 's/HASH/MD5/g' $^ > $@

rmd160hl.c: helper.c
	@$(GEN_MESSAGE)
	$(AM_V_GEN) $(SED) -e 's/hashinc/rmd160.h/g' -e 's/HASH/RMD160/g' $^ > $@

sha1hl.c: helper.c
	@$(GEN_MESSAGE)
	$(AM_V_GEN) $(SED) -e 's/hashinc/sha1.h/g' -e 's/HASH/SHA1/g' $^ > $@

sha224hl.c: helper.c
	@$(GEN_MESSAGE)
	$(AM_V_GEN) $(SED) -e 's/hashinc/sha2.h/g' -e 's/HASH/SHA224/g' \
	                -e 's/SHA[0-9][0-9][0-9]_CTX/SHA2_CTX/g' $^ > $@

sha256hl.c: helper.c
	@$(GEN_MESSAGE)
	$(AM_V_GEN) $(SED) -e 's/hashinc/sha2.h/g' -e 's/HASH/SHA256/g' \
	                -e 's/SHA[0-9][0-9][0-9]_CTX/SHA2_CTX/g' $^ > $@

sha384hl.c: helper.c
	@$(GEN_MESSAGE)
	$(AM_V_GEN) $(SED) -e 's/hashinc/sha2.h/g' -e 's/HASH/SHA384/g' \
	                -e 's/SHA[0-9][0-9][0-9]_CTX/SHA2_CTX/g' $^ > $@

sha512hl.c: helper.c
	@$(GEN_MESSAGE)
	$(AM_V_GEN) $(SED) -e 's/hashinc/sha2.h/g' -e 's/HASH/SHA512/g' \
	                -e 's/SHA[0-9][0-9][0-9]_CTX/SHA2_CTX/g' $^ > $@

sha512_256hl.c: helper.c
	@$(GEN_MESSAGE)
	$(AM_V_GEN) $(SED) -e 's/hashinc/sha2.h/g' -e 's/HASH/SHA512_256/g' \
	                -e 's/SHA512_256_CTX/SHA2_CTX/g' $^ > $@

libmd_la_helper_sources = \
        md2hl.c \
        md4hl.c \
        md5hl.c \
        rmd160hl.c \
        sha1hl.c \
        sha224hl.c \
        sha256hl.c \
        sha384hl.c \
        sha512hl.c \
        sha512_256hl.c \
        # EOL

clean::
	$(VERBOSE)$(RM) $(libmd_la_helper_sources)
