Product SiteDocumentation Site

9.3. Сборка окружения с параметрами

При сборке пакетов иногда необходимо собирать пакеты с разными параметрами конфигурационного окружения (которые описываются флагами configure). Например, пакет сопровождается обширной документацией, для пересборки которой необходим TeXlive, или секция %check выполняется несколько десятков минут. Во время отладки сборки хочется уметь отключать эти ресурсоёмкие действия (или, допустим, наоборот — включать профилирование), не меняя spec-файла. Для этого в сооществе ALT придумали макросы-переключатели %def_enable/%def_with.
Парные к ним макросы %subst_enable/%subst_with превращаются в соответствующий параметр confgure:
[user@VM ~]$ rpm --eval "%def_enable trololo
%{subst_enable trololo}"

--enable-trololo
Значение макроса RPM выставляется в spec-файле, но может быть переопределено из командной строки при запуске, например, rpmbuild … --disable=keypad ….
Добавим возможность включения и выключения режима распознавания функциональных клавиш при сборке. Для этого в spec-файле добавим макрос-переключатель на соответствующий параметр:
@user: autoenv-pkg/autoenv-pkg.spec
%def_enable keypad

Name: autoenv-pkg
Version: 1.0
Release: alt1

Summary: Test pkg with autotool

License: GPL-3.0-or-later
Group: Development/Other

Source0: %name-%version.tar.gz
BuildRequires: libncurses-devel

%description
This is a small testing package, builded by autotools

%prep
%setup

%build
%autoreconf
%configure %{subst_enable keypad}
%make_build

%install
%makeinstall_std

%check
make check

