# $Id: moomps.mk,v 1.2 2004/01/18 23:14:30 jfontain Exp $


VERSION = 4.6

# note: TCLSH and WISH must include path as they are used
# as shell interpreters inside scripts (using the #! syntax)
TCLSH = /usr/bin/tclsh

# only use as the temporary installation directory, such as from a rpm
# specification file, otherwise change the directories below instead:
ROOTDIR =

# you may change the directories below:
BASEDIR =
LIBDIR = $(BASEDIR)/usr/lib
SBINDIR = $(BASEDIR)/usr/sbin
ETCDIR = $(BASEDIR)/etc
INITDIR = $(BASEDIR)/etc/rc.d/init.d
MANDIR = $(BASEDIR)/usr/share/man
DOCDIR = $(BASEDIR)/usr/share/doc
MOODSSLIBDIR = $(LIBDIR)/moodss
# where the modules will be finally installed (useful in rpm specification):
MODULESDIR = $(MOODSSLIBDIR)
MOOMPSDOCDIR = $(DOCDIR)/moomps-$(VERSION)
MOOMPSHTMLDIR = $(MOOMPSDOCDIR)
MOOMPSRCFILE = $(ETCDIR)/moomps/rc


### You should not need to change anything below this line ###
###    (let me know at jfontain@free.fr if you have to)    ###

all: moomps

install:
	mkdir -p $(ROOTDIR)$(SBINDIR)
	mkdir -p $(ROOTDIR)$(ETCDIR)/moomps
	mkdir -p $(ROOTDIR)$(INITDIR)
	mkdir -p $(ROOTDIR)$(MANDIR)/man1
	mkdir -p $(ROOTDIR)$(MOOMPSDOCDIR)
	# append final modules directory to Tcl automatic package path:
	sed -e 's,$$::tcl_library/moodss,$(MODULESDIR),;' moomps > $(ROOTDIR)$(SBINDIR)/moomps
	chmod 755 $(ROOTDIR)$(SBINDIR)/moomps
	cp -f moomps.sh $(ROOTDIR)$(INITDIR)/moomps
	# possibly generate an empty but valid XML resources file with the proper attributes:
	if [ ! -f $(ROOTDIR)$(MOOMPSRCFILE) ]; then\
		echo -e '<?xml version="1.0"?>\n<!DOCTYPE moompsPreferences>\n\n<moompsPreferences></moompsPreferences>' >\
			$(ROOTDIR)$(MOOMPSRCFILE);\
		chmod 600 $(ROOTDIR)$(MOOMPSRCFILE);\
	fi
	cp -f documentation/moomps.1 $(ROOTDIR)$(MANDIR)/man1/
	cd documentation;\
		cp -f COPYRIGHT moomps.htm $(ROOTDIR)$(MOOMPSDOCDIR)/;\
	cd ..


clean:
	rm -f moomps

# combine all source into a single Tcl code file:
moomps:
	rm -f $@
	echo '#!$(TCLSH)' > $@
	$(TCLSH) source.tcl -d 1 moomps.tcl >> $@
	sed\
		-e 's/if {\[catch {package require stooop.*/if 1 {/;'\
		-e 's/if {\[catch {package require switched.*/if 1 {/;'\
		$@ > moomps.tmp
	mv -f moomps.tmp $@
	chmod 755 $@
