Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | |
| 3 | # finish-swig-Python.sh |
| 4 | # |
| 5 | # For the Python script interpreter (external to liblldb) to be able to import |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 6 | # and use the lldb module, there must be two files, lldb.py and _lldb.so, that |
| 7 | # it can find. lldb.py is generated by SWIG at the same time it generates the |
| 8 | # C++ file. _lldb.so is actually a symlink file that points to the |
| 9 | # LLDB shared library/framework. |
| 10 | # |
| 11 | # The Python script interpreter needs to be able to automatically find |
| 12 | # these two files. On Darwin systems it searches in the LLDB.framework, as |
| 13 | # well as in all the normal Python search paths. On non-Darwin systems |
| 14 | # these files will need to be put someplace where Python will find them. |
| 15 | # |
| 16 | # This shell script creates the _lldb.so symlink in the appropriate place, |
| 17 | # and copies the lldb.py (and embedded_interpreter.py) file to the correct |
| 18 | # directory. |
| 19 | # |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 21 | # SRC_ROOT is the root of the lldb source tree. |
| 22 | # TARGET_DIR is where the lldb framework/shared library gets put. |
| 23 | # CONFIG_BUILD_DIR is where the build-swig-Python-LLDB.sh shell script |
| 24 | # put the lldb.py file it was generated from running SWIG. |
| 25 | # PYTHON_INSTALL_DIR is where non-Darwin systems want to put the .py and .so |
| 26 | # files so that Python can find them automatically. |
| 27 | # debug_flag (optional) determines whether or not this script outputs |
| 28 | # additional information when running. |
| 29 | |
| 30 | SRC_ROOT=$1 |
| 31 | TARGET_DIR=$2 |
| 32 | CONFIG_BUILD_DIR=$3 |
| 33 | PYTHON_INSTALL_DIR=$4 |
| 34 | debug_flag=$5 |
| 35 | |
| 36 | if [ -n "$debug_flag" -a "$debug_flag" == "-debug" ] |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | then |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 38 | Debug=1 |
| 39 | else |
| 40 | Debug=0 |
| 41 | fi |
| 42 | |
| 43 | OS_NAME=`uname -s` |
| 44 | PYTHON_VERSION=`/usr/bin/python --version 2>&1 | sed -e 's,Python ,,' -e 's,[.][0-9],,2' -e 's,[a-z][a-z][0-9],,'` |
| 45 | |
| 46 | |
| 47 | if [ $Debug == 1 ] |
| 48 | then |
| 49 | echo "The current OS is $OS_NAME" |
| 50 | echo "The Python version is $PYTHON_VERSION" |
| 51 | fi |
| 52 | |
| 53 | # |
| 54 | # Determine where to put the files. |
| 55 | |
| 56 | if [ ${OS_NAME} == "Darwin" ] |
| 57 | then |
| 58 | # We are on a Darwin system, so all the lldb Python files can go |
| 59 | # into the LLDB.framework/Resources/Python subdirectory. |
| 60 | |
| 61 | if [ ! -d "${TARGET_DIR}/LLDB.framework" ] |
| 62 | then |
| 63 | echo "Error: Unable to find LLDB.framework" >&2 |
| 64 | exit 1 |
| 65 | else |
| 66 | if [ $Debug == 1 ] |
| 67 | then |
| 68 | echo "Found ${TARGET_DIR}/LLDB.framework." |
| 69 | fi |
| 70 | fi |
| 71 | |
| 72 | # Make the Python directory in the framework if it doesn't already exist |
| 73 | |
| 74 | framework_python_dir="${TARGET_DIR}/LLDB.framework/Resources/Python" |
| 75 | else |
| 76 | # We are on a non-Darwin system, so use the PYTHON_INSTALL_DIR argument, |
| 77 | # and append the python version directory to the end of it. Depending on |
| 78 | # the system other stuff may need to be put here as well. |
| 79 | |
| 80 | framework_python_dir="${PYTHON_INSTALL_DIR}/python${PYTHON_VERSION}" |
| 81 | fi |
| 82 | |
| 83 | # |
| 84 | # Look for the directory in which to put the Python files; if it does not |
| 85 | # already exist, attempt to make it. |
| 86 | # |
| 87 | |
| 88 | if [ $Debug == 1 ] |
| 89 | then |
| 90 | echo "Python files will be put in ${framework_python_dir}" |
| 91 | fi |
| 92 | |
| 93 | if [ ! -d "${framework_python_dir}" ] |
| 94 | then |
| 95 | if [ $Debug == 1 ] |
| 96 | then |
| 97 | echo "Making directory ${framework_python_dir}" |
| 98 | fi |
| 99 | mkdir -p "${framework_python_dir}" |
| 100 | else |
| 101 | if [ $Debug == 1 ] |
| 102 | then |
| 103 | echo "${framework_python_dir} already exists." |
| 104 | fi |
| 105 | fi |
| 106 | |
| 107 | if [ ! -d "${framework_python_dir}" ] |
| 108 | then |
| 109 | echo "Error: Unable to find or create ${framework_python_dir}" >&2 |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 110 | exit 1 |
| 111 | fi |
| 112 | |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 113 | # Make the symlink that the script bridge for Python will need in the |
| 114 | # Python framework directory |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 116 | if [ ! -L "${framework_python_dir}/_lldb.so" ] |
| 117 | then |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 118 | if [ $Debug == 1 ] |
| 119 | then |
| 120 | echo "Creating symlink for _lldb.so" |
| 121 | fi |
| 122 | if [ ${OS_NAME} == "Darwin" ] |
| 123 | then |
| 124 | cd "${framework_python_dir}" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 125 | ln -s "../../LLDB" _lldb.so |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 126 | else |
| 127 | cd "${TARGET_DIR}" |
| 128 | ln -s "./LLDB" _lldb.so |
| 129 | fi |
| 130 | else |
| 131 | if [ $Debug == 1 ] |
| 132 | then |
| 133 | echo "${framework_python_dir}/_lldb.so already exists." |
| 134 | fi |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 135 | fi |
| 136 | |
| 137 | # Copy the python module (lldb.py) that was generated by SWIG |
| 138 | # over to the framework Python directory |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 139 | if [ -f "${CONFIG_BUILD_DIR}/lldb.py" ] |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 140 | then |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 141 | if [ $Debug == 1 ] |
| 142 | then |
| 143 | echo "Copying lldb.py to ${framework_python_dir}" |
| 144 | fi |
| 145 | cp "${CONFIG_BUILD_DIR}/lldb.py" "${framework_python_dir}" |
| 146 | else |
| 147 | if [ $Debug == 1 ] |
| 148 | then |
| 149 | echo "Unable to find ${CONFIG_BUILD_DIR}/lldb.py" |
| 150 | fi |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 151 | fi |
| 152 | |
| 153 | # Copy the embedded interpreter script over to the framework Python directory |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 154 | if [ -f "${SRC_ROOT}/source/Interpreter/embedded_interpreter.py" ] |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 155 | then |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 156 | if [ $Debug == 1 ] |
| 157 | then |
| 158 | echo "Copying embedded_interpreter.py to ${framework_python_dir}" |
| 159 | fi |
| 160 | cp "${SRC_ROOT}/source/Interpreter/embedded_interpreter.py" "${framework_python_dir}" |
| 161 | else |
| 162 | if [ $Debug == 1 ] |
| 163 | then |
| 164 | echo "Unable to find ${SRC_ROOT}/source/Interpreter/embedded_interpreter.py" |
| 165 | fi |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 166 | fi |
| 167 | |
| 168 | exit 0 |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 169 | |