# -*- Mode: sh

TARGET=libmpdm.a
LIB=$(TARGET)

all: $(TARGET) docs

PROJ=mpdm

ADD_DOCS=RELEASE_NOTES
GRUTATXT_DOCS=doc/mpdm_overview.html
MP_DOCCER_DOCS=doc/mpdm_api.html

OBJS=mpdm_v.o mpdm_a.o mpdm_h.o mpdm_d.o mpdm_s.o mpdm_f.o \
	mpdm_r.o gnu_regex.o

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

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

version:
	@echo $(VERSION)

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

dep:
	gcc -MM *.c > makefile.depend

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

stress: stress.c $(LIB)
	$(CC) $(CFLAGS) `cat config.ldflags` stress.c -L. -lmpdm -o $@

.SUFFIXES: .txt .html

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

doc/mpdm_api.html: mpdm_*.c
	mp_doccer mpdm_*.c -o doc/mpdm_api -f html1 \
	-t "MPDM C API ($(VERSION))" \
	-a 'Angel Ortega - angel@triptico.com'

docs: $(DOCS)

docsclean:
	rm -f doc/*.html

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

distclean: clean
	rm -f config.h config.cflags config.ldflags makefile.opts .config.log Makefile

realclean: distclean docsclean

realdistclean: realclean

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)

.po.mo:
	msgfmt -o $@ $<

build-mo:
	for a in po/*.po ; do \
		B=`basename $$a .po` ; \
		mkdir -p po/$$B/LC_MESSAGES ; \
		msgfmt -o po/$$B/LC_MESSAGES/stress.mo $$a ; \
	done

installdoc:
	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
