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