blob: 4fd1d376912f13d6edf07f07c082f0b75ab73fbc [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
Greg Clayton3e4238d2011-11-04 03:34:56 +000036# Make sure SDKROOT is not set, since if it is this is an iOS build where python
37# is disabled
38if [ "x$SDKROOT" = "x" ] ; then
39
Caroline Tice9dbe7172010-06-16 19:26:52 +000040if [ -n "$debug_flag" -a "$debug_flag" == "-debug" ]
Chris Lattner24943d22010-06-08 16:52:24 +000041then
Caroline Tice9dbe7172010-06-16 19:26:52 +000042 Debug=1
43else
44 Debug=0
45fi
46
47OS_NAME=`uname -s`
48PYTHON_VERSION=`/usr/bin/python --version 2>&1 | sed -e 's,Python ,,' -e 's,[.][0-9],,2' -e 's,[a-z][a-z][0-9],,'`
49
50
51if [ $Debug == 1 ]
52then
53 echo "The current OS is $OS_NAME"
54 echo "The Python version is $PYTHON_VERSION"
55fi
56
57#
58# Determine where to put the files.
59
60if [ ${OS_NAME} == "Darwin" ]
61then
62 # We are on a Darwin system, so all the lldb Python files can go
63 # into the LLDB.framework/Resources/Python subdirectory.
64
65 if [ ! -d "${TARGET_DIR}/LLDB.framework" ]
66 then
67 echo "Error: Unable to find LLDB.framework" >&2
68 exit 1
69 else
70 if [ $Debug == 1 ]
71 then
72 echo "Found ${TARGET_DIR}/LLDB.framework."
73 fi
74 fi
75
76 # Make the Python directory in the framework if it doesn't already exist
77
78 framework_python_dir="${TARGET_DIR}/LLDB.framework/Resources/Python"
79else
80 # We are on a non-Darwin system, so use the PYTHON_INSTALL_DIR argument,
81 # and append the python version directory to the end of it. Depending on
82 # the system other stuff may need to be put here as well.
83
84 framework_python_dir="${PYTHON_INSTALL_DIR}/python${PYTHON_VERSION}"
85fi
86
87#
88# Look for the directory in which to put the Python files; if it does not
89# already exist, attempt to make it.
90#
91
92if [ $Debug == 1 ]
93then
94 echo "Python files will be put in ${framework_python_dir}"
95fi
96
97if [ ! -d "${framework_python_dir}" ]
98then
99 if [ $Debug == 1 ]
100 then
101 echo "Making directory ${framework_python_dir}"
102 fi
103 mkdir -p "${framework_python_dir}"
104else
105 if [ $Debug == 1 ]
106 then
107 echo "${framework_python_dir} already exists."
108 fi
109fi
110
111if [ ! -d "${framework_python_dir}" ]
112then
113 echo "Error: Unable to find or create ${framework_python_dir}" >&2
Chris Lattner24943d22010-06-08 16:52:24 +0000114 exit 1
115fi
116
Caroline Tice9dbe7172010-06-16 19:26:52 +0000117# Make the symlink that the script bridge for Python will need in the
118# Python framework directory
Chris Lattner24943d22010-06-08 16:52:24 +0000119
Chris Lattner24943d22010-06-08 16:52:24 +0000120if [ ! -L "${framework_python_dir}/_lldb.so" ]
121then
Caroline Tice9dbe7172010-06-16 19:26:52 +0000122 if [ $Debug == 1 ]
123 then
124 echo "Creating symlink for _lldb.so"
125 fi
126 if [ ${OS_NAME} == "Darwin" ]
127 then
128 cd "${framework_python_dir}"
Chris Lattner24943d22010-06-08 16:52:24 +0000129 ln -s "../../LLDB" _lldb.so
Caroline Tice9dbe7172010-06-16 19:26:52 +0000130 else
131 cd "${TARGET_DIR}"
132 ln -s "./LLDB" _lldb.so
133 fi
134else
135 if [ $Debug == 1 ]
136 then
137 echo "${framework_python_dir}/_lldb.so already exists."
138 fi
Chris Lattner24943d22010-06-08 16:52:24 +0000139fi
140
141# Copy the python module (lldb.py) that was generated by SWIG
142# over to the framework Python directory
Caroline Tice9dbe7172010-06-16 19:26:52 +0000143if [ -f "${CONFIG_BUILD_DIR}/lldb.py" ]
Chris Lattner24943d22010-06-08 16:52:24 +0000144then
Caroline Tice9dbe7172010-06-16 19:26:52 +0000145 if [ $Debug == 1 ]
146 then
147 echo "Copying lldb.py to ${framework_python_dir}"
148 fi
149 cp "${CONFIG_BUILD_DIR}/lldb.py" "${framework_python_dir}"
150else
151 if [ $Debug == 1 ]
152 then
153 echo "Unable to find ${CONFIG_BUILD_DIR}/lldb.py"
154 fi
Chris Lattner24943d22010-06-08 16:52:24 +0000155fi
156
157# Copy the embedded interpreter script over to the framework Python directory
Caroline Tice9dbe7172010-06-16 19:26:52 +0000158if [ -f "${SRC_ROOT}/source/Interpreter/embedded_interpreter.py" ]
Chris Lattner24943d22010-06-08 16:52:24 +0000159then
Caroline Tice9dbe7172010-06-16 19:26:52 +0000160 if [ $Debug == 1 ]
161 then
162 echo "Copying embedded_interpreter.py to ${framework_python_dir}"
163 fi
164 cp "${SRC_ROOT}/source/Interpreter/embedded_interpreter.py" "${framework_python_dir}"
165else
166 if [ $Debug == 1 ]
167 then
168 echo "Unable to find ${SRC_ROOT}/source/Interpreter/embedded_interpreter.py"
169 fi
Chris Lattner24943d22010-06-08 16:52:24 +0000170fi
171
Enrico Granataf501c592011-08-17 22:13:59 +0000172# Copy the C++ STL formatters over to the framework Python directory
173if [ -f "${SRC_ROOT}/examples/synthetic/gnu_libstdcpp.py" ]
Enrico Granata074e3b62011-08-17 19:07:52 +0000174then
175 if [ $Debug == 1 ]
176 then
Enrico Granataf501c592011-08-17 22:13:59 +0000177 echo "Copying gnu_libstdcpp.py to ${framework_python_dir}"
Enrico Granata074e3b62011-08-17 19:07:52 +0000178 fi
Enrico Granataf501c592011-08-17 22:13:59 +0000179 cp "${SRC_ROOT}/examples/synthetic/gnu_libstdcpp.py" "${framework_python_dir}"
Enrico Granata074e3b62011-08-17 19:07:52 +0000180else
181 if [ $Debug == 1 ]
182 then
Enrico Granataf501c592011-08-17 22:13:59 +0000183 echo "Unable to find ${SRC_ROOT}/examples/synthetic/gnu_libstdcpp.py"
Enrico Granata074e3b62011-08-17 19:07:52 +0000184 fi
185fi
186
Enrico Granatab8dc7332012-01-31 17:01:51 +0000187# Copy the ObjC formatters over to the framework Python directory
Enrico Granata8f84cfb2012-02-23 23:10:03 +0000188if [ -f "${SRC_ROOT}/examples/summaries/objc.py" ]
Enrico Granatab8dc7332012-01-31 17:01:51 +0000189then
190 if [ $Debug == 1 ]
191 then
192 echo "Copying objc.py to ${framework_python_dir}"
193 fi
194 cp "${SRC_ROOT}/examples/summaries/objc.py" "${framework_python_dir}"
195else
196 if [ $Debug == 1 ]
197 then
198 echo "Unable to find ${SRC_ROOT}/examples/summaries/objc.py"
199 fi
200fi
201
Enrico Granata8f84cfb2012-02-23 23:10:03 +0000202# Copy the Cocoa formatters over to the framework Python directory
203if [ -f "${SRC_ROOT}/examples/summaries/cocoa/CFArray.py" ]
204then
205 if [ $Debug == 1 ]
206 then
207 echo "Copying CFArray.py to ${framework_python_dir}"
208 fi
209 cp "${SRC_ROOT}/examples/summaries/cocoa/CFArray.py" "${framework_python_dir}"
210else
211 if [ $Debug == 1 ]
212 then
213 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/CFArray.py"
214 fi
215fi
216
217if [ -f "${SRC_ROOT}/examples/summaries/cocoa/CFDictionary.py" ]
218then
219 if [ $Debug == 1 ]
220 then
221 echo "Copying CFDictionary.py to ${framework_python_dir}"
222 fi
223 cp "${SRC_ROOT}/examples/summaries/cocoa/CFDictionary.py" "${framework_python_dir}"
224else
225 if [ $Debug == 1 ]
226 then
227 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/CFDictionary.py"
228 fi
229fi
230
231if [ -f "${SRC_ROOT}/examples/summaries/cocoa/CFString.py" ]
232then
233 if [ $Debug == 1 ]
234 then
235 echo "Copying CFString.py to ${framework_python_dir}"
236 fi
237 cp "${SRC_ROOT}/examples/summaries/cocoa/CFString.py" "${framework_python_dir}"
238else
239 if [ $Debug == 1 ]
240 then
241 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/CFString.py"
242 fi
243fi
244
245if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSData.py" ]
246then
247 if [ $Debug == 1 ]
248 then
249 echo "Copying NSData.py to ${framework_python_dir}"
250 fi
251 cp "${SRC_ROOT}/examples/summaries/cocoa/NSData.py" "${framework_python_dir}"
252else
253 if [ $Debug == 1 ]
254 then
255 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSData.py"
256 fi
257fi
258
259if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSMachPort.py" ]
260then
261 if [ $Debug == 1 ]
262 then
263 echo "Copying NSMachPort.py to ${framework_python_dir}"
264 fi
265 cp "${SRC_ROOT}/examples/summaries/cocoa/NSMachPort.py" "${framework_python_dir}"
266else
267 if [ $Debug == 1 ]
268 then
269 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSMachPort.py"
270 fi
271fi
272
273if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSSet.py" ]
274then
275 if [ $Debug == 1 ]
276 then
277 echo "Copying NSSet.py to ${framework_python_dir}"
278 fi
279 cp "${SRC_ROOT}/examples/summaries/cocoa/NSSet.py" "${framework_python_dir}"
280else
281 if [ $Debug == 1 ]
282 then
283 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSSet.py"
284 fi
285fi
286
287if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSNotification.py" ]
288then
289 if [ $Debug == 1 ]
290 then
291 echo "Copying NSNotification.py to ${framework_python_dir}"
292 fi
293 cp "${SRC_ROOT}/examples/summaries/cocoa/NSNotification.py" "${framework_python_dir}"
294else
295 if [ $Debug == 1 ]
296 then
297 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSNotification.py"
298 fi
299fi
300
301if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSException.py" ]
302then
303 if [ $Debug == 1 ]
304 then
305 echo "Copying NSException.py to ${framework_python_dir}"
306 fi
307 cp "${SRC_ROOT}/examples/summaries/cocoa/NSException.py" "${framework_python_dir}"
308else
309 if [ $Debug == 1 ]
310 then
311 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSException.py"
312 fi
313fi
314
315if [ -f "${SRC_ROOT}/examples/summaries/cocoa/CFBag.py" ]
316then
317 if [ $Debug == 1 ]
318 then
319 echo "Copying CFBag.py to ${framework_python_dir}"
320 fi
321 cp "${SRC_ROOT}/examples/summaries/cocoa/CFBag.py" "${framework_python_dir}"
322else
323 if [ $Debug == 1 ]
324 then
325 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/CFBag.py"
326 fi
327fi
328
329if [ -f "${SRC_ROOT}/examples/summaries/cocoa/CFBinaryHeap.py" ]
330then
331 if [ $Debug == 1 ]
332 then
333 echo "Copying CFBinaryHeap.py to ${framework_python_dir}"
334 fi
335 cp "${SRC_ROOT}/examples/summaries/cocoa/CFBinaryHeap.py" "${framework_python_dir}"
336else
337 if [ $Debug == 1 ]
338 then
339 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/CFBinaryHeap.py"
340 fi
341fi
342
343if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSURL.py" ]
344then
345 if [ $Debug == 1 ]
346 then
347 echo "Copying NSURL.py to ${framework_python_dir}"
348 fi
349 cp "${SRC_ROOT}/examples/summaries/cocoa/NSURL.py" "${framework_python_dir}"
350else
351 if [ $Debug == 1 ]
352 then
353 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSURL.py"
354 fi
355fi
356
357if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSBundle.py" ]
358then
359 if [ $Debug == 1 ]
360 then
361 echo "Copying NSBundle.py to ${framework_python_dir}"
362 fi
363 cp "${SRC_ROOT}/examples/summaries/cocoa/NSBundle.py" "${framework_python_dir}"
364else
365 if [ $Debug == 1 ]
366 then
367 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSBundle.py"
368 fi
369fi
370
371if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSNumber.py" ]
372then
373 if [ $Debug == 1 ]
374 then
375 echo "Copying NSNumber.py to ${framework_python_dir}"
376 fi
377 cp "${SRC_ROOT}/examples/summaries/cocoa/NSNumber.py" "${framework_python_dir}"
378else
379 if [ $Debug == 1 ]
380 then
381 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSNumber.py"
382 fi
383fi
384
Enrico Granata1328b142012-02-29 03:28:49 +0000385if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSDate.py" ]
386then
387 if [ $Debug == 1 ]
388 then
389 echo "Copying NSDate.py to ${framework_python_dir}"
390 fi
391 cp "${SRC_ROOT}/examples/summaries/cocoa/NSDate.py" "${framework_python_dir}"
392else
393 if [ $Debug == 1 ]
394 then
395 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSDate.py"
396 fi
397fi
398
Enrico Granata83410e52012-03-01 19:32:33 +0000399if [ -f "${SRC_ROOT}/examples/summaries/cocoa/NSIndexSet.py" ]
400then
401 if [ $Debug == 1 ]
402 then
403 echo "Copying NSIndexSet.py to ${framework_python_dir}"
404 fi
405 cp "${SRC_ROOT}/examples/summaries/cocoa/NSIndexSet.py" "${framework_python_dir}"
406else
407 if [ $Debug == 1 ]
408 then
409 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/NSIndexSet.py"
410 fi
411fi
412
Enrico Granata86fcb162012-03-02 00:55:53 +0000413if [ -f "${SRC_ROOT}/examples/summaries/cocoa/Selector.py" ]
414then
415 if [ $Debug == 1 ]
416 then
417 echo "Copying Selector.py to ${framework_python_dir}"
418 fi
419 cp "${SRC_ROOT}/examples/summaries/cocoa/Selector.py" "${framework_python_dir}"
420else
421 if [ $Debug == 1 ]
422 then
423 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/Selector.py"
424 fi
425fi
426
Enrico Granata8f84cfb2012-02-23 23:10:03 +0000427if [ -f "${SRC_ROOT}/examples/summaries/cocoa/cache.py" ]
428then
429 if [ $Debug == 1 ]
430 then
431 echo "Copying cache.py to ${framework_python_dir}"
432 fi
433 cp "${SRC_ROOT}/examples/summaries/cocoa/cache.py" "${framework_python_dir}"
434else
435 if [ $Debug == 1 ]
436 then
437 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/cache.py"
438 fi
439fi
440
441if [ -f "${SRC_ROOT}/examples/summaries/cocoa/metrics.py" ]
442then
443 if [ $Debug == 1 ]
444 then
445 echo "Copying metrics.py to ${framework_python_dir}"
446 fi
447 cp "${SRC_ROOT}/examples/summaries/cocoa/metrics.py" "${framework_python_dir}"
448else
449 if [ $Debug == 1 ]
450 then
451 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/metrics.py"
452 fi
453fi
454
455if [ -f "${SRC_ROOT}/examples/summaries/cocoa/objc_lldb.py" ]
456then
457 if [ $Debug == 1 ]
458 then
459 echo "Copying objc_lldb.py to ${framework_python_dir}"
460 fi
461 cp "${SRC_ROOT}/examples/summaries/cocoa/objc_lldb.py" "${framework_python_dir}"
462else
463 if [ $Debug == 1 ]
464 then
465 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/objc_lldb.py"
466 fi
467fi
468
469if [ -f "${SRC_ROOT}/examples/summaries/cocoa/objc_runtime.py" ]
470then
471 if [ $Debug == 1 ]
472 then
473 echo "Copying objc_runtime.py to ${framework_python_dir}"
474 fi
475 cp "${SRC_ROOT}/examples/summaries/cocoa/objc_runtime.py" "${framework_python_dir}"
476else
477 if [ $Debug == 1 ]
478 then
479 echo "Unable to find ${SRC_ROOT}/examples/summaries/cocoa/objc_runtime.py"
480 fi
481fi
482
Greg Clayton3e4238d2011-11-04 03:34:56 +0000483fi
484
Chris Lattner24943d22010-06-08 16:52:24 +0000485exit 0
Caroline Tice9dbe7172010-06-16 19:26:52 +0000486