|
| 1 | +#!/bin/bash |
| 2 | +# Build the FBOSS BSP within the Distro Image framework |
| 3 | + |
| 4 | +set -e |
| 5 | + |
| 6 | +SPEC_FILE="rpmbuild/fboss_bsp_kmods.spec" |
| 7 | + |
| 8 | +# Install build dependencies for the spec |
| 9 | +dnf builddep -y --spec "$SPEC_FILE" |
| 10 | + |
| 11 | +# Use gcc-toolset-12 for the build |
| 12 | +sudo update-alternatives --set gcc /opt/rh/gcc-toolset-12/root/usr/bin/gcc |
| 13 | +source /opt/rh/gcc-toolset-12/enable |
| 14 | + |
| 15 | +echo "Setting up RPM build environment in $FBOSS_BSP_DIR/rpmbuild..." |
| 16 | + |
| 17 | +# Get the absolute path to the fboss-bsp directory and switch to it |
| 18 | +FBOSS_BSP_DIR="$(dirname "$(readlink -f "$0")")" |
| 19 | +cd "$FBOSS_BSP_DIR" |
| 20 | + |
| 21 | +# Create RPM build directory structure |
| 22 | +mkdir -p rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} |
| 23 | +rm -rf rpmbuild/RPMS/* |
| 24 | + |
| 25 | +# Copy spec file to SPECS directory |
| 26 | +cp "$SPEC_FILE" rpmbuild/SPECS/ |
| 27 | + |
| 28 | +# Create source tarball from kmods |
| 29 | +mkdir -p rpmbuild/SOURCES/fboss-bsp/kmods |
| 30 | +NAME="fboss_bsp_kmods" |
| 31 | +VERSION=$(grep '^Version:' "$SPEC_FILE" | awk '{print $2}') |
| 32 | + |
| 33 | +tar -czvf "rpmbuild/SOURCES/${NAME}-${VERSION}.tar.gz" \ |
| 34 | + --transform "s,^,fboss_bsp_kmods-${VERSION}/," \ |
| 35 | + kmods/ |
| 36 | + |
| 37 | +# Build the RPM |
| 38 | +rpmbuild -ba rpmbuild/SPECS/"$(basename "$SPEC_FILE")" --define "_topdir $FBOSS_BSP_DIR/rpmbuild" |
| 39 | + |
| 40 | +RPM_PATH=$(find rpmbuild/RPMS -name "*.rpm" | head -1) |
| 41 | + |
| 42 | +if [ -n "$RPM_PATH" ]; then |
| 43 | + echo "RPM built successfully: $RPM_PATH" |
| 44 | +else |
| 45 | + echo "Error: RPM build failed or RPM not found" |
| 46 | + exit 1 |
| 47 | +fi |
| 48 | + |
| 49 | +# Package the built RPMs into /output tarball for the Distro image |
| 50 | +cd rpmbuild/RPMS/* |
| 51 | +tar -cf /output/bsp-fboss.tar --strip-components=3 *.rpm |
0 commit comments