| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# Copyright © 2020 – 2022 Red Hat Inc. |
| 4 |
# |
| 5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
# you may not use this file except in compliance with the License. |
| 7 |
# You may obtain a copy of the License at |
| 8 |
# |
| 9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
# |
| 11 |
# Unless required by applicable law or agreed to in writing, software |
| 12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
# See the License for the specific language governing permissions and |
| 15 |
# limitations under the License. |
| 16 |
# |
| 17 |
|
| 18 |
|
| 19 |
if [ "$#" -ne 7 ]; then |
| 20 |
echo "go-build-wrapper: wrong arguments" >&2 |
| 21 |
echo "Usage: go-build-wrapper [SOURCE DIR]" >&2 |
| 22 |
echo " [OUTPUT ROOT DIR]" >&2 |
| 23 |
echo " [OUTPUT FILE]" >&2 |
| 24 |
echo " [VERSION]" >&2 |
| 25 |
echo " [C COMPILER]" >&2 |
| 26 |
echo " [DYNAMIC LINKER]" >&2 |
| 27 |
echo " [MIGRATION PATH FOR COREOS/TOOLBOX]" >&2 |
| 28 |
exit 1 |
| 29 |
fi |
| 30 |
|
| 31 |
if ! cd "$1"; then |
| 32 |
echo "go-build-wrapper: failed to enter source directory $1" |
| 33 |
exit 1 |
| 34 |
fi |
| 35 |
|
| 36 |
tags="" |
| 37 |
if $7; then |
| 38 |
tags="-tags migration_path_for_coreos_toolbox" |
| 39 |
fi |
| 40 |
|
| 41 |
if ! libc_dir=$("$5" --print-file-name=libc.so); then |
| 42 |
echo "go-build-wrapper: failed to read the path to libc.so" >&2 |
| 43 |
exit 1 |
| 44 |
fi |
| 45 |
|
| 46 |
if ! libc_dir_canonical=$(readlink --canonicalize "$libc_dir"); then |
| 47 |
echo "go-build-wrapper: failed to canonicalize the path to libc.so" >&2 |
| 48 |
exit 1 |
| 49 |
fi |
| 50 |
|
| 51 |
if ! libc_dir_canonical_dirname=$(dirname "$libc_dir_canonical"); then |
| 52 |
echo "go-build-wrapper: failed to read the dirname of the canonicalized path to libc.so" >&2 |
| 53 |
exit 1 |
| 54 |
fi |
| 55 |
|
| 56 |
if ! dynamic_linker_basename=$(basename "$6"); then |
| 57 |
echo "go-build-wrapper: failed to read the basename of dynamic linker $6" >&2 |
| 58 |
exit 1 |
| 59 |
fi |
| 60 |
|
| 61 |
if ! dynamic_linker_canonical=$(readlink --canonicalize "$6"); then |
| 62 |
echo "go-build-wrapper: failed to canonicalize dynamic linker $6" >&2 |
| 63 |
exit 1 |
| 64 |
fi |
| 65 |
|
| 66 |
if ! dynamic_linker_canonical_dirname=$(dirname "$dynamic_linker_canonical"); then |
| 67 |
echo "go-build-wrapper: failed to read the dirname of the canonicalized dynamic linker $dynamic_linker_canonical" >&2 |
| 68 |
exit 1 |
| 69 |
fi |
| 70 |
|
| 71 |
dynamic_linker="/run/host$dynamic_linker_canonical_dirname/$dynamic_linker_basename" |
| 72 |
|
| 73 |
# shellcheck disable=SC2086 |
| 74 |
go build \ |
| 75 |
$tags \ |
| 76 |
-trimpath \ |
| 77 |
-ldflags "-extldflags '-Wl,-dynamic-linker,$dynamic_linker -Wl,-rpath,/run/host$libc_dir_canonical_dirname' -linkmode external -X github.com/containers/toolbox/pkg/version.currentVersion=$4" \ |
| 78 |
-o "$2/$3" |
| 79 |
|
| 80 |
exit "$?" |