File arduino-cli.spec of Package arduino-cli

#
# spec file for package arduino-cli
#
# Copyright (c) 2021 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

%global import_path  github.com/arduino/arduino-cli
%global gcc_ver      11
%global goflags      -buildmode=pie -trimpath -mod=vendor
%define arduinodir   %{_libdir}/arduino


Name:           arduino-cli
Version:        0.35.1
Release:        0
Summary:        Arduino command line tool
Group:          Development/Tools/Other
License:        GPL-3.0-only
URL:            https://github.com/arduino/arduino-cli
#Source0:        https://github.com/arduino/arduino-cli/archive/%%{version}/%%{name}-%%{version}.tar.gz
Source0:        %{name}-%{version}.tar.gz
Source1:        vendor.tar.gz
Source2:        arduino-cli-update-message.txt
Source10:       %{name}.obsinfo
# even though the doc says 1.14, the usage of go:embed requires 1.16 IIUC --seife
BuildRequires:  go >= 1.21
BuildRequires:  golang-packaging
#Requires:       cross-avr-gcc%%{gcc_ver}
Requires:       /usr/bin/avr-gcc
Requires:       avrdude
Requires:       avr-libc
Requires:       arduino-core
Requires:       arduino-ctags

%description
Arduino CLI is an all-in-one solution that provides builder, Boards/Library Manager, uploader,
discovery and many other tools needed to use any Arduino compatible board and platforms.

%package docs
Summary:        Documentation for %{name}
Group:          Development/Tools/Other
Requires:       %{name} = %{version}
BuildArch:      noarch

%description docs
Arduino CLI is an all-in-one solution that provides builder, Boards/Library Manager, uploader,
discovery and many other tools needed to use any Arduino compatible board and platforms.

This package contains documentation files for %{name}.

%package bash-completion
Summary:        Bash Completion for %{name}
Group:          Development/Tools/Other
Requires:       %{name} = %{version}
Requires:       bash-completion
Supplements:    (arduino-cli and bash-completion)
BuildArch:      noarch

%description bash-completion
Bash command line completion support for %{name}.

%package zsh-completion
Summary:        ZSH Completion for %{name}
Group:          Development/Tools/Other
Requires:       %{name} = %{version}
Supplements:    (arduino-cli and zsh)
BuildArch:      noarch

%description zsh-completion
ZSH command line completion support for %{name}.

%if 0%{?is_opensuse}
%package fish-completion
Summary:        Fish completion for %{name}
Group:          Development/Tools/Other
Requires:       %{name} = %{version}
Supplements:    (arduino-cli and fish)
BuildArch:      noarch

%description fish-completion
Fish command line completion support for %{name}.
%endif

%prep
%setup -q -a 1

%build
go build %{goflags} -ldflags="-linkmode=external \
	-X %{import_path}/version.versionString=%{version} \
	-X %{import_path}/version.commit=%(sed -n 's/^commit\:\ \+//ip' %{S:10}) \
	-X %{import_path}/version.date=%(date +"%d-%m-%Y" --date=@%(sed -n 's/^mtime\:\ \+//ip' %{S:10}))" .

%install
# build completions
./%{name} completion bash | install -Dm644 /dev/stdin \
	%{buildroot}%{_datadir}/bash-completion/completions/%{name}
./%{name} completion zsh  | install -Dm644 /dev/stdin \
	%{buildroot}%{_datadir}/zsh/site-functions/_%{name}
%if 0%{?is_opensuse}
./%{name} completion fish  | install -Dm644 /dev/stdin \
        %{buildroot}%{_datadir}/fish/vendor_completions.d/%{name}.fish
%endif

install -Dm755 %{name} %{buildroot}%{arduinodir}/%{name}
mkdir -p %{buildroot}%{_bindir}
ln -s %{arduinodir}/%{name} %{buildroot}%{_bindir}/%{name}
mkdir -p %{buildroot}%{_localstatedir}/adm/update-messages
cp -p %{S:2} %{buildroot}%{_localstatedir}/adm/update-messages/%{name}-%{version}-%{release}-1

%files
%license LICENSE.txt
%doc README.md
%{_bindir}/%{name}
%dir %attr(0755,root,root) %{arduinodir}
%{arduinodir}/%{name}
%{_localstatedir}/adm/update-messages/%{name}-%{version}-%{release}-1

%files bash-completion
%{_datadir}/bash-completion/completions/%{name}

%files zsh-completion
%dir %attr(0755,root,root) %{_datadir}/zsh
%dir %attr(0755,root,root) %{_datadir}/zsh/site-functions
%{_datadir}/zsh/site-functions/_%{name}

%if 0%{?is_opensuse}
%files fish-completion
%dir %attr(0755,root,root) %{_datadir}/fish
%dir %attr(0755,root,root) %{_datadir}/fish/vendor_completions.d
%{_datadir}/fish/vendor_completions.d/%{name}.fish
%endif

%files docs
%doc docs/*.md

%changelog
openSUSE Build Service is sponsored by