blob: f412fb89cdc6169bdd92e694018089fa11b05fa1 [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
19
20swig_output_file=${SRC_ROOT}/source/LLDBWrapPython.cpp
21swig_input_file=${SRC_ROOT}/scripts/lldb.swig
Caroline Tice7826c882010-10-26 03:11:13 +000022swig_input_file2=${SRC_ROOT}/scripts/Python/python-extensions.swig
Caroline Tice9dbe7172010-06-16 19:26:52 +000023
Chris Lattner24943d22010-06-08 16:52:24 +000024
25if [ -n "$debug_flag" -a "$debug_flag" == "-debug" ]
26then
27 Debug=1
28else
29 Debug=0
30fi
31
32
Greg Claytond8c62532010-10-07 04:19:01 +000033HEADER_FILES="${SRC_ROOT}/include/lldb/lldb-include.h"\
Caroline Ticec8b0e902010-10-18 23:00:51 +000034" ${SRC_ROOT}/include/lldb/lldb-defines.h"\
35" ${SRC_ROOT}/include/lldb/lldb-enumerations.h"\
36" ${SRC_ROOT}/include/lldb/lldb-forward.h"\
37" ${SRC_ROOT}/include/lldb/lldb-forward-rtti.h"\
38" ${SRC_ROOT}/include/lldb/lldb-types.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000039" ${SRC_ROOT}/include/lldb/API/SBAddress.h"\
40" ${SRC_ROOT}/include/lldb/API/SBBlock.h"\
41" ${SRC_ROOT}/include/lldb/API/SBBreakpoint.h"\
42" ${SRC_ROOT}/include/lldb/API/SBBreakpointLocation.h"\
43" ${SRC_ROOT}/include/lldb/API/SBBroadcaster.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000044" ${SRC_ROOT}/include/lldb/API/SBCommandInterpreter.h"\
45" ${SRC_ROOT}/include/lldb/API/SBCommandReturnObject.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000046" ${SRC_ROOT}/include/lldb/API/SBCommunication.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000047" ${SRC_ROOT}/include/lldb/API/SBCompileUnit.h"\
48" ${SRC_ROOT}/include/lldb/API/SBDebugger.h"\
49" ${SRC_ROOT}/include/lldb/API/SBError.h"\
50" ${SRC_ROOT}/include/lldb/API/SBEvent.h"\
Johnny Chen4ead2e92010-08-27 22:35:26 +000051" ${SRC_ROOT}/include/lldb/API/SBFileSpec.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000052" ${SRC_ROOT}/include/lldb/API/SBFrame.h"\
53" ${SRC_ROOT}/include/lldb/API/SBFunction.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000054" ${SRC_ROOT}/include/lldb/API/SBHostOS.h"\
55" ${SRC_ROOT}/include/lldb/API/SBInputReader.h"\
Greg Clayton5c4c7462010-10-06 03:09:58 +000056" ${SRC_ROOT}/include/lldb/API/SBInstruction.h"\
57" ${SRC_ROOT}/include/lldb/API/SBInstructionList.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000058" ${SRC_ROOT}/include/lldb/API/SBLineEntry.h"\
59" ${SRC_ROOT}/include/lldb/API/SBListener.h"\
60" ${SRC_ROOT}/include/lldb/API/SBModule.h"\
61" ${SRC_ROOT}/include/lldb/API/SBProcess.h"\
62" ${SRC_ROOT}/include/lldb/API/SBSourceManager.h"\
Caroline Tice1ca48b02010-09-22 16:41:52 +000063" ${SRC_ROOT}/include/lldb/API/SBStream.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000064" ${SRC_ROOT}/include/lldb/API/SBStringList.h"\
65" ${SRC_ROOT}/include/lldb/API/SBSymbol.h"\
66" ${SRC_ROOT}/include/lldb/API/SBSymbolContext.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000067" ${SRC_ROOT}/include/lldb/API/SBSymbolContextList.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000068" ${SRC_ROOT}/include/lldb/API/SBTarget.h"\
69" ${SRC_ROOT}/include/lldb/API/SBThread.h"\
70" ${SRC_ROOT}/include/lldb/API/SBType.h"\
Caroline Tice1ca48b02010-09-22 16:41:52 +000071" ${SRC_ROOT}/include/lldb/API/SBValue.h"\
72" ${SRC_ROOT}/include/lldb/API/SBValueList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000073
74
75if [ $Debug == 1 ]
76then
77 echo "Header files are:"
78 echo ${HEADER_FILES}
79fi
80
81NeedToUpdate=0
82
Chris Lattner24943d22010-06-08 16:52:24 +000083
Johnny Chenb4d1fff2010-08-26 20:04:17 +000084if [ ! -f ${swig_output_file} ]
Chris Lattner24943d22010-06-08 16:52:24 +000085then
86 NeedToUpdate=1
87 if [ $Debug == 1 ]
88 then
89 echo "Failed to find LLDBWrapPython.cpp"
90 fi
91fi
92
93if [ $NeedToUpdate == 0 ]
94then
95 for hdrfile in ${HEADER_FILES}
96 do
Johnny Chenb4d1fff2010-08-26 20:04:17 +000097 if [ $hdrfile -nt ${swig_output_file} ]
Chris Lattner24943d22010-06-08 16:52:24 +000098 then
99 NeedToUpdate=1
100 if [ $Debug == 1 ]
101 then
102 echo "${hdrfile} is newer than ${swig_output_file}"
103 echo "swig file will need to be re-built."
104 fi
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000105 break
Chris Lattner24943d22010-06-08 16:52:24 +0000106 fi
107 done
108fi
109
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000110if [ $NeedToUpdate == 0 ]
111then
112 if [ ${swig_input_file} -nt ${swig_output_file} ]
113 then
114 NeedToUpdate=1
115 if [ $Debug == 1 ]
116 then
117 echo "${swig_input_file} is newer than ${swig_output_file}"
118 echo "swig file will need to be re-built."
119 fi
120 fi
121fi
122
Caroline Tice7826c882010-10-26 03:11:13 +0000123if [ $NeedToUpdate == 0 ]
124then
125 if [ ${swig_input_file2} -nt ${swig_output_file} ]
126 then
127 NeedToUpdate=1
128 if [ $Debug == 1 ]
129 then
130 echo "${swig_input_file2} is newer than ${swig_output_file}"
131 echo "swig file will need to be re-built."
132 fi
133 fi
134fi
135
Caroline Tice9dbe7172010-06-16 19:26:52 +0000136os_name=`uname -s`
137python_version=`/usr/bin/python --version 2>&1 | sed -e 's,Python ,,' -e 's,[.][0-9],,2' -e 's,[a-z][a-z][0-9],,'`
138
139if [ "$os_name" == "Darwin" ]
140then
141 framework_python_dir="${TARGET_DIR}/LLDB.framework/Resources/Python"
142else
143 framework_python_dir="${PYTHON_INSTALL_DIR}/python${python_version}"
144fi
145
Chris Lattner24943d22010-06-08 16:52:24 +0000146
147if [ ! -L "${framework_python_dir}/_lldb.so" ]
148then
149 NeedToUpdate=1
150fi
151
152if [ ! -f "${framework_python_dir}/lldb.py" ]
153then
154 NeedToUpdate=1
155fi
156
157
158if [ $NeedToUpdate == 0 ]
159then
160 echo "Everything is up-to-date."
161 exit 0
162else
163 echo "SWIG needs to be re-run."
Caroline Tice7826c882010-10-26 03:11:13 +0000164 if [ -f ${swig_output_file} ]
165 then
166 rm ${swig_output_file}
167 fi
Chris Lattner24943d22010-06-08 16:52:24 +0000168fi
169
170
171# Build the SWIG C++ wrapper file for Python.
172
Greg Claytond8c62532010-10-07 04:19:01 +0000173swig -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 +0000174
Caroline Tice558be582010-06-30 16:22:25 +0000175# Append global variable to lldb Python module.
176
177current_dir=`pwd`
178if [ -f "${current_dir}/append-debugger-id.py" ]
179then
180 python ${current_dir}/append-debugger-id.py ${CONFIG_BUILD_DIR}
181fi
Caroline Tice5790e062010-10-28 21:51:20 +0000182
183# Fix the "#include" statement in the swig output file
184
185if [ -f "${current_dir}/edit-swig-python-wrapper-file.py" ]
186then
187 python ${current_dir}/edit-swig-python-wrapper-file.py
188 if [ -f "${swig_output_file}.edited" ]
189 then
190 mv "${swig_output_file}.edited" ${swig_output_file}
191 fi
192fi