view world/Makefile @ 2510:83967e0447f7

Move pieces around in build system for some more clarity.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 02 Aug 2023 12:57:42 +0300
parents 6878dbdbc11e
children ec4294c93585
line wrap: on
line source

###
### Includes and settings
###
include ../config.mak
include ../Makefile.maps
include ../Makefile.paths

BINPATH=../bin/
EXEEXT=


ifeq ($(HAVE_CURL),yes)
HTTPGET ?= curl -o
else
ifeq ($(HAVE_WGET),yes)
HTTPGET ?= wget -O
else
ifeq ($(HTTPGET),)
$(error Required utility 'curl' or 'wget' not found in PATH. You can configure HTTPGET variable in config.mak.)
endif
endif
endif


###
### Main targets
###
TARGETS = \
	$(addsuffix .html,$(WORLD_MAPS)) \
	$(addsuffix .ansi,$(WORLD_MAPS)) \
	$(addsuffix .png,$(WORLD_MAPS)) \
	$(addsuffix .htm,$(WORLD_MAPS)) \
	util.js changelog.txt

LOCFILES = $(addsuffix .loc,$(WORLD_MAPS)) special.loc limbo.loc

ifeq ($(HAVE_PHP),yes)
TARGETS += markers.xml
EXTRA_UPLOAD += markers.xml
endif


###
### If no target specified, show some help
###
all:
	@echo "Usage: make <target>"
	@echo "Available targets are as follows:"
	@echo
	@echo "maps    : Build HTML, HTML+JS, PNG image and ANSI format maps."
	@echo "fetch   : Fetch latest raw ASCII map data from bat.org."
	@echo
	@echo "diff    : Do special diff operation between new data (gotten via 'fetch')"
	@echo "          and update .loc files for each continent with new locations."
	@echo "          A diff -u of new and old location files is outputted."
	@echo
	@echo "upload  : Uploads map and loc-files via SCP to server specified in"
	@echo "          ../config.mak"
	@echo
	@echo "clean   : Delete all the generated files."
	@echo


###
### Targets
###
maps: $(addsuffix .ppm,$(WORLD_MAPS)) $(TARGETS)


%.script: %.map %.loc title.png $(WORLDMAP_FONT_FILE) $(MKLOC_BIN)
	@echo "MKLOC $@"
	@$(MKLOC_BIN) $(MKLOC_OPTS) -S -m $< -l $(patsubst %.map,%.loc,$<) -f $(WORLDMAP_FONT_SCALE) -u $(WORLDMAP_UNIT_SIZE) -s $(WORLDMAP_SCALE) | \
	sed -e "s/@OPTS_START@/-font $(WORLDMAP_FONT_FILE) -pointsize 14 -type TruecolorMatte/g" \
	-e "s/@OPTS_END@/\t-geometry +0+0 title.png -composite -compose screen \\\\\n\t-pointsize 20 -fill white -box none -draw \"text 5,50 \'@PAF@\n\n\n/g" | \
	sed -e "/@PAF@/r $(patsubst %.map,%.desc,$<)" -e "s/@PAF@//g" > $@

%.ppm: %.map
	@echo "MAP2PPM $@"
	@$(MAP2PPM_BIN) $(MAP2PPM_OPTS) -s $(WORLDMAP_SCALE) $(COLORMAP_EXTRA) $< -o $@

ifeq ($(HAVE_GIMP_CONSOLE),yes)
%_rgb.png: %.ppm %.script %.desc
	@echo "PNG $@"
	@/bin/sh $(patsubst %.ppm,%.script,$<) $< $@

%.png: %_rgb.png
	@echo "GIMP $@"
	@gimp-console -c -d -i -b \
	"(let* ( \
	(img (car (file-png-load RUN-NONINTERACTIVE \"$<\" \"$<\"))) \
	(drawable (car (gimp-image-active-drawable img)))) \
	(gimp-convert-indexed img NO-DITHER MAKE-PALETTE 64 FALSE FALSE \"\") \
	(file-png-save2 RUN-NONINTERACTIVE img drawable \"$@\" \"$@\" 0 9 0 0 0 0 0 0 0))" \
	-b '(gimp-quit 0)'
