# Change these if you need to.
BINDIR =	/usr/local/bin
MANDIR =	/usr/local/man

# If you need to change this to gcc or pcc or whatever, go ahead.
CC =		cc

# Uncommenting DEBUG makes e generate an ELOG file with debugging messages.
#DEBUG =	-DDEBUG

# Uncommenting NO_LEAKFINDER makes the program *not* check for memory leaks.
# The default, once leakfinder is installed, is to check.
#NO_LEAKFINDER =	-DNO_LEAKFINDER

# Most of these compiler flags are for adding extra checks. If your
# compiler doesn't support them, feel free to get rid of them.

# -Wno-cast-qual
CFLAGS =	-ansi -g -O -U__STRICT_ANSI__ -Wall -Wpointer-arith -Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wno-long-long $(DEBUG) $(NO_LEAKFINDER)

# NOTE!!! ncursesw required for wide chars! - sudo apt-get install libncursesw5-dev

CURSES_LIB =	-lncursesw

LDFLAGS =	-g $(CURSES_LIB)

all:		e

e:		e.c version.h buffer.h undo.h str.h port.h popen2.h leakfinder.h key_bindings.h teache.h enews.h buffer.o undo.o str.o port.o popen2.o leakfinder.o
	$(CC) -o e $(CFLAGS) e.c buffer.o undo.o str.o port.o popen2.o leakfinder.o $(LDFLAGS)

buffer.o:	buffer.c buffer.h leakfinder.h
	$(CC) $(CFLAGS) -c buffer.c

undo.o:		undo.c undo.h leakfinder.h
	$(CC) $(CFLAGS) -c undo.c

str.o:		str.c str.h leakfinder.h
	$(CC) $(CFLAGS) -c str.c

port.o:		port.c port.h
	$(CC) $(CFLAGS) -c port.c

popen2.o:	popen2.c popen2.h
	$(CC) $(CFLAGS) -c popen2.c

leakfinder.o:	leakfinder.c leakfinder.h
	$(CC) $(CFLAGS) -c leakfinder.c

key_bindings.h:	key_bindings.txt bindings_to_h
	./bindings_to_h key_bindings.txt > key_bindings.h

teache.h:	teache.txt txt_to_h
	./txt_to_h teache.txt > teache.h

enews.h:		enews.txt txt_to_h
	./txt_to_h enews.txt > enews.h

getch:		getch.c
	$(CC) $(CFLAGS) getch.c $(LDFLAGS) -o getch

clean:
	rm -f e key_bindings.h teache.h enews.h getch *.o core core.* *.core

install:	all
	rm -f $(BINDIR)/e
	-mkdir -p $(BINDIR)
	cp e $(BINDIR)
	rm -f $(MANDIR)/man1/e.1
	-mkdir -p $(MANDIR)/man1
	cp e.1 $(MANDIR)/man1

tar:
	tar -cvzf e.tar.gz bindings_to_h  e.1        getch.c           leakfinder.h  popen2.c  port.h \
			   str.c          test.a60   undo.h            buffer.c      e.c       key_bindings.txt \
			   license.html   popen2.h   README            str.h         txt_to_h  version.h \
	                   buffer.h       enews.txt  leakfinder.c      Makefile      port.c    teache.txt  undo.c
