File: dh_lisp

package info (click to toggle)
dh-lisp 0.6.6
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 72 kB
  • ctags: 2
  • sloc: perl: 136; makefile: 8
file content (249 lines) | stat: -rwxr-xr-x 7,039 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/usr/bin/perl -w

#
# Debhelper to automatically register Common Lisp components
#
#  Copyright (C) 2005, 2006 by René van Bevern
#

=head1 NAME

dh_lisp - register Common Lisp source and implementations

=head1 SYNOPSIS

B<dh_lisp> [S<I<debhelper options>>] [S<I<implementation>>]

=head1 DESCRIPTION

dh_lisp is a debhelper program that is responsible for registering
Common Lisp source and implementations with the Common Lisp Controller.

For Common Lisp library packages dh_lisp will automatically generate the
postinst and prerm commands needed to interface with the Common Lisp
Controller. It also links the given ASDF system definitions
appropriately. It takes into account all ASDs that you installed below
usr/share/common-lisp/source (for example with L<dh_install>(1)).

If dh_lisp finds precompiled files from CLISP, SBCL or CMUCL, it will
add a dependency on the implementation that can read the FASL version
used by the implementation currently installed. (this is most likely
the one which built the binaries in the package)

If you supply I<implementation>, dh_lisp automatically installs the
implementation-specific script, which is expected to reside in
debian/I<implementation>.sh. dh_lisp automatically generates the
necessary maintainer scripts to register the implementation with
the Common Lisp Controller.

=head1 OPTIONS

=over 4

=item B<-n>, B<--noscripts>

do not add to maintainer scripts

=item B<-d>

do not generate dependencies on implementations for binary files in
the package

=item I<implementation>

Install the debian/I<implementation>.sh script and generate maintainer
scripts to (un)register I<implementation> at the Common Lisp Controller.

=back

=head1 NOTES

Note that this command is not idempotent. "dh_clean -k" should be called
between invocations of this command. Otherwise, it may cause multiple
instances of the same text to be added to maintainer scripts.

=head1 SEE ALSO

L<debhelper(7)>,

The Common Lisp in Debian Manual: S<I<http://cl-debian.alioth.debian.org/clid/>>

=head1 AUTHOR

RenE<eacute> van Bevern <rvb@debian.org>

=cut

use strict;
use File::Find;
use Debian::Debhelper::Dh_Lib;

init();

my $common_lisp_systems = "/usr/share/common-lisp/systems/";
my $common_lisp_sources = "/usr/share/common-lisp/source/";
my $common_lisp_bin = "/usr/lib/common-lisp/bin/";

my @interesting_files = ("fasl", "x86f", "asd", "fas");

my %formats = (
    "# FASL" => "sbcl",
    "FASL FILE output from" => "cmucl",
    '\(SYSTEM::VERSION ' => "clisp",
    "\177ELF" => "ecl");

my %version_info = (
    "sbcl" => '--noinform --noprint --eval "(progn (format t \"~A~&\"
               sb-fasl:+fasl-file-version+) (quit))"',
    "cmucl" => '-quiet -noinit -batch -eval "(progn (format t \"~A~&\"
                (c:backend-fasl-file-version c:*backend*)) (quit))"',
    "clisp" => '-x --quiet "(car (system::version))"',
    "ecl" => '-eval "(progn (format t \"~A~&\" (lisp-implementation-version))
              (quit))"'
);

sub make_substvars {
    addsubstvar(shift, "misc:Depends", "common-lisp-controller", ">= 5.11");
}

sub get_type {
    my $filename = shift;

    if ($filename =~ m/.+\.asd$/) {
	return("asd");
    } else {
	open(FILE, $filename) || error("Could not open " . $filename
				       . " for reading");
	my $line = <FILE>;
	foreach my $magic (keys %formats) {
	    if($line =~ m/^$magic/) {
		close(FILE);
		return($formats{$magic});
	    }
	}
	close(FILE);
	return("unknown");
    }
}

