SHELL=/bin/sh
@SET_MAKE@

INSTALL=@INSTALL@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
libdir=@libdir@
includedir=@includedir@
mandir=@mandir@

top_srcdir=@top_srcdir@
srcdir=@srcdir@
VPATH=@srcdir@

CC=@CC@
CPPFLAGS=@CPPFLAGS@
DEFS=@DEFS@ -DNAWM_DEFAULT_LIBPATH=\"$(libdir)/nawm\"
CFLAGS=@CFLAGS@
X_CFLAGS=@X_CFLAGS@
ALL_CFLAGS=$(DEFS) $(CPPFLAGS) $(CFLAGS) $(X_CFLAGS)
LDFLAGS=@LDFLAGS@
X_LDFLAGS=@X_LIBS@ @X_LIBRARIES@ 
ALL_LDFLAGS=$(LDFLAGS) $(X_LDFLAGS)
LIBS=@LIBS@ @X_PRE_LIBS@ -lXtst -lXext -lX11 @X_EXTRA_LIBS@
INSTALL=@INSTALL@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
MV=mv
RM=rm -f

YACC=@YACC@ -t

LEX=@LEX@
LEX_OUTPUT_ROOT=@LEX_OUTPUT_ROOT@

all: nawm mods

SRCS=	parser.c array.c bindings.c builtins.c cache.c dtype.c eval.c \
	keymap.c lexer.c mem.c mod.c nawm.c
OBJS=	parser.o array.o bindings.o builtins.o cache.o dtype.o eval.o \
	keymap.o lexer.o mem.o mod.o nawm.o

.c.o:
	$(CC) -c -I. -I$(srcdir) $(ALL_CFLAGS) $<

parser.c: parser.y
	$(YACC) -d $(srcdir)/parser.y
	@$(MV) y.tab.c parser.c
	@cmp -s y.tab.h parser.h || $(MV) y.tab.h parser.h
	-@$(RM) y.tab.c y.tab.h

lexer.c: lexer.l
	$(LEX) $(srcdir)/lexer.l
	@$(MV) $(LEX_OUTPUT_ROOT).c lexer.c
	-@$(RM) $(LEX_OUTPUT_ROOT).c

nawm: $(OBJS)
	$(CC) -o nawm $(ALL_LDFLAGS) $(OBJS) $(LIBS)

mods:
	@echo "Making all in modules"
	@(cd modules; $(MAKE) all)

clean:
	-$(RM) nawm $(OBJS) parser.c parser.h lexer.c
	-$(RM) *~ core nawm.core
	@(cd modules; $(MAKE) clean)

distclean: clean
	-$(RM) Makefile config.cache config.log config.status
	@(cd modules; $(MAKE) distclean)

install: all
	${top_srcdir}/mkinstalldirs $(DESTDIR)$(bindir)
	${top_srcdir}/mkinstalldirs $(DESTDIR)$(includedir)
	${top_srcdir}/mkinstalldirs $(DESTDIR)$(mandir)/man1
	$(INSTALL) -m 755 nawm $(DESTDIR)$(bindir)
	$(INSTALL) -m 644 $(top_srcdir)/nawmmod.h $(DESTDIR)$(includedir)
	$(INSTALL) -m 644 $(top_srcdir)/nawm.1 $(DESTDIR)$(mandir)/man1
	@(cd modules; $(MAKE) install)

array.o: nawm.h
bindings.o: nawm.h parser.h
builtins.o: builtins.h cache.h nawm.h parser.h
cache.o: cache.h nawm.h
dtype.o: nawm.h
eval.o: nawm.h parser.h
keymap.o: nawm.h
lexer.o: nawm.h parser.h
mem.o: nawm.h
mod.o: nawm.h
nawm.o: builtins.h cache.h nawm.h
parser.o: nawm.h
