# $Id: Makefile.in,v 1.21 2004/03/01 17:43:06 nygren Exp $

srcdir = .

prefix = /usr/local
exec_prefix = ${prefix}
datadir = ${prefix}/share
bindir = ${exec_prefix}/bin
mandir = ${prefix}/man

CC=gcc
LIBS=-lzephyr -lkrb4 -lkrb5 -lresolv -ldes425 -lk5crypto -lsocket -lnsl -lcom_err -lncurses -L/mit/ktools/lib -L./libfaim -lfaim
CFLAGS=-I/mit/ktools/include -Wall -g -I/usr/athena/include  -D_REENTRANT -DDEBUGGING -fno-strict-aliasing -I/usr/athena/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  -I/usr/athena/lib/perl5/5.8.3/sun4-solaris-thread-multi/CORE  -I. -I./libfaim -DDATADIR=\"${datadir}\"
LDFLAGS=-L/usr/athena/lib -R/usr/athena/lib   -Wl  -L/usr/athena/lib  /usr/athena/lib/perl5/5.8.3/sun4-solaris-thread-multi/auto/DynaLoader/DynaLoader.a -L/usr/athena/lib/perl5/5.8.3/sun4-solaris-thread-multi/CORE -lperl -lsocket -lnsl -ldl -lm -lpthread -lc
XSUBPPDIR=/usr/athena/lib/perl5/5.8.3/ExtUtils
INSTALL=/usr/athena/bin/install -c
INSTALL_PROGRAM=${INSTALL}
INSTALL_DATA=${INSTALL} -m 644

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 buddy.c buddylist.c timer.c style.c stylefunc.c errqueue.c \
     zbuddylist.c muxevents.c popexec.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)
	cp -r . ../old/`date +%Y-%m-%d`

tester: $(AUTOGEN) $(OBJS) tester.o
	./athstatic $(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 $@ || { \
	 test -f $@ && 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
