diff --git a/README.md b/README.md index cc493d2..9e7c29f 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ The `main` branch contains this README and a sample build script. The `.spec` an - [Prerequisites](#Prerequisites) * [Clone this git repository](#Clone-this-git-repository) * [Install build dependencies](#Install-build-dependencies) +- [Building with script](#Building-with-script) +- [Building Manually](#Building-Manually) - [Related](#Other-NVIDIA-driver-packages) * [Precompiled kernel modules](#Precompiled-kernel-modules) * [NVIDIA driver](#NVIDIA-driver) @@ -92,6 +94,52 @@ git clone -b ${branch} https://github.com/NVIDIA/yum-packaging-dkms-nvidia yum install rpm-build dkms ``` + +## Building with script + +### Fetch script from `main` branch + +```shell +cd yum-packaging-dkms-nvidia +git checkout remotes/origin/main -- build.sh +``` + +### Usage + +```shell +./build.sh path/to/*.run +> ex: time ./build.sh ~/Downloads/NVIDIA-Linux-x86_64-450.102.04.run +``` + + +## Building Manually + +### Generate tarball from runfile + +```shell +version="450.102.04" +sh NVIDIA-Linux-x86_64-${version}.run --extract-only --target extract +mkdir nvidia-kmod-${version}-x86_64 +mv extract/kernel nvidia-kmod-${version}-x86_64/ +tar -cJf nvidia-kmod-${version}-x86_64.tar.xz nvidia-kmod-${version}-x86_64 +``` + +### Packaging + +```shell +mkdir BUILD BUILDROOT RPMS SRPMS SOURCES SPECS +cp dkms-nvidia.conf SOURCES/ +cp nvidia-kmod-${version}-x86_64.tar.xz SOURCES/ +cp dkms-nvidia.spec SPECS/ + +rpmbuild \ + --define "%_topdir $(pwd)" \ + --define "debug_package %{nil}" \ + --define "version $version" \ + --define "epoch 3" \ + -v -bb SPECS/dkms-nvidia.spec +``` + ## Related ### Precompiled kernel modules diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..1c7d4f9 --- /dev/null +++ b/build.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +runfile="$1" +topdir="$HOME/dkms-nvidia" +arch="x86_64" +epoch="3" + +drvname=$(basename "$runfile") +version=$(echo "$drvname" | sed -e "s|NVIDIA\-Linux\-${arch}\-||" -e 's|\.run$||') + +tarball=nvidia-kmod-${version}-${arch} +unpackDir="unpack" + +err() { echo; echo "ERROR: $*"; exit 1; } +kmd() { echo; echo ">>> $*" | fold -s; eval "$*" || err "at line \`$*\`"; } + +generate_tarballs() +{ + mkdir "${tarball}" + sh "${runfile}" --extract-only --target ${unpackDir} + mv "${unpackDir}/kernel" "${tarball}/" + rm -rf ${unpackDir} + tar --remove-files -cJf "${tarball}.tar.xz" "${tarball}" +} + +build_rpm() +{ + mkdir -p "$topdir" + (cd "$topdir" && mkdir -p BUILD BUILDROOT RPMS SRPMS SOURCES SPECS) + + cp -v -- *conf* "$topdir/SOURCES/" + cp -v -- *tar* "$topdir/SOURCES/" + cp -v -- *.spec "$topdir/SPECS/" + cd "$topdir" || err "Unable to cd into $topdir" + + kmd rpmbuild \ + --define "'%_topdir $(pwd)'" \ + --define "'debug_package %{nil}'" \ + --define "'version $version'" \ + --define "'epoch $epoch'" \ + -v -bb SPECS/dkms-nvidia.spec + + cd - || err "Unable to cd into $OLDPWD" +} + +# Create tarball from runfile contents +if [[ -f ${tarball}.tar.xz ]]; then + echo "[SKIP] generate_tarballs()" +else + echo "==> generate_tarballs()" + generate_tarballs +fi + +# Build RPMs +empty=$(find "$topdir/RPMS" -maxdepth 0 -type d -empty 2>/dev/null) +found=$(find "$topdir/RPMS" -mindepth 2 -maxdepth 2 -type f -name "*${version}*" 2>/dev/null) +if [[ ! -d "$topdir/RPMS" ]] || [[ $empty ]] || [[ ! $found ]]; then + echo "==> build_rpm(${version})" + build_rpm +else + echo "[SKIP] build_rpm(${version})" +fi + +echo "---" +find "$topdir/RPMS" -mindepth 2 -maxdepth 2 -type f -name "*${version}*" diff --git a/dkms-nvidia.spec b/dkms-nvidia.spec index 69b546f..d400d5f 100755 --- a/dkms-nvidia.spec +++ b/dkms-nvidia.spec @@ -2,7 +2,7 @@ %global dkms_name nvidia Name: kmod-%{dkms_name}-latest-dkms -Version: 430.14 +Version: %{?version}%{?!version:430.14} Release: 1%{?dist} Summary: NVIDIA display driver kernel module Epoch: 3