#############################################################################
# default: generate all
all:	mined help manual mnemodoc


#############################################################################
# generation
mined:
	./makemined

minced:
	./makemined minced

help:
	cd src; make help

mnemodoc:
	cd src; make mnemodoc

manual:
	cd man; make


#############################################################################
# installation
install:
	./makemined install

localinstall:
	./makemined localinstall

optinstall:
	./makemined optinstall

homeinstall:
	./makemined homeinstall


#############################################################################
# source distribution and private archives
archive:	all
	./makearch +

beta:	all
	if egrep -e "^printf" -e "^#define debug" src/*.c; then false; fi
	./makearch -

VER=$(shell sed -e 's,^[^0-9]*,,' -e 's,[^0-9][^0-9]*,.,g' -e q VERSION )
LSM=release/mined.lsm
SPEC=release/mined.spec

release:	distribution lsm

lsm:	$(LSM)

rpm:	$(SPEC)

$(SPEC):	DESCR makefile
	echo $(VER)
	echo "# partial spec file for mined" > $(SPEC)
	echo "Name:         mined" >> $(SPEC)
	echo "Group:        Productivity/Editors/Other" >> $(SPEC)
	echo "Version:      $(VER)" >> $(SPEC)
	echo "URL:          http://towo.net/mined/" >> $(SPEC)
	echo "Summary:      Powerful text editor with extensive Unicode and CJK support." >> $(SPEC)
	echo "" >> $(SPEC)
	echo "%description" >> $(SPEC)
	sed -e "s,^,	," DESCR >> $(SPEC)
	echo "" >> $(SPEC)

distribution:	all DESCR
	if egrep -e "^printf" -e "^#define debug" src/*.c; then false; fi
	if tail -1 src/keymaps.cfg | egrep '^#Ful'; then true; else false; fi
	cd src; make check
	./makearch


#############################################################################
# specific distribution packages

packages:	cygwin

REL=$(shell sed -e 's,.*[Rr]elease *\([0-9]*\).*,\1,' -e q README.cygwin )

cygrel=release/cygwin

cygwin:	release/mined-$(VER).tar.gz cygwinbin cygwinsrc

cygwinsrc:
	echo making cygwin source package release $(REL) of mined $(VER)
	mkdir -p $(cygrel)/
	gunzip -c release/mined-$(VER).tar.gz | bzip2 -c > $(cygrel)/mined-$(VER)-$(REL)-src.tar.bz2

cygwinbin:	$(cygrel)/setup.hint
	echo making cygwin package release $(REL) of mined $(VER)
	mkdir -p $(cygrel)/usr/bin $(cygrel)/usr/share/mined $(cygrel)/usr/share/man/man1/
	mkdir -p $(cygrel)/usr/share/doc/Cygwin
	mkdir -p $(cygrel)/usr/share/doc/mined
	cp -fp src/mined.exe $(cygrel)/usr/bin/
	cp -fp usrshare/* $(cygrel)/usr/share/mined/
	cp -fp man/mined.1 $(cygrel)/usr/share/man/man1/
	cp -fp README.cygwin $(cygrel)/usr/share/doc/Cygwin/mined.README
	cp -fp README* LICENSE.GNU CHANGES $(cygrel)/usr/share/doc/mined/
	cd $(cygrel); tar -cf mined-$(VER)-$(REL).tar usr
	cd $(cygrel); rm -f mined-$(VER)-$(REL).tar.bz2
	cd $(cygrel); bzip2 mined-$(VER)-$(REL).tar

$(cygrel)/setup.hint:	DESCR makefile
	mkdir -p $(cygrel)
	echo '# cygwin setup file' > $(cygrel)/setup.hint
	echo '@ mined' >> $(cygrel)/setup.hint
	echo 'sdesc: Powerful text mode editor with extensive Unicode and CJK encoding support.' >> $(cygrel)/setup.hint
	echo 'category: Editors' >> $(cygrel)/setup.hint
	echo 'requires: cygwin' >> $(cygrel)/setup.hint
	echo 'ldesc: "' >> $(cygrel)/setup.hint
	cat DESCR >> $(cygrel)/setup.hint
	echo '"' >> $(cygrel)/setup.hint

$(LSM):	DESCR makefile release/mined-$(VER).tar.gz
	mkdir -p release
	echo $(VER)
	echo "Begin4" > $(LSM)
	echo "Title:		mined" >> $(LSM)
	echo "Version:	$(VER)" >> $(LSM)
	echo "Entered-date:	`date +%Y-%m-%d`" >> $(LSM)
	echo "Description:	Powerful text editor with extensive Unicode and CJK support." >> $(LSM)
	sed -e "s,^,	," DESCR >> $(LSM)
	echo "Keywords:	text editor, Unicode editor, UTF-8 editor, CJK editor" >> $(LSM)
	echo "Author:		mined@towo.net (Thomas Wolff)" >> $(LSM)
	echo "Primary-site:	http://towo.net/mined/" >> $(LSM)
	(cd release; ls -l mined-$(VER).tar.gz) | sed -e "s,[^ ]* *[^ ]* *[^ ]* *[^ ]* *\([^ ]*\).* \([^ ]*\)$$,		\1 \2," >> $(LSM)
	echo "Alternate-site:	http://www.ibiblio.org/pub/Linux/apps/editors/mined-$(VER).tar.gz" >> $(LSM)
	echo "Platforms:	Unix (Linux/Sun/HP/BSD/Mac and more), DOS (djgpp), Windows (cygwin)" >> $(LSM)
	echo "Copying-policy:	GPL with comments" >> $(LSM)
	echo "End" >> $(LSM)

# NetBSD pkgsrc entry
DESCR:	doc/overview.html descr.sed makefile
	sed -f descr.sed doc/overview.html | sed -e "/./ b" -e "$$ d" > DESCR


release/mined-$(VER).tar.gz:	distribution


# PC binary archives (development target, doesn't currently work locally)
bin:	release/mined-$(VER)-cygwin.zip release/mined-$(VER)-dj.zip

release/mined-$(VER)-cygwin.zip:	src/cyg/mined.exe src/cyg/cyg*.dll usrshare/mined.hlp README README.cygwin
	mkdir -p release
	cd src/cyg; zip mined-$(VER)-cygwin.zip mined.exe cyg*.dll
	mv -f src/cyg/mined-$(VER)-cygwin.zip release/
	cd usrshare; zip ../release/mined-$(VER)-cygwin.zip mined.hlp minedmar.bat
	cp -fp README release/mined.txt
	cp -fp README.cygwin release/minedcyg.txt
	cd release; zip mined-$(VER)-cygwin.zip mined.txt minedcyg.txt
	rm -f release/mined.txt release/minedcyg.txt

release/mined-$(VER)-dj.zip:	src/dj/mined.exe usrshare/mined.hlp README
	mkdir -p release
	cd src/dj; zip mined-$(VER)-dj.zip mined.exe
	mv -f src/dj/mined-$(VER)-dj.zip release/
	cd usrshare; zip ../release/mined-$(VER)-dj.zip mined.hlp minedmar.bat
	cp -fp README release/mined.txt
	cd release; zip mined-$(VER)-dj.zip mined.txt
	rm -f release/mined.txt


#############################################################################
# end
