Package libstdc++9: Specfile

%global _unpackaged_files_terminate_build 1

# I'm putting here the GCC version this lib is based on
# (and the corresponding lcc is claimed to be compatible with;
# as printed by gcc --version):
%global compat_gcc_branch 9
%global compat_gcc_version %compat_gcc_branch.3

%global lcc_branch 1.26
%global sover 6
%global soverfull 6.0.28
%global llcs_ver 1.26.16

Name:     libstdc++%compat_gcc_branch
Version:  %lcc_branch.16
Release:  alt1.E2K.1

Summary:  Standard C++ libraries
License:  GPLv3+ with GCC-exception-3.1
Group:    Development/C++
Url:      http://www.mcst.ru/

Source: libstdc++-v3.tar
BuildRequires: gcc-c++ libgcc-devel lcc-libs-common-source = %llcs_ver
ExclusiveArch: %e2k

# This (and the dir for the devel *.so) probably can be whatever place you like,
# because it is not to be used directly, but rather by g++ (lcc) via internal symlinks.
#define gxx_include_dir %%_prefix/include/c++/g++-v3
%define gxx_include_dir %_includedir/c++/g++-v3

%package -n libstdc++%sover
Summary:  Standard C++ libraries for lcc
Group:    Development/C++

%package devel
Summary:  Standard C++ libraries and headers for C++ development
Group:    Development/C++
# (">=" would work
# if we packaged libstdc++%%sover from another srpm with a different version):
Requires: libstdc++%sover >= %EVR

%package devel-static
Summary:  Static standard C++ libraries for C++ development
Group:    Development/C++
# Headers are needed:
Requires: %name-devel = %EVR

%global desc The GNU implementation of the standard C++ libraries tweaked for\
use with lcc. It includes a rewritten implementation of STL.

%description
%desc

%description -n libstdc++%sover
%desc

%description devel
%desc

This package includes libraries and headers needed for C++\
development. %name-devel and g++ (from lcc*-c++) are
not really useful without each other, but their sources are different.

%description devel-static
%desc

This package includes static libraries needed for C++\
development.

%prep
%setup -n libstdc++-v3
tar xf /usr/src/lcc-libs-common-source/%llcs_ver/gcc-%{compat_gcc_branch}.tar --one-top-level=..

%build
#===============================================================================
# Инициализация
%define install_dir_include %_includedir/c++/g++-v3

# К CFLAGS принудительно добавляем -fvisibility=protected (см. bug #81005)
# Причём добавляем спереди, чтобы можно было перебить опцией -fvisibility=default
# (если вдруг понадобится)
%add_optflags -fvisibility=protected

# Из-за системы контроля версий даты изменения файлов нарушаются, и при
# запуске make может быть осуществлена попытка пересоздать "устаревшие"
# компоненты сборки с помощью autotools. Если следующие переменные окружения
# установлены, для переконфигурации будут использованы именно они.
# Устанавливаем их в пустые команды, поскольку реально файлы изменены не были.
export AUTOCONF=:
export AUTOHEADER=:
export AUTOMAKE=:
export ACLOCAL=:

#===============================================================================
# Конфигурация

# CXX и CXXFLAGS устанавливаем так, как это делает GCC.
%global __cxx %__cxx -nostdinc++ -shared-libgcc
%add_optflags -D_GNU_SOURCE

# See how these vars are set in GCC's toplevel configure.ac
# and passed down in Makefile.in (but not necessarily used there).
export AR=%__ar
export AS=%__as
export NM=%__nm
export STRIP=%__strip
export RANLIB=%__ranlib
export CXXFILT=c++filt
export OBJDUMP=%__objdump
export LDFLAGS='%optflags'

# gthr*.h headers are provided by libgcc-devel in /usr/include
sed -i 's|${toplevel_srcdir}/libgcc|/usr/include|g' include/Makefile.{am,in}

# Параметры конфигурации.
# --disable-multilib
#   Отключаем multilib. Не поддерживаются необходимые опции компилятора.
# --disable-nls
#   Отключаем многоязыковую поддержку. Она включает в себя перевод пары строк
#   на французский и немецкий языки. Нам оно ни к чему.
# --disable-libstdcxx-pch
#   Отключаем попытки сборки с использованием PCH. У нас не поддерживается.
# --enable-shared, --disable-shared
#   Подаются в зависимости от того, нужна ли динамеческая версия библиотеки.
# --with-target-subdir is required for config-ml.in to be found properly
%configure \
--with-gxx-include-dir=%gxx_include_dir \
--disable-multilib \
--disable-nls \
--disable-libstdcxx-pch \
--enable-shared \
--with-target-subdir="."

#===============================================================================
# Сборка

%make_build

%install
#===============================================================================
# Установка

