blob: 6ccea31d8b9519cd6a4b41720b9b99b7127d0492 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001#!/bin/sh
2
3# build-swig-Python.sh
4
Caroline Tice9dbe7172010-06-16 19:26:52 +00005# 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 Lattner24943d22010-06-08 16:52:24 +000013
Caroline Tice9dbe7172010-06-16 19:26:52 +000014SRC_ROOT=$1
15TARGET_DIR=$2
16CONFIG_BUILD_DIR=$3
17PYTHON_INSTALL_DIR=$4
18debug_flag=$5
Jim Ingham2396b9f2011-03-01 01:39:04 +000019SWIG=$6
Caroline Tice9dbe7172010-06-16 19:26:52 +000020
21swig_output_file=${SRC_ROOT}/source/LLDBWrapPython.cpp
22swig_input_file=${SRC_ROOT}/scripts/lldb.swig
Johnny Chenf530bfe2011-08-22 22:10:57 +000023swig_python_extensions=${SRC_ROOT}/scripts/Python/python-extensions.swig
24swig_python_wrapper=${SRC_ROOT}/scripts/Python/python-wrapper.swig
Enrico Granatab62d4c62012-02-02 17:26:00 +000025swig_python_typemaps=${SRC_ROOT}/scripts/Python/python-typemaps.swig
Chris Lattner24943d22010-06-08 16:52:24 +000026
Greg Clayton3e4238d2011-11-04 03:34:56 +000027if [ "x$SDKROOT" = "x" ] ; then
28
Chris Lattner24943d22010-06-08 16:52:24 +000029if [ -n "$debug_flag" -a "$debug_flag" == "-debug" ]
30then
31 Debug=1
32else
33 Debug=0
34fi
35
36
Greg Claytonb3448432011-03-24 21:19:54 +000037HEADER_FILES="${SRC_ROOT}/include/lldb/lldb.h"\
Caroline Ticec8b0e902010-10-18 23:00:51 +000038" ${SRC_ROOT}/include/lldb/lldb-defines.h"\
39" ${SRC_ROOT}/include/lldb/lldb-enumerations.h"\
40" ${SRC_ROOT}/include/lldb/lldb-forward.h"\
41" ${SRC_ROOT}/include/lldb/lldb-forward-rtti.h"\
42" ${SRC_ROOT}/include/lldb/lldb-types.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000043" ${SRC_ROOT}/include/lldb/API/SBAddress.h"\
44" ${SRC_ROOT}/include/lldb/API/SBBlock.h"\
45" ${SRC_ROOT}/include/lldb/API/SBBreakpoint.h"\
46" ${SRC_ROOT}/include/lldb/API/SBBreakpointLocation.h"\
47" ${SRC_ROOT}/include/lldb/API/SBBroadcaster.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000048" ${SRC_ROOT}/include/lldb/API/SBCommandInterpreter.h"\
49" ${SRC_ROOT}/include/lldb/API/SBCommandReturnObject.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000050" ${SRC_ROOT}/include/lldb/API/SBCommunication.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000051" ${SRC_ROOT}/include/lldb/API/SBCompileUnit.h"\
Enrico Granata91544802011-09-06 19:20:51 +000052" ${SRC_ROOT}/include/lldb/API/SBData.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000053" ${SRC_ROOT}/include/lldb/API/SBDebugger.h"\
54" ${SRC_ROOT}/include/lldb/API/SBError.h"\
55" ${SRC_ROOT}/include/lldb/API/SBEvent.h"\
Johnny Chen4ead2e92010-08-27 22:35:26 +000056" ${SRC_ROOT}/include/lldb/API/SBFileSpec.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000057" ${SRC_ROOT}/include/lldb/API/SBFrame.h"\
58" ${SRC_ROOT}/include/lldb/API/SBFunction.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000059" ${SRC_ROOT}/include/lldb/API/SBHostOS.h"\
60" ${SRC_ROOT}/include/lldb/API/SBInputReader.h"\
Greg Clayton5c4c7462010-10-06 03:09:58 +000061" ${SRC_ROOT}/include/lldb/API/SBInstruction.h"\
62" ${SRC_ROOT}/include/lldb/API/SBInstructionList.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000063" ${SRC_ROOT}/include/lldb/API/SBLineEntry.h"\
64" ${SRC_ROOT}/include/lldb/API/SBListener.h"\
65" ${SRC_ROOT}/include/lldb/API/SBModule.h"\
66" ${SRC_ROOT}/include/lldb/API/SBProcess.h"\
67" ${SRC_ROOT}/include/lldb/API/SBSourceManager.h"\
Caroline Tice1ca48b02010-09-22 16:41:52 +000068" ${SRC_ROOT}/include/lldb/API/SBStream.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000069" ${SRC_ROOT}/include/lldb/API/SBStringList.h"\
70" ${SRC_ROOT}/include/lldb/API/SBSymbol.h"\
71" ${SRC_ROOT}/include/lldb/API/SBSymbolContext.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000072" ${SRC_ROOT}/include/lldb/API/SBSymbolContextList.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000073" ${SRC_ROOT}/include/lldb/API/SBTarget.h"\
74" ${SRC_ROOT}/include/lldb/API/SBThread.h"\
75" ${SRC_ROOT}/include/lldb/API/SBType.h"\
Caroline Tice1ca48b02010-09-22 16:41:52 +000076" ${SRC_ROOT}/include/lldb/API/SBValue.h"\
Johnny Chen092bd152011-09-27 01:19:20 +000077" ${SRC_ROOT}/include/lldb/API/SBValueList.h"\
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000078" ${SRC_ROOT}/include/lldb/API/SBWatchpoint.h"\
Chris Lattner24943d22010-06-08 16:52:24 +000079
Johnny Chenc39793d2011-09-09 17:37:06 +000080INTERFACE_FILES="${SRC_ROOT}/scripts/Python/interface/SBAddress.i"\
81" ${SRC_ROOT}/scripts/Python/interface/SBBlock.i"\
82" ${SRC_ROOT}/scripts/Python/interface/SBBreakpoint.i"\
83" ${SRC_ROOT}/scripts/Python/interface/SBBreakpointLocation.i"\
84" ${SRC_ROOT}/scripts/Python/interface/SBBroadcaster.i"\
85" ${SRC_ROOT}/scripts/Python/interface/SBCommandInterpreter.i"\
86" ${SRC_ROOT}/scripts/Python/interface/SBCommandReturnObject.i"\
87" ${SRC_ROOT}/scripts/Python/interface/SBCommunication.i"\
88" ${SRC_ROOT}/scripts/Python/interface/SBCompileUnit.i"\
89" ${SRC_ROOT}/scripts/Python/interface/SBData.i"\
90" ${SRC_ROOT}/scripts/Python/interface/SBDebugger.i"\
91" ${SRC_ROOT}/scripts/Python/interface/SBError.i"\
92" ${SRC_ROOT}/scripts/Python/interface/SBEvent.i"\
93" ${SRC_ROOT}/scripts/Python/interface/SBFileSpec.i"\
94" ${SRC_ROOT}/scripts/Python/interface/SBFrame.i"\
95" ${SRC_ROOT}/scripts/Python/interface/SBFunction.i"\
96" ${SRC_ROOT}/scripts/Python/interface/SBHostOS.i"\
97" ${SRC_ROOT}/scripts/Python/interface/SBInputReader.i"\
98" ${SRC_ROOT}/scripts/Python/interface/SBInstruction.i"\
99" ${SRC_ROOT}/scripts/Python/interface/SBInstructionList.i"\
100" ${SRC_ROOT}/scripts/Python/interface/SBLineEntry.i"\
101" ${SRC_ROOT}/scripts/Python/interface/SBListener.i"\
102" ${SRC_ROOT}/scripts/Python/interface/SBModule.i"\
103" ${SRC_ROOT}/scripts/Python/interface/SBProcess.i"\
104" ${SRC_ROOT}/scripts/Python/interface/SBSourceManager.i"\
105" ${SRC_ROOT}/scripts/Python/interface/SBStream.i"\
106" ${SRC_ROOT}/scripts/Python/interface/SBStringList.i"\
107" ${SRC_ROOT}/scripts/Python/interface/SBSymbol.i"\
108" ${SRC_ROOT}/scripts/Python/interface/SBSymbolContext.i"\
109" ${SRC_ROOT}/scripts/Python/interface/SBTarget.i"\
110" ${SRC_ROOT}/scripts/Python/interface/SBThread.i"\
111" ${SRC_ROOT}/scripts/Python/interface/SBType.i"\
112" ${SRC_ROOT}/scripts/Python/interface/SBValue.i"\
Johnny Chen092bd152011-09-27 01:19:20 +0000113" ${SRC_ROOT}/scripts/Python/interface/SBValueList.i"\
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000114" ${SRC_ROOT}/scripts/Python/interface/SBWatchpoint.i"
Chris Lattner24943d22010-06-08 16:52:24 +0000115
116if [ $Debug == 1 ]
117then
118 echo "Header files are:"
119 echo ${HEADER_FILES}
120fi
121
Enrico Granata91544802011-09-06 19:20:51 +0000122if [ $Debug == 1 ]
123then
124 echo "SWIG interface files are:"
125 echo ${INTERFACE_FILES}
126fi
127
Chris Lattner24943d22010-06-08 16:52:24 +0000128NeedToUpdate=0
129
Chris Lattner24943d22010-06-08 16:52:24 +0000130
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000131if [ ! -f ${swig_output_file} ]
Chris Lattner24943d22010-06-08 16:52:24 +0000132then
133 NeedToUpdate=1
134 if [ $Debug == 1 ]
135 then
136 echo "Failed to find LLDBWrapPython.cpp"
137 fi
138fi
139
140if [ $NeedToUpdate == 0 ]
141then
142 for hdrfile in ${HEADER_FILES}
143 do
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000144 if [ $hdrfile -nt ${swig_output_file} ]
Chris Lattner24943d22010-06-08 16:52:24 +0000145 then
146 NeedToUpdate=1
147 if [ $Debug == 1 ]
148 then
149 echo "${hdrfile} is newer than ${swig_output_file}"
150 echo "swig file will need to be re-built."
151 fi
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000152 break
Chris Lattner24943d22010-06-08 16:52:24 +0000153 fi
154 done
155fi
156
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000157if [ $NeedToUpdate == 0 ]
158then
Enrico Granata91544802011-09-06 19:20:51 +0000159 for intffile in ${INTERFACE_FILES}
160 do
161 if [ $intffile -nt ${swig_output_file} ]
162 then
163 NeedToUpdate=1
164 if [ $Debug == 1 ]
165 then
166 echo "${intffile} is newer than ${swig_output_file}"
167 echo "swig file will need to be re-built."
168 fi
169 break
170 fi
171 done
172fi
173
174if [ $NeedToUpdate == 0 ]
175then
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000176 if [ ${swig_input_file} -nt ${swig_output_file} ]
177 then
178 NeedToUpdate=1
179 if [ $Debug == 1 ]
180 then
181 echo "${swig_input_file} is newer than ${swig_output_file}"
182 echo "swig file will need to be re-built."
183 fi
184 fi
185fi
186
Caroline Tice7826c882010-10-26 03:11:13 +0000187if [ $NeedToUpdate == 0 ]
188then
Johnny Chenf530bfe2011-08-22 22:10:57 +0000189 if [ ${swig_python_extensions} -nt ${swig_output_file} ]
Caroline Tice7826c882010-10-26 03:11:13 +0000190 then
191 NeedToUpdate=1
192 if [ $Debug == 1 ]
193 then
Johnny Chenf530bfe2011-08-22 22:10:57 +0000194 echo "${swig_python_extensions} is newer than ${swig_output_file}"
195 echo "swig file will need to be re-built."
196 fi
197 fi
198fi
199
200if [ $NeedToUpdate == 0 ]
201then
202 if [ ${swig_python_wrapper} -nt ${swig_output_file} ]
203 then
204 NeedToUpdate=1
205 if [ $Debug == 1 ]
206 then
207 echo "${swig_python_wrapper} is newer than ${swig_output_file}"
Caroline Tice7826c882010-10-26 03:11:13 +0000208 echo "swig file will need to be re-built."
209 fi
210 fi
211fi
212
Enrico Granatab62d4c62012-02-02 17:26:00 +0000213if [ $NeedToUpdate == 0 ]
214then
215 if [ ${swig_python_typemaps} -nt ${swig_output_file} ]
216 then
217 NeedToUpdate=1
218 if [ $Debug == 1 ]
219 then
220 echo "${swig_python_typemaps} is newer than ${swig_output_file}"
221 echo "swig file will need to be re-built."
222 fi
223 fi
224fi
225
Caroline Tice9dbe7172010-06-16 19:26:52 +0000226os_name=`uname -s`
227python_version=`/usr/bin/python --version 2>&1 | sed -e 's,Python ,,' -e 's,[.][0-9],,2' -e 's,[a-z][a-z][0-9],,'`
228
229if [ "$os_name" == "Darwin" ]
230then
231 framework_python_dir="${TARGET_DIR}/LLDB.framework/Resources/Python"
232else
233 framework_python_dir="${PYTHON_INSTALL_DIR}/python${python_version}"
234fi
235
Chris Lattner24943d22010-06-08 16:52:24 +0000236
237if [ ! -L "${framework_python_dir}/_lldb.so" ]
238then
239 NeedToUpdate=1
240fi
241
242if [ ! -f "${framework_python_dir}/lldb.py" ]
243then
244 NeedToUpdate=1
245fi
246
247
248if [ $NeedToUpdate == 0 ]
249then
250 echo "Everything is up-to-date."
251 exit 0
252else
253 echo "SWIG needs to be re-run."
Caroline Tice7826c882010-10-26 03:11:13 +0000254 if [ -f ${swig_output_file} ]
255 then
256 rm ${swig_output_file}
257 fi
Chris Lattner24943d22010-06-08 16:52:24 +0000258fi
259
260
261# Build the SWIG C++ wrapper file for Python.
262
Jim Ingham2396b9f2011-03-01 01:39:04 +0000263$SWIG -c++ -shadow -python -I"/usr/include" -I"${SRC_ROOT}/include" -I./. -outdir "${CONFIG_BUILD_DIR}" -o "${swig_output_file}" "${swig_input_file}"
Chris Lattner24943d22010-06-08 16:52:24 +0000264
Johnny Chen22e418a2011-04-29 19:22:24 +0000265# Implement the iterator protocol and/or eq/ne operators for some lldb objects.
Caroline Tice558be582010-06-30 16:22:25 +0000266# Append global variable to lldb Python module.
Johnny Chen14097802011-04-28 21:31:18 +0000267# And initialize the lldb debugger subsystem.
Caroline Tice558be582010-06-30 16:22:25 +0000268current_dir=`pwd`
Johnny Chen14097802011-04-28 21:31:18 +0000269if [ -f "${current_dir}/modify-python-lldb.py" ]
Caroline Tice558be582010-06-30 16:22:25 +0000270then
Johnny Chen14097802011-04-28 21:31:18 +0000271 python ${current_dir}/modify-python-lldb.py ${CONFIG_BUILD_DIR}
Caroline Tice558be582010-06-30 16:22:25 +0000272fi
Caroline Tice5790e062010-10-28 21:51:20 +0000273
274# Fix the "#include" statement in the swig output file
275
276if [ -f "${current_dir}/edit-swig-python-wrapper-file.py" ]
277then
278 python ${current_dir}/edit-swig-python-wrapper-file.py
279 if [ -f "${swig_output_file}.edited" ]
280 then
281 mv "${swig_output_file}.edited" ${swig_output_file}
282 fi
283fi
Greg Clayton3e4238d2011-11-04 03:34:56 +0000284
285else
286 # SDKROOT was not empty, which currently means iOS cross build where python is disabled
287 rm -rf ${swig_output_file}
288 touch ${swig_output_file}
289fi