#! /usr/bin/env python
# CONFIDENTIAL. (C) 2022 Cadence Design Systems, Inc. (Cadence)
# All rights reserved.
# ALL SOFTWARE BELOW IS PROPRIETARY AND CONFIDENTIAL TO CADENCE
# AND IS SUBJECT TO THE FULL PROTECTION OF COPYRIGHT AND TRADE SECRET LAW.
# Copying or modifying this software is strictly prohibited and illegal.
# Using this software without a valid license from Cadence is strictly
# prohibited and illegal.  De-obfuscating, de-minimizing, or any other
# attempt to reverse engineer or discover the workings of this software,
# is strictly prohibited. Even if software is exposed or visible, it is
# still proprietary and confidential and the above prohibitions apply.
# This software is NOT "Sample Code". For purposes of customization or
# interoperation with other software you must use Sample Code
# specifically labeled as such.
# Please contact Cadence at eyesopen.com/legal if you have any questions
# about this warning.
from __future__ import print_function
import os
import sys
import getopt
import openeye_platform

def main(argv=[__name__]):
    """
    Print out a string representing OpenEye architecture string for
    the machine this script is running on.

    --python     => append the python version used to run this script
    --pythonlibs => implies --python, also append the compiler version
                    for this python interpreter
    --arch <val> => overrides the detected architecture by setting <val> in
                    the environment, used for creating single-build packages
    --python_compiler <val> => overrides the detected python compiler by
                               setting <val> in the environment, used for
                               creating single-builds
    """

    if sys.platform.startswith("win") and "--pythonlibs" in argv:
        return 0

    opt, args = getopt.getopt(argv[1:],"",
                    ["arch=", "python", "pythonlibs", "python_compiler="])
    for o,v in opt:
        if o == "--arch":
            os.environ["OE_PIP_ARCH"] = v
        if o == "--python_compiler":
            os.environ["OE_PYTHON_COMPILER"] = v

    parts = []
    if "--pythonlibs" in argv or "--python" in argv:
        parts.append(openeye_platform.openeye_python_version())

    parts.extend(openeye_platform.openeye_platform())

    if "--pythonlibs" in argv:
        parts.append(openeye_platform.openeye_python_compilers()[0])

    print("-".join(parts))

    return 1

if __name__ == "__main__":
    sys.exit(main(sys.argv))

