# Makefile for building argon2.wasm

# If you run out of memory (ARGON2_MEMORY_ALLOCATION_ERROR) and it's not being caused by a memory leak, try increasing this.
TOTAL_MEMORY=48MB

CC=emcc
WASM=argon2.wasm

ARGON2_DIR=../../../../../libs/phc-winner-argon2

all: ${WASM}
clean:
	rm -f ${WASM}
${WASM}:
	${CC} \
    	"${ARGON2_DIR}/src/argon2.c" \
    	"${ARGON2_DIR}/src/core.c" \
    	"${ARGON2_DIR}/src/ref.c" \
    	"${ARGON2_DIR}/src/blake2/blake2b.c" \
    	-I "${ARGON2_DIR}/include" \
    	-DARGON2_NO_THREADS \
    	-flto \
    	-O3 \
    	--no-entry \
    	-s TOTAL_MEMORY=${TOTAL_MEMORY} \
    	-s EXPORTED_FUNCTIONS="['_argon2id_hash_raw', '_malloc', '_free']" \
    	-o ${WASM}
