build.sh 8.35 KB
Newer Older
1
#!/bin/bash -e
Brendan Long's avatar
Brendan Long committed
2

3 4 5 6 7 8 9 10 11 12 13 14
function getBranch {
    local result

    # Use the option from --branch if it was given explicitly
    if [[ -n "$BRANCH" ]]; then
        result="$BRANCH"
    else
        # In upstream repos, the default branch is master
        if $USE_UPSTREAM || [[ "${NO_UPSTREAM_MODULES[@]}" == *"$module"* ]]; then
            result=master

        # In our repos, the default branch is ruih/master
15 16 17 18 19 20 21
        else
            result=ruih/master
        fi
    fi
    echo $result
}

22
unset BRANCH
23
INSTALL_DEPS=true
Brendan Long's avatar
Brendan Long committed
24
RECONFIGURE=false
25 26 27 28
UPDATE_MODULES=true
USE_UPSTREAM=false
VERBOSE=false

29 30
errors=

31 32 33
while true; do
  case "$1" in
    -h | --help )
34
        echo "usage: $0 [-h | --help ] [--branch (branch name)] "
35
        echo "                  [--no-update] [--no-deps]"
36
        echo "                  [--reconfigure] [--upstream]"
37
        echo " "
Brendan Long's avatar
Brendan Long committed
38
        echo "    -h | --help       Print this help message."
39
        echo "    -v | --verbose    Verbose build output."
40
        echo "    --branch [branch] The branch to check out."
Brendan Long's avatar
Brendan Long committed
41 42 43
        echo "    --no-update       Don't pull and rebase before building."
        echo "    --no-deps         Don't install dependencies before building."
        echo "    --reconfigure     Force a reconfigure, even if a Makefile already exists."
44 45
        echo "    --upstream        Clone from upstream where possible, instead of "
        echo "                      our repos (you probably don't want to do this)."
46 47
        exit;;
    -v | --verbose ) VERBOSE=true; shift ;;
48
    --branch ) shift; BRANCH=$1 ; shift ;;
49 50
    --no-update ) UPDATE_MODULES=false; shift ;;
    --no-deps ) INSTALL_DEPS=false; shift ;;
Brendan Long's avatar
Brendan Long committed
51
    --reconfigure ) RECONFIGURE=true; shift ;;
52 53 54 55 56 57
    --upstream ) USE_UPSTREAM=true; shift ;;
    -- ) shift; break ;;
    * ) break ;;
  esac
done

Brendan Long's avatar
Brendan Long committed
58
# List all modules to setup
59
GST_MODULES=(orc gstreamer gst-plugins-{base,good,bad,ugly} gst-libav)
Brendan Long's avatar
Brendan Long committed
60

61
# List modules that don't have an APT package to install deps from
62
NO_PACKAGE_MODULES=(gst-cablelabs-ruih-test)
63

Brendan Long's avatar
Brendan Long committed
64 65 66
# Modules that have a "clean-cruft" make target
CLEAN_CRUFT_MODULES=(gstreamer gst-plugins-{base,good,bad,ugly} gst-libav)

67
# Modules which aren't available upstream
68
NO_UPSTREAM_MODULES=()
69

Brendan Long's avatar
Brendan Long committed
70 71
# Where to find git repos
if ! $USE_UPSTREAM ; then
72
    GITHUB_MODULES=(orc gstreamer gst-plugins-{base,good,bad,ugly} gst-libav gst-cablelabs-ruih-test)
73
fi
Brendan Long's avatar
Brendan Long committed
74

75
if $INSTALL_DEPS ; then
76 77
    RAN_APT_GET_UPDATE=false

78 79
    # We need this for installing packages
    OS=$(lsb_release -si)
80
    VER=$(lsb_release -sr)
81

82 83
    # Setup GStreamer PPA if on Ubuntu 12.04
    if [ "$OS" == "Ubuntu" ] && [ "$VER" == "12.04" ] && [ ! -f /etc/apt/sources.list.d/gstreamer-developers-ppa-*.list ] ; then
