# 
# Makefile to build a custom+ SSO for skunkware
# hess@sco.com
#

HERE=`pwd`
CFG=-config cdmt.config
CDCFG=-config cdmt.cd.config

#all:: cdmt.config cdmt.cd.config sso ssoCD
all:: sso 

# If we are exporting to the system from this SSO, then this 
# rule will wipe out the existing (installed) SSO, making it uninstalled
# and perhaps leaving custom databases in an awkward state.
# so be warned
ssoCD : input/default.prd cdmt.cd.config Makefile
	rm -rf $@	
	CDMT_DIR=$(HERE) cdmtParse  $(CDCFG)
	CDMT_DIR=$(HERE) cdmtCompress  $(CDCFG)
	CDMT_DIR=$(HERE) cdmtArchive -f $(CDCFG)
sso: input/default.prd cdmt.config Makefile
	rm -rf $@	
	CDMT_DIR=$(HERE) cdmtParse  $(CFG)
	CDMT_DIR=$(HERE) cdmtCompress  $(CFG)
	CDMT_DIR=$(HERE) cdmtArchive -f $(CFG)

#install ::
#	@echo To install the skunk SSO on this machine run 
#	@echo as root 
#	@echo make export enable 
#
# install the archives/TAPE onto my machine, two passes, Load and Enable

# must be root to do this
install:: load enable

# custom load is -L, -z is the image directory
export load:: archives/TAPE
	custom -p SKUNK:default -L -z $(HERE)/archives/TAPE

# custom enable, this requires that it be "loaded", then we can populate 
# the /usr space. 
enable: /opt/P/SKUNK
	custom -p SKUNK:default -e

no_skunk really_clean_sys : disable remove clean_system
# custom disable, but dont remove
disable:
	custom -p SKUNK:default -d
# really remove the files from /opt/?/SKUNK
remove:
	custom -p SKUNK:default -r
# remove SKUNK from the /opt area
clean_system::
	rm -rf /opt/?/SKUNK /var/opt/K/SKUNK

# export the ssoCD to my machine
# do a quick install on my own machine
# start by disabling the skunk on my machine 
# only works if the perms in the ssoCD dir allow those binaries to be
# executed and read ...  to get this right run "make fixall"
export_CD:  ssoCD 
	-custom -p SKUNK:default -d
	rm -rf /opt/?/SKUNK /var/opt/K/SKUNK
	-mkdir -p /opt/P/SKUNK/default /opt/K/SKUNK /var/opt/K/SKUNK
	( cd ./ssoCD ; for i in opt/P/SKUNK/default/5.0; do \
		ln -s $(HERE)/$$i /$$i ; \
	done )
	( cd ./ssoCD ; for i in opt/K/SKUNK/*; do \
		mkdir -p /$$i ; \
	done )
	( cd ./ssoCD ; for i in opt/K/SKUNK/*/*; do \
		ln -s $(HERE)/$$i /$$i ; \
	done )

# just a quick fix, for stuff we know we need to tweak ...
# dont run this on a readonly ssoCD 
fixup_perms fp quickfix: 
	find ./ssoCD -name "ccs" -exec chmod +x {} \;  
	chmod +x ./ssoCD/opt/K/SKUNK/xmcd/1.4/libdi.d/configure.sh 

# this is not quick at all ...
# and you must be root, should be done after a "make export" 
# and before make enable
fixall fix_all fixperms fixperm: 
	custom -p SKUNK:default -v quick -x >/dev/null

# to test the prd database file
parse.prd parse prd :
	cdmtParse -prd input/default.prd  $(CFG) 

# after a compress and parse
archCD : 
	CDMT_DIR=$(HERE) cdmtArchive -f $(CDCFG)
arch : 
	CDMT_DIR=$(HERE) cdmtArchive -f $(CFG)



fresco: ../X11/Fresco/fresco.cmpnt
acm : ../Games/acm-4.7/acm.cmpnt
xpilot : ../Games/xpilot-3.3.1/xpilot.cmpnt
gds : ../Tools/gds/gds.cmpnt
groff: ../Tools/groff-1.09/groff.cmpnt
xmcd: ../X11/xmcd-1.4/xmcd.cmpnt
xsw: ../X11/xsw/xsw.cmpnt
xv: ../X11/xv-3.10/xv.cmpnt
perl: ../Tools/perl-5.000/perl.cmpnt

CMPNTS=../X11/Fresco/fresco.cmpnt \
	../Games/acm-4.7/acm.cmpnt \
	../Games/xpilot-3.3.1/xpilot.cmpnt \
	../Tools/gds/gds.cmpnt \
	../Tools/groff-1.09/groff.cmpnt \
	../X11/xmcd-1.4/xmcd.cmpnt \
	../Tools/perl-5.000/perl.cmpnt \
	../X11/xsw/xsw.cmpnt \
	../X11/xv-3.10/xv.cmpnt

.PRECIOUS:$(CMPNTS)
$(CMPNTS) : cdmt.config 
	cdmtParse -cmpnt $@
	cdmtCompress -cmpnt $@
	#cdmtArchive 


# some rules for building and test install of one cmpnt
# first run 
# make xmcd arch 
# then 
# make xmcd_try 
# 
# we disable, them remove, then load from the arch, then enable ... 
# this can be done for other cmpnts/packages as well
xmcd_try : 
	custom -p SKUNK:default -d SKUNK:xmcd
	custom -p SKUNK:default -r SKUNK:xmcd 
	custom -p SKUNK:default -L SKUNK:xmcd -z $(HERE)/archives/TAPE
	custom -p SKUNK:default -e SKUNK:xmcd
gds_try : 
	custom -p SKUNK:default -d SKUNK:gds
	custom -p SKUNK:default -r SKUNK:gds 
	custom -p SKUNK:default -L SKUNK:gds -z $(HERE)/archives/TAPE
	custom -p SKUNK:default -e SKUNK:gds
groff_try : 
	custom -p SKUNK:default -d SKUNK:groff
	custom -p SKUNK:default -r SKUNK:groff 
	custom -p SKUNK:default -L SKUNK:groff -z $(HERE)/archives/TAPE
	custom -p SKUNK:default -e SKUNK:groff


