include Makefile.config
include Makefile.build

EXAMPLES= animator converter crop edgedetect gifanim lv monochrome \
	   normalize resize tiffps ttfimg

all: byte
byte: all.byte
allopt:opt
opt: all.opt

.PHONY: examples install

examples:
	for i in $(EXAMPLES); do (cd "examples/$$i"; $(MAKE)); done

examples.opt:
	for i in $(EXAMPLES); do (cd "examples/$$i"; $(MAKE) opt); done

cleanexamples:
	for i in $(EXAMPLES); do (cd "examples/$$i"; $(MAKE) -k clean); done

config:
	rm -f config.cache
	./configure	

clean::
	for i in $(BUILDDIRS); do (cd $$i; $(MAKE) clean) || exit $$?; done

veryclean: clean
	rm -f config.cache config.log config.status config.h \
		$(COREDIR)/camlimages.ml
	$(MAKE) cleanexamples

veryveryclean: veryclean
	rm -f configure
	rm -f autoconf.info *~ */*~ #* */#*
	rm -f Makefile.config Makefile.fortools

clean::
	cd test; $(MAKE) clean

all.byte:
	for i in $(BUILDDIRS); do (cd $$i; $(MAKE) all.byte) || exit $$?; done

all.opt:
	for i in $(BUILDDIRS); do (cd $$i; $(MAKE) all.opt) || exit $$?; done

top: 
	$(CAMLMKTOP) $(CUSTOM) -o customtop \
		$(COMPFLAGS_CAMLIMAGES) \
		$(WITH_UNIX) \
		$(WITH_CAMLIMAGES) \
		$(WITH_GRAPHICS) \
		$(WITH_GIF) \
		$(WITH_JPEG) \
		$(WITH_TIFF) \
		$(WITH_BMP) \
		$(WITH_PNG) \
		$(WITH_XPM) \
		$(WITH_FREETYPE)

install:
	for i in $(BUILDDIRS); do (cd $$i; $(MAKE) install) || exit $$?; done
	cp Makefile.config $(LIBDIR)
	$(RANLIB) $(LIBDIR)/*.a

depend:
	for i in $(BUILDDIRS); do (cd $$i; $(MAKE) depend) || exit $$?; done

# Just for MMM maintainers, distribution of the software
FTPDIR=/net/pauillac/infosystems/ftp/cristal/ocaml/bazar-ocaml/
WWWDIR=/net/pauillac/infosystems/www/camlimages/
VERSION=2.10

distribute: tar_and_web rpm

tar_and_web:
	rm -rf release
	mkdir release
	cd release; cvs co bazar-ocaml/camlimages; \
	find . -name '.cvsignore' -print | xargs rm; \
	find . -name 'CVS' -print | xargs rm -rf; \
	mv bazar-ocaml/camlimages camlimages-$(VERSION); \
	rm -rf camlimages-$(VERSION)/tools; \
	tar zcvf camlimages-$(VERSION).tgz camlimages-$(VERSION); \
	mv -f camlimages-$(VERSION).tgz $(FTPDIR)
	chgrp caml $(FTPDIR)/camlimages-$(VERSION).tgz
	rm -rf release
	cp INSTALL doc/*.jpg doc/*.htm $(WWWDIR)
	chgrp caml $(WWWDIR)/*
	chmod g+w $(WWWDIR)/*

rpm:
	if test -d /usr/src/redhat; then rpmdir=/usr/src/redhat; \
	else if test -d /usr/src/RPM; then rpmdir=/usr/src/RPM; fi; fi; \
	if test "X$$rpmdir" = "X"; then \
		echo "cannot create rpm"; exit 2; fi; \
	echo YOU NEED TO SU ROOT; \
	su root -c "cp $(FTPDIR)/camlimages-$(VERSION).tgz $$rpmdir/SOURCES/; rpm -bs --clean ./camlimages.spec"; \
	cp $$rpmdir/SRPMS/camlimages-$(VERSION)-1.src.rpm $(FTPDIR)
# 	cp $$rpmdir/SRPMS/camlimages-$(VERSION)-1.src.rpm \
# 	   $$rpmdir/RPMS/*/camlimages-$(VERSION)-1.*.rpm $(FTPDIR)
