#!/usr/bin/perl

#system ("/www/garmin/kraje/cut_cz.sh");

sub create_img () {
  for ($i = 0; $i < 14; $i++) {
    $j = $i + 1;
    $mapname = sprintf("%04d", $j);
    $filename = "osm/";
    $filename .= sprintf("%02d", $j);
    $filename .= ".osm";
    print "mkgmap $filename $j\n";
    system("/usr/bin/java -Xmx512m -jar mkgmap.jar --country-name=czechrepublic --country-abbr=CZ --mapname=4201$mapname --description='osm-cz-walley$mapname' $filename");
  }
}

sub create_mapset() {
  system("rm gmapsupp.img 42010000.tdb 42010000.img");
  system("/usr/bin/java -Xmx512m -jar mkgmap.jar --mapname=42010000 --overview-mapname=42010100 --tdbfile --product-id=420  --country-name=czechrepublic --country-abbr=CZ --gmapsupp 420*.img converted/*img");

  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  $year += 1900;
  $mon = sprintf("%02d", ++$mon);
  $mday = sprintf("%02d", $mday);
  $all_name="all$year$mon$mday.zip";
  system("/usr/bin/zip $all_name *.img *.tdb converted/*.img");
  system("ln -sf $all_name all_latest.zip");
}

print "create_maps\n";
&create_img();
print "compile mapset\n";
&create_mapset();
print "done\n";