84
        echo "Setting up GStreamer PPA"
85 86 87 88 89 90
        if ! hash add-apt-repository 2> /dev/null ; then
            if ! $RAN_APT_GET_UPDATE ; then
                sudo apt-get update
            fi
            sudo apt-get install -y python-software-properties
        fi
91
        sudo add-apt-repository -y ppa:gstreamer-developers/ppa
92
        sudo apt-get update
93
        RAN_APT_GET_UPDATE=true
94
    fi
95

96 97 98 99 100
    # Get build dependencies
    packages=
    for module in ${GST_MODULES[@]} ; do
        if [[ ! "${NO_PACKAGE_MODULES[@]}" == *"$module"* ]] ; then
            if [ "$OS" == "Ubuntu" ] ; then
101 102 103 104 105
                if [ "$module" == "orc" ] ; then
                    packages="$packages ${module}"
                else
                    packages="$packages ${module}1.0"
                fi
106 107 108 109 110
            elif [ "$OS" == "Fedora" ] ; then
                packages="$packages $(echo $module | sed 's/\(gst\|gstreamer\)/gstreamer1/')"
                if [ "$module" == "gst-plugins-bad" ] ; then
                    packages="$packages-free"
                fi
111 112
            fi
        fi
113 114 115
    done

    if [ "$OS" == "Ubuntu" ]; then
116 117 118 119 120 121
        if ! $RAN_APT_GET_UPDATE ; then
            sudo apt-get update
            RAN_APT_GET_UPDATE=true
        fi

        if ! hash apt-rdepends 2> /dev/null ; then
122 123 124
            sudo apt-get -y install apt-rdepends
        fi

125
        # Work around an issue where Ubuntu 13.04 and 13.10 try to install the
126 127 128
        # nVidia drivers for OpenCV, and conflicts when we try to install libegl
        # due to the "Raring" packages having broken dependencies.
        depends=$(apt-rdepends -b --follow=DEPENDS $packages | grep Build-Depends | grep -v nvidia | grep -v opencv | grep -v libegl | grep -v libgles | cut -d ' ' -f 4 | paste -s -d ' ')
129 130 131

        if [[ -n "$depends" ]] ; then
            echo "Installing build dependencies for$packages"
132
            echo 'Run with --no-deps to skip this step (you need to run this step at least once!)'
133
            sudo apt-get -y install $depends libgles2-mesa-dev
134
        fi
135
    elif [ "$OS" == "Fedora" ]; then
136 137
        echo "Installing build dependencies for$packages"
        echo 'Run with --no-deps to skip this step (you need to run this step at least once!)'
138
        sudo yum-builddep -y -q $packages
Brendan Long's avatar
Brendan Long committed
139
    fi
140
fi
141

