@SET_MAKE@

srcdir = @srcdir@
VPATH = @srcdir@

top_srcdir = @top_srcdir@

INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = $(INSTALL_PROGRAM) -s
MKDIR_P = @MKDIR_P@

include ../config.make

PRE_CPPFLAGS = -I.. -I$(top_srcdir)
PRE_LDFLAGS = -L..

HOGWEED_TARGETS = pkcs1-conv$(EXEEXT)
TARGETS = sexp-conv$(EXEEXT) nettle-hash$(EXEEXT) nettle-lfib-stream$(EXEEXT) \
	  @IF_HOGWEED@ $(HOGWEED_TARGETS)

all: $(TARGETS)

sexp_conv_SOURCES = sexp-conv.c input.c output.c parse.c \
	getopt.c getopt1.c misc.c
pkcs1_conv_SOURCES = pkcs1-conv.c getopt.c getopt1.c misc.c
nettle_hash_SOURCES = nettle-hash.c getopt.c getopt1.c misc.c

SOURCES = $(sexp_conv_SOURCES) nettle-hash.c nettle-lfib-stream.c pkcs1-conv.c

DISTFILES = $(SOURCES) Makefile.in getopt.h input.h misc.h output.h parse.h

sexp_conv_OBJS = $(sexp_conv_SOURCES:.c=.$(OBJEXT))
sexp-conv$(EXEEXT): $(sexp_conv_OBJS) ../libnettle.a
	$(LINK) $(sexp_conv_OBJS) -lnettle $(LIBS) -o $@

nettle-lfib-stream$(EXEEXT): nettle-lfib-stream.$(OBJEXT) ../libnettle.a
	$(LINK) nettle-lfib-stream.$(OBJEXT) -lnettle $(LIBS) -o $@

pkcs1_conv_OBJS = $(pkcs1_conv_SOURCES:.c=.$(OBJEXT))
pkcs1-conv$(EXEEXT): $(pkcs1_conv_OBJS) ../libnettle.a ../libhogweed.a
	$(LINK) $(pkcs1_conv_OBJS) -lhogweed -lnettle $(LIBS) -o $@

# FIXME: Avoid linking with gmp
nettle_hash_OBJS = $(nettle_hash_SOURCES:.c=.$(OBJEXT))
nettle-hash$(EXEEXT): $(nettle_hash_OBJS) ../libnettle.a
	$(LINK) $(nettle_hash_OBJS) -lnettle $(LIBS) -o $@


.c.$(OBJEXT):
	$(COMPILE) -c $< && $(DEP_PROCESS)


Makefile: $(srcdir)/Makefile.in ../config.status
	cd .. && $(SHELL) ./config.status tools/$@

check:
	true

install: $(TARGETS)
	$(MKDIR_P) $(DESTDIR)$(bindir)
	for f in $(TARGETS) ; do \
	  $(INSTALL_PROGRAM) $$f $(DESTDIR)$(bindir) ; \
	done

uninstall:
	for f in $(TARGETS) ; do \
	  rm -f $(DESTDIR)$(bindir)/$$f ; \
	done

# NOTE: I'd like to use $^, but that's a GNU extension. $? should be
# more portable, equivalent for phony targets.
distdir: $(DISTFILES)
	cp $? $(distdir)

clean:
	-rm -f $(TARGETS) *.o

distclean: clean
	-rm -f Makefile *.d

tags:
	etags -o $(srcdir)/TAGS --include $(top_srcdir) $(srcdir)/*.c $(srcdir)/*.h

@DEP_INCLUDE@ $(SOURCES:.c=.$(OBJEXT).d)
