SHELL = /bin/bash BINDIR = bin TMPDIR = tmp DOCDIR = doc PATH := $(PATH):$(BINDIR) # list of itineraries to generate GPX and HTML files from and to crosscheck ITINERARIES = $(basename $(notdir $(wildcard $(DOCDIR)/*.xls))) # list of itineraries whose GPX and HTML files should be installed in the corresponding holiday directories INSTALLABLE_ITINERARIES = $(ITINERARIES) # generator and crosschecker tool CSV2XXX_CMD = csv2xxx # tolerance 0.0001 degrees is fine, but at 0.00011 degrees then it # starts thinking different camps are actually the same camps (mainly # round Prague). CSV2XXX_TOLERANCE_OPT = --tolerance=0.0001035 CSV2XXX_MISMATCH_OPT = $(TMPDIR)/camping-guide.kml: $(TMPDIR)/all-gpx-and-html-installed.timestamp $(TMPDIR)/camping-guide-installed.timestamp: $(TMPDIR)/camping-guide.kml scp -q $(TMPDIR)/camping-guide.kml root@vesuvio:/var/www/suzanneramsay.freemyip.com/wp-content/uploads/private/campsite-guide/camping-guide-map.kml $(TMPDIR)/all-gpx-and-html-installed.timestamp: $(TMPDIR)/all-csv-crosschecked.timestamp $(TMPDIR)/all-gpx-generated.timestamp $(TMPDIR)/all-html-generated.timestamp @[ "$(findstring s,$(MAKEFLAGS))" ] || echo "cp $(TMPDIR)/*.gpx ../holidays/.../waypoints/..." @[ "$(findstring s,$(MAKEFLAGS))" ] || echo "cp $(TMPDIR)/*.html ../holidays/.../html/..." @for GPX in $(TMPDIR)/*.gpx; do \ for HOLIDAY_DIR in ../holidays/20????-*; do \ [[ $$GPX =~ $(TMPDIR)/(.*)\.gpx ]] || continue; \ GPX_STEM=$${BASH_REMATCH[1]}; \ [[ $$HOLIDAY_DIR =~ \.\./holidays/20....-(.*) ]] || continue; \ HOLIDAY_DIR_STEM=$${BASH_REMATCH[1]}; \ [ $$GPX_STEM = $$HOLIDAY_DIR_STEM ] || continue; \ cp $$GPX $$HOLIDAY_DIR/waypoints/$$HOLIDAY_DIR_STEM-waypoints-camps.gpx; \ cp $${GPX%.gpx}.html $$HOLIDAY_DIR/html/$$HOLIDAY_DIR_STEM-camps.html; \ done; \ done touch $@ $(TMPDIR)/all-csv-crosschecked.timestamp: $(TMPDIR)/all-csv-generated.timestamp $(CSV2XXX_CMD) $(CSV2XXX_TOLERANCE_OPT) $(CSV2XXX_MISMATCH_OPT) --output-format=null $(TMPDIR)/*.csv touch $@ $(TMPDIR)/all-gpx-generated.timestamp: $(addprefix $(TMPDIR)/,$(addsuffix .gpx, $(ITINERARIES))) touch $@ $(TMPDIR)/all-csv-generated.timestamp: $(addprefix $(TMPDIR)/,$(addsuffix .csv, $(ITINERARIES))) touch $@ $(TMPDIR)/all-html-generated.timestamp: $(addprefix $(TMPDIR)/,$(addsuffix .html, $(ITINERARIES))) touch $@ $(TMPDIR)/%.gpx: $(TMPDIR)/%.csv $(CSV2XXX_CMD) --output-format=gpx $^ > $@ $(TMPDIR)/%.html: $(TMPDIR)/%.csv $(CSV2XXX_CMD) --output-format=html $^ > $@ $(TMPDIR)/%.kml: $(TMPDIR)/%.csv @# Note that camping-guide.kml depends on the .timestamp file that indicates @# all crosschecks have been done, so we need to filter out the .timestamp file. $(CSV2XXX_CMD) --output-format=kml $(filter-out %.timestamp, $^) > $@ # See https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options, # especially the examples right at the end of the page. The important bits here are # '76' meaning UTF, 'true' meaning 'quote all text fields' $(TMPDIR)/%.csv: $(DOCDIR)/%.xls @[ "$(findstring s,$(MAKEFLAGS))" ] || echo "libreoffice ... --convert-to csv ... $<" @libreoffice -env:UserInstallation=file:///var/tmp/$$USER/.libreoffice-alt --headless --convert-to "csv:Text - txt - csv (StarCalc):44,34,76,1,1/1,,true" --outdir $(TMPDIR) $< > /dev/null clean: rm -f $(TMPDIR)/*