#
# Makefile.in for Kannel, the Open Source WAP and SMS Gateway.
#

SHELL = @SHELL@

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@

bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include

docdir = @docdir@

DESTDIR =

pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@

top_builddir = .

ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@

NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
CC = @CC@
MAKEINFO = @MAKEINFO@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
SHELL = @SHELL@
VERSION = @VERSION@
SUFFIX = @SUFFIX@
LEX = @LEX@
PERL = @PERL@
YACC = @YACC@

# -v gives verbose output.
YFLAGS = -d -p ws_yy_


mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = config.h
CONFIG_CLEAN_FILES =


LIBOBJS=@LIBOBJS@
LIBSRCS=$(LIBOBJS:.o=.c)

LIBS=@LIBS@
CFLAGS=-D_REENTRANT=1 -I. -Igw @CFLAGS@
LDFLAGS=@LDFLAGS@

MKDEPEND=$(CC) $(CFLAGS) -MM

JADE=@JADE@
JADETEX=@JADETEX@
PDFJADETEX=@PDFJADETEX@
DVIPS=@DVIPS@
FIG2DEV=@FIG2DEV@
CONVERT=@CONVERT@

HTML_DSL=@HTML_DSL@
TEX_DSL=@TEX_DSL@

# Set this to something if you want all installed binaries to have a suffix.
# Version number is common.
suffix = $(SUFFIX)

#
# You probably don't need to touch anything below this, if you're just
# compiling and installing the software.
#

STARTSTOPDAEMONSRC=@STARTSTOPDAEMONSRC@

binsrcs = \
	wmlscript/wmlsc.c \
	wmlscript/wmlsdasm.c \
	utils/seewbmp.c
sbinsrcs = \
	gw/bearerbox.c \
	utils/run_kannel_box.c \
	$(STARTSTOPDAEMONSRC)
progsrcs = $(binsrcs) $(sbinsrcs)
progobjs = $(progsrcs:.c=.o)
progs = $(progsrcs:.c=@EXE_EXT@)
binprogs = $(binsrcs:.c=)
sbinprogs = $(sbinsrcs:.c=)

gwsrcs = $(wildcard gw/*.c) $(wildcard gw/smsc/*.c)
gwobjs = $(gwsrcs:.c=.o)

libsrcs = $(wildcard gwlib/*.c) $(LIBSRCS)
libobjs = $(libsrcs:.c=.o) $(LIBOBJS)

wapsrcs = $(wildcard wap/*.c)
wapobjs = $(wapsrcs:.c=.o)

mmssrcs = $(wildcard mms/*.c)
mmsobjs = $(mmssrcs:.c=.o)

wmlscriptsrcs = $(wildcard wmlscript/*.c)
wmlscriptobjs = $(wmlscriptsrcs:.c=.o)

testsrcs = $(wildcard test/*.c)
testobjs = $(testsrcs:.c=.o)
testprogs = $(testsrcs:.c=@EXE_EXT@)
tests = $(testprogs) $(wildcard test/*.sh)

checksrcs = $(wildcard checks/*.c)
checkobjs = $(checksrcs:.c=.o)
checkprogs = $(checksrcs:.c=@EXE_EXT@)
checks = $(checkprogs) $(wildcard checks/*.sh)

benchformats = \
    benchmarks/report.pdf \
    benchmarks/report.ps \
    benchmarks/report.html
benchscripts = benchmarks/run-benchmarks $(wildcard benchmarks/*.sh)
benchoutputs = \
    $(benchformats) \
    $(wildcard benchmarks/*.ps) \
    $(wildcard benchmarks/*.png) \
    $(wildcard benchmarks/*.xml)

srcs = $(wildcard */*.c)
objs = $(srcs:.c=.o)

libs = libgw.a libwmlscript.a libwap.a libgwlib.a libmms.a

srcdirs = gw gw/smsc gwlib test utils wmlscript checks wap mms

man1pages = utils/seewbmp.1 wmlscript/wmlsc.1 wmlscript/wmlsdasm.1
man8pages = gw/kannel.8 utils/run_kannel_box.8