else
%.png: %.ppm %.script %.desc
	@echo "PNG $@"
	@/bin/sh $(patsubst %.ppm,%.script,$<) $< $@
endif


###
### Diff target between .map file and .new file. Makes necessary changes in .map and .loc
###
%.diff: %.map %.new
	@echo "DIFFING $< ..."
	@if $(DIFFMAP_BIN) $(DIFFMAP_OPTS) $+ -o $@ -a; then \
		echo "PATCHING ..."; \
		$(MAP2PPM_BIN) $@ -o $@.ppm -d; \
		$(PATCHMAP_BIN) $< $@ -o $<; \
	fi
	@echo "UPDATING LOCATIONS ..."
	@$(MKLOC_BIN) -v -m $(patsubst %.map,%.new,$<) -l $(patsubst %.map,%.loc,$<) -L -g -o $(patsubst %.map,%.nloc,$<)
	@diff -ubB $(patsubst %.map,%.loc,$<) $(patsubst %.map,%.nloc,$<) | patch
# Fetch raw ASCII maps from bat.org to *.new
fetch:
	@for AMAP in $(CONT_MAPS); do echo "Fetching $${AMAP}.new"; $(HTTPGET) "$${AMAP}.new" "$(BATMAPURL)$${AMAP}.txt"; done


# Remove all temporary .diff files
cleardiff:
	$(RM) *.diff

# Diff target - run diff for each .map and .new (fetched via 'fetch' target).
# Finally do 'hg diff' to show changes.
diff: cleardiff $(addsuffix .diff,$(CONT_MAPS))
	@hg diff .

%.js:: ../src/%.js
	@ln -s $< $@


changelog.txt: $(addsuffix .map,$(WORLD_MAPS)) \
	$(addsuffix .loc,$(WORLD_MAPS)) \
	$(addprefix ../$(MISC_MAPS_PATH),$(addsuffix .map,$(MISC_MAPS))) \
	$(addprefix ../$(MISC_MAPS_PATH),$(addsuffix .loc,$(MISC_MAPS)))
	@hg up && ( echo '<?xml version="1.0"?>' && echo '<log>' && \
	hg log $+ -M -v -f --template \
	'<logentry revision="{rev}"><author>{author|escape}</author><date>{date|isodate}</date><paths><path>{files}</path></paths><msg>{desc|escape}</msg></logentry>\n' && \
	echo '</log>' ) | \
	iconv -f "iso-8859-1" -t "utf-8" | \
	xsltproc --stringparam strip-prefix "" \
		 --stringparam linelen 80 \
		 --stringparam groupbyday yes \
		 --stringparam include-rev no \
		 "svn2cl.xsl" - | \
	sed 's/world\///g;s/maps\///g;s/Matti .*/Ggr/g;s/Jarkko .*/Jeskko/g' \
	> $@


# Build Batclient markers.xml
markers.xml: $(addsuffix .loc,$(WORLD_MAPS)) $(MKLOC_BIN) ../www/world.inc.php
	php ../src/genbcxml.php $(MKLOC_BIN) ./ ../www/world.inc.php $@


# Upload changed files to site
upload: $(TARGETS) $(LOCFILES) $(EXTRA_UPLOAD)
	$(RSCP) $? $(UPLOAD_URL)
	@touch $@

# Upload only *.loc files
uploc: $(LOCFILES) $(EXTRA_UPLOAD)
	$(RSCP) $+ $(UPLOAD_URL)

# Clean temporary and generated targets
clean:
	$(RM) $(TARGETS) *.diff *.ppm *.o *.script

srcclean: clean
	$(RM) *~