%files
%_bindir/*

%changelog
* Mon Jul 21 2025 UsamG1t <usamg1t@altlinux.org> 1.0-alt1
- Initial build
Соберём пакет с помощью gear-hsh. Заметим, что поскольку по умолчанию макрос определяется, как enabled, сборка без явного указания параметра привела к автоматической подстановке ключа --enable-keypad:
@user
[user@VM autoenv-pkg]$ gear-hsh -v
<...>
+ ./configure --build=x86_64-alt-linux --host=x86_64-alt-linux --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/lib --localstatedir=/var/lib --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --disable-dependency-tracking --disable-silent-rules --runstatedir=/var/run --without-included-gettext --enable-keypad
<...>
Wrote: /usr/src/RPM/SRPMS/autoenv-pkg-1.0-alt1.src.rpm (w2.lzdio)
Wrote: /usr/src/RPM/RPMS/x86_64/autoenv-pkg-1.0-alt1.x86_64.rpm (w2.lzdio)
Wrote: /usr/src/RPM/RPMS/x86_64/autoenv-pkg-debuginfo-1.0-alt1.x86_64.rpm (w2.lzdio)
4.09user 3.23system 0:11.55elapsed 63%CPU (0avgtext+0avgdata 23496maxresident)k
576inputs+5800outputs (0major+381106minor)pagefaults 0swaps
[user@VM autoenv-pkg]$
Установим пакет в hasher и проверим распознавание функциональных клавиш. Для этого воспользуемся сценарием hypersh, с помощью которого развернём пакет с исходным кодом в окружении и установим зависимости для пакета:
@user
[user@VM ~]$ hypersh hasher/repo/SRPMS.hasher/autoenv-pkg-1.0-alt1.src.rpm
<...>
<13>Jul 24 20:52:04 rpmi: libncurses6-6.3.20220618-alt4 sisyphus+327286.4600.14.1 1711486705 installed
<13>Jul 24 20:52:04 rpmi: libtinfo-devel-6.3.20220618-alt4 sisyphus+327286.4600.14.1 1711486705 installed
<13>Jul 24 20:52:04 rpmi: libncurses-devel-6.3.20220618-alt4 sisyphus+327286.4600.14.1 1711486705 installed
<...>
[builder@localhost .in]$
logout
[user@VM ~]$ cp hasher/repo/x86_64/RPMS.hasher/autoenv-pkg-1.0-alt1.x86_64.rpm hasher/chroot/.in
[user@VM ~]$ hypersh --rooter
mesg: /dev/pts/0: Read-only file system
[root@localhost .in]# rpm -i autoenv-pkg-1.0-alt1.x86_64.rpm
<13>Jul 24 20:52:58 rpm: autoenv-pkg-1.0-alt1 1753389819 installed

[root@localhost .in]# which autoenv
/usr/bin/autoenv
[root@localhost .in]#
autoenv
autoenv-pkg-1.0 (UsamG1t)


  ┌───────────────────────────────────────┐
  │ Key: 68, Name: D                      │
  │ Key: 100, Name: d                     │
  │ Key: 265, Name: KEY_F(1)              │
  │ Key: 266, Name: KEY_F(2)              │
  │ Key: 267, Name: KEY_F(3)              │
  │ Key: 268, Name: KEY_F(4)              │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  └───────────────────────────────────────┘
Теперь соберём пакет прямо в hasher с явным указанием выключенного keypad:
@builder
[builder@localhost ~]$ tree -A
.
├── RPM
│   ├── BUILD
│   ├── RPMS
│   │   └── noarch
│   ├── SOURCES
│   │   └── autoenv-pkg-1.0.tar.gz
│   ├── SPECS
│   │   └── autoenv-pkg.spec
│   └── SRPMS
├── debug
├── in
│   ├── SOURCE_DATE_EPOCH
│   ├── nosrpm
│   │   └── autoenv-pkg-1.0-alt1.nosrc.rpm
│   └── srpm
│       └── autoenv-pkg-1.0-alt1.src.rpm
└── tmp

13 directories, 5 files
[builder@localhost ~]$ rpmbuild -ba --disable=keypad RPM/SPECS/autoenv-pkg.spec
<...>
+ ./configure --build=x86_64-alt-linux --host=x86_64-alt-linux --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/lib --localstatedir=/var/lib --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --disable-dependency-tracking --disable-silent-rules --runstatedir=/var/run --without-included-gettext --disable-keypad
<...>
Wrote: /usr/src/RPM/SRPMS/autoenv-pkg-1.0-alt1.src.rpm (w2.lzdio)
Wrote: /usr/src/RPM/RPMS/x86_64/autoenv-pkg-1.0-alt1.x86_64.rpm (w2.lzdio)
Wrote: /usr/src/RPM/RPMS/x86_64/autoenv-pkg-debuginfo-1.0-alt1.x86_64.rpm (w2.lzdio)
[builder@localhost ~]$
Установим эту версию пакета и убедимся, что функциональные клавиши не опознаются:
@rooter
[root@localhost .in]# rpm -i /usr/src/RPM/RPMS/x86_64/autoenv-pkg-1.0-alt1.x86_64.rpm
<13>Jul 24 21:07:51 rpm: autoenv-pkg-1.0-alt1 1753391141 installed

[root@localhost .in]# which autoenv
/usr/bin/autoenv
[root@localhost .in]# ls -la /usr/bin/autoenv
-rwxr-xr-x 1 root root 14608 Jul 24 21:05 /usr/bin/autoenv
[root@localhost .in]# date
Thu Jul 24 21:08:23 UTC 2025
[root@localhost .in]#
autoenv
autoenv-pkg-1.0 (UsamG1t)


  ┌───────────────────────────────────────┐
  │ Key: 68, Name: D                      │
  │ Key: 100, Name: d                     │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  └───────────────────────────────────────┘
Поскольку функциональные клавиши больше не считываются как символы для вывода, программа автоматически завершается при получении соответствующего сигнала.
Второй параметр сборки — frame — требует задавать некоторое значение. Явно укажем его в качестве параметра configure, а для определения будем использовать специальную ifdef-конструкцию: configure … --enable-frame=%{?framewidth:%framewidth}%{!?framewidth:3}. Тогда при вызове rpmbuild можно будет переопределить значение макроса с помощью rpmbuild --define 'framewidth 20' …, а при его отсутствии будет использоваться значение по умолчанию.
Добавим обработку frame в наш пакет:
@user: autoenv-pkg/autoenv-pkg.spec
%def_enable keypad

Name: autoenv-pkg
Version: 1.0
Release: alt1

Summary: Test pkg with autotool

License: GPL-3.0-or-later
Group: Development/Other

Source0: %name-%version.tar.gz
BuildRequires: libncurses-devel

%description
This is a small testing package, builded by autotools

%prep
%setup

%build
%autoreconf
%configure %{subst_enable keypad} --enable-frame=%{?framewidth:%framewidth}%{!?framewidth:3}

%make_build

%install
%makeinstall_std

%check
make check

%files
%_bindir/*

%changelog
* Mon Jul 21 2025 UsamG1t <usamg1t@altlinux.org> 1.0-alt1
- Initial build
Соберём пакет через gear-hsh и установим его в hasher:
@user
[user@VM autoenv-pkg]$ gear-hsh -v
<...>
+ ./configure --build=x86_64-alt-linux --host=x86_64-alt-linux --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/lib --localstatedir=/var/lib --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --disable-dependency-tracking --disable-silent-rules --runstatedir=/var/run --without-included-gettext --enable-keypad --enable-frame=3
<...>
[user@VM autoenv-pkg]$
@user
[user@VM ~]$ hypersh hasher/repo/SRPMS.hasher/autoenv-pkg-1.0-alt1.src.rpm
<...>
<13>Jul 24 21:25:13 rpmi: libncurses6-6.3.20220618-alt4 sisyphus+327286.4600.14.1 1711486705 installed
<13>Jul 24 21:25:13 rpmi: libtinfo-devel-6.3.20220618-alt4 sisyphus+327286.4600.14.1 1711486705 installed
<13>Jul 24 21:25:13 rpmi: libncurses-devel-6.3.20220618-alt4 sisyphus+327286.4600.14.1 1711486705 installed
<...>
[builder@localhost .in]$
logout
[user@VM ~]$ cp hasher/repo/x86_64/RPMS.hasher/autoenv-pkg-1.0-alt1.x86_64.rpm hasher/chroot/.in
[user@VM ~]$ hypersh --rooter
mesg: /dev/pts/0: Read-only file system
[root@localhost .in]# rpm -i autoenv-pkg-1.0-alt1.x86_64.rpm
<13>Jul 24 21:26:25 rpm: autoenv-pkg-1.0-alt1 1753392208 installed

[root@localhost .in]#
autoenv
autoenv-pkg-1.0 (UsamG1t)


  ┌───────────────────────────────────────┐
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  │                                       │
  └───────────────────────────────────────┘
Аналогично соберём пакет с другим размером рамки:
@builder
[builder@localhost ~]$ rpmbuild -ba --define 'framewidth 20' RPM/SPECS/autoenv-pkg.spec
<...>
+ ./configure --build=x86_64-alt-linux --host=x86_64-alt-linux --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/lib --localstatedir=/var/lib --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --disable-dependency-tracking --disable-silent-rules --runstatedir=/var/run --without-included-gettext --enable-keypad --enable-frame=20
<...>
Wrote: /usr/src/RPM/SRPMS/autoenv-pkg-1.0-alt1.src.rpm (w2.lzdio)
Wrote: /usr/src/RPM/RPMS/x86_64/autoenv-pkg-1.0-alt1.x86_64.rpm (w2.lzdio)
Wrote: /usr/src/RPM/RPMS/x86_64/autoenv-pkg-debuginfo-1.0-alt1.x86_64.rpm (w2.lzdio)
[builder@localhost ~]$
@rooter
[root@localhost .in]# rpm -i --replacefiles /usr/src/RPM/RPMS/x86_64/autoenv-pkg-1.0-alt1.x86_64.rpm
<13>Jul 28 06:28:55 rpm: autoenv-pkg-1.0-alt1 1753683871 installed
[root@localhost .in]#
autoenv
autoenv-pkg-1.0 (UsamG1t)



















                   ┌───────────────────────────────────────┐
                   │                                       │
                   │                                       │
                   │                                       │
                   │                                       │
                   │                                       │
                   │                                       │
                   │                                       │
                   │                                       │
                   │                                       │
                   │                                       │
                   │                                       │
                   └───────────────────────────────────────┘