#!/usr/bin/env python3
#
# sizes -- explore the sizes of static gpsd binaries
#
# This code runs compatibly under Python 2 and 3.x for x >= 2.
# Preserve this property!
from __future__ import absolute_import, print_function, division

import os

# NMEA variants other than vanilla NMEA
nmea_variants = [
  "fv18=no",
  "mtk3301=no",
  "tnt=no",
  "gpsclock=no",
]

# Binary GPS protocols
binary_gps = [
  "oncore=no",
  "sirf=no",
  "superstar2=no",
  "tsip=no",
  "tripmate=no",
  "earthmate=no",
  "itrax=no",
  "ashtech=no",
  "navcom=no",
  "garmin=no",
  "garmintxt=no",
  "ubx=no",
  "geostar=no",
  "evermore=no",
]

# Differential correction and AIVDM
non_gps = [
  "ntrip=no",
  "aivdm=no",
  ]

# Debugging and profiling
debugging = [
  "clientdebug=no",
  "oldstyle=no",
  ]


class BuildFailed(BaseException):
    "Build failed for this configuration."
    pass


def sizeit(legend, tag, options):
    print(legend + ":")
    print("Options:", " ".join(options))
    os.system("scons -c > /dev/null; rm -fr .scon*")
    status = os.system("scons shared=no " + " ".join(options)
                       + " gpsd >/dev/null")
    if status != 0:
        raise BuildFailed(options)
    os.rename("gpsd", "gpsd-" + tag + "-build")
    os.rename("gpsd_config.h", "gpsd_config.h-" + tag)


# Main sequence
os.system("uname -a")
sizeit("Minimalist build, stripped to NMEA only with shm interface",
       "minimalist",
       ["socket_export=no",
        "control_socket=no",
        "ipv6=no",
        "netfeed=no",
        "passthrough=no",
        "fixed_port_speed=9600",
        "max_devices=1",
        ] + nmea_variants + binary_gps + non_gps + debugging)
sizeit("Normal build, configure options defaulted", "normal", [])
os.system("size gpsd-*-build")
# os.system("rm gpsd-*-build gpsd.h-*")
os.system("scons -c > /dev/null; rm -fr .scon*")

# end
