blob: 1b2897e314938c9bace4748106e4845ba95817df [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"\
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 Chen4ead2e92010-08-27 22:35:26 +000052" ${SRC_ROOT}/include/lldb/API/SBFileSpec.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000053" ${SRC_ROOT}/include/lldb/API/SBFrame.h"\
54" ${SRC_ROOT}/include/lldb/API/SBFunction.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000055" ${SRC_ROOT}/include/lldb/API/SBHostOS.h"\
56" ${SRC_ROOT}/include/lldb/API/SBInputReader.h"\
Greg Clayton5c4c7462010-10-06 03:09:58 +000057" ${SRC_ROOT}/include/lldb/API/SBInstruction.h"\
58" ${SRC_ROOT}/include/lldb/API/SBInstructionList.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000059" ${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 Tice1ca48b02010-09-22 16:41:52 +000064" ${SRC_ROOT}/include/lldb/API/SBStream.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000065" ${SRC_ROOT}/include/lldb/API/SBStringList.h"\
66" ${SRC_ROOT}/include/lldb/API/SBSymbol.h"\
67" ${SRC_ROOT}/include/lldb/API/SBSymbolContext.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000068" ${SRC_ROOT}/include/lldb/API/SBSymbolContextList.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000069" ${SRC_ROOT}/include/lldb/API/SBTarget.h"\
70" ${SRC_ROOT}/include/lldb/API/SBThread.h"\
71" ${SRC_ROOT}/include/lldb/API/SBType.h"\
Caroline Tice1ca48b02010-09-22 16:41:52 +000072" ${SRC_ROOT}/include/lldb/API/SBValue.h"\
73" ${SRC_ROOT}/include/lldb/API/SBValueList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000074
75
76if [ $Debug == 1 ]
77then
78 echo "Header files are:"
79 echo ${HEADER_FILES}
80fi
81
82NeedToUpdate=0
83
Chris Lattner24943d22010-06-08 16:52:24 +000084
Johnny Chenb4d1fff2010-08-26 20:04:17 +000085if [ ! -f ${swig_output_file} ]
Chris Lattner24943d22010-06-08 16:52:24 +000086then
87 NeedToUpdate=1
88 if [ $Debug == 1 ]
89 then
90 echo "Failed to find LLDBWrapPython.cpp"
91 fi
92fi
93
94if [ $NeedToUpdate == 0 ]
95then
96 for hdrfile in ${HEADER_FILES}
97 do
Johnny Chenb4d1fff2010-08-26 20:04:17 +000098 if [ $hdrfile -nt ${swig_output_file} ]
Chris Lattner24943d22010-06-08 16:52:24 +000099 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 Chenb4d1fff2010-08-26 20:04:17 +0000106 break
Chris Lattner24943d22010-06-08 16:52:24 +0000107 fi
108 done
109fi
110
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000111if [ $NeedToUpdate == 0 ]
112then
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
122fi
123
Caroline Tice7826c882010-10-26 03:11:13 +0000124if [ $NeedToUpdate == 0 ]
125then
Johnny Chenf530bfe2011-08-22 22:10:57 +0000126 if [ ${swig_python_extensions} -nt ${swig_output_file} ]
Caroline Tice7826c882010-10-26 03:11:13 +0000127 then
128 NeedToUpdate=1
129 if [ $Debug == 1 ]
130 then
Johnny Chenf530bfe2011-08-22 22:10:57 +0000131 echo "${swig_python_extensions} is newer than ${swig_output_file}"
132 echo "swig file will need to be re-built."
133 fi
134 fi
135fi
136
137if [ $NeedToUpdate == 0 ]
138then
139 if [ ${swig_python_wrapper} -nt ${swig_output_file} ]
140 then
141 NeedToUpdate=1
142 if [ $Debug == 1 ]
143 then
144 echo "${swig_python_wrapper} is newer than ${swig_output_file}"
Caroline Tice7826c882010-10-26 03:11:13 +0000145 echo "swig file will need to be re-built."
146 fi
147 fi
148fi
149
Caroline Tice9dbe7172010-06-16 19:26:52 +0000150os_name=`uname -s`
151python_version=`/usr/bin/python --version 2>&1 | sed -e 's,Python ,,' -e 's,[.][0-9],,2' -e 's,[a-z][a-z][0-9],,'`
152
153if [ "$os_name" == "Darwin" ]
154then
155 framework_python_dir="${TARGET_DIR}/LLDB.framework/Resources/Python"
156else
157 framework_python_dir="${PYTHON_INSTALL_DIR}/python${python_version}"
158fi
159
Chris Lattner24943d22010-06-08 16:52:24 +0000160
161if [ ! -L "${framework_python_dir}/_lldb.so" ]
162then
163 NeedToUpdate=1
164fi
165
166if [ ! -f "${framework_python_dir}/lldb.py" ]
167then
168 NeedToUpdate=1
169fi
170
171
172if [ $NeedToUpdate == 0 ]
173then
174 echo "Everything is up-to-date."
175 exit 0
176else
177 echo "SWIG needs to be re-run."
Caroline Tice7826c882010-10-26 03:11:13 +0000178 if [ -f ${swig_output_file} ]
179 then
180 rm ${swig_output_file}
181 fi
Chris Lattner24943d22010-06-08 16:52:24 +0000182fi
183
184
185# Build the SWIG C++ wrapper file for Python.
186
Jim Ingham2396b9f2011-03-01 01:39:04 +0000187$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 +0000188
Johnny Chen22e418a2011-04-29 19:22:24 +0000189# Implement the iterator protocol and/or eq/ne operators for some lldb objects.
Caroline Tice558be582010-06-30 16:22:25 +0000190# Append global variable to lldb Python module.
Johnny Chen14097802011-04-28 21:31:18 +0000191# And initialize the lldb debugger subsystem.
Caroline Tice558be582010-06-30 16:22:25 +0000192current_dir=`pwd`
Johnny Chen14097802011-04-28 21:31:18 +0000193if [ -f "${current_dir}/modify-python-lldb.py" ]
Caroline Tice558be582010-06-30 16:22:25 +0000194then
Johnny Chen14097802011-04-28 21:31:18 +0000195 python ${current_dir}/modify-python-lldb.py ${CONFIG_BUILD_DIR}
Caroline Tice558be582010-06-30 16:22:25 +0000196fi
Caroline Tice5790e062010-10-28 21:51:20 +0000197
198# Fix the "#include" statement in the swig output file
199
200if [ -f "${current_dir}/edit-swig-python-wrapper-file.py" ]
201then
202 python ${current_dir}/edit-swig-python-wrapper-file.py
203 if [ -f "${swig_output_file}.edited" ]
204 then
205 mv "${swig_output_file}.edited" ${swig_output_file}
206 fi
207fi