docsrcs = $(wildcard grep -l '<!DOCTYPE ' doc/*/*.xml)
docs = $(docsrcs:.xml=.html) $(docsrcs:.xml=.rtf) $(docsrcs:.xml=.ps) $(docsrcs:.xml=.pdf)
DOCSTARGET=@DOCSTARGET@
DOCDRAFTS=@DOCDRAFTS@

pssrcs = $(wildcard doc/alligata/*.png doc/wtls/*.png)
ps = $(pssrcs:.png=.ps)  

figsrcs = $(wildcard doc/userguide/*.fig doc/arch/*.fig)
figs = $(figsrcs:.fig=.png)  $(figsrcs:.fig=.ps)


.SUFFIXES: $(SUFFIXES) .xml .html .rtf .ps .fig .png .y .c .o .pdf

.xml.html:
	sed "s/#FIGTYPE#/.png/;s/#VERSION#/${VERSION}/;s/#DATE#/`date +%Y.%m.%d`/;s/#DRAFTS#/${DOCDRAFTS}/" $< > $*.tmp
	${JADE} -V nochunks -t sgml -d $(HTML_DSL) $*.tmp > $@
	rm -f $*.tmp

.xml.rtf:
	sed "s/#FIGTYPE#/.ps/;s/#VERSION#/${VERSION}/;s/#DATE#/`date +%Y.%m.%d`/;s/#DRAFTS#/${DOCDRAFTS}/" $< > $*.tmp
	cd `dirname $<` && $(JADE) -o `basename $*`.rtf -t rtf -d $(TEX_DSL) `basename $*`.tmp
	rm -f $*.tmp

.xml.ps:
	sed "s/#FIGTYPE#/.ps/;s/#VERSION#/${VERSION}/;s/#DATE#/`date +%Y.%m.%d`/;s/#DRAFTS#/${DOCDRAFTS}/" $< > $*.tmp
	$(JADE) -o $*.tex -t tex -d $(TEX_DSL) $*.tmp
	rm -f $*.tmp
	cd `dirname $<` && $(JADETEX) `basename $*`.tex >/dev/null || true
	cd `dirname $<` && $(JADETEX) `basename $*`.tex >/dev/null || true
	cd `dirname $<` && $(JADETEX) `basename $*`.tex >/dev/null || \
	    ( echo Check `dirname $<`/`basename $*`.log for errors && false)
	rm -f $*.log
	cd `dirname $<` && $(DVIPS) -q -o `basename $*`.ps `basename $*`.dvi
	rm -f $*.dvi $*.tex $*.aux 

.xml.pdf:
	sed "s/#FIGTYPE#/.png/;s/#VERSION#/${VERSION}/;s/#DATE#/`date +%Y.%m.%d`/;s/#DRAFTS#/${DOCDRAFTS}/" $< > $*.tmp
	$(JADE) -o $*.tex -t tex -d $(TEX_DSL) $*.tmp
	rm -f $*.tmp
	cd `dirname $<` && $(JADETEX) `basename $*`.tex >/dev/null || true
	cd `dirname $<` && $(JADETEX) `basename $*`.tex >/dev/null || true
	cd `dirname $<` && $(JADETEX) `basename $*`.tex >/dev/null || true
	rm -f $*.log $*.dvi
	cd `dirname $<` && $(PDFJADETEX) `basename $*`.tex > /dev/null || true 
	test -r $*.pdf || false
	rm -f $*.log $*.tex $*.aux $*.out

.fig.png:
	$(FIG2DEV) -Lpng $< $@

.fig.ps:
	$(FIG2DEV) -Lps $< $@

.png.ps:
	$(CONVERT) $< $@

.y.c:
	$(YACC) $(YFLAGS) $< && mv y.tab.c $*.c
	if test -f y.tab.h; then \
	if cmp -s y.tab.h $*.h; then rm y.tab.h; else mv y.tab.h $*.h; fi; \
	else :; fi

.c.o:
	$(CC) $(CFLAGS) -o $@ -c $<

all: progs $(testprogs) $(checkprogs) $(DOCSTARGET)
progs: $(progs)
docs: figs ps $(docs)
no-docs:
figs: $(figs)
ps: $(ps)

check: all
	utils/run-checks $(checks)

bench: all $(benchformats)
benchmarks/report.xml: dummy
	benchmarks/run-benchmarks benchmarks/*.sh
dummy:

install: all
	$(INSTALL) -d $(DESTDIR)$(bindir)
	for prog in $(binprogs); do \
		$(INSTALL) $$prog \
		    $(DESTDIR)$(bindir)/`basename $$prog`$(suffix); \
	done
	$(INSTALL) -d $(DESTDIR)$(sbindir)
	for prog in $(sbinprogs); do \
		$(INSTALL) $$prog \
		    $(DESTDIR)$(sbindir)/`basename $$prog`$(suffix); \
	done
	$(INSTALL) -d $(DESTDIR)$(mandir)/man1
	$(INSTALL) $(man1pages) $(DESTDIR)$(mandir)/man1
	$(INSTALL) -d $(DESTDIR)$(mandir)/man8
	$(INSTALL) $(man8pages) $(DESTDIR)$(mandir)/man8

install-test: all
	$(INSTALL) -d $(DESTDIR)$(libdir)/kannel
	$(INSTALL) -d $(DESTDIR)$(libdir)/kannel/test
	(cd test && find . -type f ! -name "*.c" ! -name "*.o" | grep -v ".cvsignore" | grep -v "/CVS/" | while read a ; do $(INSTALL_DATA) $$a $(DESTDIR)$(libdir)/kannel/test ; done)
	for prog in $(tests) ; do \
                chmod 755 $(DESTDIR)$(libdir)/kannel/$$prog ; \
        done

install-checks: all
	$(INSTALL) -d $(DESTDIR)$(libdir)/kannel/checks
	(cd checks && find . -type f ! -name "*.c" ! -name "*.o" | grep -v ".cvsignore" | grep -v "/CVS/" | while read a ; do $(INSTALL_DATA) $$a $(DESTDIR)$(libdir)/kannel/checks ; done)
	for prog in $(checks) ; do \
                chmod 755 $(DESTDIR)$(libdir)/kannel/$$prog ; \
        done

install-contrib: all
	$(INSTALL) -d $(DESTDIR)$(docdir)/contrib
	(cd contrib && find . -type d ! -name "CVS" | while read a ; do $(INSTALL) -d $(DESTDIR)$(docdir)/contrib/$$a ; done )
	(cd contrib && find . -type f ! -name ".cvsignore" | grep -v "/CVS/" | while read a ; do $(INSTALL_DATA) $$a $(DESTDIR)$(docdir)/contrib/$$a ; done )
	find $(DESTDIR)$(docdir)/contrib/ -name "*.pl" -o -name "*.sh" -o -name "*.cgi" -o -name "sendsms" -o -name "kannel.monitor" | while read a ; do chmod 755 "$$a" ; done

install-docs:
	$(INSTALL) -d $(DESTDIR)$(docdir)/examples
	$(INSTALL_DATA) doc/examples/*.conf $(DESTDIR)$(docdir)/examples
	for docfile in userguide alligata wtls ; do \
		$(INSTALL) -d $(DESTDIR)$(docdir)/$$docfile ; \
		$(INSTALL_DATA) doc/$$docfile/$$docfile.ps $(DESTDIR)$(docdir)/$$docfile ; \
		$(INSTALL_DATA) doc/$$docfile/$$docfile.html $(DESTDIR)$(docdir)/$$docfile ; \
		$(INSTALL_DATA) doc/$$docfile/$$docfile.rtf $(DESTDIR)$(docdir)/$$docfile ; \
		$(INSTALL_DATA) doc/$$docfile/$$docfile.pdf $(DESTDIR)$(docdir)/$$docfile ; \
		$(INSTALL_DATA) doc/$$docfile/*.png $(DESTDIR)$(docdir)/$$docfile ; \
	done
clean:
	rm -f */*.o gw/smsc/*.o *.a core $(progs) $(testprogs) $(checkprogs)
	rm -f $(figs) $(ps) $(docs)
	rm -f $(benchoutputs)

distclean: clean
	rm -f Makefile config.h config.cache config.log config.status .depend

nag:
	utils/find-long-lines

depend .depend: wmlscript/wsgram.h config.h
	for dir in $(srcdirs); do \
		$(MKDEPEND) $$dir/*.c | sed "s:^[^ ]:$$dir/&:"; done > .depend
include .depend

libgw.a: $(gwobjs)
	@LIBTOOL@ libgw.a $(gwobjs)
	$(RANLIB) libgw.a

libgwlib.a: $(libobjs)
	@LIBTOOL@  libgwlib.a $(libobjs)
	$(RANLIB) libgwlib.a

libwmlscript.a: $(wmlscriptobjs)
	@LIBTOOL@ libwmlscript.a $(wmlscriptobjs)
	$(RANLIB) libwmlscript.a

libwap.a: $(wapobjs)
	@LIBTOOL@ libwap.a $(wapobjs)
	$(RANLIB) libwap.a

libmms.a: $(mmsobjs)
	@LIBTOOL@ libmms.a $(mmsobjs)
	$(RANLIB) libmms.a

wmlscript/wsgram.h: wmlscript/wsgram.c

make-op-table: $(srcdir)/wmlscript/make-op-table.in
	sed 's%@PERLPROG@%@PERL@%g' $(srcdir)/wmlscript/make-op-table.in \
		> make-op-table
	chmod a+x make-op-table

opcodes:
	./make-op-table $(srcdir)/wmlscript/wsasm.h \
		> $(srcdir)/wmlscript/wsopcodes.h

$(progs): $(libs) $(progobjs)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(@:@EXE_EXT@=).o $(libs) $(LIBS)

$(testprogs): $(testobjs) $(libs)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(@:@EXE_EXT@=).o $(libs) $(LIBS)

$(checkprogs): $(checkobjs) $(libs)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(@:@EXE_EXT@=).o $(libs) $(LIBS)

pkg: all
	(cd solaris; mk-solaris-package.sh)
	echo Package is now in solaris directory
