--- /opt/local/var/macports/sources/svn.macports.org/trunk/dports/science/sumo/Portfile	2014-05-05 19:41:41.000000000 -0700
+++ Portfile	2014-06-14 14:05:50.000000000 -0700
@@ -1,11 +1,12 @@
 # -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
-# $Id: Portfile 119599 2014-05-02 07:55:38Z ryandesign@macports.org $
+# $Id: Portfile 119083 2014-04-16 20:47:35Z macsforever2000@macports.org $
 
 PortSystem          1.0
 
 name                sumo
 conflicts           sumo-devel
 version             0.20.0
+revision            2
 categories          science devel
 platforms           darwin
 maintainers         me.com:jens.fahnenbruck \
@@ -22,6 +23,7 @@
 homepage            http://sumo-sim.org/
 master_sites        sourceforge:project/sumo/sumo/version%20${version}/
 
+
 distname            ${name}-src-${version}
 worksrcdir          ${name}-${version}
 
@@ -35,6 +37,141 @@
     port:proj \
     port:xercesc
 
+# py27-matplotlib requires perl so let it choose which version
+depends_lib-append \
+    port:python27 \
+    port:py27-matplotlib
+
+set sharedir          ${prefix}/share/${name}
+set docdir            ${prefix}/share/doc/${name}
+set python_bin        ${frameworks_dir}/Python.framework/Versions/2.7/bin/python2.7
+set python_lib        ${frameworks_dir}/Python.framework/Versions/2.7/lib/python2.7/site-packages
+set perl_bin          "/usr/bin/env perl"
+
+post-patch {
+    reinplace "s#std::getenv(\"SUMO_HOME\")#\"${sharedir}\"#" src/utils/xml/SUMOSAXReader.cpp
+    reinplace "s#\./PHEMlight/#${sharedir}/data/PHEMlight/#" src/microsim/MSFrame.cpp
+    reinplace "s#\./PHEMlight/#${sharedir}/data/PHEMlight/#" src/router/ROFrame.cpp
+    reinplace -locale C "s#./PHEMlight/#${sharedir}/data/PHEMlight/#" src/tools/emissionsDrivingCycle_main.cpp
+    reinplace -locale C "s#./PHEMlight/#${sharedir}/data/PHEMlight/#" src/tools/emissionsMap_main.cpp
+    set python_bin ${frameworks_dir}/Python.framework/Versions/2.7/bin/python2.7
+    foreach f $python_scripts {
+        reinplace "s#/usr/bin/env python#${python_bin}#" $f
+        reinplace -E "s|^(sys.path.append)|# \\1|" $f
+        reinplace -E "s#^from (dijkstra|inputs)#from assign.\\1#" $f
+        reinplace -E "s#^import (xsd|collectinghandler|connections|turndefinitions|rmsd)#from sumolib import \\1#" $f
+        reinplace -E "s#^import (os,.*), helpers#import \\1, sumolib.helpers as helpers#" $f
+    }
+    foreach f $perl_scripts {
+        reinplace "s#/usr/bin/perl#${perl_bin}#" $f
+    }
+}
+
+# List of all python scripts. Used later to ensure usage of python27
+# (instead of the currently active python)
+set python_scripts [ list \
+    tools/bin/traceExporter.py \
+    tools/assign/Assignment.py \
+    tools/assign/cadytsIterate.py \
+    tools/assign/costFunctionChecker.py \
+    tools/assign/duaIterate.py \
+    tools/assign/duaIterate_analysis.py \
+    tools/assign/matrixDailyToHourly.py \
+    tools/assign/networkStatistics.py \
+    tools/assign/one-shot.py \
+    tools/assign/run.py \
+    tools/detector/aggregateFlows.py \
+    tools/detector/deleteUnusedDetectors.py \
+    tools/detector/flowFromRoutes.py \
+    tools/net/0103to0110.py \
+    tools/net/0123to0130.py \
+    tools/net/batch0103to0110.py \
+    tools/net/createRoundaboutConnections.py \
+    tools/net/netcheck.py \
+    tools/net/netdiff.py \
+    tools/net/netduplicate.py \
+    tools/net/netextract.py \
+    tools/net/netextract_subPart.py \
+    tools/net/netmatch.py \
+    tools/net/netshiftadaptor.py \
+    tools/net/netstats.py \
+    tools/net/network_statistics.py \
+    tools/net/odConnectionsCheck.py \
+    tools/net/OrderedMultiSet.py \
+    tools/net/patchNetFiles.py \
+    tools/net/prepareVISUM.py \
+    tools/net/reprojectpolys.py \
+    tools/net/visum_mapDistricts.py \
+    tools/net/xmlconnections_mapEdges.py \
+    tools/net/xmledges_applyOffset.py \
+    tools/net/xmlnodes_applyOffset.py \
+    tools/output/accelerations.py \
+    tools/output/analyze_teleports.py \
+    tools/output/generateITetrisIntersectionMetrics.py \
+    tools/output/generateITetrisNetworkMetrics.py \
+    tools/output/generateMeanDataDefinitions.py \
+    tools/output/generateTLSE1Detectors.py \
+    tools/output/generateTLSE2Detectors.py \
+    tools/output/generateTLSE3Detectors.py \
+    tools/output/netdumpdiff.py \
+    tools/output/netdumpmean.py \
+    tools/output/timingStats.py \
+    tools/output/vehLanes.py \
+    tools/output/vehrouteDiff.py \
+    tools/route/cutRoutes.py \
+    tools/route/extract_route_edges.py \
+    tools/route/findUTurns.py \
+    tools/route/kShortest.py \
+    tools/route/route2alts.py \
+    tools/route/route2poly.py \
+    tools/route/route_1htoDay.py \
+    tools/route/route_departOffset.py \
+    tools/route/routecheck.py \
+    tools/route/routecompare.py \
+    tools/route/routes2OD.py \
+    tools/route/routes_Join.py \
+    tools/route/sort_routes.py \
+    tools/route/tracegenerator.py \
+    tools/route/tracemapper.py \
+    tools/route/vehicle2flow.py \
+    tools/shapes/circlePolygon.py \
+    tools/shapes/CSV2polyconvertXML.py \
+    tools/shapes/poi_alongRoads.py \
+    tools/shapes/poi_atTLS.py \
+    tools/shapes/pois2inductionLoops.py \
+    tools/trigger/csv2vss.py \
+    tools/trip/randomTrips.py \
+    tools/trip/generateTripsXml.py \
+    tools/trip/route2trips.py \
+    tools/turn-defs/generateTurnDefs.py \
+    tools/visualization/mpl_dump_onNet.py \
+    tools/visualization/mpl_dump_timeline.py \
+    tools/visualization/mpl_dump_twoAgainst.py \
+    tools/visualization/mpl_tripinfos_twoAgainst.py \
+    tools/visualization/plot_csv_bars.py \
+    tools/visualization/plot_csv_pie.py \
+    tools/visualization/plot_csv_timeline.py \
+    tools/visualization/plot_net_dump.py \
+    tools/visualization/plot_net_selection.py \
+    tools/visualization/plot_net_speeds.py \
+    tools/visualization/plot_net_trafficLights.py \
+    tools/visualization/plot_summary.py \
+    tools/visualization/plot_tripinfo_distributions.py \
+    tools/xml/addSchema.py \
+    tools/xml/binary2plain.py \
+    tools/xml/csv2xml.py \
+    tools/xml/protobuf2xml.py \
+    tools/xml/rebuildSchemata.py \
+    tools/xml/schemaCheck.py \
+    tools/xml/xml2csv.py \
+    tools/xml/xml2protobuf.py \
+    tools/xml/xsd.py ]
+
+set perl_scripts [ list \
+    tools/trip/removeGeometryInTrips.pl \
+    tools/trip/removeTripsIfNotInInterval.pl \
+    tools/trip/splitTripsByHours.pl ]
+
 # required for the gui to be enabled
 configure.args-append \
     --with-fox=${prefix}
