# $Id: moomps.mk,v 1.7 2006/10/07 09:54:06 jfontain Exp $


VERSION = 5.8

# 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
# where the dashboards should be according to the Filesystem Hierarchy Standard:
DATADIR = $(BASEDIR)/srv
INITDIR = $(BASEDIR)/etc/rc.d/init.d
MANDIR = $(BASEDIR)/usr/share/man
DOCDIR = $(BASEDIR)/usr/share/doc
MOODSSLIBDIR = $(LIBDIR)/moodss
PIDFILE = $(BASEDIR)/var/run/moomps.pid
LOCKFILE = $(BASEDIR)/var/lock/subsys/moomps
# 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: all
	mkdir -p $(ROOTDIR)$(SBINDIR)
	mkdir -p $(ROOTDIR)$(ETCDIR)/moomps
	mkdir -p $(ROOTDIR)$(DATADIR)/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),;' -e 's,variable moompsResourceFile /etc/moomps/rc,variable moompsResourceFile $(MOOMPSRCFILE),;' moomps >$(ROOTDIR)$(SBINDIR)/moomps
	chmod 755 $(ROOTDIR)$(SBINDIR)/moomps
	sed -e 's,$$SBINDIR,$(SBINDIR),g;' -e 's,$$MOOMPSRCFILE,$(MOOMPSRCFILE),g;' -e 's,$$PIDFILE,$(PIDFILE),g;' -e 's,$$LOCKFILE,$(LOCKFILE),g;' -e 's,$$DATADIR,$(DATADIR),g;' moomps.sh >$(ROOTDIR)$(INITDIR)/moomps
	chmod 755 $(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" encoding="utf-8"?>\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 $@
