# The main MMSS makefile. You shouldn't need to edit this at all.
# Hopefully.
# Looking for way to compile news entries into separate pages
# for the news section. That may need this file to be edited
# (to add new rules and commands).
#
# Edited from a TEST makefile, some old messing about still remains.

# NOTE: The VPATH variable should almost certainly be EMPTY.
# directory searching is done explicitly, and doing it any
# other way could end up with index.html files clobbering
# each other.

crd=.
cdir=.
# should these be in root.targets too?
all: root_targets rest_targets upload

#*.html: $(crd)/template.m4 $(crd)/site.nav
*.html: template.m4 site.nav site.cfg
# gah! this doesn't seem to work for subdirs...
# as such, this should actually be in root.targets.
# furthermore, the files now depend on site.cfg (template.m4 need hardly
# change at all now except for code improvements...)


# new style layouts build system:
#   env REALTARGET=copy.cfg m4 -P  shebang.m4
#   which for the makefile turns into:
#   cd $(cdir); env REALTARGET=$(<F)  m4 -P -I$(crd) $(crd)/template.m4 shebang.m4 > $(@F)

%.html: %.layout %.pnav
	cd $(cdir); m4 -P -I$(crd) $(crd)/template.m4 $(<F) > $(@F)
	@echo $@ >>updates.list


#upload command:
#ftp-upload --host `clipcode host.cfg ftphost` --user `clipcode host.cfg user` -s  --full-path `cat updates.list ` 

# giving a rule for an updates.list target has messed things up in the
#  past. What I really want is something so it either touches the file
#  if it's missing in order to create it, or just a notice "you must
#  create the file with touch updates.list" and then exiting.
# But previously, having a rule for it meant it'd get automatically
# called even when the file was new...

updates.list:
	@touch updates.list
	@echo The file "updates.list" was missing, so it\'s
	@echo just been created. It would have been created
	@echo anyway if there were any updates to upload, but
	@echo otherwise, you\'d just get weird
	@echo \ \"no rule to make target updates.list\"
	@echo errors from make. You shouldn\'t hear this again,
	@echo rather, you\'ll be told \"nothing to be done for all\"
	@echo until you update your content.
	@echo Now exiting \(with error\) to avoid spurious upload, have a nice day.
	@touch upload
	@false

upload: updates.list
	@echo preparing to upload...
	@echo normalising updates list #just to get rid of dupes
	@TEMPLIST=`tempfile`; cat updates.list | sort | uniq > $$TEMPLIST ; mv $$TEMPLIST updates.list 
	@echo -----updates.list:-----
	@cat updates.list
	@echo -------uploading-------
	@echo  -enter ftp password \(or ^D to quit\) :
	@# previously used /usr/games/random -e 2 as test command...
	@if ftp-upload --host `clipcode host.cfg ftphost` \
	   --user `clipcode host.cfg user` -s \
	   --full-path `cat updates.list` ;\
	 then \
	   echo -e upload succeeded\\nclearing updates list;\
	   rm updates.list; touch updates.list;\
	   echo making timestamp; touch upload;\
	 else \
	   echo -e \\nupload failed, try again later;\
	 fi
	@echo -----------------------

include root.targets
include rest.targets

