Chore: Upgrade Jenkins-job-builder to 6.3.0
[releng/global-jjb.git] / shell / autotools-build.sh
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 # Invokes configure and make with the specified options.
13 # Optionally runs make install and tars up all files from the install prefix,
14 # then uses sudo to extract those files to /usr/local and runs ldconfig,
15 # leaving shared lib(s) ready for use.
16 # Prereqs:
17 # The build minion has make, gcc etc.
18 # The project repo has an executable shell script "configure"
19 # Environment variables:
20 # WORKSPACE is a non-empty path (required)
21 # INSTALL_PREFIX is a non-empty path (required)
22 # PROJECT is a non-empty name (required)
23 # CONFIGURE_OPTS has options for configure (optional, empty default)
24 # MAKE_OPTS has options for make (optional, empty default)
25 # INSTALL is "true" or "false" (optional, default false)
26
27 echo "---> autotools-build.sh"
28
29 # be careful and verbose
30 set -eux -o pipefail
31
32 c="$WORKSPACE/configure"
33 if [[ ! -f $c || ! -x $c ]]; then
34     echo "ERROR: failed to find executable file $c"
35     exit 1
36 fi
37
38 configure_opts="${CONFIGURE_OPTS:-}"
39 make_opts="${MAKE_OPTS:-}"
40 install="${INSTALL:-false}"
41 # Not a misspelling as shellcheck reports.
42 # shellcheck disable=SC2153
43 project="${PROJECT//\//\-}"
44
45 # use eval to disable bash quoting behavior;
46 # e.g., if configure-opts=CXXFLAGS="-O0 --coverage"
47 # configure needs to wordsplit to pass options
48 # shellcheck disable=SC2086
49 eval $c --prefix="$INSTALL_PREFIX" $configure_opts
50
51 # show make version to assist debugging
52 make -version
53 # use eval to disable bash quoting behavior
54 # $make_opts may be empty
55 # make needs to wordsplit to pass options
56 # shellcheck disable=SC2086
57 eval make $make_opts
58
59 if [[ $install == true ]]; then
60     make install
61     mkdir -p "$WORKSPACE/dist"
62     tar -cJvf "$WORKSPACE/dist/$project.tar.xz" -C "$INSTALL_PREFIX" .
63     sudo tar -xvf "$WORKSPACE/dist/$project.tar.xz" -C "/usr/local"
64     sudo ldconfig
65 fi
66
67 echo "---> autotools-build.sh ends"