# GNU makefile used to compile and install the Calculating Infinity website.

# By Mark J. Skinner. From: https://www.cinfinity.info/makefile



SERVER_DOMAIN =		cinfinity.info
SERVER_USER =		root

SERVER_DIR =		/var/chroot/lighttpd/www
# SERVER_DIR =		/var/chroot/lighttpd/www/tmp
SERVER_URL =		$(SERVER_USER)@$(SERVER_DOMAIN):$(SERVER_DIR)/

# SERVER_DIR =		/tmp/extra/www
# SERVER_URL =		$(SERVER_DIR)/

ARCHIVE_FILE =		"www.cinfinity.info.tar"

SCRIPTS_DIR =		bin
SRC_DIR =		src
OLDSRC_DIR =		src/old
IMAGES_DIR =		images
PHOTOS_DIR =		photos
ICONS_DIR =		icons


CFG_FILE =		meta.cfg
TPL_FILE =		template.html

HTML_FILES =		index.html \
			stdconfig.html startd.html std3d.html goldstein.html \
			cdfp.html standards.html install.html \
			emotion.html it.html glossary.html ect-edl.html \
			islam-action.html medieval-nazism.html \
			feminism-docos.html communism-docos.html \
			islam-docos.html misc-docos.html \
			snowden-quotes.html \
			$(SRC_DIR)/index.html $(OLDSRC_DIR)/index.html \
			$(IMAGES_DIR)/index.html \
			$(IMAGES_DIR)/std3d-captures/index.html \
			$(IMAGES_DIR)/goldstein-captures/index.html \
			$(IMAGES_DIR)/nineteen-eighty-four/index.html \
			$(IMAGES_DIR)/the-soviet-story/index.html \
			$(PHOTOS_DIR)/index.html \
			$(SCRIPTS_DIR)/index.html $(ICONS_DIR)/index.html

