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 | |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 36 | # Make sure SDKROOT is not set, since if it is this is an iOS build where python |
| 37 | # is disabled |
| 38 | if [ "x$SDKROOT" = "x" ] ; then |
| 39 | |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 40 | if [ -n "$debug_flag" -a "$debug_flag" == "-debug" ] |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | then |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 42 | Debug=1 |
| 43 | else |
| 44 | Debug=0 |
| 45 | fi |
| 46 | |
| 47 | OS_NAME=`uname -s` |
| 48 | 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],,'` |
| 49 | |
| 50 | |
| 51 | if [ $Debug == 1 ] |
| 52 | then |
| 53 | echo "The current OS is $OS_NAME" |
| 54 | echo "The Python version is $PYTHON_VERSION" |
| 55 | fi |
| 56 | |
| 57 | # |
| 58 | # Determine where to put the files. |
| 59 | |
| 60 | if [ ${OS_NAME} == "Darwin" ] |
| 61 | then |
| 62 | # We are on a Darwin system, so all the lldb Python files can go |
| 63 | # into the LLDB.framework/Resources/Python subdirectory. |
| 64 | |
| 65 | if [ ! -d "${TARGET_DIR}/LLDB.framework" ] |
| 66 | then |
| 67 | echo "Error: Unable to find LLDB.framework" >&2 |
| 68 | exit 1 |
| 69 | else |
| 70 | if [ $Debug == 1 ] |
| 71 | then |
| 72 | echo "Found ${TARGET_DIR}/LLDB.framework." |
| 73 | fi |
| 74 | fi |
| 75 | |
| 76 | # Make the Python directory in the framework if it doesn't already exist |
| 77 | |
| 78 | framework_python_dir="${TARGET_DIR}/LLDB.framework/Resources/Python" |
| 79 | else |
| 80 | # We are on a non-Darwin system, so use the PYTHON_INSTALL_DIR argument, |
| 81 | # and append the python version directory to the end of it. Depending on |
| 82 | # the system other stuff may need to be put here as well. |
| 83 | |
| 84 | framework_python_dir="${PYTHON_INSTALL_DIR}/python${PYTHON_VERSION}" |
| 85 | fi |
| 86 | |
| 87 | # |
| 88 | # Look for the directory in which to put the Python files; if it does not |
| 89 | # already exist, attempt to make it. |
| 90 | # |
| 91 | |
| 92 | if [ $Debug == 1 ] |
| 93 | then |
| 94 | echo "Python files will be put in ${framework_python_dir}" |
| 95 | fi |
| 96 | |
| 97 | if [ ! -d "${framework_python_dir}" ] |
| 98 | then |
| 99 | if [ $Debug == 1 ] |
| 100 | then |
| 101 | echo "Making directory ${framework_python_dir}" |
| 102 | fi |
| 103 | mkdir -p "${framework_python_dir}" |
| 104 | else |
| 105 | if [ $Debug == 1 ] |
| 106 | then |
| 107 | echo "${framework_python_dir} already exists." |
| 108 | fi |
| 109 | fi |
| 110 | |
| 111 | if [ ! -d "${framework_python_dir}" ] |
| 112 | then |
| 113 | echo "Error: Unable to find or create ${framework_python_dir}" >&2 |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 114 | exit 1 |
| 115 | fi |
| 116 | |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 117 | # Make the symlink that the script bridge for Python will need in the |
| 118 | # Python framework directory |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 119 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 120 | if [ ! -L "${framework_python_dir}/_lldb.so" ] |
| 121 | then |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 122 | if [ $Debug == 1 ] |
| 123 | then |
| 124 | echo "Creating symlink for _lldb.so" |
| 125 | fi |
| 126 | if [ ${OS_NAME} == "Darwin" ] |
| 127 | then |
| 128 | cd "${framework_python_dir}" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 129 | ln -s "../../LLDB" _lldb.so |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 130 | else |
| 131 | cd "${TARGET_DIR}" |
| 132 | ln -s "./LLDB" _lldb.so |
| 133 | fi |
| 134 | else |
| 135 | if [ $Debug == 1 ] |
| 136 | then |
| 137 | echo "${framework_python_dir}/_lldb.so already exists." |
| 138 | fi |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 139 | fi |
| 140 | |
| 141 | # Copy the python module (lldb.py) that was generated by SWIG |
| 142 | # over to the framework Python directory |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 143 | if [ -f "${CONFIG_BUILD_DIR}/lldb.py" ] |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 144 | then |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 145 | if [ $Debug == 1 ] |
| 146 | then |
| 147 | echo "Copying lldb.py to ${framework_python_dir}" |
| 148 | fi |
| 149 | cp "${CONFIG_BUILD_DIR}/lldb.py" "${framework_python_dir}" |
| 150 | else |
| 151 | if [ $Debug == 1 ] |
| 152 | then |
| 153 | echo "Unable to find ${CONFIG_BUILD_DIR}/lldb.py" |
| 154 | fi |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 155 | fi |
| 156 | |
| 157 | # Copy the embedded interpreter script over to the framework Python directory |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 158 | if [ -f "${SRC_ROOT}/source/Interpreter/embedded_interpreter.py" ] |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 159 | then |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 160 | if [ $Debug == 1 ] |
| 161 | then |
| 162 | echo "Copying embedded_interpreter.py to ${framework_python_dir}" |
| 163 | fi |
| 164 | cp "${SRC_ROOT}/source/Interpreter/embedded_interpreter.py" "${framework_python_dir}" |
| 165 | else |
| 166 | if [ $Debug == 1 ] |
| 167 | then |
| 168 | echo "Unable to find ${SRC_ROOT}/source/Interpreter/embedded_interpreter.py" |
| 169 | fi |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 170 | fi |
| 171 | |
Enrico Granata | f501c59 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 172 | # Copy the C++ STL formatters over to the framework Python directory |
| 173 | if [ -f "${SRC_ROOT}/examples/synthetic/gnu_libstdcpp.py" ] |
Enrico Granata | 074e3b6 | 2011-08-17 19:07:52 +0000 | [diff] [blame] | 174 | then |
| 175 | if [ $Debug == 1 ] |
| 176 | then |
Enrico Granata | f501c59 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 177 | echo "Copying gnu_libstdcpp.py to ${framework_python_dir}" |
Enrico Granata | 074e3b6 | 2011-08-17 19:07:52 +0000 | [diff] [blame] | 178 | fi |
Enrico Granata | f501c59 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 179 | cp "${SRC_ROOT}/examples/synthetic/gnu_libstdcpp.py" "${framework_python_dir}" |
Enrico Granata | 074e3b6 | 2011-08-17 19:07:52 +0000 | [diff] [blame] | 180 | else |
| 181 | if [ $Debug == 1 ] |
| 182 | then |
Enrico Granata | f501c59 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 183 | echo "Unable to find ${SRC_ROOT}/examples/synthetic/gnu_libstdcpp.py" |
Enrico Granata | 074e3b6 | 2011-08-17 19:07:52 +0000 | [diff] [blame] | 184 | fi |
| 185 | fi |
| 186 | |
Enrico Granata | b8dc733 | 2012-01-31 17:01:51 +0000 | [diff] [blame^] | 187 | # Copy the ObjC formatters over to the framework Python directory |
| 188 | if [ -f "${SRC_ROOT}/examples/synthetic/objc.py" ] |
| 189 | then |
| 190 | if [ $Debug == 1 ] |
| 191 | then |
| 192 | echo "Copying objc.py to ${framework_python_dir}" |
| 193 | fi |
| 194 | cp "${SRC_ROOT}/examples/summaries/objc.py" "${framework_python_dir}" |
| 195 | else |
| 196 | if [ $Debug == 1 ] |
| 197 | then |
| 198 | echo "Unable to find ${SRC_ROOT}/examples/summaries/objc.py" |
| 199 | fi |
| 200 | fi |
| 201 | |
Greg Clayton | 3e4238d | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 202 | fi |
| 203 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 204 | exit 0 |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 205 | |