Lott, Christopher (cl778h) | 7751aa0 | 2020-03-30 20:06:30 -0400 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # SPDX-License-Identifier: EPL-1.0 |
| 3 | ############################################################################## |
| 4 | # Copyright (c) 2020 The Linux Foundation and others. |
| 5 | # |
| 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 | ############################################################################## |
| 11 | |
| 12 | # Creates a build directory then invokes cmake and make |
| 13 | # from that dir with only the specified options/targets. |
| 14 | # Supports projects that create DEB/RPM package files for |
| 15 | # upload to PackageCloud or other repository, which must |
| 16 | # use a system install prefix like /usr/local. Calling |
| 17 | # the "install" goal with a system prefix requires sudo, |
| 18 | # but building a package doesn't require the install step. |
| 19 | # Prereqs: |
| 20 | # The build minion has cmake, make, gcc etc. |
| 21 | # Environment variables: |
| 22 | # WORKSPACE is a non-empty path (required) |
| 23 | # CMAKE_INSTALL_PREFIX is a non-empty path (required) |
| 24 | # BUILD_DIR is a path (optional; has usable default) |
| 25 | # CMAKE_OPTS has options for cmake (optional, empty default) |
| 26 | # MAKE_OPTS has options for make (optional, empty default) |
| 27 | |
| 28 | echo "---> cmake-package.sh" |
| 29 | |
| 30 | build_dir="${BUILD_DIR:-$WORKSPACE/build}" |
| 31 | cmake_opts="${CMAKE_OPTS:-}" |
| 32 | make_opts="${MAKE_OPTS:-}" |
| 33 | echo "build_dir: $build_dir" |
| 34 | echo "cmake_opts: $cmake_opts" |
| 35 | echo "make_opts: $make_opts" |
| 36 | |
| 37 | # be careful and verbose |
| 38 | set -eux -o pipefail |
| 39 | |
| 40 | mkdir -p "$build_dir" |
| 41 | cd "$build_dir" || exit |
| 42 | cmake -version |
| 43 | # $cmake_opts needs to wordsplit to pass options. |
| 44 | # shellcheck disable=SC2086 |
| 45 | eval cmake -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" $cmake_opts .. |
| 46 | make -version |
| 47 | # $make_opts needs to wordsplit to pass options. |
| 48 | # shellcheck disable=SC2086 |
| 49 | make $make_opts |
| 50 | |
| 51 | echo "---> cmake-package.sh ends" |