# # Name: MpBuildPyc.pyx # # Purpose: This module is used to help create .pyc compiled bytecode files # from the .py source code. # # The primary thing this script does is make sure that the # directory containing the libMx shared C library is included # in the shared library path. This is LD_LIBRARY_PATH on # many platforms. # # It turns out that Python ignores any changes to LD_LIBRARY_PATH # that are made after the interpreter starts up. That means that # we cannot modify LD_LIBRARY_PATH and then do an import using # the modified path using a single process. In order to get the # effect we want, it is necessary to change LD_LIBRARY_PATH in # one process and then invoke a second process which will inherit # the modified LD_LIBRARY_PATH. # # Note: This script has the extension .pyx so that 'make install' # will not copy it to the installation directory. # # Author: William Lavender # #----------------------------------------------------------------------- # # Copyright 2002, 2009 Illinois Institute of Technology # # See the file "LICENSE" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # import os, sys ### Get the module name from argv. ### module_name = sys.argv[1] ### Find the MX installation directory. ### try: mxdir = os.environ["MXDIR"] except: if ( sys.platform == "win32" ): mxdir = "c:\\opt\\mx" else: mxdir = "/opt/mx" ### Find the default shared library path. ### if ( sys.platform == "win32" ): path_name = "PATH" elif ( sys.platform == "darwin" ): path_name = "DYLD_LIBRARY_PATH" else: path_name = "LD_LIBRARY_PATH" try: library_path = os.environ[path_name] except: library_path = "" ### Add the directories most likely to contain libMx and libMp to the path. ### if ( sys.platform == "win32" ): dirlist = [ "..\\..\\mp\\libMp", "..\\..\\mx\libMx", mxdir + "\\lib", "." ] else: dirlist = [ "../../mp/libMp", "../../mx/libMx", mxdir + "/lib", "." ] for dir in dirlist: dir = os.path.normpath( dir ) library_path = dir + os.pathsep + library_path ### Replace the shared library search path. ### os.environ[path_name] = library_path ### Build the .pyc file using the modified shared library search path. ### command = '%s -c "import %s"' % ( sys.executable, module_name ) os.system( command )