#!/bin/env python

"""Builds a list of standard libs and stores this in stdlib.json
   this list/file is needed by find_missing_bins.py

"""

import os
import re
import cjson

fnLiblst = "stdlibs.json"
# list of OS libs for which we do not take into account the dependencies
liblst = ['libjawt.so']

def buildStdlibList():
    cwd_save = os.getcwd()
    std_locations = (
      '/usr/lib',
      '/usr/dt/lib',
      '/usr/openwin/lib',
      '/usr/X11/lib',
      '/usr/ucblib',
      '/usr/sfw/lib',
    )
    for libdir in std_locations:
        if os.path.isdir(libdir):
            os.chdir(libdir)
            for lib in os.listdir('.'):
                if re.match('lib[a-zA-Z0-9_-]*.so.[0-9]+$',lib):
                    liblst.append(lib)
    os.chdir(cwd_save)
    with open(fnLiblst, 'w') as fd:
        fd.write(cjson.encode(liblst))
