1#!/bin/sh
2
3# build-swig-wrapper-classes.sh
4#
5# For each scripting language liblldb supports, we need to create the
6# appropriate Script Bridge wrapper classes for that language so that
7# users can call Script Bridge functions from within the script interpreter.
8#
9# We use SWIG to help create the appropriate wrapper classes/functions for
10# the scripting language.  In some cases the file generated by SWIG may
11# need some tweaking before it is completely ready to use.
12
13# Below are the arguments/parameters that this script takes (and passes along
14# to all the language-specific build scripts that it calls):
15#
16# SRC_ROOT is the root of the lldb source tree.
17# TARGET_DIR is where the lldb framework/shared library gets put.
18# CONFIG_BUILD_DIR is where the build-swig-Python-LLDB.sh  shell script
19#           put the lldb.py file it was generated from running SWIG.
20# PREFIX is where non-Darwin systems want to put the .py and .so
21#           files so that Python can find them automatically.
22# debug_flag (optional) determines whether or not this script outputs
23#           additional information when running.
24
25SRC_ROOT=$1
26TARGET_DIR=$2
27CONFIG_BUILD_DIR=$3
28PREFIX=$4
29
30shift 4
31
32#
33# Check to see if we are in debug-mode or not.
34#
35
36if [ -n "$1" -a "$1" = "-debug" ]
37then
38    debug_flag="$1"
39    Debug=1
40    shift
41else
42    debug_flag=""
43    Debug=0
44fi
45
46#
47# Check to see if we were called from the Makefile system. If we were, check
48# if the caller wants swig to generate a dependency file.
49#
50
51if [ -n "$1" -a "$1" = "-m" ]
52then
53    makefile_flag="$1"
54    shift
55    if [ -n "$1" -a "$1" = "-M" ]
56    then
57        dependency_flag="$1"
58        shift
59    else
60        dependency_flag=""
61    fi
62else
63    makefile_flag=""
64    dependency_flag=""
65fi
66
67#
68# Verify that 'lldb.swig' exists.
69#
70
71if [ ! -f ${SRC_ROOT}/scripts/lldb.swig ]
72then
73    echo Error: unable to find file 'lldb.swig' >&2
74    exit 1
75fi
76
77if [ $Debug -eq 1 ]
78then
79    echo "Found lldb.swig file"
80fi
81
82#
83# Next look for swig
84#
85
86SWIG=`which swig`
87if [ ! -x "$SWIG" -a -f /usr/bin/swig ]
88then
89    SWIG=/usr/bin/swig
90else
91    if [ -f /usr/local/bin/swig ]
92    then
93        SWIG=/usr/local/bin/swig
94    fi
95fi
96
97if [ ${SWIG}a = a ]
98then
99    echo Error: could not find the swig binary
100    exit 1
101fi
102
103#
104# For each scripting language, make sure the build script for that language
105# exists, and if so, call it.
106#
107# For now the only language we support is Python, but we expect this to
108# change.
109
110languages="Python"
111cwd=${SRC_ROOT}/scripts
112
113for curlang in $languages
114do
115    if [ $Debug -eq 1 ]
116    then
117        echo "Current language is $curlang"
118    fi
119
120    if [ ! -d "$cwd/$curlang" ]
121    then
122        echo "Error:  unable to find $curlang script sub-dirctory" >&2
123        continue
124    else
125
126        if [ $Debug -eq 1 ]
127        then
128            echo "Found $curlang sub-directory"
129        fi
130
131        cd $cwd/$curlang
132
133        filename="./build-swig-${curlang}.sh"
134
135        if [ ! -f $filename ]
136        then
137            echo "Error: unable to find swig build script for $curlang: $filename" >&2
138            continue
139        else
140
141            if [ $Debug -eq 1 ]
142            then
143                echo "Found $curlang build script."
144                echo "Executing $curlang build script..."
145            fi
146
147            ./build-swig-${curlang}.sh  "$SRC_ROOT" "$TARGET_DIR" "$CONFIG_BUILD_DIR" "${PREFIX}" "${debug_flag}" "${SWIG}" "${makefile_flag}" "${dependency_flag}" || exit $?
148        fi
149    fi
150done
151
152