File rc.spec of Package rc

#
# spec file for package harec
#
# Copyright (c) 2023 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/
#


%define  haredir  %{_usrsrc}/hare
Name:           rc
Release:        0
Version:        0+git.1725436050.2b2d211
Summary:        A simple shell
URL:            https://git.sr.ht/~sircmpwn/rc
Source0:        %{name}-%{version}.tar.zst
# PATCH-FIX-OPENSUSE no-rebuild.patch mcepl@suse.com
# rc target is quite certainly not PHONY (REJECTed upstream)
Patch0:         no-rebuild.patch
BuildRequires:  make
BuildRequires:  hare
BuildRequires:  madeline
BuildRequires:  scdoc
BuildRequires:  zstd
# For testing
BuildRequires:  bc
# End testing
# Because it conflicts with /usr/bin/rc
Conflicts:      rtags
License:        GPL-3.0-only

%description
rc is an experimental shell for Unix inspired by Plan 9's rc.

More information on the original rc is at
https://doc.cat-v.org/plan_9/4th_edition/papers/rc, or
https://en.wikipedia.org/wiki/Rc.

%prep
%autosetup -p1

# Fix Hare syntax for newer compiler
# Fix alloc() calls - need type hints and error handling
sed -i 's/let rd: \[\]redir = alloc(\[\], len(cmd.redirs));/let rd: []redir = alloc([]: []redir, len(cmd.redirs))!;/' ast/command.ha
sed -i 's/let new: script = alloc(\[\], len(sc));/let new: script = alloc([]: script, len(sc))!;/' ast/command.ha
sed -i 's/let cases: \[\]switch_case = alloc(\[\], len(sw.cases));/let cases: []switch_case = alloc([]: []switch_case, len(sw.cases))!;/' ast/command.ha

sed -i 's/let cmds: \[\]command = alloc(\[\], len(val.cmds));/let cmds: []command = alloc([]: []command, len(val.cmds))!;/' ast/value.ha
sed -i 's/let new: \[\]\*value = alloc(\[\], len(val));/let new: []*value = alloc([]: []*value, len(val))!;/' ast/value.ha

# Fix append() calls - need error handling
sed -i 's/append(rd, redir {$/append(rd, redir {/g' ast/command.ha
sed -i '/append(rd, redir {/{N;N;N;s/});/})!;/}' ast/command.ha

sed -i 's/append(new, command_dup(\&sc\[i\]));/append(new, command_dup(\&sc[i]))!;/' ast/command.ha
sed -i '/append(cases, switch_case {/{N;N;N;N;N;s/});/})!;/}' ast/command.ha
sed -i 's/append(cmds, command_dup(\&val.cmds\[i\]));/append(cmds, command_dup(\&val.cmds[i]))!;/' ast/value.ha
sed -i 's/append(new, alloc(value_dup(val\[i\])));/append(new, alloc(value_dup(val[i]))!)!;/' ast/value.ha

# Fix alloc() and strings calls - need error handling
sed -i 's/lval = alloc(command_dup(cmd.lval)),/lval = alloc(command_dup(cmd.lval))!,/' ast/command.ha
sed -i 's/rval = alloc(command_dup(cmd.rval)),/rval = alloc(command_dup(cmd.rval))!,/' ast/command.ha
sed -i 's/target = strings::dup(cmd.target),/target = strings::dup(cmd.target)!,/' ast/command.ha
sed -i 's/value = alloc(value_dup(cmd.value)),/value = alloc(value_dup(cmd.value))!,/' ast/command.ha
sed -i 's/name = strings::dup(cmd.name),/name = strings::dup(cmd.name)!,/' ast/command.ha
sed -i 's/args = strings::dupall(cmd.args),/args = strings::dupall(cmd.args)!,/' ast/command.ha
sed -i 's/body = alloc(command_dup(cmd.body))/body = alloc(command_dup(cmd.body))!/' ast/command.ha

sed -i 's/cond = alloc(command_dup(stmt.cond)),/cond = alloc(command_dup(stmt.cond))!,/' ast/command.ha
sed -i 's/body = alloc(command_dup(stmt.body)),/body = alloc(command_dup(stmt.body))!,/' ast/command.ha
sed -i 's/yield alloc(command_dup(cmd));/yield alloc(command_dup(cmd))!;/' ast/command.ha

sed -i 's/bind = strings::dup(loop.bind),/bind = strings::dup(loop.bind)!,/' ast/command.ha
sed -i 's/body = alloc(command_dup(loop.body)),/body = alloc(command_dup(loop.body))!,/' ast/command.ha
sed -i 's/cmd = alloc(command_dup(loop.cmd)),/cmd = alloc(command_dup(loop.cmd))!,/' ast/command.ha

sed -i 's/yield alloc(value_dup(val));/yield alloc(value_dup(val))!;/' ast/command.ha
sed -i 's/command = alloc(command_dup(c.command)),/command = alloc(command_dup(c.command))!,/' ast/command.ha
sed -i 's/subject = alloc(value_dup(sw.subject)),/subject = alloc(value_dup(sw.subject))!,/' ast/command.ha
sed -i 's/command = alloc(command_dup(sub.command)),/command = alloc(command_dup(sub.command))!,/' ast/command.ha
sed -i 's/command = alloc(command_dup(n.command)),/command = alloc(command_dup(n.command))!,/' ast/command.ha

sed -i 's/target = strings::dup(val.target),/target = strings::dup(val.target)!,/' ast/value.ha
sed -i 's/yield alloc(value_dup(v));/yield alloc(value_dup(v))!;/' ast/value.ha
sed -i 's/ifs = strings::dup(val.ifs),/ifs = strings::dup(val.ifs)!,/' ast/value.ha
sed -i 's/const left = alloc(value_dup(val.0));/const left = alloc(value_dup(val.0))!;/' ast/value.ha
sed -i 's/const right = alloc(value_dup(val.1));/const right = alloc(value_dup(val.1))!;/' ast/value.ha

%build
%make_build


%install
# Shells should go to /bin
%make_install PREFIX="%{_prefix}"


%check
make check

%files
%{_bindir}/%{name}*
%license COPYING
%doc README.md
%{_mandir}/man1/%{name}.1%{?ext_man}

%changelog
openSUSE Build Service is sponsored by