TMP_FILES =		tmp.html */dir.html */*/dir.html \
			it_list.html it_intro.html it_body.html sm/*_body.html


HTMLMETA =		$(SCRIPTS_DIR)/html-meta
HTMLDIR =		$(SCRIPTS_DIR)/html-dir

STDCONFIGTOOL =		stdconfig-tool -format=html-list -dir-name-images=icons/red-ball.png,icons/yellow-ball.png,icons/green-ball.png,icons/cyan-ball.png,icons/blue-ball.png,icons/violet-ball.png
SMHTML =		sm-html

RSYNC =			rsync --delete --archive --update --chmod=D755,F644 \
			--verbose
RSYNC_EXCLUDES =	--exclude '*.md' --exclude '*_*.html' --exclude '*~' \
			--exclude dir.html --exclude images.html \
			--exclude archive --exclude www.cinfinity.info.tar\*

TAR =			tar --create --directory=$(dir $(SERVER_DIR)) \
			$(notdir $(SERVER_DIR))
TAR_EXCLUDES =		--exclude www/src/old/*.xz* \
			--exclude www/src/old/*.gz* \
			--exclude www/audio \
			--exclude www/video \
			--exclude www/tmp \
			--exclude www/www.cinfinity.info.tar\*

GZIP =			gzip --best



all:			$(HTML_FILES)

# prevent automatic removal of intermediate (*_body.html) files
.SECONDARY:


%.html:			%.md $(TPL_FILE) $(CFG_FILE)
			$(HTMLMETA) $(TPL_FILE) $(CFG_FILE) $< $@


it.html:		it_body.html $(TPL_FILE) $(CFG_FILE)
			$(HTMLMETA) $(TPL_FILE) $(CFG_FILE) $< $@ it.conf

it_body.html:		it_intro.html it_list.html
			cat $^ > $@

it_list.html:		it.conf
			$(STDCONFIGTOOL) $< $@

it_intro.html:		it_intro.md
			kramdown $< > $@


feminism-docos.html:	feminism-docos_list.html $(TPL_FILE) $(CFG_FILE)
			$(HTMLMETA) $(TPL_FILE) $(CFG_FILE) $< $@

communism-docos.html:	communism-docos_list.html $(TPL_FILE) $(CFG_FILE)
			$(HTMLMETA) $(TPL_FILE) $(CFG_FILE) $< $@

islam-docos.html:	islam-docos_list.html $(TPL_FILE) $(CFG_FILE)
			$(HTMLMETA) $(TPL_FILE) $(CFG_FILE) $< $@

misc-docos.html:	misc-docos_list.html $(TPL_FILE) $(CFG_FILE)
			$(HTMLMETA) $(TPL_FILE) $(CFG_FILE) $< $@


$(IMAGES_DIR)/index.html:	$(IMAGES_DIR)/images.html \
			$(TPL_FILE) $(CFG_FILE)
			$(HTMLMETA) $(TPL_FILE) $(CFG_FILE) $< $@

$(IMAGES_DIR)/std3d-captures/index.html: \
			$(IMAGES_DIR)/std3d-captures/images.html \
			$(TPL_FILE) $(CFG_FILE)
			$(HTMLMETA) $(TPL_FILE) $(CFG_FILE) $< $@

$(IMAGES_DIR)/goldstein-captures/index.html: \
			$(IMAGES_DIR)/goldstein-captures/images.html \
			$(TPL_FILE) $(CFG_FILE)
			$(HTMLMETA) $(TPL_FILE) $(CFG_FILE) $< $@

$(IMAGES_DIR)/nineteen-eighty-four/index.html: \
			$(IMAGES_DIR)/nineteen-eighty-four/images.html \
			$(TPL_FILE) $(CFG_FILE)
			$(HTMLMETA) $(TPL_FILE) $(CFG_FILE) $< $@

$(IMAGES_DIR)/the-soviet-story/index.html: \
			$(IMAGES_DIR)/the-soviet-story/images.html \
			$(TPL_FILE) $(CFG_FILE)
			$(HTMLMETA) $(TPL_FILE) $(CFG_FILE) $< $@

$(PHOTOS_DIR)/index.html:	$(PHOTOS_DIR)/photos.html \
			$(TPL_FILE) $(CFG_FILE)
			$(HTMLMETA) $(TPL_FILE) $(CFG_FILE) $< $@


$(SRC_DIR)/index.html:	$(SRC_DIR)/dir.html $(TPL_FILE) $(CFG_FILE)
			$(HTMLMETA) $(TPL_FILE) $(CFG_FILE) $< $@

$(SRC_DIR)/dir.html:	$(SRC_DIR)/*.xz* $(SRC_DIR)/*.gz* $(SRC_DIR)/*.zip $(SRC_DIR)/rsa-pubkey.gpg
			$(HTMLDIR) $@ $(SERVER_DOMAIN) $(SRC_DIR)/old/ $^


$(OLDSRC_DIR)/index.html:	$(OLDSRC_DIR)/dir.html $(TPL_FILE) $(CFG_FILE)
			$(HTMLMETA) $(TPL_FILE) $(CFG_FILE) $< $@

$(OLDSRC_DIR)/dir.html:	$(OLDSRC_DIR)/*.xz* $(OLDSRC_DIR)/*.gz*
			$(HTMLDIR) $@ $(SERVER_DOMAIN) $^


$(SCRIPTS_DIR)/index.html:	$(SCRIPTS_DIR)/dir.html $(TPL_FILE) $(CFG_FILE)
			$(HTMLMETA) $(TPL_FILE) $(CFG_FILE) $< $@

$(SCRIPTS_DIR)/dir.html:	$(HTMLMETA) $(HTMLDIR)
			$(HTMLDIR) $@ $(SERVER_DOMAIN) $^


$(ICONS_DIR)/index.html:	$(ICONS_DIR)/dir.html $(TPL_FILE) $(CFG_FILE)
			$(HTMLMETA) $(TPL_FILE) $(CFG_FILE) $< $@

$(ICONS_DIR)/dir.html:	$(ICONS_DIR)/*.png
			$(HTMLDIR) $@ $(SERVER_DOMAIN) $^



install:		all
			$(RSYNC) $(RSYNC_EXCLUDES) ./ $(SERVER_URL)

check:			all
			$(RSYNC) --dry-run $(RSYNC_EXCLUDES) ./ $(SERVER_URL)


archive-file:
			$(TAR) $(TAR_EXCLUDES) > $(ARCHIVE_FILE)
			$(GZIP) $(ARCHIVE_FILE)


clean:
			$(RM) $(HTML_FILES) $(TMP_FILES)


