blob: 762496adad547d3d725835d12a05a5d115b49f8f [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001#! /bin/sh
2
3# finish-swig-Python.sh
4#
5# For the Python script interpreter (external to liblldb) to be able to import
Caroline Tice9dbe7172010-06-16 19:26:52 +00006# and use the lldb module, there must be two files, lldb.py and _lldb.so, that
7# it can find. lldb.py is generated by SWIG at the same time it generates the
8# C++ file. _lldb.so is actually a symlink file that points to the
9# LLDB shared library/framework.
10#
11# The Python script interpreter needs to be able to automatically find
12# these two files. On Darwin systems it searches in the LLDB.framework, as
13# well as in all the normal Python search paths. On non-Darwin systems
14# these files will need to be put someplace where Python will find them.
15#
16# This shell script creates the _lldb.so symlink in the appropriate place,
17# and copies the lldb.py (and embedded_interpreter.py) file to the correct
18# directory.
19#
Chris Lattner24943d22010-06-08 16:52:24 +000020
Caroline Tice9dbe7172010-06-16 19:26:52 +000021# SRC_ROOT is the root of the lldb source tree.
22# TARGET_DIR is where the lldb framework/shared library gets put.
23# CONFIG_BUILD_DIR is where the build-swig-Python-LLDB.sh shell script
24# put the lldb.py file it was generated from running SWIG.
25# PYTHON_INSTALL_DIR is where non-Darwin systems want to put the .py and .so
26# files so that Python can find them automatically.
27# debug_flag (optional) determines whether or not this script outputs
28# additional information when running.
29
30SRC_ROOT=$1
31TARGET_DIR=$2
32CONFIG_BUILD_DIR=$3
33PYTHON_INSTALL_DIR=$4
34debug_flag=$5
35
36if [ -n "$debug_flag" -a "$debug_flag" == "-debug" ]
Chris Lattner24943d22010-06-08 16:52:24 +000037then
Caroline Tice9dbe7172010-06-16 19:26:52 +000038 Debug=1
39else
40 Debug=0
41fi
42
43OS_NAME=`uname -s`
44PYTHON_VERSION=`/usr/bin/python --version 2>&1 | sed -e 's,Python ,,' -e 's,[.][0-9],,2' -e 's,[a-z][a-z][0-9],,'`
45
46
47if [ $Debug == 1 ]
48then
49 echo "The current OS is $OS_NAME"
50 echo "The Python version is $PYTHON_VERSION"
51fi
52
53#
54# Determine where to put the files.
55
56if [ ${OS_NAME} == "Darwin" ]
57then
58 # We are on a Darwin system, so all the lldb Python files can go
59 # into the LLDB.framework/Resources/Python subdirectory.
60
61 if [ ! -d "${TARGET_DIR}/LLDB.framework" ]
62 then
63 echo "Error: Unable to find LLDB.framework" >&2
64 exit 1
65 else
66 if [ $Debug == 1 ]
67 then
68 echo "Found ${TARGET_DIR}/LLDB.framework."
69 fi
70 fi
71
72 # Make the Python directory in the framework if it doesn't already exist
73
74 framework_python_dir="${TARGET_DIR}/LLDB.framework/Resources/Python"
75else
76 # We are on a non-Darwin system, so use the PYTHON_INSTALL_DIR argument,
77 # and append the python version directory to the end of it. Depending on
78 # the system other stuff may need to be put here as well.
79
80 framework_python_dir="${PYTHON_INSTALL_DIR}/python${PYTHON_VERSION}"
81fi
82
83#
84# Look for the directory in which to put the Python files; if it does not
85# already exist, attempt to make it.
86#
87
88if [ $Debug == 1 ]
89then
90 echo "Python files will be put in ${framework_python_dir}"
91fi
92
93if [ ! -d "${framework_python_dir}" ]
94then
95 if [ $Debug == 1 ]
96 then
97 echo "Making directory ${framework_python_dir}"
98 fi
99 mkdir -p "${framework_python_dir}"
100else
101 if [ $Debug == 1 ]
102 then
103 echo "${framework_python_dir} already exists."
104 fi
105fi
106
107if [ ! -d "${framework_python_dir}" ]
108then
109 echo "Error: Unable to find or create ${framework_python_dir}" >&2
Chris Lattner24943d22010-06-08 16:52:24 +0000110 exit 1
111fi
112
Caroline Tice9dbe7172010-06-16 19:26:52 +0000113# Make the symlink that the script bridge for Python will need in the
114# Python framework directory
Chris Lattner24943d22010-06-08 16:52:24 +0000115
Chris Lattner24943d22010-06-08 16:52:24 +0000116if [ ! -L "${framework_python_dir}/_lldb.so" ]
117then
Caroline Tice9dbe7172010-06-16 19:26:52 +0000118 if [ $Debug == 1 ]
119 then
120 echo "Creating symlink for _lldb.so"
121 fi
122 if [ ${OS_NAME} == "Darwin" ]
123 then
124 cd "${framework_python_dir}"
Chris Lattner24943d22010-06-08 16:52:24 +0000125 ln -s "../../LLDB" _lldb.so
Caroline Tice9dbe7172010-06-16 19:26:52 +0000126 else
127 cd "${TARGET_DIR}"
128 ln -s "./LLDB" _lldb.so
129 fi
130else
131 if [ $Debug == 1 ]
132 then
133 echo "${framework_python_dir}/_lldb.so already exists."
134 fi
Chris Lattner24943d22010-06-08 16:52:24 +0000135fi
136
137# Copy the python module (lldb.py) that was generated by SWIG
138# over to the framework Python directory
Caroline Tice9dbe7172010-06-16 19:26:52 +0000139if [ -f "${CONFIG_BUILD_DIR}/lldb.py" ]
Chris Lattner24943d22010-06-08 16:52:24 +0000140then
Caroline Tice9dbe7172010-06-16 19:26:52 +0000141 if [ $Debug == 1 ]
142 then
143 echo "Copying lldb.py to ${framework_python_dir}"
144 fi
145 cp "${CONFIG_BUILD_DIR}/lldb.py" "${framework_python_dir}"
146else
147 if [ $Debug == 1 ]
148 then
149 echo "Unable to find ${CONFIG_BUILD_DIR}/lldb.py"
150 fi
Chris Lattner24943d22010-06-08 16:52:24 +0000151fi
152
153# Copy the embedded interpreter script over to the framework Python directory
Caroline Tice9dbe7172010-06-16 19:26:52 +0000154if [ -f "${SRC_ROOT}/source/Interpreter/embedded_interpreter.py" ]
Chris Lattner24943d22010-06-08 16:52:24 +0000155then
Caroline Tice9dbe7172010-06-16 19:26:52 +0000156 if [ $Debug == 1 ]
157 then
158 echo "Copying embedded_interpreter.py to ${framework_python_dir}"
159 fi
160 cp "${SRC_ROOT}/source/Interpreter/embedded_interpreter.py" "${framework_python_dir}"
161else
162 if [ $Debug == 1 ]
163 then
164 echo "Unable to find ${SRC_ROOT}/source/Interpreter/embedded_interpreter.py"
165 fi
Chris Lattner24943d22010-06-08 16:52:24 +0000166fi
167
168exit 0
Caroline Tice9dbe7172010-06-16 19:26:52 +0000169