blob: 021f6601e9d7c27199542b14f978738950285ad2 [file] [log] [blame]
Lott, Christopher (cl778h)7751aa02020-03-30 20:06:30 -04001#!/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
28echo "---> cmake-package.sh"
29
30build_dir="${BUILD_DIR:-$WORKSPACE/build}"
31cmake_opts="${CMAKE_OPTS:-}"
32make_opts="${MAKE_OPTS:-}"
33echo "build_dir: $build_dir"
34echo "cmake_opts: $cmake_opts"
35echo "make_opts: $make_opts"
36
37# be careful and verbose
38set -eux -o pipefail
39
40mkdir -p "$build_dir"
41cd "$build_dir" || exit
42cmake -version
43# $cmake_opts needs to wordsplit to pass options.
44# shellcheck disable=SC2086
45eval cmake -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" $cmake_opts ..
46make -version
47# $make_opts needs to wordsplit to pass options.
48# shellcheck disable=SC2086
49make $make_opts
50
51echo "---> cmake-package.sh ends"