# $Id: Makefile.in,v 1.15 2003/07/06 22:42:10 nygren Exp $

srcdir = @srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
datadir = @datadir@
bindir = @bindir@
mandir = @mandir@

CC=@CC@
LIBS=@LIBS@ -L./libfaim -lfaim
CFLAGS=@CFLAGS@ -I. -I./libfaim -DDATADIR=\"${datadir}\"
LDFLAGS=@LDFLAGS@
XSUBPPDIR=@XSUBPPDIR@
INSTALL=@INSTALL@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
INSTALL_DATA=@INSTALL_DATA@

BASE_SRCS=list.c message.c mainwin.c popwin.c zephyr.c messagelist.c \
     commands.c global.c text.c fmtext.c editwin.c util.c logging.c \
     perlconfig.c keys.c functions.c zwrite.c viewwin.c help.c filter.c \
     regex.c history.c view.c dict.c variable.c filterelement.c pair.c \
     keypress.c keymap.c keybinding.c cmd.c context.c zcrypt.c \
     aim.c buddylist.c timer.c style.c stylefunc.c 
OWL_SRC = owl.c
TESTER_SRC = tester.c

BASE_OBJS = $(BASE_SRCS:.c=.o)

GEN_C = varstubs.c perlglue.c perlwrap.c
GEN_H = owl_prototypes.h 
GEN_O = $(GEN_C:.c=.o)

OBJS = $(BASE_OBJS) $(GEN_O)

AUTOGEN=$(GEN_C) $(GEN_H)
#AUTOGEN=$(GEN_C)


owl: $(AUTOGEN) $(OBJS) owl.o libfaim
	./athstatic $(CC) -o owl owl.o $(OBJS) $(LDFLAGS) $(LIBS)

tester: $(OBJS) tester.o
	$(CC) -o tester tester.o $(OBJS) $(LDFLAGS) $(LIBS)

test: tester
	./tester reg

clean: libfaimclean
	$(RM) owl tester *.o $(AUTOGEN) owl_prototypes.h.new

distclean: clean libfaimdistclean
	$(RM) config.cache config.log config.status Makefile config.h TAGS *~ core

proto: owl_prototypes.h

perlglue.c: perlglue.xs
	perl $(XSUBPPDIR)/xsubpp -typemap $(XSUBPPDIR)/typemap -prototypes perlglue.xs > perlglue.c

varstubs.c: variable.c stubgen.pl
	perl stubgen.pl > varstubs.c

perlwrap.c: perlwrap.pm encapsulate.pl
	perl encapsulate.pl perlwrap.pm owl_perlwrap_codebuff > perlwrap.c

# Only move owl_prototypes.h into place if the new one is different
owl_prototypes.h: codelist.pl varstubs.c $(BASE_SRCS)
	perl codelist.pl > owl_prototypes.h.new
	@cmp -s owl_prototypes.h.new $@ || { \
	 echo 'Interfaces changed!'; \
	 echo mv -f owl_prototypes.h.new $@; \
	      mv -f owl_prototypes.h.new $@; }
#owl_prototypes.h:

.PHONY: tags clean distclean proto test

tags: TAGS

TAGS: $(BASE_SRCS) $(OWL_SRC) $(TESTER_SRC) $(GEN_C) owl.h $(GEN_H)
	etags $(BASE_SRCS) $(OWL_SRC) $(TESTER_SRC) $(GEN_C) owl.h $(GEN_H)

$(BASE_OBJS) varstubs.h:: owl.h config.h owl_prototypes.h
#$(BASE_OBJS) varstubs.h:: owl.h config.h

libfaim: libfaim/libfaim.a

libfaim/libfaim.a:
	(cd libfaim; $(MAKE))

libfaimclean:
	(cd libfaim; $(MAKE) clean)

libfaimdistclean:
	(cd libfaim; $(MAKE) distclean)

all: owl

install: all installdirs
	${INSTALL_PROGRAM} owl ${bindir}/owl
	${INSTALL_DATA} doc/owl.1 ${mandir}/man1/owl.1

installdirs: mkinstalldirs
	${srcdir}/mkinstalldirs ${bindir} ${mandir}/man1 ${datadir}/owl
