diff --git a/debian/changelog b/debian/changelog index aefbf06..9a247bd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +osmo-smalltalk (1-2) unstable; urgency=low + + * Fix the dependencies between star files by using script from gst. + + -- Holger Freyther Fri, 12 Oct 2012 13:15:38 +0200 + osmo-smalltalk (1-1) unstable; urgency=low * Package all of the Smalltalk for Osmocom. diff --git a/debian/control b/debian/control index d0341e3..f1313cb 100644 --- a/debian/control +++ b/debian/control @@ -10,61 +10,61 @@ Homepage: http://osmocom.org Package: osmo-st-asn1 Architecture: all -Depends: ${misc:Depends} +Depends: ${misc:Depends} ${gst:Depends} Description: TODO Package: osmo-st-core Architecture: all -Depends: ${misc:Depends} +Depends: ${misc:Depends} ${gst:Depends} Description: TODO Package: osmo-st-gsm Architecture: all -Depends: ${misc:Depends} +Depends: ${misc:Depends} ${gst:Depends} Description: TODO Package: osmo-st-logging Architecture: all -Depends: ${misc:Depends} +Depends: ${misc:Depends} ${gst:Depends} Description: TODO Package: osmo-st-mgcp Architecture: all -Depends: ${misc:Depends} +Depends: ${misc:Depends} ${gst:Depends} Description: TODO Package: osmo-st-msc Architecture: all -Depends: ${misc:Depends} +Depends: ${misc:Depends} ${gst:Depends} Description: TODO Package: osmo-st-network Architecture: all -Depends: ${misc:Depends} +Depends: ${misc:Depends} ${gst:Depends} Description: TODO Package: osmo-st-sip Architecture: all -Depends: ${misc:Depends} +Depends: ${misc:Depends} ${gst:Depends} Description: TODO Package: osmo-st-testphone Architecture: all -Depends: ${misc:Depends} +Depends: ${misc:Depends} ${gst:Depends} Description: TODO Package: petitparser Architecture: all -Depends: ${misc:Depends} +Depends: ${misc:Depends} ${gst:Depends} Description: TODO Package: petitparser-tests Architecture: all -Depends: ${misc:Depends} +Depends: ${misc:Depends} ${gst:Depends} Description: TODO Package: soapopera Architecture: all -Depends: ${misc:Depends} +Depends: ${misc:Depends} ${gst:Depends} Description: TODO diff --git a/debian/dh_fixstars b/debian/dh_fixstars new file mode 100644 index 0000000..a0a4eaa --- /dev/null +++ b/debian/dh_fixstars @@ -0,0 +1,125 @@ +#!/usr/bin/perl -w + +=head1 NAME + +dh_fixstars - fixes GNU Smalltalk archives (.star) + +=cut + +use strict; +use File::Find; +use Debian::Debhelper::Dh_Lib; +#use Dpkg::Arch qw(get_raw_host_arch debarch_to_multiarch); +use Dpkg::Arch qw(get_raw_host_arch); + +=head1 SYNOPSIS + +B [S>] + +=head1 DESCRIPTION + +dh_fixstars is a debhelper program that is responsible for fixing +things when using .star files. + +Today, it creates missing symlinks for dlopen()'ed shared libraries +so that the .star file work without the associated -dev package. + +For instance, NCurses.star loads libncurses.so + +=cut + +init(); + +my $pwd = `pwd`; +chomp $pwd; + +verbose_print("Loading shlibs..."); +my %shlibdata; + +open(SHLIBS, "cat /var/lib/dpkg/info/*.shlibs debian/shlibs.local debian/*/DEBIAN/shlibs 2> /dev/null |"); + +while () { + /(\S+)\s+(\S+)\s+(\w.*)\n?/; + $shlibdata{$1} = "$1.so.$2"; +} + +close(SHLIBS); + +foreach my $package (@{$dh{DOPACKAGES}}) { + my $tmp = tmpdir($package); + + find(sub { + return unless -f && !-l && /\.star$/; + add_symlinks($tmp, $_); + }, $tmp + ); +} + +sub path_to_shlib { + my $lib = shift; + #my $multiarch_dir = debarch_to_multiarch(get_raw_host_arch()); + my %dirs = ( + "/lib/$lib" => "/lib/$lib", + "/usr/lib/$lib" => "../$lib", +# "/usr/lib/$multiarch_dir/$lib" => "../$multiarch_dir/$lib", +# "/lib/$multiarch_dir/$lib" => "/lib/$multiarch_dir/$lib" + ); + + # Found path; can be empty. + my $path; + + while (my ($k, $v) = each(%dirs)) { + if (-e "$k") { + $path = "$v"; + last; + } + } + + return $path; +} + +sub add_symlinks { + my $tmp = shift; + my $star_file = shift; + + open(PACKAGEXML, "unzip -p $star_file package.xml |"); + + while() { + chomp; + + # Package that loads a library at runtime, with dlopen() + if (/(\S+)<\/library>/) { + my $sym = "$pwd/$tmp/usr/lib/gnu-smalltalk/$1.so"; + my $lib = $shlibdata{$1}; + + if ($lib) { + my $target = path_to_shlib($lib); + if ($target) { + doit("rm", "-f", "$sym"); + doit("mkdir", "-p", "$pwd/$tmp/usr/lib/gnu-smalltalk"); + doit("ln", "-s", "$target", "$sym"); + doit("chown", "--no-dereference", "0:0", "$sym"); + } else { + error("Can't find \"$lib\" (\"$1\" in \"$star_file\")!"); + } + + } else { + error("Unknown library \"$1\" in \"$star_file\"!"); + } + } + } + + close(PACKAGEXML); +} + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +Thomas Girard , heavily based on code from +Mirco Bauer and Eduard Bloch +for dh_clideps. + +=cut diff --git a/debian/dh_makestarlibs b/debian/dh_makestarlibs new file mode 100644 index 0000000..6e4faee --- /dev/null +++ b/debian/dh_makestarlibs @@ -0,0 +1,117 @@ +#!/usr/bin/perl -w + +=head1 NAME + +dh_makestarlibs - creates starlibs files for GNU Smalltalk archives + +=cut + +use strict; +use Debian::Debhelper::Dh_Lib; + +=head1 SYNOPSIS + +B [S>] + +=head1 DESCRIPTION + +dh_makestarlibs is a debhelper script that is responsible for generating +starlibs files that will be used to compute GNU SmallTalk ARchives +(.star files) dependencies. + +=cut + +init(); + +foreach my $package (@{$dh{DOPACKAGES}}) { + next if is_udeb($package); + + my $tmp = tmpdir($package); + my %seen; + + doit("rm", "-f", "$tmp/DEBIAN/starlibs"); + + if (-e "debian/$package.starlibs") { + complex_doit("cat debian/$package.starlibs > $tmp/DEBIAN/starlibs"); + } else { + open(FIND, "find $tmp -type f -name '*.star' |"); + + while () { + chomp; + my $starchive = $_; + $starchive =~ s,.*/([^/]+)\.star$,$1,; + + if (!-d "$tmp/DEBIAN") { + doit("install", "-d", "$tmp/DEBIAN"); + } + + my $deps = depends($package); + my $line = "$starchive $deps"; + + if (!$seen{$line}) { + $seen{$line} = 1; + complex_doit("echo '$line' >> $tmp/DEBIAN/starlibs"); + } + } + + close FIND; + + # Support packages.xml + if (open(META, "$tmp/usr/share/gnu-smalltalk/packages.xml")) { + my @lines = ; + my $content = join("", @lines); + + if (my @pkgs = $content =~ m,\s*(\w+),gi) { + foreach my $p (@pkgs) { + verbose_print("adding virtual package $p"); + my $deps = depends($package); + complex_doit("echo '$p $deps' >> $tmp/DEBIAN/starlibs"); + } + } + } + + if (-e "$tmp/DEBIAN/starlibs") { + doit("chmod", 644, "$tmp/DEBIAN/starlibs"); + doit("chown", "0:0", "$tmp/DEBIAN/starlibs"); + } + } +} + +sub depends { + my $package = shift; + my $deps = $package; + + # Call isnative because it sets $dh{VERSION} + # as a side effect. + isnative($package); + my $version = $dh{VERSION}; + + # Old compatibility levels include the + # debian revision, while new do not. + if (!compat(3)) { + # Remove debian version, if any. + $version =~ s/-[^-]+$//; + } + + if ($dh{V_FLAG_SET}) { + if ($dh{V_FLAG} ne '') { + $deps = $dh{V_FLAG}; + } else { + $deps = "$package (>= $version)"; + } + } + + return $deps; +} + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +Thomas Girard , heavily based on code from +Mirco Bauer and Eduard Bloch +for dh_makeclilibs. + +=cut diff --git a/debian/dh_stardeps b/debian/dh_stardeps new file mode 100644 index 0000000..b184de3 --- /dev/null +++ b/debian/dh_stardeps @@ -0,0 +1,146 @@ +#!/usr/bin/perl -w + +=head1 NAME + +dh_stardeps - calculates GNU Smalltalk archives (.star) dependencies + +=cut + +use strict; +use File::Find; +use Debian::Debhelper::Dh_Lib; + +=head1 SYNOPSIS + +B [S>] + +=head1 DESCRIPTION + +dh_stardeps is a debhelper program that is responsible for generating the +${gst:Depends} substitutions and adding them to substvars files. + +The program wil look at .star files in your package, and will use the +dependency information generated by dh_makestarlibs to compute the +${gst:Depends} variable. + +=cut + +init(); + +verbose_print("Loading starlibs..."); +my %starlibdata; + +open(STARLIBS, "cat /var/lib/dpkg/info/*.starlibs debian/*/DEBIAN/starlibs 2> /dev/null |"); + +while () { + /(\S+)\s+(\w.*)\n?/; + $starlibdata{$1} = $2; +} + +close(STARLIBS); + +verbose_print("Loading shlibs..."); +my %shlibdata; + +open(SHLIBS, "cat /var/lib/dpkg/info/*.shlibs debian/shlibs.local debian/*/DEBIAN/shlibs 2> /dev/null |"); + +while () { + /(\S+)\s+(\S+)\s+(\w.*)\n?/; + $shlibdata{$1} = $3; +} + +close(SHLIBS); + +foreach my $package (@{$dh{DOPACKAGES}}) { + my $tmp = tmpdir($package); + my @depends = (); + + # for idempotency + delsubstvar($package, "gst:Depends"); + + find(sub { + return unless -f && !-l && /\.star$/; + my $file = $_; + push(@depends, resolve_starlib_ref($package, $file)); + }, $tmp + ); + + @depends = unique(@depends); + + addsubstvar($package, "gst:Depends", join(", ", @depends)); +} + +sub resolve_starlib_ref { + my $package = shift; + my $star_file = shift; + my @deps = (); + my $in_test = 0; + + open(PACKAGEXML, "unzip -p $star_file package.xml |"); + + while() { + chomp; + + if (//) { + $in_test = 1; + } elsif (/<\/test>/) { + $in_test = 0; + } + + # Handle prereq packages -- but not for tests + elsif (/(\S+)<\/prereq>/ and not $in_test) { + my $dep = $starlibdata{$1}; + + if ($dep) { + if ($dep !~ m/^$package(?:\s+.+)?$/) { + push(@deps, $dep); + } + } else { + error("Unknown dependency \"$1\" in \"$star_file\"!"); + } + + # Package with unit tests; depends on SUnit. This dependency might + # already be captured, but we'll remove duplicates later. + } elsif (//) { + if (exists($starlibdata{"SUnit"})) { + # Only if this is not the package containing SUnit already + if ($starlibdata{"SUnit"} !~ m/^$package(?:\s+.+)?$/) { + push(@deps, $starlibdata{"SUnit"}); + } + } else { + warning("Unable to store SUnit dependency for \"$star_file\""); + } + + # Package that loads a library at runtime, with dlopen() + } elsif (/(\S+)<\/library>/) { + my $lib = $shlibdata{$1}; + + if ($lib) { + push(@deps, $lib); + } else { + error("Unknown library dependency \"$1\" in \"$star_file\"!"); + } + } + } + + close(PACKAGEXML); + + return @deps; +} + +sub unique { + my %seen = (); + return grep(!$seen{$_}++, @_); +} + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +Thomas Girard , heavily based on code from +Mirco Bauer and Eduard Bloch +for dh_clideps. + +=cut diff --git a/debian/rules b/debian/rules index 3322298..c0619b4 100755 --- a/debian/rules +++ b/debian/rules @@ -27,3 +27,11 @@ override_dh_auto_install: build $(MAKE) GST_PACKAGE_ARGS="--destdir $(CURDIR)/debian/tmp" install +override_dh_installdeb: + perl -w debian/dh_makestarlibs -i -V + dh_installdeb -i + +override_dh_gencontrol: + perl -w debian/dh_stardeps -i + perl -w debian/dh_fixstars -i + dh_gencontrol -i