Source1000: vdb.lua %include %{S:1000} %global major 0 %global minor 7 %global git 37.gee75dd5969 # 2020-11-03 %global hidapi hidraw %global pkgconf /usr/bin/pkg-config # Some distros have `pkgconf`, some other — `pkg-config`. Let's use older `pkg-config`, # since `pkgconf` provides `pkg-config` for compatibility. For the same reason let's require # program, not a package. Name: usbrelay Version: %{major}.%{minor}.%{git} Release: 0.vdb.3%{?dist} Summary: USB Relay Driver For Linux License: GPLv2+ URL: https://github.com/darrylb123/usbrelay Source0: %{name}-%{major}.%{minor}.%{git}.tar.gz Source1: usbrelay-0.7-configure.sh Source2: usbrelay-make-tarball.sh Source3: usbrelay.rules BuildRequires: gcc BuildRequires: make BuildRequires: %{pkgconf} BuildRequires: pkgconfig(hidapi-%{hidapi}) # In some systems (e. g. Fedora) _udevrulesdir macro is defined in macros.systemd, which is part of # systemd-rpm-macros package. In other systems (e. g. Mageia or Epel 7) there is no such package. %{lua: -- Complex condition looks simpler in Lua rather than in raw spec code. if get( "fedora" ) or get( "epel", 0 ) >= 8 or get( "suse_version" ) then spec( "BuildRequires: systemd-rpm-macros", "" ) end } Requires(pre): shadow-utils %description %{lua: descr( [[ A cheap USB relay available from Ebay with 1, 2, 4 or 8 relay output. The double throw relay ratings are 10A 250VAC each. The USB device is HID compatible and comes with Windows control software. This code can control the relay vi HIDAPI which is a cross platform library. This code was tested under linux both on x86 and Raspberry Pi ARM. The program is command line only as it is likely to be used by shell scripts. ]] ) } %prep %setup -q -n %{name} # usbrelay doesn't have configure script. Let's add fake configure script to save CFLAGS, # CPPFLAGS and few other variables specified by `configure` rpm macro: cp %{S:1} ./conf''igure chmod a+x ./conf''igure cp %{S:3} ./50-%{name}.rules %configure %build # Import CFLAGS, CPPFLAGS and other variables set by `configure` rpm macro: . ./environ.sh # CFLAGS="$CFLAGS -std=c99 $( %{pkgconf} --cflags hidapi-%{hidapi} )" LDFLAGS="$LDFLAGS $( %{pkgconf} --libs hidapi-%{hidapi} )" %{make_build} HIDAPI=%{hidapi} DIR_VERSION=%{version} %install %{make_install} %_install_D -m 0644 -p -t %{buildroot}%{_pkgdocdir} README.md %{name}.jpg %_install_D -m 0644 -p -t %{buildroot}%{_udevrulesdir} 50-%{name}.rules %files %{_libdir}/libusbrelay.so %{_bindir}/usbrelay %{_udevrulesdir}/50-%{name}.rules %doc %dir %{_pkgdocdir} %doc %{_pkgdocdir}/* %license LICENSE.md %pre getent group %{name} >/dev/null && rc=$? || rc=$? case $rc in ( 0 ) # Group already exists, nothing to do. ;; ( 2 ) # Group does not exist, create it. groupadd -f -r %{name} ;; ( * ) # Unexpected error. echo "getent exited with status $rc" >&2 exit $rc ;; esac %changelog * Mon Nov 30 2020 Van de Bugger - 0.7.37.gee75dd5969-0.vdb.3 - Description updated. * Mon Nov 30 2020 Van de Bugger - 0.7.37.gee75dd5969-0.vdb.2 - "usbrelay" group added. - Udev rule added to make usbrelay device files belongs to "usbrelay" group. * Tue Nov 3 2020 Van de Bugger - 0.7.37.gee75dd5969-0.vdb.1 - Initial release.