CFLAGS	= @CFLAGS@
CPPFLAGS = @DEFS@ -Iinclude -I../include @CPPFLAGS@
LDFLAGS	= @LDFLAGS@ -L. -lcanlock
CC	= @CC@
PRELIB	= @LIB_PREFIX@
o	= .@OBJEXT@
ARCHIVE = @AR@ @ARFLAGS@
RANLIB  = @RANLIB@
RM	= rm

LIBOBJS = src/secret.o src/usha.o src/sha1.o src/sha224-256.o src/sha384-512.o src/hmac.o src/base64.o src/canlock.o
LOCKLIB = $(PRELIB)canlock.a

.c$o :
	@SHOW_CC@
	@ECHO_CC@$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

all : shatest canlocktest canlock

canlock : util/canlock.c $(LOCKLIB)
	@SHOW_CC@
	@ECHO_CC@$(CC) $(CPPFLAGS) $(CFLAGS) util/$@.c -o $@ $(LDFLAGS)

canlocktest : test/canlocktest.c $(LOCKLIB)
	@SHOW_CC@
	@ECHO_CC@$(CC) $(CPPFLAGS) $(CFLAGS) test/$@.c -o $@ $(LDFLAGS)

shatest : test/hkdf.o $(LOCKLIB)
	@SHOW_CC@
	@ECHO_CC@$(CC) $(CPPFLAGS) $(CFLAGS) test/$@.c -o $@ test/hkdf.o $(LDFLAGS)

src/base64.o : src/base64.c include/base64.h
src/canlock.o : src/canlock.c include/canlock.h
src/secret.o : src/secret.c include/canlock.h
src/hmac.o : src/hmac.c include/sha.h
src/usha.o : src/usha.c include/sha.h
src/sha1.o : src/sha1.c include/sha.h
src/sha224-256.o : src/sha224-256.c include/sha.h
src/sha384-512.o : src/sha384-512.c include/sha.h
test/hkdf.o : test/hkdf.c include/sha.h

lib : $(LOCKLIB)
$(LOCKLIB) : $(LIBOBJS)
	@-$(RM) -f $(LOCKLIB)
	$(ARCHIVE) $(LOCKLIB) $(LIBOBJS)
	$(RANLIB) $(LOCKLIB)

clean :
	@-$(RM) -f src/*.o test/*.o test/*.out *.gmon gmon.*

distclean : clean
	@-$(RM) -f *.a canlock canlocktest shatest *.exe
	@-$(RM) -rf canlock.dSYM canlocktest.dSYM shatest.dSYM

test : canlocktest shatest
	@echo "shatest: "
	@./shatest -p
	@echo
	@echo "canlocktest: "
	@./canlocktest
