def build()

in build.py [0:0]


def build():
    os.chdir(os.path.dirname(os.path.abspath(__file__)))

    # Clear .build
    if os.path.exists('.build'):
        shutil.rmtree('.build')

    env = {}

    # Set up temporary GOPATH
    os.makedirs(os.path.normpath('.build/src/github.com/openai'))
    os.symlink('../../../..', '.build/src/github.com/openai/go-vncdriver')
    env['GOPATH'] = os.path.join(os.getcwd(), '.build')
    env['GO15VENDOREXPERIMENT'] = '1' # Needed on Go 1.5, no-op on Go 1.6+

    # We need to prevent from linking against Anaconda Python's libpjpeg.
    #
    # Right now we hardcode these paths, and fall back to actually looking
    # it up.
    libjpg = os.getenv('LIBJPG')
    if not libjpg:
        for i in ['/usr/lib/x86_64-linux-gnu/libjpeg.so', '/usr/local/opt/jpeg-turbo/lib/libjpeg.dylib']:
            if os.path.exists(i):
                libjpg = i
                break

    # Note this might mean not getting libjpeg-turbo, which is quite nice
    # to have. Also, it doesn't work on macOS.
    if not libjpg:
        try:
            output = subprocess.check_output(['ld', '-ljpeg', '--trace-symbol', 'jpeg_CreateDecompress', '-e', '0'], stderr=subprocess.STDOUT)
            libjpg = output.decode().split(':')[0]
        except (subprocess.CalledProcessError, OSError):
            raise BuildException("Could not find libjpeg. HINT: try 'sudo apt-get install libjpeg-turbo8-dev' on Ubuntu or 'brew install libjpeg-turbo' on OSX")

    numpy_include = numpy.get_include()
    py_include = distutils.sysconfig.get_python_inc()
    plat_py_include = distutils.sysconfig.get_python_inc(plat_specific=1)
    includes = [numpy_include, py_include]
    if plat_py_include != py_include:
        includes.append(plat_py_include)
    env['CGO_CFLAGS'] = '-I' + ' -I'.join(includes)

    if os.uname()[0] == 'Darwin':
        # Don't link to libpython, since some installs only have a static version available,
        # and statically linking libpython doesn't work for a C extension -- it will duplicate
        # all the global variables, among other things.
        #
        # Instead, just leave Python symbols undefined and let the loader resolve them
        # at runtime. TODO(jeremy): We might want this behavior on Linux, too.
        #
        # In Darwin, ld returns an error by default on undefined symbols. Use dynamic_lookup instead.
        ldflags = '-undefined dynamic_lookup -s'
    else:
        library = sysconfig.get_config_var('LIBRARY')
        match = re.search('^lib(.*)\.a', library)
        if match is None:
          raise BuildException('Could not parse LIBRARY: {}'.format(library))
        ldflags = '-L{} -l{}'.format(sysconfig.get_config_var('LIBDIR'), match.group(1))

    env['CGO_LDFLAGS'] = ' '.join([libjpg, ldflags])

    def build_no_gl():
        cmd = 'go build -tags no_gl -buildmode=c-shared -o go_vncdriver.so github.com/openai/go-vncdriver'
        eprint('Building without OpenGL: GOPATH={} {}'.format(os.getenv('GOPATH'), cmd))
        if subprocess.call(cmd.split()):
            raise BuildException('''