blob: 59394f9cc0ea13d979ce7819767461b1373b774d [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
Filipe Cabecinhas4bb4f302012-09-14 17:09:15 +000021os_name=`uname -s`
Jason Molendae2801e12012-09-27 21:26:57 +000022if [ "$os_name" = "Darwin" ]
Filipe Cabecinhas4bb4f302012-09-14 17:09:15 +000023then
24 swig_output_file=${SRC_ROOT}/source/LLDBWrapPython.cpp
25else
26 swig_output_file=${TARGET_DIR}/LLDBWrapPython.cpp
27fi
Caroline Tice9dbe7172010-06-16 19:26:52 +000028swig_input_file=${SRC_ROOT}/scripts/lldb.swig
Johnny Chenf530bfe2011-08-22 22:10:57 +000029swig_python_extensions=${SRC_ROOT}/scripts/Python/python-extensions.swig
30swig_python_wrapper=${SRC_ROOT}/scripts/Python/python-wrapper.swig
Enrico Granatab62d4c62012-02-02 17:26:00 +000031swig_python_typemaps=${SRC_ROOT}/scripts/Python/python-typemaps.swig
Chris Lattner24943d22010-06-08 16:52:24 +000032
Filipe Cabecinhas4bb4f302012-09-14 17:09:15 +000033if [ "$LLDB_DISABLE_PYTHON" = "1" ] ; then
Jim Inghamf4ec2ea2012-05-26 00:23:52 +000034 # We don't want Python for this build, but touch the output file so we don't have to
35 # conditionalize the build on this as well.
36 # Note, at present iOS doesn't have Python, so if you're building for iOS be sure to
37 # set LLDB_DISABLE_PYTHON to 1.
Jim Inghamb7e62f82012-05-24 01:16:09 +000038 rm -rf ${swig_output_file}
39 touch ${swig_output_file}
40
41else
Greg Clayton3e4238d2011-11-04 03:34:56 +000042
Jason Molendae2801e12012-09-27 21:26:57 +000043if [ -n "$debug_flag" -a "$debug_flag" = "-debug" ]
Chris Lattner24943d22010-06-08 16:52:24 +000044then
45 Debug=1
46else
47 Debug=0
48fi
49
Jason Molendac48ca822012-02-21 05:33:55 +000050# If this project is being built with LLDB_DISABLE_PYTHON defined,
51# don't bother generating Python swig bindings -- we don't have
52# Python available.
53
54if echo $GCC_PREPROCESSOR_DEFINITIONS | grep LLDB_DISABLE_PYTHON
55then
56 echo "" > "${swig_output_file}"
57 exit 0
58fi
Chris Lattner24943d22010-06-08 16:52:24 +000059
Greg Claytonb3448432011-03-24 21:19:54 +000060HEADER_FILES="${SRC_ROOT}/include/lldb/lldb.h"\
Caroline Ticec8b0e902010-10-18 23:00:51 +000061" ${SRC_ROOT}/include/lldb/lldb-defines.h"\
62" ${SRC_ROOT}/include/lldb/lldb-enumerations.h"\
63" ${SRC_ROOT}/include/lldb/lldb-forward.h"\
64" ${SRC_ROOT}/include/lldb/lldb-forward-rtti.h"\
65" ${SRC_ROOT}/include/lldb/lldb-types.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000066" ${SRC_ROOT}/include/lldb/API/SBAddress.h"\
67" ${SRC_ROOT}/include/lldb/API/SBBlock.h"\
68" ${SRC_ROOT}/include/lldb/API/SBBreakpoint.h"\
69" ${SRC_ROOT}/include/lldb/API/SBBreakpointLocation.h"\
70" ${SRC_ROOT}/include/lldb/API/SBBroadcaster.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000071" ${SRC_ROOT}/include/lldb/API/SBCommandInterpreter.h"\
72" ${SRC_ROOT}/include/lldb/API/SBCommandReturnObject.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000073" ${SRC_ROOT}/include/lldb/API/SBCommunication.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000074" ${SRC_ROOT}/include/lldb/API/SBCompileUnit.h"\
Enrico Granata91544802011-09-06 19:20:51 +000075" ${SRC_ROOT}/include/lldb/API/SBData.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000076" ${SRC_ROOT}/include/lldb/API/SBDebugger.h"\
77" ${SRC_ROOT}/include/lldb/API/SBError.h"\
78" ${SRC_ROOT}/include/lldb/API/SBEvent.h"\
Jim Ingham47beabb2012-10-16 21:41:58 +000079" ${SRC_ROOT}/include/lldb/API/SBExpressionOptions.h"\
Johnny Chen4ead2e92010-08-27 22:35:26 +000080" ${SRC_ROOT}/include/lldb/API/SBFileSpec.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000081" ${SRC_ROOT}/include/lldb/API/SBFrame.h"\
82" ${SRC_ROOT}/include/lldb/API/SBFunction.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000083" ${SRC_ROOT}/include/lldb/API/SBHostOS.h"\
84" ${SRC_ROOT}/include/lldb/API/SBInputReader.h"\
Greg Clayton5c4c7462010-10-06 03:09:58 +000085" ${SRC_ROOT}/include/lldb/API/SBInstruction.h"\
86" ${SRC_ROOT}/include/lldb/API/SBInstructionList.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000087" ${SRC_ROOT}/include/lldb/API/SBLineEntry.h"\
88" ${SRC_ROOT}/include/lldb/API/SBListener.h"\
89" ${SRC_ROOT}/include/lldb/API/SBModule.h"\
90" ${SRC_ROOT}/include/lldb/API/SBProcess.h"\
91" ${SRC_ROOT}/include/lldb/API/SBSourceManager.h"\
Caroline Tice1ca48b02010-09-22 16:41:52 +000092" ${SRC_ROOT}/include/lldb/API/SBStream.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000093" ${SRC_ROOT}/include/lldb/API/SBStringList.h"\
94" ${SRC_ROOT}/include/lldb/API/SBSymbol.h"\
95" ${SRC_ROOT}/include/lldb/API/SBSymbolContext.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000096" ${SRC_ROOT}/include/lldb/API/SBSymbolContextList.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000097" ${SRC_ROOT}/include/lldb/API/SBTarget.h"\
98" ${SRC_ROOT}/include/lldb/API/SBThread.h"\
99" ${SRC_ROOT}/include/lldb/API/SBType.h"\
Enrico Granata16376ed2012-02-15 02:34:21 +0000100" ${SRC_ROOT}/include/lldb/API/SBTypeCategory.h"\
101" ${SRC_ROOT}/include/lldb/API/SBTypeFilter.h"\
102" ${SRC_ROOT}/include/lldb/API/SBTypeFormat.h"\
103" ${SRC_ROOT}/include/lldb/API/SBTypeNameSpecifier.h"\
104" ${SRC_ROOT}/include/lldb/API/SBTypeSummary.h"\
105" ${SRC_ROOT}/include/lldb/API/SBTypeSynthetic.h"\
Caroline Tice1ca48b02010-09-22 16:41:52 +0000106" ${SRC_ROOT}/include/lldb/API/SBValue.h"\
Johnny Chen092bd152011-09-27 01:19:20 +0000107" ${SRC_ROOT}/include/lldb/API/SBValueList.h"\
Enrico Granata6d101882012-09-28 23:57:51 +0000108" ${SRC_ROOT}/include/lldb/API/SBWatchpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +0000109
Johnny Chenc39793d2011-09-09 17:37:06 +0000110INTERFACE_FILES="${SRC_ROOT}/scripts/Python/interface/SBAddress.i"\
111" ${SRC_ROOT}/scripts/Python/interface/SBBlock.i"\
112" ${SRC_ROOT}/scripts/Python/interface/SBBreakpoint.i"\
113" ${SRC_ROOT}/scripts/Python/interface/SBBreakpointLocation.i"\
114" ${SRC_ROOT}/scripts/Python/interface/SBBroadcaster.i"\
115" ${SRC_ROOT}/scripts/Python/interface/SBCommandInterpreter.i"\
116" ${SRC_ROOT}/scripts/Python/interface/SBCommandReturnObject.i"\
117" ${SRC_ROOT}/scripts/Python/interface/SBCommunication.i"\
118" ${SRC_ROOT}/scripts/Python/interface/SBCompileUnit.i"\
119" ${SRC_ROOT}/scripts/Python/interface/SBData.i"\
120" ${SRC_ROOT}/scripts/Python/interface/SBDebugger.i"\
Enrico Granata49306142012-10-10 22:54:17 +0000121" ${SRC_ROOT}/scripts/Python/interface/SBDeclaration.i"\
Johnny Chenc39793d2011-09-09 17:37:06 +0000122" ${SRC_ROOT}/scripts/Python/interface/SBError.i"\
123" ${SRC_ROOT}/scripts/Python/interface/SBEvent.i"\
Jim Ingham47beabb2012-10-16 21:41:58 +0000124" ${SRC_ROOT}/scripts/Python/interface/SBExpressionOptions.i"\
Johnny Chenc39793d2011-09-09 17:37:06 +0000125" ${SRC_ROOT}/scripts/Python/interface/SBFileSpec.i"\
126" ${SRC_ROOT}/scripts/Python/interface/SBFrame.i"\
127" ${SRC_ROOT}/scripts/Python/interface/SBFunction.i"\
128" ${SRC_ROOT}/scripts/Python/interface/SBHostOS.i"\
129" ${SRC_ROOT}/scripts/Python/interface/SBInputReader.i"\
130" ${SRC_ROOT}/scripts/Python/interface/SBInstruction.i"\
131" ${SRC_ROOT}/scripts/Python/interface/SBInstructionList.i"\
132" ${SRC_ROOT}/scripts/Python/interface/SBLineEntry.i"\
133" ${SRC_ROOT}/scripts/Python/interface/SBListener.i"\
134" ${SRC_ROOT}/scripts/Python/interface/SBModule.i"\
135" ${SRC_ROOT}/scripts/Python/interface/SBProcess.i"\
136" ${SRC_ROOT}/scripts/Python/interface/SBSourceManager.i"\
137" ${SRC_ROOT}/scripts/Python/interface/SBStream.i"\
138" ${SRC_ROOT}/scripts/Python/interface/SBStringList.i"\
139" ${SRC_ROOT}/scripts/Python/interface/SBSymbol.i"\
140" ${SRC_ROOT}/scripts/Python/interface/SBSymbolContext.i"\
141" ${SRC_ROOT}/scripts/Python/interface/SBTarget.i"\
142" ${SRC_ROOT}/scripts/Python/interface/SBThread.i"\
143" ${SRC_ROOT}/scripts/Python/interface/SBType.i"\
Enrico Granata16376ed2012-02-15 02:34:21 +0000144" ${SRC_ROOT}/scripts/Python/interface/SBTypeCategory.i"\
145" ${SRC_ROOT}/scripts/Python/interface/SBTypeFilter.i"\
146" ${SRC_ROOT}/scripts/Python/interface/SBTypeFormat.i"\
147" ${SRC_ROOT}/scripts/Python/interface/SBTypeNameSpecifier.i"\
148" ${SRC_ROOT}/scripts/Python/interface/SBTypeSummary.i"\
149" ${SRC_ROOT}/scripts/Python/interface/SBTypeSynthetic.i"\
Johnny Chenc39793d2011-09-09 17:37:06 +0000150" ${SRC_ROOT}/scripts/Python/interface/SBValue.i"\
Johnny Chen092bd152011-09-27 01:19:20 +0000151" ${SRC_ROOT}/scripts/Python/interface/SBValueList.i"\
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000152" ${SRC_ROOT}/scripts/Python/interface/SBWatchpoint.i"
Chris Lattner24943d22010-06-08 16:52:24 +0000153
Jason Molendae2801e12012-09-27 21:26:57 +0000154if [ $Debug -eq 1 ]
Chris Lattner24943d22010-06-08 16:52:24 +0000155then
156 echo "Header files are:"
157 echo ${HEADER_FILES}
158fi
159
Jason Molendae2801e12012-09-27 21:26:57 +0000160if [ $Debug -eq 1 ]
Enrico Granata91544802011-09-06 19:20:51 +0000161then
162 echo "SWIG interface files are:"
163 echo ${INTERFACE_FILES}
164fi
165
Chris Lattner24943d22010-06-08 16:52:24 +0000166NeedToUpdate=0
167
Chris Lattner24943d22010-06-08 16:52:24 +0000168
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000169if [ ! -f ${swig_output_file} ]
Chris Lattner24943d22010-06-08 16:52:24 +0000170then
171 NeedToUpdate=1
Jason Molendae2801e12012-09-27 21:26:57 +0000172 if [ $Debug -eq 1 ]
Chris Lattner24943d22010-06-08 16:52:24 +0000173 then
174 echo "Failed to find LLDBWrapPython.cpp"
175 fi
176fi
177
Jason Molendae2801e12012-09-27 21:26:57 +0000178if [ $NeedToUpdate -eq 0 ]
Chris Lattner24943d22010-06-08 16:52:24 +0000179then
180 for hdrfile in ${HEADER_FILES}
181 do
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000182 if [ $hdrfile -nt ${swig_output_file} ]
Chris Lattner24943d22010-06-08 16:52:24 +0000183 then
184 NeedToUpdate=1
Jason Molendae2801e12012-09-27 21:26:57 +0000185 if [ $Debug -eq 1 ]
Chris Lattner24943d22010-06-08 16:52:24 +0000186 then
187 echo "${hdrfile} is newer than ${swig_output_file}"
188 echo "swig file will need to be re-built."
189 fi
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000190 break
Chris Lattner24943d22010-06-08 16:52:24 +0000191 fi
192 done
193fi
194
Jason Molendae2801e12012-09-27 21:26:57 +0000195if [ $NeedToUpdate -eq 0 ]
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000196then
Enrico Granata91544802011-09-06 19:20:51 +0000197 for intffile in ${INTERFACE_FILES}
198 do
199 if [ $intffile -nt ${swig_output_file} ]
200 then
201 NeedToUpdate=1
Jason Molendae2801e12012-09-27 21:26:57 +0000202 if [ $Debug -eq 1 ]
Enrico Granata91544802011-09-06 19:20:51 +0000203 then
204 echo "${intffile} is newer than ${swig_output_file}"
205 echo "swig file will need to be re-built."
206 fi
207 break
208 fi
209 done
210fi
211
Jason Molendae2801e12012-09-27 21:26:57 +0000212if [ $NeedToUpdate -eq 0 ]
Enrico Granata91544802011-09-06 19:20:51 +0000213then
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000214 if [ ${swig_input_file} -nt ${swig_output_file} ]
215 then
216 NeedToUpdate=1
Jason Molendae2801e12012-09-27 21:26:57 +0000217 if [ $Debug -eq 1 ]
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000218 then
219 echo "${swig_input_file} is newer than ${swig_output_file}"
220 echo "swig file will need to be re-built."
221 fi
222 fi
223fi
224
Jason Molendae2801e12012-09-27 21:26:57 +0000225if [ $NeedToUpdate -eq 0 ]
Caroline Tice7826c882010-10-26 03:11:13 +0000226then
Johnny Chenf530bfe2011-08-22 22:10:57 +0000227 if [ ${swig_python_extensions} -nt ${swig_output_file} ]
Caroline Tice7826c882010-10-26 03:11:13 +0000228 then
229 NeedToUpdate=1
Jason Molendae2801e12012-09-27 21:26:57 +0000230 if [ $Debug -eq 1 ]
Caroline Tice7826c882010-10-26 03:11:13 +0000231 then
Johnny Chenf530bfe2011-08-22 22:10:57 +0000232 echo "${swig_python_extensions} is newer than ${swig_output_file}"
233 echo "swig file will need to be re-built."
234 fi
235 fi
236fi
237
Jason Molendae2801e12012-09-27 21:26:57 +0000238if [ $NeedToUpdate -eq 0 ]
Johnny Chenf530bfe2011-08-22 22:10:57 +0000239then
240 if [ ${swig_python_wrapper} -nt ${swig_output_file} ]
241 then
242 NeedToUpdate=1
Jason Molendae2801e12012-09-27 21:26:57 +0000243 if [ $Debug -eq 1 ]
Johnny Chenf530bfe2011-08-22 22:10:57 +0000244 then
245 echo "${swig_python_wrapper} is newer than ${swig_output_file}"
Caroline Tice7826c882010-10-26 03:11:13 +0000246 echo "swig file will need to be re-built."
247 fi
248 fi
249fi
250
Jason Molendae2801e12012-09-27 21:26:57 +0000251if [ $NeedToUpdate -eq 0 ]
Enrico Granatab62d4c62012-02-02 17:26:00 +0000252then
253 if [ ${swig_python_typemaps} -nt ${swig_output_file} ]
254 then
255 NeedToUpdate=1
Jason Molendae2801e12012-09-27 21:26:57 +0000256 if [ $Debug -eq 1 ]
Enrico Granatab62d4c62012-02-02 17:26:00 +0000257 then
258 echo "${swig_python_typemaps} is newer than ${swig_output_file}"
259 echo "swig file will need to be re-built."
260 fi
261 fi
262fi
263
Filipe Cabecinhas4bb4f302012-09-14 17:09:15 +0000264python_version=`/usr/bin/env python --version 2>&1 | sed -e 's,Python ,,' -e 's,[.][0-9],,2' -e 's,[a-z][a-z][0-9],,'`
Caroline Tice9dbe7172010-06-16 19:26:52 +0000265
Jason Molendae2801e12012-09-27 21:26:57 +0000266if [ "$os_name" = "Darwin" ]
Caroline Tice9dbe7172010-06-16 19:26:52 +0000267then
268 framework_python_dir="${TARGET_DIR}/LLDB.framework/Resources/Python"
269else
270 framework_python_dir="${PYTHON_INSTALL_DIR}/python${python_version}"
271fi
272
Chris Lattner24943d22010-06-08 16:52:24 +0000273
274if [ ! -L "${framework_python_dir}/_lldb.so" ]
275then
276 NeedToUpdate=1
277fi
278
279if [ ! -f "${framework_python_dir}/lldb.py" ]
280then
281 NeedToUpdate=1
282fi
283
284
Jason Molendae2801e12012-09-27 21:26:57 +0000285if [ $NeedToUpdate -eq 0 ]
Chris Lattner24943d22010-06-08 16:52:24 +0000286then
287 echo "Everything is up-to-date."
288 exit 0
289else
290 echo "SWIG needs to be re-run."
Caroline Tice7826c882010-10-26 03:11:13 +0000291 if [ -f ${swig_output_file} ]
292 then
293 rm ${swig_output_file}
294 fi
Chris Lattner24943d22010-06-08 16:52:24 +0000295fi
296
297
298# Build the SWIG C++ wrapper file for Python.
299
Johnny Chen8165d432012-08-18 04:14:54 +0000300$SWIG -c++ -shadow -python -threads -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 +0000301
Johnny Chen22e418a2011-04-29 19:22:24 +0000302# Implement the iterator protocol and/or eq/ne operators for some lldb objects.
Caroline Tice558be582010-06-30 16:22:25 +0000303# Append global variable to lldb Python module.
Johnny Chen14097802011-04-28 21:31:18 +0000304# And initialize the lldb debugger subsystem.
Caroline Tice558be582010-06-30 16:22:25 +0000305current_dir=`pwd`
Johnny Chen14097802011-04-28 21:31:18 +0000306if [ -f "${current_dir}/modify-python-lldb.py" ]
Caroline Tice558be582010-06-30 16:22:25 +0000307then
Johnny Chen14097802011-04-28 21:31:18 +0000308 python ${current_dir}/modify-python-lldb.py ${CONFIG_BUILD_DIR}
Caroline Tice558be582010-06-30 16:22:25 +0000309fi
Caroline Tice5790e062010-10-28 21:51:20 +0000310
311# Fix the "#include" statement in the swig output file
312
313if [ -f "${current_dir}/edit-swig-python-wrapper-file.py" ]
314then
315 python ${current_dir}/edit-swig-python-wrapper-file.py
316 if [ -f "${swig_output_file}.edited" ]
317 then
318 mv "${swig_output_file}.edited" ${swig_output_file}
319 fi
320fi
Greg Clayton3e4238d2011-11-04 03:34:56 +0000321
Greg Clayton3e4238d2011-11-04 03:34:56 +0000322fi