2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2018 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
12 # Creates a build subdir then invokes cmake and make from that dir with the
13 # specified install prefix and options. Optionally runs make install and tars
14 # up all files from the install prefix, then uses sudo to extract those files
15 # to /usr/local and run ldconfig, leaving shared lib(s) ready for use.
17 # The build minion has cmake, make, gcc etc.
18 # Environment variables:
19 # WORKSPACE is a non-empty path (required)
20 # CMAKE_INSTALL_PREFIX is a non-empty path (required)
21 # PROJECT is a non-empty name (required)
22 # BUILD_DIR is a path (optional; has usable default)
23 # CMAKE_OPTS has options for cmake (optional, empty default)
24 # MAKE_OPTS has options for make (optional, empty default)
25 # INSTALL is "true" or "false" (optional, default true)
27 echo "---> cmake-build.sh"
29 # be careful and verbose
32 build_dir="${BUILD_DIR:-$WORKSPACE/target}"
33 cmake_opts="${CMAKE_OPTS:-}"
34 make_opts="${MAKE_OPTS:-}"
35 install="${INSTALL:-true}"
36 # Not a misspelling as shellcheck reports.
37 # shellcheck disable=SC2153
38 project="${PROJECT//\//\-}"
41 cd "$build_dir" || exit
43 # $cmake_opts needs to wordsplit to pass options.
44 # shellcheck disable=SC2086
45 eval cmake -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" $cmake_opts ..
47 # $make_opts needs to wordsplit to pass options.
48 # shellcheck disable=SC2086
51 if [[ $install == true ]]; then
53 mkdir -p "$WORKSPACE/dist"
54 tar -cJvf "$WORKSPACE/dist/$project.tar.xz" -C "$INSTALL_PREFIX" .
55 sudo tar -xvf "$WORKSPACE/dist/$project.tar.xz" -C "/usr/local"
59 echo "---> cmake-build.sh ends"