| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
# dh_octave_substvar: Generate variables ${octave:Depends} and |
| 4 |
# ${octave:Upstream-Description} for Octave add-on |
| 5 |
# Debian packages. Also, adds the virtual package |
| 6 |
# octave-abi-N to ${shlibs:Depends} |
| 7 |
# |
| 8 |
# This file is part of the dh-octave Debian package and was also part |
| 9 |
# of the deprecated octave-pkg-dev package. |
| 10 |
|
| 11 |
# Copyright (c) 2018, 2019, 2022, 2025 Rafael Laboissière <[email protected]> |
| 12 |
# |
| 13 |
# This program is free software; you can redistribute it and/or modify |
| 14 |
# it under the terms of the GNU General Public License as published by |
| 15 |
# the Free Software Foundation; either version 3 of the License, or |
| 16 |
# (at your option) any later version. |
| 17 |
# |
| 18 |
# This program is distributed in the hope that it will be useful, |
| 19 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
# GNU General Public License for more details. |
| 22 |
# |
| 23 |
# You should have received a copy of the GNU General Public License along |
| 24 |
# with this program; if not, see <https://www.gnu.org/licenses/>. |
| 25 |
|
| 26 |
=encoding utf8 |
| 27 |
|
| 28 |
=head1 NAME |
| 29 |
|
| 30 |
dh_octave_substvar - generate substitution variables for an Octave add-on package |
| 31 |
|
| 32 |
=cut |
| 33 |
|
| 34 |
use strict; |
| 35 |
use Debian::Debhelper::Dh_Lib; |
| 36 |
use MIME::Head; |
| 37 |
use File::Find::Rule; |
| 38 |
use Text::Wrapper; |
| 39 |
|
| 40 |
init (); |
| 41 |
|
| 42 |
=head1 SYNOPSIS |
| 43 |
|
| 44 |
B<dh_octave_substvar> [S<I<debhelper options>>] |
| 45 |
|
| 46 |
=head1 DESCRIPTION |
| 47 |
|
| 48 |
B<dh_octave_substvar> generates the substitution variables |
| 49 |
C<${octave:Depends}>, C<${octave:Recommends}>, and |
| 50 |
C<${octave:Upstream-Description}> needed for building an Octave add-on |
| 51 |
Debian package. It also injects the dependency on the appropriate |
| 52 |
virtual package octave-abi-N into C<${shlibs:Depends}>, for packages |
| 53 |
that contain *.oct and *.mex, according to the current Octave's |
| 54 |
API_VERSION. |
| 55 |
|
| 56 |
=cut |
| 57 |
|
| 58 |
sub find_oct_or_mex { |
| 59 |
my $F = $File::Find::name; |
| 60 |
if ($F =~ /\.oct$/ or $F =~ /\.mex$/ ) { |
| 61 |
print "$F\n"; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
sub process_dependencies { |
| 66 |
my $value = shift; |
| 67 |
my %relations = (); |
| 68 |
map { |
| 69 |
if (/([^ ]+) \((.*)\)/) { |
| 70 |
my $pkg = $1 eq "octave" ? $1 : "octave-$1"; |
| 71 |
my $ver = $2; |
| 72 |
my $out = qx{apt-cache show $pkg | grep ^Version: | head -n1}; |
| 73 |
chomp $out; |
| 74 |
my $epoch = ""; |
| 75 |
if ($out =~ /^Version: (\d+):.*/) { |
| 76 |
$epoch = "$1:"; |
| 77 |
} |
| 78 |
$ver =~ s/(\d)/$epoch$1/; |
| 79 |
$relations {$pkg} = $ver; |
| 80 |
} else { |
| 81 |
## Remove trailing newline, see Bug#1025714 |
| 82 |
chomp; |
| 83 |
## At 2026-08-12, no package has an unversioned octave dependency, |
| 84 |
## but stay on the safe side. |
| 85 |
my $pkg = $_ eq "octave" ? $_ : "octave-$_"; |
| 86 |
$relations {$pkg} = ""; |
| 87 |
} |
| 88 |
} split (", ", $value); |
| 89 |
return %relations; |
| 90 |
} |
| 91 |
|
| 92 |
my %depends = (); |
| 93 |
my %recommends = (); |
| 94 |
my $desc = ""; |
| 95 |
|
| 96 |
### Prefix for the Octave ABI virtual package name |
| 97 |
my $octave_abi_pkg_prefix = "octave-abi-"; |
| 98 |
|
| 99 |
if (-f "DESCRIPTION") { |
| 100 |
|
| 101 |
my $fields = MIME::Head->new->from_file ("DESCRIPTION"); |
| 102 |
|
| 103 |
my $deps = $fields->get ('depends'); |
| 104 |
if (defined $deps) { |
| 105 |
%depends = process_dependencies ($deps) |
| 106 |
} |
| 107 |
if (!exists $depends {"octave"}) { |
| 108 |
## Ensure that there is a dependency on octave, if the DESCRIPTION file |
| 109 |
## does not contain one (e.g. octave-iso2mesh as of 2026-08-12) |
| 110 |
$depends {"octave"} = ""; |
| 111 |
} |
| 112 |
|
| 113 |
my $optdeps = $fields->get ('optionaldepends'); |
| 114 |
if (defined $optdeps) { |
| 115 |
%recommends = process_dependencies ($optdeps) |
| 116 |
} |
| 117 |
|
| 118 |
$desc = $fields->get ('description'); |
| 119 |
$desc =~ s/\n */ /g; |
| 120 |
my $wrapper = Text::Wrapper->new (columns => 75); |
| 121 |
$desc = $wrapper->wrap ($desc); |
| 122 |
chomp $desc; |
| 123 |
$desc =~ s/\n/\${Newline}/g; |
| 124 |
|
| 125 |
} |
| 126 |
|
| 127 |
### Get the current ABI verson of Octave |
| 128 |
my $api_version = qx {/usr/bin/mkoctfile --print API_VERSION}; |
| 129 |
$api_version =~ s/api-v//; |
| 130 |
chomp $api_version; |
| 131 |
|
| 132 |
foreach my $package (@{$dh{DOPACKAGES}}) { |
| 133 |
delsubstvar ($package, 'octave:Depends'); |
| 134 |
for my $pkg (keys %depends) { |
| 135 |
# add dependencies from the DESCRIPTION file |
| 136 |
addsubstvar ($package, 'octave:Depends', $pkg, $depends {$pkg}); |
| 137 |
} |
| 138 |
|
| 139 |
delsubstvar ($package, 'octave:Recommends'); |
| 140 |
for my $pkg (keys %recommends) { |
| 141 |
# add optional dependencies from the DESCRIPTION file |
| 142 |
addsubstvar ($package, 'octave:Recommends', $pkg, $recommends {$pkg}); |
| 143 |
} |
| 144 |
|
| 145 |
## Add the appropiate octave-abi-N dependency if the package contains |
| 146 |
## dynamically loadable files (*,oct and *.mex). |
| 147 |
my $dir = "debian/$package"; |
| 148 |
my @oct_files = File::Find::Rule->file()->name('*.oct')->in($dir); |
| 149 |
my @mex_files = File::Find::Rule->file()->name('*.mex')->in($dir); |
| 150 |
if (scalar @oct_files > 0 or scalar @mex_files > 0) { |
| 151 |
addsubstvar ($package, 'shlibs:Depends', "$octave_abi_pkg_prefix$api_version"); |
| 152 |
} |
| 153 |
delsubstvar ($package, 'octave:Upstream-Description'); |
| 154 |
addsubstvar ($package, 'octave:Upstream-Description', $desc); |
| 155 |
} |
| 156 |
|
| 157 |
=head1 SEE ALSO |
| 158 |
|
| 159 |
L<debhelper(7)>, L<dh(1)>, L<dh_octave_clean(1)>, L<dh_octave_check(1)>, |
| 160 |
L<dh_octave_version(1)>, L<dh_octave_changelogs(1)>, , L<dh_octave_examples(1)> |
| 161 |
|
| 162 |
This program is meant to be used together with debhelper for Debian |
| 163 |
packages derived from Octave add-on packages. |
| 164 |
It is recommended to enable it by adding the dh-sequence-octave |
| 165 |
virtual package to Build-Depends, Build-Depends-Arch or |
| 166 |
Build-Depends-Indep. |
| 167 |
This is equivalent to adding dh-octave to the same field and adding |
| 168 |
--with=octave to the dh sequencer in debian/rules, except that only |
| 169 |
-arch/-indep/profiled builds are affected. |
| 170 |
This is also slightly more simple in the most common case. |
| 171 |
|
| 172 |
=head1 AUTHOR |
| 173 |
|
| 174 |
Rafael Laboissière <[email protected]> |
| 175 |
|
| 176 |
=cut |
| 177 |
|
| 178 |
exit; |
| 179 |
|
| 180 |
# Local Variables: |
| 181 |
# indent-tabs-mode: nil |
| 182 |
# tab-width: 4 |
| 183 |
# End: |