blob: 97b1680f2cc260537b5b48394e7a1adeff9e088e [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
Jim Inghamb7e62f82012-05-24 01:16:09 +000027if [ $LLDB_DISABLE_PYTHON = "1" ] ; then
Johnny Chen4ff16d72012-05-24 18:14:18 +000028 # LLDB_DISABLE_PYTHON is set, which currently means iOS cross build where python is disabled
Jim Inghamb7e62f82012-05-24 01:16:09 +000029 rm -rf ${swig_output_file}
30 touch ${swig_output_file}
31
32else
Greg Clayton3e4238d2011-11-04 03:34:56 +000033
Chris Lattner24943d22010-06-08 16:52:24 +000034if [ -n "$debug_flag" -a "$debug_flag" == "-debug" ]
35then
36 Debug=1
37else
38 Debug=0
39fi
40
Jason Molendac48ca822012-02-21 05:33:55 +000041# If this project is being built with LLDB_DISABLE_PYTHON defined,
42# don't bother generating Python swig bindings -- we don't have
43# Python available.
44
45if echo $GCC_PREPROCESSOR_DEFINITIONS | grep LLDB_DISABLE_PYTHON
46then
47 echo "" > "${swig_output_file}"
48 exit 0
49fi
Chris Lattner24943d22010-06-08 16:52:24 +000050
Greg Claytonb3448432011-03-24 21:19:54 +000051HEADER_FILES="${SRC_ROOT}/include/lldb/lldb.h"\
Caroline Ticec8b0e902010-10-18 23:00:51 +000052" ${SRC_ROOT}/include/lldb/lldb-defines.h"\
53" ${SRC_ROOT}/include/lldb/lldb-enumerations.h"\
54" ${SRC_ROOT}/include/lldb/lldb-forward.h"\
55" ${SRC_ROOT}/include/lldb/lldb-forward-rtti.h"\
56" ${SRC_ROOT}/include/lldb/lldb-types.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000057" ${SRC_ROOT}/include/lldb/API/SBAddress.h"\
58" ${SRC_ROOT}/include/lldb/API/SBBlock.h"\
59" ${SRC_ROOT}/include/lldb/API/SBBreakpoint.h"\
60" ${SRC_ROOT}/include/lldb/API/SBBreakpointLocation.h"\
61" ${SRC_ROOT}/include/lldb/API/SBBroadcaster.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000062" ${SRC_ROOT}/include/lldb/API/SBCommandInterpreter.h"\
63" ${SRC_ROOT}/include/lldb/API/SBCommandReturnObject.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000064" ${SRC_ROOT}/include/lldb/API/SBCommunication.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000065" ${SRC_ROOT}/include/lldb/API/SBCompileUnit.h"\
Enrico Granata91544802011-09-06 19:20:51 +000066" ${SRC_ROOT}/include/lldb/API/SBData.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000067" ${SRC_ROOT}/include/lldb/API/SBDebugger.h"\
68" ${SRC_ROOT}/include/lldb/API/SBError.h"\
69" ${SRC_ROOT}/include/lldb/API/SBEvent.h"\
Johnny Chen4ead2e92010-08-27 22:35:26 +000070" ${SRC_ROOT}/include/lldb/API/SBFileSpec.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000071" ${SRC_ROOT}/include/lldb/API/SBFrame.h"\
72" ${SRC_ROOT}/include/lldb/API/SBFunction.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000073" ${SRC_ROOT}/include/lldb/API/SBHostOS.h"\
74" ${SRC_ROOT}/include/lldb/API/SBInputReader.h"\
Greg Clayton5c4c7462010-10-06 03:09:58 +000075" ${SRC_ROOT}/include/lldb/API/SBInstruction.h"\
76" ${SRC_ROOT}/include/lldb/API/SBInstructionList.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000077" ${SRC_ROOT}/include/lldb/API/SBLineEntry.h"\
78" ${SRC_ROOT}/include/lldb/API/SBListener.h"\
79" ${SRC_ROOT}/include/lldb/API/SBModule.h"\
80" ${SRC_ROOT}/include/lldb/API/SBProcess.h"\
81" ${SRC_ROOT}/include/lldb/API/SBSourceManager.h"\
Caroline Tice1ca48b02010-09-22 16:41:52 +000082" ${SRC_ROOT}/include/lldb/API/SBStream.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000083" ${SRC_ROOT}/include/lldb/API/SBStringList.h"\
84" ${SRC_ROOT}/include/lldb/API/SBSymbol.h"\
85" ${SRC_ROOT}/include/lldb/API/SBSymbolContext.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000086" ${SRC_ROOT}/include/lldb/API/SBSymbolContextList.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000087" ${SRC_ROOT}/include/lldb/API/SBTarget.h"\
88" ${SRC_ROOT}/include/lldb/API/SBThread.h"\
89" ${SRC_ROOT}/include/lldb/API/SBType.h"\
Enrico Granata16376ed2012-02-15 02:34:21 +000090" ${SRC_ROOT}/include/lldb/API/SBTypeCategory.h"\
91" ${SRC_ROOT}/include/lldb/API/SBTypeFilter.h"\
92" ${SRC_ROOT}/include/lldb/API/SBTypeFormat.h"\
93" ${SRC_ROOT}/include/lldb/API/SBTypeNameSpecifier.h"\
94" ${SRC_ROOT}/include/lldb/API/SBTypeSummary.h"\
95" ${SRC_ROOT}/include/lldb/API/SBTypeSynthetic.h"\
Caroline Tice1ca48b02010-09-22 16:41:52 +000096" ${SRC_ROOT}/include/lldb/API/SBValue.h"\
Johnny Chen092bd152011-09-27 01:19:20 +000097" ${SRC_ROOT}/include/lldb/API/SBValueList.h"\
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000098" ${SRC_ROOT}/include/lldb/API/SBWatchpoint.h"\
Chris Lattner24943d22010-06-08 16:52:24 +000099
Johnny Chenc39793d2011-09-09 17:37:06 +0000100INTERFACE_FILES="${SRC_ROOT}/scripts/Python/interface/SBAddress.i"\
101" ${SRC_ROOT}/scripts/Python/interface/SBBlock.i"\
102" ${SRC_ROOT}/scripts/Python/interface/SBBreakpoint.i"\
103" ${SRC_ROOT}/scripts/Python/interface/SBBreakpointLocation.i"\
104" ${SRC_ROOT}/scripts/Python/interface/SBBroadcaster.i"\
105" ${SRC_ROOT}/scripts/Python/interface/SBCommandInterpreter.i"\
106" ${SRC_ROOT}/scripts/Python/interface/SBCommandReturnObject.i"\
107" ${SRC_ROOT}/scripts/Python/interface/SBCommunication.i"\
108" ${SRC_ROOT}/scripts/Python/interface/SBCompileUnit.i"\
109" ${SRC_ROOT}/scripts/Python/interface/SBData.i"\
110" ${SRC_ROOT}/scripts/Python/interface/SBDebugger.i"\
111" ${SRC_ROOT}/scripts/Python/interface/SBError.i"\
112" ${SRC_ROOT}/scripts/Python/interface/SBEvent.i"\
113" ${SRC_ROOT}/scripts/Python/interface/SBFileSpec.i"\
114" ${SRC_ROOT}/scripts/Python/interface/SBFrame.i"\
115" ${SRC_ROOT}/scripts/Python/interface/SBFunction.i"\
116" ${SRC_ROOT}/scripts/Python/interface/SBHostOS.i"\
117" ${SRC_ROOT}/scripts/Python/interface/SBInputReader.i"\
118" ${SRC_ROOT}/scripts/Python/interface/SBInstruction.i"\
119" ${SRC_ROOT}/scripts/Python/interface/SBInstructionList.i"\
120" ${SRC_ROOT}/scripts/Python/interface/SBLineEntry.i"\
121" ${SRC_ROOT}/scripts/Python/interface/SBListener.i"\
122" ${SRC_ROOT}/scripts/Python/interface/SBModule.i"\
123" ${SRC_ROOT}/scripts/Python/interface/SBProcess.i"\
124" ${SRC_ROOT}/scripts/Python/interface/SBSourceManager.i"\
125" ${SRC_ROOT}/scripts/Python/interface/SBStream.i"\
126" ${SRC_ROOT}/scripts/Python/interface/SBStringList.i"\
127" ${SRC_ROOT}/scripts/Python/interface/SBSymbol.i"\
128" ${SRC_ROOT}/scripts/Python/interface/SBSymbolContext.i"\
129" ${SRC_ROOT}/scripts/Python/interface/SBTarget.i"\
130" ${SRC_ROOT}/scripts/Python/interface/SBThread.i"\
131" ${SRC_ROOT}/scripts/Python/interface/SBType.i"\
Enrico Granata16376ed2012-02-15 02:34:21 +0000132" ${SRC_ROOT}/scripts/Python/interface/SBTypeCategory.i"\
133" ${SRC_ROOT}/scripts/Python/interface/SBTypeFilter.i"\
134" ${SRC_ROOT}/scripts/Python/interface/SBTypeFormat.i"\
135" ${SRC_ROOT}/scripts/Python/interface/SBTypeNameSpecifier.i"\
136" ${SRC_ROOT}/scripts/Python/interface/SBTypeSummary.i"\
137" ${SRC_ROOT}/scripts/Python/interface/SBTypeSynthetic.i"\
Johnny Chenc39793d2011-09-09 17:37:06 +0000138" ${SRC_ROOT}/scripts/Python/interface/SBValue.i"\
Johnny Chen092bd152011-09-27 01:19:20 +0000139" ${SRC_ROOT}/scripts/Python/interface/SBValueList.i"\
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000140" ${SRC_ROOT}/scripts/Python/interface/SBWatchpoint.i"
Chris Lattner24943d22010-06-08 16:52:24 +0000141
142if [ $Debug == 1 ]
143then
144 echo "Header files are:"
145 echo ${HEADER_FILES}
146fi
147
Enrico Granata91544802011-09-06 19:20:51 +0000148if [ $Debug == 1 ]
149then
150 echo "SWIG interface files are:"
151 echo ${INTERFACE_FILES}
152fi
153
Chris Lattner24943d22010-06-08 16:52:24 +0000154NeedToUpdate=0
155
Chris Lattner24943d22010-06-08 16:52:24 +0000156
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000157if [ ! -f ${swig_output_file} ]
Chris Lattner24943d22010-06-08 16:52:24 +0000158then
159 NeedToUpdate=1
160 if [ $Debug == 1 ]
161 then
162 echo "Failed to find LLDBWrapPython.cpp"
163 fi
164fi
165
166if [ $NeedToUpdate == 0 ]
167then
168 for hdrfile in ${HEADER_FILES}
169 do
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000170 if [ $hdrfile -nt ${swig_output_file} ]
Chris Lattner24943d22010-06-08 16:52:24 +0000171 then
172 NeedToUpdate=1
173 if [ $Debug == 1 ]
174 then
175 echo "${hdrfile} is newer than ${swig_output_file}"
176 echo "swig file will need to be re-built."
177 fi
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000178 break
Chris Lattner24943d22010-06-08 16:52:24 +0000179 fi
180 done
181fi
182
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000183if [ $NeedToUpdate == 0 ]
184then
Enrico Granata91544802011-09-06 19:20:51 +0000185 for intffile in ${INTERFACE_FILES}
186 do
187 if [ $intffile -nt ${swig_output_file} ]
188 then
189 NeedToUpdate=1
190 if [ $Debug == 1 ]
191 then
192 echo "${intffile} is newer than ${swig_output_file}"
193 echo "swig file will need to be re-built."
194 fi
195 break
196 fi
197 done
198fi
199
200if [ $NeedToUpdate == 0 ]
201then
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000202 if [ ${swig_input_file} -nt ${swig_output_file} ]
203 then
204 NeedToUpdate=1
205 if [ $Debug == 1 ]
206 then
207 echo "${swig_input_file} is newer than ${swig_output_file}"
208 echo "swig file will need to be re-built."
209 fi
210 fi
211fi
212
Caroline Tice7826c882010-10-26 03:11:13 +0000213if [ $NeedToUpdate == 0 ]
214then
Johnny Chenf530bfe2011-08-22 22:10:57 +0000215 if [ ${swig_python_extensions} -nt ${swig_output_file} ]
Caroline Tice7826c882010-10-26 03:11:13 +0000216 then
217 NeedToUpdate=1
218 if [ $Debug == 1 ]
219 then
Johnny Chenf530bfe2011-08-22 22:10:57 +0000220 echo "${swig_python_extensions} is newer than ${swig_output_file}"
221 echo "swig file will need to be re-built."
222 fi
223 fi
224fi
225
226if [ $NeedToUpdate == 0 ]
227then
228 if [ ${swig_python_wrapper} -nt ${swig_output_file} ]
229 then
230 NeedToUpdate=1
231 if [ $Debug == 1 ]
232 then
233 echo "${swig_python_wrapper} is newer than ${swig_output_file}"
Caroline Tice7826c882010-10-26 03:11:13 +0000234 echo "swig file will need to be re-built."
235 fi
236 fi
237fi
238
Enrico Granatab62d4c62012-02-02 17:26:00 +0000239if [ $NeedToUpdate == 0 ]
240then
241 if [ ${swig_python_typemaps} -nt ${swig_output_file} ]
242 then
243 NeedToUpdate=1
244 if [ $Debug == 1 ]
245 then
246 echo "${swig_python_typemaps} is newer than ${swig_output_file}"
247 echo "swig file will need to be re-built."
248 fi
249 fi
250fi
251
Caroline Tice9dbe7172010-06-16 19:26:52 +0000252os_name=`uname -s`
253python_version=`/usr/bin/python --version 2>&1 | sed -e 's,Python ,,' -e 's,[.][0-9],,2' -e 's,[a-z][a-z][0-9],,'`
254
255if [ "$os_name" == "Darwin" ]
256then
257 framework_python_dir="${TARGET_DIR}/LLDB.framework/Resources/Python"
258else
259 framework_python_dir="${PYTHON_INSTALL_DIR}/python${python_version}"
260fi
261
Chris Lattner24943d22010-06-08 16:52:24 +0000262
263if [ ! -L "${framework_python_dir}/_lldb.so" ]
264then
265 NeedToUpdate=1
266fi
267
268if [ ! -f "${framework_python_dir}/lldb.py" ]
269then
270 NeedToUpdate=1
271fi
272
273
274if [ $NeedToUpdate == 0 ]
275then
276 echo "Everything is up-to-date."
277 exit 0
278else
279 echo "SWIG needs to be re-run."
Caroline Tice7826c882010-10-26 03:11:13 +0000280 if [ -f ${swig_output_file} ]
281 then
282 rm ${swig_output_file}
283 fi
Chris Lattner24943d22010-06-08 16:52:24 +0000284fi
285
286
287# Build the SWIG C++ wrapper file for Python.
288
Jim Ingham2396b9f2011-03-01 01:39:04 +0000289$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 +0000290
Johnny Chen22e418a2011-04-29 19:22:24 +0000291# Implement the iterator protocol and/or eq/ne operators for some lldb objects.
Caroline Tice558be582010-06-30 16:22:25 +0000292# Append global variable to lldb Python module.
Johnny Chen14097802011-04-28 21:31:18 +0000293# And initialize the lldb debugger subsystem.
Caroline Tice558be582010-06-30 16:22:25 +0000294current_dir=`pwd`
Johnny Chen14097802011-04-28 21:31:18 +0000295if [ -f "${current_dir}/modify-python-lldb.py" ]
Caroline Tice558be582010-06-30 16:22:25 +0000296then
Johnny Chen14097802011-04-28 21:31:18 +0000297 python ${current_dir}/modify-python-lldb.py ${CONFIG_BUILD_DIR}
Caroline Tice558be582010-06-30 16:22:25 +0000298fi
Caroline Tice5790e062010-10-28 21:51:20 +0000299
300# Fix the "#include" statement in the swig output file
301
302if [ -f "${current_dir}/edit-swig-python-wrapper-file.py" ]
303then
304 python ${current_dir}/edit-swig-python-wrapper-file.py
305 if [ -f "${swig_output_file}.edited" ]
306 then
307 mv "${swig_output_file}.edited" ${swig_output_file}
308 fi
309fi
Greg Clayton3e4238d2011-11-04 03:34:56 +0000310
Greg Clayton3e4238d2011-11-04 03:34:56 +0000311fi