foreach my $package (@{$dh{DOPACKAGES}})
{
    my $tmp = tmpdir ($package);
    my %matches;

    # traverse common-lisp/source directory and record interesing
    # files)

    if ( -d $tmp) {
	find(sub {
	    foreach my $format (@interesting_files) {
		if ($File::Find::name !~ /^$tmp$common_lisp_systems.*/
		    && $File::Find::name =~ m/.+\.$format$/) {
		    push(@{$matches{get_type($_)}}, $File::Find::name);
		}
	    }
	}, $tmp);
    }

    if ($matches{"asd"} && @{$matches{"asd"}}) {
	doit("install", "-d", "$tmp/$common_lisp_systems");
	if(! $dh{NOSCRIPTS}) {
	    make_substvars($package);
	}

	# link asd system definitions approprietly and generate
	# maintainer scripts for the common-lisp-controller

	my @registered_dirs;
	foreach my $asdf (@{$matches{"asd"}}) {
	    $asdf =~ s/^(\Q$tmp$common_lisp_sources\E)//;

	    # only register if asd file is in the right direcotry
	    if ($1 && $asdf =~ m:^/?([^/]+)/.+\.asd$: ) {
		my $dir_to_register = $1;

		doit("ln", "-sf", "../source/" . $asdf,
		     ($tmp . $common_lisp_systems . basename($asdf)));

		if((! $dh{NOSCRIPTS}) &&
		   (!grep(/^$dir_to_register$/, @registered_dirs)))
		{
		    autoscript($package, "postinst", "postinst-clc-source",
			       "s/#SYSTEMDIR#/$dir_to_register/g;");

		    autoscript($package, "prerm", "prerm-clc-source",
			       "s/#SYSTEMDIR#/$dir_to_register/g;");

		    push(@registered_dirs, $dir_to_register);
		}
	    }
	}
    }

    # install implementation control script from
    # debian/$implementation.sh and create maintainer scripts for the
    # common-lisp-controller

    my $implementation = shift;
    if(defined $implementation) {
	if ( -f "debian/" . $implementation . ".sh" ) {
	    doit("install", "-d", $tmp . "/" . $common_lisp_bin);
	    doit("install", "debian/" . $implementation . ".sh",
		 ($tmp . $common_lisp_bin));

	    if(! $dh{NOSCRIPTS}) {
		make_substvars($package);

		autoscript($package, "postinst",
			   "postinst-clc-implementation",
			   "s/#IMPLEMENTATION#/$implementation/g;");

		autoscript($package, "prerm",
			   "prerm-clc-implementation",
			   "s/#IMPLEMENTATION#/$implementation/g;");
	    }
	} else {
	    error("Implementation script debian/" . $implementation
		  . ".sh not found: registration with Common "
		  . "Lisp Controller is not possible.");
	}
    }

    # find out fasl versions for implementations and add dependencies
    # to them

    if(! $dh{D_FLAG}) {
	foreach my $impl (keys %matches) {

	    # only add dependencies on implementation if the
	    # implementation is not the one to be installed

	    if($impl ne "unknown" && $impl ne "asd" &&
	       !($implementation && $impl eq $implementation)) {

		if ( -x "/usr/bin/" . $impl ) {
		    my $fasl_version = `$impl $version_info{$impl}`;

		    if ($impl eq "sbcl" || $impl eq "clisp") {
			addsubstvar($package, "misc:Depends",
				    $impl . "-fasl-loader-" . $fasl_version, "");
		    } elsif ($impl eq "cmucl") {
			addsubstvar($package, "misc:Depends", "$impl",
				    ">= " . sprintf("%X", $fasl_version));
			addsubstvar($package, "misc:Depends", "$impl",
				    "< ". sprintf("%X", $fasl_version + 1));
		    } elsif ($impl eq "ecl") {
			addsubstvar($package, "misc:Depends", "$impl",
				    ">= " . $fasl_version);
		    }
		} else {
		    warning("Implementation " . $impl . " seems not to be "
			    . "installed on this system to build the "
			    . "binary files included in this package. If "
			    . "this package is part of the implementation"
			    . "itself, ignore this warning.");
		}
	    }
	}
    }
}