%global ptrmode 64
%global ml_subdir /ptr%ptrmode

# Имитируем включение multilib'a, чтобы установка архитектурно-зависимых
# заголовочных файлов прошла в $gxx_include_dir/$host_alias$ml_subdir/bits.
# Подробнее в config-ml.in и libstdc++-v3/include/Makefile.am
sed -i 's:^MULTISUBDIR[ \t]*=.*$:MULTISUBDIR = %ml_subdir:' \
    include/Makefile

# --no-finish подаётся в libtool, чтобы после установки библиотек
# не вызывалась утилита ldconfig.
%makeinstall_std LIBTOOLFLAGS=--no-finish

# Создаём фиксированную ссылку на архитектурно-зависимый каталог. Костыль.
# Ссылка создаём относительную, не абсолютную.
ln -sv %_configure_platform%ml_subdir -T %buildroot%gxx_include_dir/tdep.ptr%ptrmode

cd %buildroot%_libdir
ln -sf libstdc++.so.%sover libstdc++.so
cd ..

%files -n libstdc++%sover
%_libdir/libstdc++.so.%{sover}*

%files devel
%gxx_include_dir
%_libdir/libsupc++.a
%_libdir/libstdc++fs.a
%_libdir/libstdc++.so

%files devel-static
%_libdir/libstdc++.a

%changelog
* Sun Mar 05 2023 Michael Shigorin <mike@altlinux.org> 1.26.16-alt1.E2K.1
- 1.26.16

* Fri Nov 26 2021 Andrew Savchenko <bircoph@altlinux.org> 1.25.20-alt1.E2K.1
- Update to 1.25.20

* Sat May 01 2021 Andrew Savchenko <bircoph@altlinux.org> 1.25.08-alt1.E2K.2
- Add Obsoletes for gcc compat branch 5.

* Wed Sep 09 2020 Andrew Savchenko <bircoph@altlinux.org> 1.25.08-alt1.E2K.1
- Update to 1.25.08

* Tue Jul 28 2020 Andrew Savchenko <bircoph@altlinux.org> 1.25.06-alt1.E2K.1
- Update to 1.25.06

* Tue Jun 16 2020 Andrew Savchenko <bircoph@altlinux.org> 1.24.11-alt1.E2K.1
- Update to 1.24.11
- libstdc++fs.a is now provided

* Mon May 25 2020 Andrew Savchenko <bircoph@altlinux.org> 1.24.07-alt1.E2K.2
- Add -D_GNU_SOURCE to flags: it affects some code.

* Fri May 22 2020 Andrew Savchenko <bircoph@altlinux.org> 1.24.07-alt1.E2K.1
- Update to 1.24.07, source build.

* Wed Apr 10 2019 Andrew Savchenko <bircoph@altlinux.org> 1.23.12-alt2.E2K.2
- Do not remove <future> header as reported by a user.

* Wed Feb 13 2019 Andrew Savchenko <bircoph@altlinux.org> 1.23.12-alt2.E2K.1
- Use so -> soname instead of so -> sofull.

* Sat Jan 19 2019 Andrey Savchenko <bircoph@altlinux.org> 1.23.12-alt2.E2K.0
- Build 1.23.12 from source.

* Sat Nov 17 2018 Andrey Savchenko <bircoph@altlinux.org> 1.23.12-alt1.E2K.0
- Update for 1.23.12 binary version.

* Fri Nov 16 2018 Andrey Savchenko <bircoph@altlinux.org> 1.21.24-alt5.E2K.1
- Build lcc-1.21 compat libs for 1.23 environment.

* Tue Jul 24 2018 Ivan Zakharyaschev <imz@altlinux.org> 1.21.24-alt5.E2K.0
- export LDFLAGS='%%optflags'
  (to pass some flags when making the lib with -shared).

* Wed Jul 04 2018 Ivan Zakharyaschev <imz@altlinux.org> 1.21.24-alt4.E2K.0
- With the goal of separating GPL'd files from non-GPL lcc:
  + Prepared the *-devel{,-static} subpkgs
  + Obsoletes: lcc1.21-libstdc++-devel < 1.21.24-alt8

* Mon Jun 25 2018 Ivan Zakharyaschev <imz@altlinux.org>  1.21.24-alt3.E2K.0
- Build from source (thx MCST's build.sh and modifications).
  (TODO: package the *-devel{,-static} files.)

* Mon May 14 2018 Ivan Zakharyaschev <imz@altlinux.org> 1.21.24-alt2.E2K.0
- The *-devel Provides dropped (in favor of the separate pkg).
- Rename according to Shared Libs Policy.

* Fri Apr 06 2018 Andrew Savchenko <bircoph@altlinux.org> 1.21.24-alt1.E2K.0
Initial release