# automatically created by config.sh - do not modify
# CC=gcc
# CFLAGS=-g -Wall
# AR=ar
# YACC=yacc
MPDM=../mpdm
DOCS=$(ADD_DOCS)
VERSION=1.0.9
PREFIX=$(DESTDIR)/usr
DOCDIR=$(DESTDIR)/usr/share/doc/mp-5
TARGET=mpsl

# -*- Mode: sh

LIB=libmpsl.a

all: $(TARGET) docs

PROJ=mpsl

ADD_DOCS=doc/mpsl_quickref.ps
GRUTATXT_DOCS=doc/mpsl_index.html doc/mpsl_overview.html doc/mpsl_internals.html
MP_DOCCER_DOCS=doc/mpsl_api.txt doc/mpsl_reference.txt
G_AND_MP_DOCS=doc/mpsl_api.html doc/mpsl_reference.html

OBJS=mpsl_c.o mpsl_l.o mpsl_m.o mpsl_y.o mpsl_f.o mpsl_d.o

DIST_TARGET=/tmp/$(PROJ)-$(VERSION)

##################################################################

version:
	@echo $(VERSION)

.c.o:
	$(CC) $(CFLAGS) `cat config.cflags` -c $<

y.tab.h: mpsl.y
	$(YACC) -d mpsl.y

y.tab.c: mpsl.y
	$(YACC) -d mpsl.y

lex.yy.c: mpsl.l
	flex mpsl.l

mpsl_l.o: lex.yy.c y.tab.h
	$(CC) $(CFLAGS) `cat config.cflags` -c lex.yy.c -o mpsl_l.o

mpsl_y.o: y.tab.c
	$(CC) $(CFLAGS) `cat config.cflags` -c y.tab.c -o mpsl_y.o

$(MPDM)/libmpdm.a:
	( cd $(MPDM); $(MAKE) )

dep:
	gcc `cat config.cflags` -MM *.c | \
		sed -e 's;$(MPDM)/;$$(MPDM)/;g' > makefile.depend

$(LIB): $(OBJS)
	$(AR) rv $(LIB) $(OBJS)

$(TARGET): $(LIB) $(MPDM)/libmpdm.a
	$(CC) $(CFLAGS) -L. -lmpsl `cat config.ldflags` -o $@

stress: stress.c $(LIB) $(MPDM)/libmpdm.a
	$(CC) $(CFLAGS) `cat config.cflags` stress.c \
		-L. -lmpsl `cat config.ldflags` -o $@

clean:
	rm -f $(TARGET) $(LIB) $(OBJS) *.o tags *.tar.gz stress

realclean: clean
	rm -f y.tab.c y.tab.h lex.yy.c

distclean: clean y.tab.c y.tab.h lex.yy.c
	rm -f config.h config.cflags config.ldflags makefile.opts .config.log Makefile

realclean: distclean docsclean

realdistclean: realclean

.SUFFIXES: .txt .html

.txt.html:
	grutatxt < $< > $@

doc/mpsl_quickref.ps: doc/mpsl_quickref.txt
	-./mpsl scripts/mkquickref.mpsl < $< > $@

doc/mpsl_api.txt: mpsl_c.c mpsl.y
	mp_doccer mpsl_c.c mpsl.y -o doc/mpsl_api -f grutatxt \
	-t "MPSL C API" \
	-b "This reference documents version $(VERSION) of the C API." \
	-a 'Angel Ortega - angel@triptico.com'

doc/mpsl_reference.txt: mpsl_f.c
	mp_doccer mpsl_f.c -o doc/mpsl_reference -f grutatxt \
	-t "MPSL Function Library Reference" \
	-b "This reference documents version $(VERSION) of the MPSL Function Library." \
	-a 'Angel Ortega - angel@triptico.com'

docs: $(DOCS)

docsclean:
	rm -f $(MP_DOCCER_DOCS) doc/*.html

distcopy: distclean
	mkdir -p $(DIST_TARGET) ; \
	tar cf - * | (cd $(DIST_TARGET) ; tar xf -)

dist: distcopy
	(cd /tmp ; tar czf - $(PROJ)-$(VERSION)/* ) > $(PROJ)-$(VERSION).tar.gz ; \
	rm -rf $(DIST_TARGET)

install: installdoc
	install $(TARGET) $(PREFIX)/bin

installdoc:
	install -d $(DOCDIR)
	install -m 644 doc/* $(DOCDIR)/
	for f in README AUTHORS COPYING TODO RELEASE_NOTES ; do \
		[ -f $$f ] && install -m 644 $$f $(DOCDIR)/$$f.$(PROJ) ; \
	done
lex.yy.o: lex.yy.c $(MPDM)/mpdm.h y.tab.h
mpsl_c.o: mpsl_c.c config.h $(MPDM)/mpdm.h mpsl.h
mpsl_d.o: mpsl_d.c config.h $(MPDM)/mpdm.h mpsl.h
mpsl_f.o: mpsl_f.c config.h $(MPDM)/mpdm.h mpsl.h
mpsl_m.o: mpsl_m.c config.h $(MPDM)/mpdm.h mpsl.h
stress.o: stress.c $(MPDM)/mpdm.h mpsl.h
y.tab.o: y.tab.c $(MPDM)/mpdm.h mpsl.h
