# ====================================================================
# Makefile for Gem Finder
# ====================================================================

SRC2HTML=source2html

TOOLSDIR=web-public/tools
UPLOADDIR=$(TOOLSDIR)/gemfinder
UPLOADHOST=one.net

PKGFILES=gemfinder Makefile README install.rb runtests.rb \
	gem/*.rb \
	doc/*.rd doc/*.blurb doc/*.rc doc/thumbshot.jpg

RUNARG=

# ====================================================================

include gem/version.rb

test: runtests.rb		# Run the test cases (DEFAULT)
	./runtests.rb --testdir gem

version: FORCE			# Display the current version number
	@cat gem/version.rb

run:				# Run Gemfinder in the development environment
	RUBYLIB=. ./gemfinder $(RUNARG)

install:			# Install the package
	ruby install.rb

publish: pre-upload upload	# Publish the package on the Net

doc: clobber-web web README FORCE # Generate the docs for the package
	$(SRC2HTML) -i doc/code2html.rc -d html gemfinder gem/*.rb 

upload: upload-html upload-tgz upload-zip # Upload the package (docs/tgz/zip)

package: clean runtests.rb README FORCE	# Create a zipped tar package file
	rm -rf pkg
	mkdir -p pkg/gemfinder-$(REV)/gem
	mkdir -p pkg/gemfinder-$(REV)/doc
	for f in $(PKGFILES); do ln $$f pkg/gemfinder-$(REV)/$$f; done
	cp $(HOME)/bin/runtests.rb pkg/gemfinder-$(REV)/runtests.rb
	( cd pkg; tar zcvf gemfinder-$(REV).tgz gemfinder-$(REV) )
	( cd pkg; zip -R gemfinder-$(REV).zip `find gemfinder-$(REV)` )

clean: FORCE			# Delete intermediate targets
	for d in . doc html gem pkg; do \
		rm -f $$d/*.bak $$d/*~ $$d/core; \
	done

clobber: clean clobber-web clobber-pkg # Delete all generated targets
	rm -f README

help: FORCE			# Display make targets
	@egrep '^[-A-Za-z0-9]+:' Makefile \
		| grep "#" \
		| sed 's/:.*\(#\)/ --/' \
		| sort

# Secondary Targets --------------------------------------------------

README: html/index.html
	lynx -nolist -dump html/index.html >README

web: html/thumbshot.jpg html/screenshot.jpg html/index.html

html:
	mkdir html

html/screenshot.jpg html/thumbshot.jpg: html doc/screenshot.jpg
	cp doc/*.jpg html

html/index.html: html doc/gemfinder.rd
	rd2 <doc/gemfinder.rd \
		| sed -e 's/<BODY>/<body bgcolor="#ffffff">/' \
		  >html/index.html

pre-upload: doc package

clobber-pkg: FORCE
	rm -fr pkg

clobber-web: FORCE
	rm -rf html

runtests.rb: $(HOME)/bin/runtests.rb
	cp $(HOME)/bin/runtests.rb runtests.rb

upload-html: FORCE
	ssh $(UPLOADHOST) rm -rf $(UPLOADDIR)
	ssh $(UPLOADHOST) mkdir -p $(UPLOADDIR)
	scp -q html/* $(UPLOADHOST):$(UPLOADDIR)
	scp -q doc/gemfinder.blurb $(UPLOADHOST):$(TOOLSDIR)

upload-tgz: FORCE
	ftpupload \
		-cd tools \
		-set ok -md gemfinder \
		pkg/gemfinder-$(REV).tgz gemfinder/gemfinder-$(REV).tgz

upload-zip: FORCE
	ftpupload \
		-cd tools \
		-set ok -md gemfinder \
		pkg/gemfinder-$(REV).zip gemfinder/gemfinder-$(REV).zip

FORCE:
