Skip to content

Commit

Permalink
Use version variable, add build.sh, update instructions
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Mittman <kmittman@nvidia.com>
  • Loading branch information
kmittman committed Mar 24, 2021
1 parent 8abb9f6 commit 5ea04e5
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 1 deletion.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
65 changes: 65 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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}*"
2 changes: 1 addition & 1 deletion dkms-nvidia.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5ea04e5

Please sign in to comment.