142 143 144
# Get the name of this gst checkout -- git for ~/gst/git
name=${PWD##*/}

145
for module in ${GST_MODULES[@]} ; do
146
    unset MODULE_BRANCH
147 148 149 150 151
    if [ "$module" == "orc" ] ; then
      GST_PREFIX=""
    else
      GST_PREFIX=~/bin/"gst-$name"
    fi
152
    # Clone or update the repo
153
    if [ ! -d "$module" ] ; then
154
        if [[ "${GITHUB_MODULES[@]}" == *"$module"* ]]; then
155
            echo "Cloning [$module] from git@github.com:cablelabs/${module}.git"
156 157 158 159
            if ! git clone "git@github.com:cablelabs/${module}.git" ; then
                errors="$errors\nUnable to clone ${module} over SSH, using HTTPS instead."
                git clone "https://github.com/cablelabs/${module}.git"
            fi
Brendan Long's avatar
Brendan Long committed
160
            cd $module
Brendan Long's avatar
Brendan Long committed
161
        else
162
            echo "Cloning [$module] from git://anongit.freedesktop.org/git/gstreamer/$module"
Brendan Long's avatar
Brendan Long committed
163
            git clone "git://anongit.freedesktop.org/git/gstreamer/$module"
Brendan Long's avatar
Brendan Long committed
164
            cd $module
Brendan Long's avatar
Brendan Long committed
165
        fi
166
        MODULE_BRANCH=$(getBranch $module)
167 168
        echo "Checking out branch $MODULE_BRANCH"
        git checkout $MODULE_BRANCH || errors="$errors\nUnable to checkout branch: $MODULE_BRANCH for repo $module"
169
    elif $UPDATE_MODULES ; then
Brendan Long's avatar
Brendan Long committed
170
        cd $module
171 172 173 174 175 176

        # This file is updated automatically by configure, and we don't care about it.
        if [ -f win32/common/config.h ] ; then
            git update-index --assume-unchanged win32/common/config.h
        fi

177
        echo "Fetching origin for [$module]"
178
        git fetch origin || errors="$errors\nUnable to update remote: origin"
179
        MODULE_BRANCH=$(getBranch $module)
180

181
        # -p means "don't remove merges"
182 183
        # requires the branch to be previously checked out
        echo "Rebasing to origin/$MODULE_BRANCH"
184 185 186 187 188
        if git checkout $MODULE_BRANCH ; then
            git rebase origin/$MODULE_BRANCH || errors="$errors\nUnable to rebase local branch $MODULE_BRANCH onto remote branch origin/$MODULE_BRANCH for repo $module"
        else
            errors="$errors\nUnable to checkout branch $MODULE_BRANCH for repo $module"
        fi
189 190
    else
        cd $module
191 192 193
        if [ -n "$BRANCH" ] ; then
            echo "Checking out branch $BRANCH"
            git checkout $BRANCH || errors="$errors\nUnable to checkout branch: $BRANCH for repo $module"
194
        fi
195
    fi
Brendan Long's avatar
Brendan Long committed
196
    if [[ ! "${NO_UPSTREAM_MODULES[@]}" == *"$module"* ]]; then
197
        git remote add upstream "git://anongit.freedesktop.org/git/gstreamer/$module" 2> /dev/null || true
198
        git fetch upstream || errors="$errors\nUnable to update remote: upstream"
199
    fi
Brendan Long's avatar
Brendan Long committed
200

201
    # Setup link for gst-$name
202
    if [ "$module" == "gstreamer" ] && [ ! -f $GST_PREFIX ] ; then
203
        mkdir -p ~/bin
204
        ln -s $PWD/scripts/gst-uninstalled $GST_PREFIX
205 206
    fi

207 208 209 210
    if [ ! -f Makefile ] || $RECONFIGURE; then
        echo "Configuring [$module]"
        if [ -f Makefile ] ; then
            make -s clean || true
Brendan Long's avatar
Brendan Long committed
211
        fi
212
        $GST_PREFIX ./autogen.sh --disable-failing-tests --disable-examples --enable-introspection -q
Brendan Long's avatar
Brendan Long committed
213
    fi
214

215 216 217
    echo "Building [$module]"
    $GST_PREFIX make -j40 -s

218
    # Cleanup old build artifacts in GStreamer repos
Brendan Long's avatar
Brendan Long committed
219
    if [[ "${CLEAN_CRUFT_MODULES[@]}" == *"$module"* ]] ; then
220 221
        make -s clean-cruft
    fi
222 223 224
    cd ..
done

225 226
echo "Fixing GStreamer's pkgconfig files to use -l[libname] instead of the full path to the .la file"
find . -name '*-uninstalled.pc' -exec sed -i -e 's/Libs: \(-L${libdir} \)\?\(.*\)\/lib\(.*\)\.la/Libs: -L\2 -l\3/' {} \;
227 228 229

echo "Build successful!"

230 231 232
if [ -n "$errors" ] ; then
    echo -e "WARNING: non-fatal errors occurred:$errors"
fi