blob: d7191221a774225e92257a9242d060582b989eed [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
Chris Lattner24943d22010-06-08 16:52:24 +000025
26if [ -n "$debug_flag" -a "$debug_flag" == "-debug" ]
27then
28 Debug=1
29else
30 Debug=0
31fi
32
33
Greg Claytonb3448432011-03-24 21:19:54 +000034HEADER_FILES="${SRC_ROOT}/include/lldb/lldb.h"\
Caroline Ticec8b0e902010-10-18 23:00:51 +000035" ${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 Tice9dbe7172010-06-16 19:26:52 +000040" ${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 Tice9dbe7172010-06-16 19:26:52 +000045" ${SRC_ROOT}/include/lldb/API/SBCommandInterpreter.h"\
46" ${SRC_ROOT}/include/lldb/API/SBCommandReturnObject.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000047" ${SRC_ROOT}/include/lldb/API/SBCommunication.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000048" ${SRC_ROOT}/include/lldb/API/SBCompileUnit.h"\
Enrico Granata91544802011-09-06 19:20:51 +000049" ${SRC_ROOT}/include/lldb/API/SBData.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000050" ${SRC_ROOT}/include/lldb/API/SBDebugger.h"\
51" ${SRC_ROOT}/include/lldb/API/SBError.h"\
52" ${SRC_ROOT}/include/lldb/API/SBEvent.h"\
Johnny Chen4ead2e92010-08-27 22:35:26 +000053" ${SRC_ROOT}/include/lldb/API/SBFileSpec.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000054" ${SRC_ROOT}/include/lldb/API/SBFrame.h"\
55" ${SRC_ROOT}/include/lldb/API/SBFunction.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000056" ${SRC_ROOT}/include/lldb/API/SBHostOS.h"\
57" ${SRC_ROOT}/include/lldb/API/SBInputReader.h"\
Greg Clayton5c4c7462010-10-06 03:09:58 +000058" ${SRC_ROOT}/include/lldb/API/SBInstruction.h"\
59" ${SRC_ROOT}/include/lldb/API/SBInstructionList.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000060" ${SRC_ROOT}/include/lldb/API/SBLineEntry.h"\
61" ${SRC_ROOT}/include/lldb/API/SBListener.h"\
62" ${SRC_ROOT}/include/lldb/API/SBModule.h"\
63" ${SRC_ROOT}/include/lldb/API/SBProcess.h"\
64" ${SRC_ROOT}/include/lldb/API/SBSourceManager.h"\
Caroline Tice1ca48b02010-09-22 16:41:52 +000065" ${SRC_ROOT}/include/lldb/API/SBStream.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000066" ${SRC_ROOT}/include/lldb/API/SBStringList.h"\
67" ${SRC_ROOT}/include/lldb/API/SBSymbol.h"\
68" ${SRC_ROOT}/include/lldb/API/SBSymbolContext.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000069" ${SRC_ROOT}/include/lldb/API/SBSymbolContextList.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000070" ${SRC_ROOT}/include/lldb/API/SBTarget.h"\
71" ${SRC_ROOT}/include/lldb/API/SBThread.h"\
72" ${SRC_ROOT}/include/lldb/API/SBType.h"\
Caroline Tice1ca48b02010-09-22 16:41:52 +000073" ${SRC_ROOT}/include/lldb/API/SBValue.h"\
Johnny Chen092bd152011-09-27 01:19:20 +000074" ${SRC_ROOT}/include/lldb/API/SBValueList.h"\
Greg Clayton1fa6b3d2011-10-13 18:08:26 +000075" ${SRC_ROOT}/include/lldb/API/SBWatchpoint.h"\
Chris Lattner24943d22010-06-08 16:52:24 +000076
Johnny Chenc39793d2011-09-09 17:37:06 +000077INTERFACE_FILES="${SRC_ROOT}/scripts/Python/interface/SBAddress.i"\
78" ${SRC_ROOT}/scripts/Python/interface/SBBlock.i"\
79" ${SRC_ROOT}/scripts/Python/interface/SBBreakpoint.i"\
80" ${SRC_ROOT}/scripts/Python/interface/SBBreakpointLocation.i"\
81" ${SRC_ROOT}/scripts/Python/interface/SBBroadcaster.i"\
82" ${SRC_ROOT}/scripts/Python/interface/SBCommandInterpreter.i"\
83" ${SRC_ROOT}/scripts/Python/interface/SBCommandReturnObject.i"\
84" ${SRC_ROOT}/scripts/Python/interface/SBCommunication.i"\
85" ${SRC_ROOT}/scripts/Python/interface/SBCompileUnit.i"\
86" ${SRC_ROOT}/scripts/Python/interface/SBData.i"\
87" ${SRC_ROOT}/scripts/Python/interface/SBDebugger.i"\
88" ${SRC_ROOT}/scripts/Python/interface/SBError.i"\
89" ${SRC_ROOT}/scripts/Python/interface/SBEvent.i"\
90" ${SRC_ROOT}/scripts/Python/interface/SBFileSpec.i"\
91" ${SRC_ROOT}/scripts/Python/interface/SBFrame.i"\
92" ${SRC_ROOT}/scripts/Python/interface/SBFunction.i"\
93" ${SRC_ROOT}/scripts/Python/interface/SBHostOS.i"\
94" ${SRC_ROOT}/scripts/Python/interface/SBInputReader.i"\
95" ${SRC_ROOT}/scripts/Python/interface/SBInstruction.i"\
96" ${SRC_ROOT}/scripts/Python/interface/SBInstructionList.i"\
97" ${SRC_ROOT}/scripts/Python/interface/SBLineEntry.i"\
98" ${SRC_ROOT}/scripts/Python/interface/SBListener.i"\
99" ${SRC_ROOT}/scripts/Python/interface/SBModule.i"\
100" ${SRC_ROOT}/scripts/Python/interface/SBProcess.i"\
101" ${SRC_ROOT}/scripts/Python/interface/SBSourceManager.i"\
102" ${SRC_ROOT}/scripts/Python/interface/SBStream.i"\
103" ${SRC_ROOT}/scripts/Python/interface/SBStringList.i"\
104" ${SRC_ROOT}/scripts/Python/interface/SBSymbol.i"\
105" ${SRC_ROOT}/scripts/Python/interface/SBSymbolContext.i"\
106" ${SRC_ROOT}/scripts/Python/interface/SBTarget.i"\
107" ${SRC_ROOT}/scripts/Python/interface/SBThread.i"\
108" ${SRC_ROOT}/scripts/Python/interface/SBType.i"\
109" ${SRC_ROOT}/scripts/Python/interface/SBValue.i"\
Johnny Chen092bd152011-09-27 01:19:20 +0000110" ${SRC_ROOT}/scripts/Python/interface/SBValueList.i"\
Greg Clayton1fa6b3d2011-10-13 18:08:26 +0000111" ${SRC_ROOT}/scripts/Python/interface/SBWatchpoint.i"
Chris Lattner24943d22010-06-08 16:52:24 +0000112
113if [ $Debug == 1 ]
114then
115 echo "Header files are:"
116 echo ${HEADER_FILES}
117fi
118
Enrico Granata91544802011-09-06 19:20:51 +0000119if [ $Debug == 1 ]
120then
121 echo "SWIG interface files are:"
122 echo ${INTERFACE_FILES}
123fi
124
Chris Lattner24943d22010-06-08 16:52:24 +0000125NeedToUpdate=0
126
Chris Lattner24943d22010-06-08 16:52:24 +0000127
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000128if [ ! -f ${swig_output_file} ]
Chris Lattner24943d22010-06-08 16:52:24 +0000129then
130 NeedToUpdate=1
131 if [ $Debug == 1 ]
132 then
133 echo "Failed to find LLDBWrapPython.cpp"
134 fi
135fi
136
137if [ $NeedToUpdate == 0 ]
138then
139 for hdrfile in ${HEADER_FILES}
140 do
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000141 if [ $hdrfile -nt ${swig_output_file} ]
Chris Lattner24943d22010-06-08 16:52:24 +0000142 then
143 NeedToUpdate=1
144 if [ $Debug == 1 ]
145 then
146 echo "${hdrfile} is newer than ${swig_output_file}"
147 echo "swig file will need to be re-built."
148 fi
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000149 break
Chris Lattner24943d22010-06-08 16:52:24 +0000150 fi
151 done
152fi
153
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000154if [ $NeedToUpdate == 0 ]
155then
Enrico Granata91544802011-09-06 19:20:51 +0000156 for intffile in ${INTERFACE_FILES}
157 do
158 if [ $intffile -nt ${swig_output_file} ]
159 then
160 NeedToUpdate=1
161 if [ $Debug == 1 ]
162 then
163 echo "${intffile} is newer than ${swig_output_file}"
164 echo "swig file will need to be re-built."
165 fi
166 break
167 fi
168 done
169fi
170
171if [ $NeedToUpdate == 0 ]
172then
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000173 if [ ${swig_input_file} -nt ${swig_output_file} ]
174 then
175 NeedToUpdate=1
176 if [ $Debug == 1 ]
177 then
178 echo "${swig_input_file} is newer than ${swig_output_file}"
179 echo "swig file will need to be re-built."
180 fi
181 fi
182fi
183
Caroline Tice7826c882010-10-26 03:11:13 +0000184if [ $NeedToUpdate == 0 ]
185then
Johnny Chenf530bfe2011-08-22 22:10:57 +0000186 if [ ${swig_python_extensions} -nt ${swig_output_file} ]
Caroline Tice7826c882010-10-26 03:11:13 +0000187 then
188 NeedToUpdate=1
189 if [ $Debug == 1 ]
190 then
Johnny Chenf530bfe2011-08-22 22:10:57 +0000191 echo "${swig_python_extensions} is newer than ${swig_output_file}"
192 echo "swig file will need to be re-built."
193 fi
194 fi
195fi
196
197if [ $NeedToUpdate == 0 ]
198then
199 if [ ${swig_python_wrapper} -nt ${swig_output_file} ]
200 then
201 NeedToUpdate=1
202 if [ $Debug == 1 ]
203 then
204 echo "${swig_python_wrapper} is newer than ${swig_output_file}"
Caroline Tice7826c882010-10-26 03:11:13 +0000205 echo "swig file will need to be re-built."
206 fi
207 fi
208fi
209
Caroline Tice9dbe7172010-06-16 19:26:52 +0000210os_name=`uname -s`
211python_version=`/usr/bin/python --version 2>&1 | sed -e 's,Python ,,' -e 's,[.][0-9],,2' -e 's,[a-z][a-z][0-9],,'`
212
213if [ "$os_name" == "Darwin" ]
214then
215 framework_python_dir="${TARGET_DIR}/LLDB.framework/Resources/Python"
216else
217 framework_python_dir="${PYTHON_INSTALL_DIR}/python${python_version}"
218fi
219
Chris Lattner24943d22010-06-08 16:52:24 +0000220
221if [ ! -L "${framework_python_dir}/_lldb.so" ]
222then
223 NeedToUpdate=1
224fi
225
226if [ ! -f "${framework_python_dir}/lldb.py" ]
227then
228 NeedToUpdate=1
229fi
230
231
232if [ $NeedToUpdate == 0 ]
233then
234 echo "Everything is up-to-date."
235 exit 0
236else
237 echo "SWIG needs to be re-run."
Caroline Tice7826c882010-10-26 03:11:13 +0000238 if [ -f ${swig_output_file} ]
239 then
240 rm ${swig_output_file}
241 fi
Chris Lattner24943d22010-06-08 16:52:24 +0000242fi
243
244
245# Build the SWIG C++ wrapper file for Python.
246
Jim Ingham2396b9f2011-03-01 01:39:04 +0000247$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 +0000248
Johnny Chen22e418a2011-04-29 19:22:24 +0000249# Implement the iterator protocol and/or eq/ne operators for some lldb objects.
Caroline Tice558be582010-06-30 16:22:25 +0000250# Append global variable to lldb Python module.
Johnny Chen14097802011-04-28 21:31:18 +0000251# And initialize the lldb debugger subsystem.
Caroline Tice558be582010-06-30 16:22:25 +0000252current_dir=`pwd`
Johnny Chen14097802011-04-28 21:31:18 +0000253if [ -f "${current_dir}/modify-python-lldb.py" ]
Caroline Tice558be582010-06-30 16:22:25 +0000254then
Johnny Chen14097802011-04-28 21:31:18 +0000255 python ${current_dir}/modify-python-lldb.py ${CONFIG_BUILD_DIR}
Caroline Tice558be582010-06-30 16:22:25 +0000256fi
Caroline Tice5790e062010-10-28 21:51:20 +0000257
258# Fix the "#include" statement in the swig output file
259
260if [ -f "${current_dir}/edit-swig-python-wrapper-file.py" ]
261then
262 python ${current_dir}/edit-swig-python-wrapper-file.py
263 if [ -f "${swig_output_file}.edited" ]
264 then
265 mv "${swig_output_file}.edited" ${swig_output_file}
266 fi
267fi