@@ -69,4 +206,41 @@
         --disable-traci
 }
 
-livecheck.regex     /${name}-all-(\[0-9.\]+)${extract.suffix}
+post-destroot {
+    xinstall -m 755 -d ${destroot}${python_lib}
+    file copy ${worksrcpath}/tools/sumolib ${destroot}${python_lib}/
+    if {![variant_isset no_traci]} {
+        file copy ${worksrcpath}/tools/traci ${destroot}${python_lib}/
+    }
+    file copy ${worksrcpath}/tools/assign ${destroot}${python_lib}/sumolib/
+    touch ${destroot}${python_lib}/sumolib/assign/__init__.py
+    file copy ${worksrcpath}/tools/turn-defs/connections.py ${destroot}${python_lib}/sumolib/
+    file copy ${worksrcpath}/tools/turn-defs/turndefinitions.py ${destroot}${python_lib}/sumolib/
+    # xinstall -m 755 -d ${destroot}${python_lib}/detector
+    xinstall -m 755 ${worksrcpath}/tools/detector/detector.py ${destroot}${python_lib}/sumolib/
+    xinstall -m 755 ${worksrcpath}/tools/turn-defs/collectinghandler.py ${destroot}${python_lib}/sumolib/
+    xinstall -m 755 ${worksrcpath}/tools/visualization/helpers.py ${destroot}${python_lib}/sumolib/
+    xinstall -m 755 ${worksrcpath}/tools/lib/rmsd.py ${destroot}${python_lib}/sumolib/
+    xinstall -m 755 ${worksrcpath}/tools/lib/play.png ${destroot}${python_lib}/sumolib/
+    xinstall -m 755 ${worksrcpath}/tools/lib/stop.png ${destroot}${python_lib}/sumolib/
+    xinstall -m 755 ${worksrcpath}/tools/lib/testUtil.py ${destroot}${python_lib}/sumolib/
+
+    foreach f [list {*}$python_scripts {*}$perl_scripts] {
+        # convert file names to use dash rather than underscore and remove trailing .py or .pl
+        set x [string map [list _ -] [file rootname [file tail ${f}]]]
+        xinstall -m 755 ${worksrcpath}/${f} ${destroot}${prefix}/bin/sumo-${x}
+    }
+
+    xinstall -m 755 -d ${destroot}${sharedir}
+    foreach d [list emissions typemap xsd] {
+        file copy ${worksrcpath}/data/${d} ${destroot}${sharedir}/${d}/
+    }
+    # tests/ is not included in the source tarball
+    # file copy ${worksrcpath}/tests ${destroot}${sharedir}/
+
+    xinstall -m 755 -d ${destroot}${docdir}
+    xinstall ${worksrcpath}/README ${destroot}${docdir}/
+    file copy ${worksrcpath}/docs/examples ${destroot}${docdir}/
+    file copy ${worksrcpath}/docs/tutorial ${destroot}${docdir}/
+    file copy ${worksrcpath}/data ${destroot}${sharedir}/data/
+}
