Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # build-swig-Python.sh |
| 4 | |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 5 | # SRC_ROOT is the root of the lldb source tree. |
| 6 | # TARGET_DIR is where the lldb framework/shared library gets put. |
| 7 | # CONFIG_BUILD_DIR is where the build-swig-Python-LLDB.sh shell script |
| 8 | # put the lldb.py file it was generated from running SWIG. |
| 9 | # PREFIX is the root directory used to determine where third-party modules |
| 10 | # for scripting languages should be installed. |
| 11 | # debug_flag (optional) determines whether or not this script outputs |
| 12 | # additional information when running. |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 14 | SRC_ROOT=$1 |
| 15 | TARGET_DIR=$2 |
| 16 | CONFIG_BUILD_DIR=$3 |
| 17 | PYTHON_INSTALL_DIR=$4 |
| 18 | debug_flag=$5 |
| 19 | |
| 20 | swig_output_file=${SRC_ROOT}/source/LLDBWrapPython.cpp |
| 21 | swig_input_file=${SRC_ROOT}/scripts/lldb.swig |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 22 | swig_input_file2=${SRC_ROOT}/scripts/Python/python-extensions.swig |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 23 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | |
| 25 | if [ -n "$debug_flag" -a "$debug_flag" == "-debug" ] |
| 26 | then |
| 27 | Debug=1 |
| 28 | else |
| 29 | Debug=0 |
| 30 | fi |
| 31 | |
| 32 | |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 33 | HEADER_FILES="${SRC_ROOT}/include/lldb/lldb-include.h"\ |
Caroline Tice | c8b0e90 | 2010-10-18 23:00:51 +0000 | [diff] [blame] | 34 | " ${SRC_ROOT}/include/lldb/lldb-defines.h"\ |
| 35 | " ${SRC_ROOT}/include/lldb/lldb-enumerations.h"\ |
| 36 | " ${SRC_ROOT}/include/lldb/lldb-forward.h"\ |
| 37 | " ${SRC_ROOT}/include/lldb/lldb-forward-rtti.h"\ |
| 38 | " ${SRC_ROOT}/include/lldb/lldb-types.h"\ |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 39 | " ${SRC_ROOT}/include/lldb/API/SBAddress.h"\ |
| 40 | " ${SRC_ROOT}/include/lldb/API/SBBlock.h"\ |
| 41 | " ${SRC_ROOT}/include/lldb/API/SBBreakpoint.h"\ |
| 42 | " ${SRC_ROOT}/include/lldb/API/SBBreakpointLocation.h"\ |
| 43 | " ${SRC_ROOT}/include/lldb/API/SBBroadcaster.h"\ |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 44 | " ${SRC_ROOT}/include/lldb/API/SBCommandInterpreter.h"\ |
| 45 | " ${SRC_ROOT}/include/lldb/API/SBCommandReturnObject.h"\ |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 46 | " ${SRC_ROOT}/include/lldb/API/SBCommunication.h"\ |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 47 | " ${SRC_ROOT}/include/lldb/API/SBCompileUnit.h"\ |
| 48 | " ${SRC_ROOT}/include/lldb/API/SBDebugger.h"\ |
| 49 | " ${SRC_ROOT}/include/lldb/API/SBError.h"\ |
| 50 | " ${SRC_ROOT}/include/lldb/API/SBEvent.h"\ |
Johnny Chen | 4ead2e9 | 2010-08-27 22:35:26 +0000 | [diff] [blame] | 51 | " ${SRC_ROOT}/include/lldb/API/SBFileSpec.h"\ |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 52 | " ${SRC_ROOT}/include/lldb/API/SBFrame.h"\ |
| 53 | " ${SRC_ROOT}/include/lldb/API/SBFunction.h"\ |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 54 | " ${SRC_ROOT}/include/lldb/API/SBHostOS.h"\ |
| 55 | " ${SRC_ROOT}/include/lldb/API/SBInputReader.h"\ |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 56 | " ${SRC_ROOT}/include/lldb/API/SBInstruction.h"\ |
| 57 | " ${SRC_ROOT}/include/lldb/API/SBInstructionList.h"\ |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 58 | " ${SRC_ROOT}/include/lldb/API/SBLineEntry.h"\ |
| 59 | " ${SRC_ROOT}/include/lldb/API/SBListener.h"\ |
| 60 | " ${SRC_ROOT}/include/lldb/API/SBModule.h"\ |
| 61 | " ${SRC_ROOT}/include/lldb/API/SBProcess.h"\ |
| 62 | " ${SRC_ROOT}/include/lldb/API/SBSourceManager.h"\ |
Caroline Tice | 1ca48b0 | 2010-09-22 16:41:52 +0000 | [diff] [blame] | 63 | " ${SRC_ROOT}/include/lldb/API/SBStream.h"\ |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 64 | " ${SRC_ROOT}/include/lldb/API/SBStringList.h"\ |
| 65 | " ${SRC_ROOT}/include/lldb/API/SBSymbol.h"\ |
| 66 | " ${SRC_ROOT}/include/lldb/API/SBSymbolContext.h"\ |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 67 | " ${SRC_ROOT}/include/lldb/API/SBSymbolContextList.h"\ |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 68 | " ${SRC_ROOT}/include/lldb/API/SBTarget.h"\ |
| 69 | " ${SRC_ROOT}/include/lldb/API/SBThread.h"\ |
| 70 | " ${SRC_ROOT}/include/lldb/API/SBType.h"\ |
Caroline Tice | 1ca48b0 | 2010-09-22 16:41:52 +0000 | [diff] [blame] | 71 | " ${SRC_ROOT}/include/lldb/API/SBValue.h"\ |
| 72 | " ${SRC_ROOT}/include/lldb/API/SBValueList.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 73 | |
| 74 | |
| 75 | if [ $Debug == 1 ] |
| 76 | then |
| 77 | echo "Header files are:" |
| 78 | echo ${HEADER_FILES} |
| 79 | fi |
| 80 | |
| 81 | NeedToUpdate=0 |
| 82 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 83 | |
Johnny Chen | b4d1fff | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 84 | if [ ! -f ${swig_output_file} ] |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 85 | then |
| 86 | NeedToUpdate=1 |
| 87 | if [ $Debug == 1 ] |
| 88 | then |
| 89 | echo "Failed to find LLDBWrapPython.cpp" |
| 90 | fi |
| 91 | fi |
| 92 | |
| 93 | if [ $NeedToUpdate == 0 ] |
| 94 | then |
| 95 | for hdrfile in ${HEADER_FILES} |
| 96 | do |
Johnny Chen | b4d1fff | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 97 | if [ $hdrfile -nt ${swig_output_file} ] |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 98 | then |
| 99 | NeedToUpdate=1 |
| 100 | if [ $Debug == 1 ] |
| 101 | then |
| 102 | echo "${hdrfile} is newer than ${swig_output_file}" |
| 103 | echo "swig file will need to be re-built." |
| 104 | fi |
Johnny Chen | b4d1fff | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 105 | break |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 106 | fi |
| 107 | done |
| 108 | fi |
| 109 | |
Johnny Chen | b4d1fff | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 110 | if [ $NeedToUpdate == 0 ] |
| 111 | then |
| 112 | if [ ${swig_input_file} -nt ${swig_output_file} ] |
| 113 | then |
| 114 | NeedToUpdate=1 |
| 115 | if [ $Debug == 1 ] |
| 116 | then |
| 117 | echo "${swig_input_file} is newer than ${swig_output_file}" |
| 118 | echo "swig file will need to be re-built." |
| 119 | fi |
| 120 | fi |
| 121 | fi |
| 122 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 123 | if [ $NeedToUpdate == 0 ] |
| 124 | then |
| 125 | if [ ${swig_input_file2} -nt ${swig_output_file} ] |
| 126 | then |
| 127 | NeedToUpdate=1 |
| 128 | if [ $Debug == 1 ] |
| 129 | then |
| 130 | echo "${swig_input_file2} is newer than ${swig_output_file}" |
| 131 | echo "swig file will need to be re-built." |
| 132 | fi |
| 133 | fi |
| 134 | fi |
| 135 | |
Caroline Tice | 9dbe717 | 2010-06-16 19:26:52 +0000 | [diff] [blame] | 136 | os_name=`uname -s` |
| 137 | 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],,'` |
| 138 | |
| 139 | if [ "$os_name" == "Darwin" ] |
| 140 | then |
| 141 | framework_python_dir="${TARGET_DIR}/LLDB.framework/Resources/Python" |
| 142 | else |
| 143 | framework_python_dir="${PYTHON_INSTALL_DIR}/python${python_version}" |
| 144 | fi |
| 145 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 146 | |
| 147 | if [ ! -L "${framework_python_dir}/_lldb.so" ] |
| 148 | then |
| 149 | NeedToUpdate=1 |
| 150 | fi |
| 151 | |
| 152 | if [ ! -f "${framework_python_dir}/lldb.py" ] |
| 153 | then |
| 154 | NeedToUpdate=1 |
| 155 | fi |
| 156 | |
| 157 | |
| 158 | if [ $NeedToUpdate == 0 ] |
| 159 | then |
| 160 | echo "Everything is up-to-date." |
| 161 | exit 0 |
| 162 | else |
| 163 | echo "SWIG needs to be re-run." |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 164 | if [ -f ${swig_output_file} ] |
| 165 | then |
| 166 | rm ${swig_output_file} |
| 167 | fi |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 168 | fi |
| 169 | |
| 170 | |
| 171 | # Build the SWIG C++ wrapper file for Python. |
| 172 | |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 173 | swig -c++ -shadow -python -I"/usr/include" -I"${SRC_ROOT}/include" -I./. -outdir "${CONFIG_BUILD_DIR}" -o "${swig_output_file}" "${swig_input_file}" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 174 | |
Caroline Tice | 558be58 | 2010-06-30 16:22:25 +0000 | [diff] [blame] | 175 | # Append global variable to lldb Python module. |
| 176 | |
| 177 | current_dir=`pwd` |
| 178 | if [ -f "${current_dir}/append-debugger-id.py" ] |
| 179 | then |
| 180 | python ${current_dir}/append-debugger-id.py ${CONFIG_BUILD_DIR} |
| 181 | fi |
Caroline Tice | 5790e06 | 2010-10-28 21:51:20 +0000 | [diff] [blame^] | 182 | |
| 183 | # Fix the "#include" statement in the swig output file |
| 184 | |
| 185 | if [ -f "${current_dir}/edit-swig-python-wrapper-file.py" ] |
| 186 | then |
| 187 | python ${current_dir}/edit-swig-python-wrapper-file.py |
| 188 | if [ -f "${swig_output_file}.edited" ] |
| 189 | then |
| 190 | mv "${swig_output_file}.edited" ${swig_output_file} |
| 191 | fi |
| 192 | fi |