###################################################
# Vars filled in by ./configure
###################################################

CC		= @CC@
CFLAGS		= @CFLAGS@
LDFLAGS = @LDFLAGS@
DEFS  = @DEFS@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ 
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
SHELL = /bin/sh

# Location of files.
prefix		= @prefix@
exec_prefix	= @exec_prefix@
sysconfdir	= @sysconfdir@
localstatedir	= @localstatedir@
libdir		= @libdir@
bindir		= @bindir@
sbindir		= @sbindir@
mandir		= @mandir@
srcdir		= @srcdir@

###################################################
# Program make rules and vars
###################################################

TARGET = vrflash

# This prolly won't work if you're not using GNU make
# VER := $(shell grep '*versionstr' main.c | awk {'print $$4'} | sed 's/^"//g')
VER = 0.24

OBJS = main.o xmodem.o vrerror.o progress.o port.o etxack.o vrfile.o
CFILES = main.c xmodem.c vrerror.c progress.c port.c etxack.c vrfile.c
HFILES = main.h xmodem.h vrerror.h progress.h port.h etxack.h xmodem-load.h vrfile.h config.h 

all: $(TARGET)

$(TARGET):  $(OBJS)
	$(CC) $(CFLAGS) -o $(TARGET) $(OBJS) $(LDFLAGS)

%.o:  %.c %.h config.h
	$(CC) $(CFLAGS) $(DEFS) -c $< -o $@

install: all
	$(INSTALL) -m 755 vrflash $(bindir)
	
uninstall:
	-rm -f $(bindir)/vrflash

tags: $(CFILES) $(HFILES)
	-rm -f ./tags
	ctags *.c *.h

dist: distclean
	-rm -rf /tmp/vrflash-${VER}
	-rm -rf ./vrflash-${VER}.tar.gz
	mkdir /tmp/vrflash-${VER}
	for i in ${srcdir}/*; do cp -rf $$i /tmp/vrflash-${VER}/$$i; done 
	cd /tmp; tar cf vrflash-${VER}.tar vrflash-${VER}
	gzip -9 /tmp/vrflash-${VER}.tar
	mv /tmp/vrflash-${VER}.tar.gz .
	rm -rf /tmp/vrflash-${VER}

maintainer-clean: 
	-rm -f tags capture.log 

clean:
	-rm -f $(OBJS) $(TARGET)

distclean:  clean maintainer-clean
	-rm -f config.cache config.log config.status
	-find . ! -name configure.in -name \*.in -print | \
	 sed 's/\.in$$//' | \
	 while read file; do rm -f $$file; done

############################################
# Remake autoconf stuff
############################################
Makefile: Makefile.in config.status
	./config.status
