File vlang-weekly.spec of Package vlang-weekly

#
# spec file for package vlang
#
# Copyright (c) 2024, 2025 Boian Berberov
#
# 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/
#

# BEGIN pre-package
%bcond_without  tcc_build

%ifnarch %ix86
	%if 0%{with tcc_build}
%global         build_with_tcc  1
		%if 0%{?fedora} || 0%{?mageia}
# error: Empty %%files file ... debugsourcefiles.list
%global         debug_package   %{nil}
		%endif
	%else
%global         build_with_tcc  0
	%endif
%else
%global         build_with_tcc  0
%endif

%global         vc_gitrev  8562ac1594794871c75af9c593bd37ed643f66be
%global         up_ver     weekly.%{version}
%global         topsrcdir  v-%{up_ver}
# END   pre-package

# BEGIN package
Name:           vlang-weekly
Version:        2025.30
Release:        0%{?dist}
Group:          Development/Languages/Other
Summary:        The V Programming Language
License:        MIT
URL:            https://vlang.io/

Source0:        https://github.com/vlang/v/archive/refs/tags/%{up_ver}.tar.gz
Source1:        https://github.com/vlang/vc/raw/%{vc_gitrev}/v.c

BuildRequires:  fdupes
BuildRequires:  findutils

%if 0%{build_with_tcc}
BuildRequires:  tcc
%else
# BEGIN multibuild BuildRequires: GCC
		%if 0%{?is_opensuse}
			%if 0%{?sle_version}
				%if 0%{?sle_version} == 150600
BuildRequires:  gcc13
%global         multi_gcc  gcc-13
				%else
					%if 0%{?sle_version} == 150500
BuildRequires:  gcc12
%global         multi_gcc  gcc-12
					%else
BuildRequires:  gcc     >= 10
%global         multi_gcc  gcc
					%endif
				%endif
			%else
BuildRequires:  gcc
%global         multi_gcc  gcc
			%endif
		%else
BuildRequires:  gcc
%global         multi_gcc  gcc
		%endif
# END   multibuild BuildRequires: GCC
%endif

# For VFLAGS="-d dynamic_boehm"
BuildRequires:  gc-devel
# Required by compiler at runtime
Requires:       gc-devel

# For cmd/tools/vshare
%if 0%{?mageia}
BuildRequires:  libx11-devel
%else
BuildRequires:  libX11-devel
%endif

# For VFLAGS="-d dynamic_boehm"
Requires:       libgc1

%if 0%{build_with_tcc}
%global         vflags     -cc tcc -d dynamic_boehm
%else
%global         vflags     -cc %{multi_gcc} -d dynamic_boehm
%endif

%description
The V Programming Language

# END   package

# BEGIN prep
%prep
%setup -q -n %{topsrcdir}
%__cp %{_sourcedir}/v.c %{_builddir}/%{topsrcdir}/v.c

# Remove .gitignore files
find %{_builddir}/%{topsrcdir} -type f -name '.gitignore' -print -delete

# Patch
%__sed -i -e '1s:/usr/local/bin/v:%{_bindir}/%{name}:' examples/v_script.vsh
# END   prep

# BEGIN build
%build

# Build-time configuration
%if 0%{build_with_tcc}
export CC=tcc
export CFLAGS='-std=gnu11 -pthread -Wall'
export LDFLAGS='-Wl,--enable-new-dtags'
%else
export CC=%{multi_gcc}
%set_build_flags
export CFLAGS="${CFLAGS} -std=gnu11 -pthread -Wno-unused-variable -Wno-unused-value -Wno-unused-label"
%endif

export VFLAGS="%{vflags} -prod"

%if 0%{?sle_version} == 150500
export STAGE0_LIBS='-lm -lpthread -lrt'
%else
export STAGE0_LIBS='-lm -lpthread'
%endif

# Build V
#${CC} ${CFLAGS} -std=gnu11 -w -o %{name}-stage1 v.c -lm -lexecinfo -lpthread ${LDFLAGS}
${CC} ${CFLAGS} ${LDFLAGS} ${STAGE0_LIBS} -o %{name}-stage1 v.c
./%{name}-stage1 ${VFLAGS} -no-parallel   -o %{name}-stage2 cmd/v
./%{name}-stage2 ${VFLAGS}                -o %{name}        cmd/v

echo "println('Use your package manager to update V')"                        > cmd/tools/vup.v
echo "println('\"%{name} self\" is disabled for the packaged versions of V')" > cmd/tools/vself.v

# TODO: Skipping building vdoc until https://github.com/vlang/markdown is embedded in build
%__sed -i -e "/^const tools_in_subfolders/s/ 'vdoc',//" cmd/tools/vbuild-tools.v
%__rm -rf cmd/tools/vdoc

# Set to not-empty to skip build-time V module cloning with `git`
export VTEST_SANDBOXED_PACKAGING='yes'

# Build-time configuration
export VEXE="%{_builddir}/%{buildsubdir}/%{name}"
export VMODULES="%{_builddir}/%{buildsubdir}/.vmodules"
export VJOBS="%{?jobs:%jobs}"

# Build V tools
# ./%%{name} test-self
# ./%%{name} doctor
./%{name} -v build-tools

# Do not attempt to rebuild after installation
echo 'disable' > cmd/tools/.disable_autorecompilation
%__chmod 0444    cmd/tools/.disable_autorecompilation
# END   build

# BEGIN install
%install
# Remove tests
%__rm -rf \
	cmd/tools/*/tests \
	vlib/*/tests \
	vlib/*/*/tests \
	vlib/*/*/*/tests \
	vlib/*/slow_tests \
	cmd/tools/*/testdata \
	vlib/*/testdata \
	vlib/*/*/testdata \
	vlib/*/*/*/testdata \
	vlib/v/pkgconfig/test_samples

# Copy files
%__install -D -m 0755 %{name} %{buildroot}%{_libexecdir}/%{name}/%{name}
%__cp -R                   -t %{buildroot}%{_libexecdir}/%{name} cmd vlib

# Run-time configuration wrapper
# TODO: Add a proper VTMP
%__install -d %{buildroot}%{_bindir}
echo '#! /usr/bin/sh

export VEXE="%{_libexecdir}/%{name}/%{name}"
export VCACHE="${HOME}/.cache/%{name}"
export VFLAGS="%{vflags}"

exec ${VEXE} $@
' > %{buildroot}%{_bindir}/%{name}
%__chmod 755 %{buildroot}%{_bindir}/%{name}

# Deduplicate
%fdupes %{buildroot}%{_libexecdir}/%{name}/vlib
%fdupes %{_builddir}/%{topsrcdir}/examples
# END   install

# %%check
# %%{name} test-self

# BEGIN files
%files
%license LICENSE
%doc     doc/docs.md
%doc     doc/vscode.md doc/img
%doc     examples
%doc     tutorials
%{_bindir}/%{name}
%{_libexecdir}/%{name}
%{_libexecdir}/%{name}/%{name}
%{_libexecdir}/%{name}/cmd/
%{_libexecdir}/%{name}/vlib/
# END   files

%changelog

* Tue Jul 15 2025 Boian Berberov
- Added changelog for openSUSE Leap 16
openSUSE Build Service is sponsored by