blob: 404cdfa8bc6f3d987f97c067a12dbf8b820a8aab [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
22
Chris Lattner24943d22010-06-08 16:52:24 +000023
24if [ -n "$debug_flag" -a "$debug_flag" == "-debug" ]
25then
26 Debug=1
27else
28 Debug=0
29fi
30
31
Greg Claytond8c62532010-10-07 04:19:01 +000032HEADER_FILES="${SRC_ROOT}/include/lldb/lldb-include.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000033" ${SRC_ROOT}/include/lldb/API/SBAddress.h"\
34" ${SRC_ROOT}/include/lldb/API/SBBlock.h"\
35" ${SRC_ROOT}/include/lldb/API/SBBreakpoint.h"\
36" ${SRC_ROOT}/include/lldb/API/SBBreakpointLocation.h"\
37" ${SRC_ROOT}/include/lldb/API/SBBroadcaster.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000038" ${SRC_ROOT}/include/lldb/API/SBCommandInterpreter.h"\
39" ${SRC_ROOT}/include/lldb/API/SBCommandReturnObject.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000040" ${SRC_ROOT}/include/lldb/API/SBCommunication.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000041" ${SRC_ROOT}/include/lldb/API/SBCompileUnit.h"\
42" ${SRC_ROOT}/include/lldb/API/SBDebugger.h"\
43" ${SRC_ROOT}/include/lldb/API/SBError.h"\
44" ${SRC_ROOT}/include/lldb/API/SBEvent.h"\
Johnny Chen4ead2e92010-08-27 22:35:26 +000045" ${SRC_ROOT}/include/lldb/API/SBFileSpec.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000046" ${SRC_ROOT}/include/lldb/API/SBFrame.h"\
47" ${SRC_ROOT}/include/lldb/API/SBFunction.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000048" ${SRC_ROOT}/include/lldb/API/SBHostOS.h"\
49" ${SRC_ROOT}/include/lldb/API/SBInputReader.h"\
Greg Clayton5c4c7462010-10-06 03:09:58 +000050" ${SRC_ROOT}/include/lldb/API/SBInstruction.h"\
51" ${SRC_ROOT}/include/lldb/API/SBInstructionList.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000052" ${SRC_ROOT}/include/lldb/API/SBLineEntry.h"\
53" ${SRC_ROOT}/include/lldb/API/SBListener.h"\
54" ${SRC_ROOT}/include/lldb/API/SBModule.h"\
55" ${SRC_ROOT}/include/lldb/API/SBProcess.h"\
56" ${SRC_ROOT}/include/lldb/API/SBSourceManager.h"\
Caroline Tice1ca48b02010-09-22 16:41:52 +000057" ${SRC_ROOT}/include/lldb/API/SBStream.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000058" ${SRC_ROOT}/include/lldb/API/SBStringList.h"\
59" ${SRC_ROOT}/include/lldb/API/SBSymbol.h"\
60" ${SRC_ROOT}/include/lldb/API/SBSymbolContext.h"\
Greg Claytond8c62532010-10-07 04:19:01 +000061" ${SRC_ROOT}/include/lldb/API/SBSymbolContextList.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000062" ${SRC_ROOT}/include/lldb/API/SBTarget.h"\
63" ${SRC_ROOT}/include/lldb/API/SBThread.h"\
64" ${SRC_ROOT}/include/lldb/API/SBType.h"\
Caroline Tice1ca48b02010-09-22 16:41:52 +000065" ${SRC_ROOT}/include/lldb/API/SBValue.h"\
66" ${SRC_ROOT}/include/lldb/API/SBValueList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000067
68
69if [ $Debug == 1 ]
70then
71 echo "Header files are:"
72 echo ${HEADER_FILES}
73fi
74
75NeedToUpdate=0
76
Chris Lattner24943d22010-06-08 16:52:24 +000077
Johnny Chenb4d1fff2010-08-26 20:04:17 +000078if [ ! -f ${swig_output_file} ]
Chris Lattner24943d22010-06-08 16:52:24 +000079then
80 NeedToUpdate=1
81 if [ $Debug == 1 ]
82 then
83 echo "Failed to find LLDBWrapPython.cpp"
84 fi
85fi
86
87if [ $NeedToUpdate == 0 ]
88then
89 for hdrfile in ${HEADER_FILES}
90 do
Johnny Chenb4d1fff2010-08-26 20:04:17 +000091 if [ $hdrfile -nt ${swig_output_file} ]
Chris Lattner24943d22010-06-08 16:52:24 +000092 then
93 NeedToUpdate=1
94 if [ $Debug == 1 ]
95 then
96 echo "${hdrfile} is newer than ${swig_output_file}"
97 echo "swig file will need to be re-built."
98 fi
Johnny Chenb4d1fff2010-08-26 20:04:17 +000099 break
Chris Lattner24943d22010-06-08 16:52:24 +0000100 fi
101 done
102fi
103
Johnny Chenb4d1fff2010-08-26 20:04:17 +0000104if [ $NeedToUpdate == 0 ]
105then
106 if [ ${swig_input_file} -nt ${swig_output_file} ]
107 then
108 NeedToUpdate=1
109 if [ $Debug == 1 ]
110 then
111 echo "${swig_input_file} is newer than ${swig_output_file}"
112 echo "swig file will need to be re-built."
113 fi
114 fi
115fi
116
Caroline Tice9dbe7172010-06-16 19:26:52 +0000117os_name=`uname -s`
118python_version=`/usr/bin/python --version 2>&1 | sed -e 's,Python ,,' -e 's,[.][0-9],,2' -e 's,[a-z][a-z][0-9],,'`
119
120if [ "$os_name" == "Darwin" ]
121then
122 framework_python_dir="${TARGET_DIR}/LLDB.framework/Resources/Python"
123else
124 framework_python_dir="${PYTHON_INSTALL_DIR}/python${python_version}"
125fi
126
Chris Lattner24943d22010-06-08 16:52:24 +0000127
128if [ ! -L "${framework_python_dir}/_lldb.so" ]
129then
130 NeedToUpdate=1
131fi
132
133if [ ! -f "${framework_python_dir}/lldb.py" ]
134then
135 NeedToUpdate=1
136fi
137
138
139if [ $NeedToUpdate == 0 ]
140then
141 echo "Everything is up-to-date."
142 exit 0
143else
144 echo "SWIG needs to be re-run."
145fi
146
147
148# Build the SWIG C++ wrapper file for Python.
149
Greg Claytond8c62532010-10-07 04:19:01 +0000150swig -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 +0000151
Caroline Tice558be582010-06-30 16:22:25 +0000152# Append global variable to lldb Python module.
153
154current_dir=`pwd`
155if [ -f "${current_dir}/append-debugger-id.py" ]
156then
157 python ${current_dir}/append-debugger-id.py ${CONFIG_BUILD_DIR}
158fi