1#!/usr/bin/perl -w
2use strict;
3
4use Config;
5use Storable qw(freeze thaw);
6
7# Lilliput decreed that eggs should be eaten small end first.
8# Belfuscu welcomed the rebels who wanted to eat big end first.
9my $kingdom = $Config{byteorder} =~ /23/ ? "Lillput" : "Belfuscu";
10
11my $frozen = freeze
12  ["This file was written with $Storable::VERSION on perl $]",
13   "$kingdom was correct", (~0 ^ (~0 >> 1) ^ 2),
14   "The End"];
15
16my $ivsize = $Config{ivsize} || $Config{longsize};
17
18my $storesize = unpack 'xxC', $frozen;
19my $storebyteorder = unpack "xxxA$storesize", $frozen;
20
21if ($Config{byteorder} eq $storebyteorder) {
22  my $ivtype = $Config{ivtype} || 'long';
23  print <<"EOM";
24You only need to run this generator program where Config.pm's byteorder string
25is not the same length as the size of IVs.
26
27This length difference should only happen on perl 5.6.x configured with IVs as
28long long on Unix, OS/2 or any platform that runs the Configure stript (ie not
29MS Windows)
30
31This is perl $], sizeof(long) is $Config{longsize}, IVs are '$ivtype', sizeof(IV) is $ivsize,
32byteorder is '$Config{byteorder}', Storable $Storable::VERSION writes a byteorder of '$storebyteorder'
33EOM
34  exit; # Grr '
35}
36
37my ($i, $l, $p, $n) = unpack "xxxx${storesize}CCCC", $frozen;
38
39print <<"EOM";
40# byteorder	 '$storebyteorder'
41# sizeof(int)	 $i
42# sizeof(long)	 $l
43# sizeof(char *) $p
44# sizeof(NV)	 $n
45EOM
46
47my $uu = pack 'u', $frozen;
48
49printf "begin %3o $kingdom,$i,$l,$p,$n\n", ord 'A';
50print $uu;
51print "\nend\n\n";
52