blob: dffc466c02fd4562b6284260374dfba1e66b7472 [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
Caroline Tice9dbe7172010-06-16 19:26:52 +000032HEADER_FILES="${SRC_ROOT}/include/lldb/lldb-types.h"\
33" ${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"\
40" ${SRC_ROOT}/include/lldb/API/SBCompileUnit.h"\
41" ${SRC_ROOT}/include/lldb/API/SBDebugger.h"\
42" ${SRC_ROOT}/include/lldb/API/SBError.h"\
43" ${SRC_ROOT}/include/lldb/API/SBEvent.h"\
Johnny Chen4ead2e92010-08-27 22:35:26 +000044" ${SRC_ROOT}/include/lldb/API/SBFileSpec.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000045" ${SRC_ROOT}/include/lldb/API/SBFrame.h"\
46" ${SRC_ROOT}/include/lldb/API/SBFunction.h"\
47" ${SRC_ROOT}/include/lldb/API/SBLineEntry.h"\
48" ${SRC_ROOT}/include/lldb/API/SBListener.h"\
49" ${SRC_ROOT}/include/lldb/API/SBModule.h"\
50" ${SRC_ROOT}/include/lldb/API/SBProcess.h"\
51" ${SRC_ROOT}/include/lldb/API/SBSourceManager.h"\
Caroline Tice1ca48b02010-09-22 16:41:52 +000052" ${SRC_ROOT}/include/lldb/API/SBStream.h"\
Caroline Tice9dbe7172010-06-16 19:26:52 +000053" ${SRC_ROOT}/include/lldb/API/SBStringList.h"\
54" ${SRC_ROOT}/include/lldb/API/SBSymbol.h"\
55" ${SRC_ROOT}/include/lldb/API/SBSymbolContext.h"\
56" ${SRC_ROOT}/include/lldb/API/SBTarget.h"\
57" ${SRC_ROOT}/include/lldb/API/SBThread.h"\
58" ${SRC_ROOT}/include/lldb/API/SBType.h"\
Caroline Tice1ca48b02010-09-22 16:41:52 +000059" ${SRC_ROOT}/include/lldb/API/SBValue.h"\
60" ${SRC_ROOT}/include/lldb/API/SBValueList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000061
62
63if [ $Debug == 1 ]
64then
65 echo "Header files are:"
66 echo ${HEADER_FILES}
67fi
68
69NeedToUpdate=0
70
Chris Lattner24943d22010-06-08 16:52:24 +000071
Johnny Chenb4d1fff2010-08-26 20:04:17 +000072if [ ! -f ${swig_output_file} ]
Chris Lattner24943d22010-06-08 16:52:24 +000073then
74 NeedToUpdate=1
75 if [ $Debug == 1 ]
76 then
77 echo "Failed to find LLDBWrapPython.cpp"
78 fi
79fi
80
81if [ $NeedToUpdate == 0 ]
82then
83 for hdrfile in ${HEADER_FILES}
84 do
Johnny Chenb4d1fff2010-08-26 20:04:17 +000085 if [ $hdrfile -nt ${swig_output_file} ]
Chris Lattner24943d22010-06-08 16:52:24 +000086 then
87 NeedToUpdate=1
88 if [ $Debug == 1 ]
89 then
90 echo "${hdrfile} is newer than ${swig_output_file}"
91 echo "swig file will need to be re-built."
92 fi
Johnny Chenb4d1fff2010-08-26 20:04:17 +000093 break
Chris Lattner24943d22010-06-08 16:52:24 +000094 fi
95 done
96fi
97
Johnny Chenb4d1fff2010-08-26 20:04:17 +000098if [ $NeedToUpdate == 0 ]
99then
100 if [ ${swig_input_file} -nt ${swig_output_file} ]
101 then
102 NeedToUpdate=1
103 if [ $Debug == 1 ]
104 then
105 echo "${swig_input_file} is newer than ${swig_output_file}"
106 echo "swig file will need to be re-built."
107 fi
108 fi
109fi
110
Caroline Tice9dbe7172010-06-16 19:26:52 +0000111os_name=`uname -s`
112python_version=`/usr/bin/python --version 2>&1 | sed -e 's,Python ,,' -e 's,[.][0-9],,2' -e 's,[a-z][a-z][0-9],,'`
113
114if [ "$os_name" == "Darwin" ]
115then
116 framework_python_dir="${TARGET_DIR}/LLDB.framework/Resources/Python"
117else
118 framework_python_dir="${PYTHON_INSTALL_DIR}/python${python_version}"
119fi
120
Chris Lattner24943d22010-06-08 16:52:24 +0000121
122if [ ! -L "${framework_python_dir}/_lldb.so" ]
123then
124 NeedToUpdate=1
125fi
126
127if [ ! -f "${framework_python_dir}/lldb.py" ]
128then
129 NeedToUpdate=1
130fi
131
132
133if [ $NeedToUpdate == 0 ]
134then
135 echo "Everything is up-to-date."
136 exit 0
137else
138 echo "SWIG needs to be re-run."
139fi
140
141
142# Build the SWIG C++ wrapper file for Python.
143
Caroline Tice9dbe7172010-06-16 19:26:52 +0000144swig -c++ -shadow -python -I"${SRC_ROOT}/include" -I./. -outdir "${CONFIG_BUILD_DIR}" -o "${swig_output_file}" "${swig_input_file}"
Chris Lattner24943d22010-06-08 16:52:24 +0000145
Caroline Tice558be582010-06-30 16:22:25 +0000146# Append global variable to lldb Python module.
147
148current_dir=`pwd`
149if [ -f "${current_dir}/append-debugger-id.py" ]
150then
151 python ${current_dir}/append-debugger-id.py ${CONFIG_BUILD_DIR}
152fi