#!/bin/bash

echo -n "LOC_FILES=" > $2
sed -e 's/^[0-9]*://g' < $1 | sort | uniq | while IFS=: read lat lng junk; do
	HASH=$(echo -n "$lat:$lng" | md5sum | cut -d ' ' -f 1)
	echo "cache/$HASH.geo \\"
done | sort | uniq >> $2

cat >> $2 << ENDL


.PHONY: locations

locations: \$(LOC_FILES)
ENDL

sed -e 's/^[0-9]*://g' < $1 | sort | uniq | while IFS=: read lat lng junk; do
	HASH=$(echo -n "$lat:$lng" | md5sum | cut -d ' ' -f 1)
	echo "cache/$HASH.geo:;"
	echo -e "\twget \"http://maps.google.com/maps/api/geocode/json?latlng=$lat,$lng&sensor=false\" -O cache/$HASH.geo"
	echo -e "\tsleep 0.5"
	echo 
done >> $2
