Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libnet-libidn-perl / libnet-libidn-perl-0.07 / Makefile.PL
1 use strict;
2 use ExtUtils::MakeMaker;
3 use Getopt::Long;
4
5 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
6 # the contents of the Makefile that is written.
7
8 my %MakeParams = InitMakeParams();
9 my $options;
10
11 WriteMakefile(%MakeParams);
12
13
14 sub MY::postamble {     
15         "
16 LibIDN.pm: _LibIDN.pm _test.pl
17         perl Makefile.PL $options
18
19 test.pl: _test.pl
20         perl Makefile.PL $options
21 "
22 }
23
24 sub InitMakeParams
25 {
26         my %Params =
27         (
28                 'NAME'                  => 'Net::LibIDN',
29                 'VERSION_FROM'  => 'LibIDN.pm', # finds $VERSION
30                 'PREREQ_PM'             => {}, # e.g., Module::Name => 1.1
31                 ($] >= 5.005 ?  ## Add these new keywords supported since 5.005
32                 (ABSTRACT_FROM  => 'LibIDN.pm', # retrieve abstract from module
33                 AUTHOR                  => 'Thomas Jacob <jacob@internet24.de>') : ()),
34 #               MAN3PODS                => { 'LibIDN.pm' },
35                 PM                              => { 'LibIDN.pm' => '$(INST_LIB)/Net/LibIDN.pm' },
36 #               PL_FILES                => {},
37 #               EXE_FILES               => [],
38                 clean                   => { FILES => "test.pl LibIDN.pm" }
39         );
40         my ($libdir, $incdir, $disable_tld);
41
42         $options=join(' ', @ARGV);
43
44         GetOptions
45         (
46                 "with-libidn=s" => \$libdir,
47                 "with-libidn-inc=s" => \$incdir,
48                 "disable-tld" => \$disable_tld
49         );
50
51         if ($libdir)
52         {
53                 $Params{LIBS} = "-L$libdir -lidn";
54         }
55         else
56         {
57                 $Params{LIBS} = '-lidn';
58         }
59
60         if ($incdir)
61         {
62                 $Params{INC} = "-I$incdir";
63         }
64         else
65         {
66                 $Params{INC} = '';
67         }
68
69         my $libidn = CheckLibidn($Params{INC}, $Params{LIBS});
70
71         die "This module requires GNU Libidn, which could not be found.\n" unless $libidn;
72
73         print "Found LibIDN, ";
74         print $libidn == 1? "without": "with";
75         print " TLD checking support\n";
76
77         if ($libidn == 2 && $disable_tld)
78         {
79                 print "TLD checking support disabled at user request\n";
80         }
81
82         $disable_tld = 1 if ($libidn<2);
83
84         if ($disable_tld)
85         {
86                 $Params{DEFINE} = '';
87         }
88         else
89         {
90                 $Params{DEFINE} = '-DHAVE_TLD';
91         }
92         FilterTLD("_LibIDN.pm", "LibIDN.pm", !$disable_tld);
93         FilterTLD("_test.pl", "test.pl", !$disable_tld);
94
95         return(%Params);
96 }
97
98 sub FilterTLD
99 {
100         my $in = shift;
101         my $out = shift;
102         my $tld = shift;
103         local *IN, *OUT;
104
105         open(IN, "<$in") || die "Can't open file $in\n";
106         open(OUT, ">$out") || die "Can't write file $out\n";
107
108         my ($inside, $else);
109         while(<IN>)
110         {
111                 if (m/^#IF_TLD/)
112                 {
113                         $inside = 1;
114                         next;
115                 }
116                 if (m/^#ELSE_TLD/)
117                 {
118                         $else = 1;
119                         next;
120                 }
121                 if (m/^#ENDIF_TLD/)
122                 {
123                         $inside = 0;
124                         $else = 0;
125                         next;
126                 }
127                 if ($inside)
128                 {
129                         if ($tld)
130                         {
131                                 print OUT $_ unless $else;
132                         }
133                         elsif($else)
134                         {
135                                 print OUT $_;
136                         }
137                 }
138                 else
139                 {
140                         print OUT $_;
141                 }
142                 
143         }
144 }
145
146 sub CheckLibidn
147 {
148         my $cflags = shift;
149         my $ldflags = shift;
150         my $result;
151         my $final;
152         local * FILE;
153
154         my $test1 = <<EOT;
155 #include <idna.h>
156 #include <stdio.h>
157 int main(void)
158 {
159         char * output;
160         int res;
161         
162         res = idna_to_ascii_8z("libidn", &output, 0);
163         printf("%d-%s", res, output);
164 }
165 EOT
166
167         open(FILE, ">__test1.c");
168         print FILE $test1;
169         close(FILE);
170
171         system "cc $cflags $ldflags -o __test1 __test1.c";
172         $final=1 if ($? >> 8);
173
174         unless ($final)
175         {
176                 open(FILE, "./__test1|");
177                 while(<FILE>)
178                 {
179                         $final=1 if $_ ne "0-libidn";
180                 }
181                 close(FILE);
182         }
183         unlink("__test1");
184         unlink("__test1.c");
185
186         return $result if ($final);
187
188         $result = 1;
189
190         my $test2 = <<EOT;
191 #include <tld.h>
192 #include <stdio.h>
193 int main(void)
194 {
195         char * output;
196         int res;
197
198         res =tld_get_z ("libidn.idn", &output); 
199         printf("%d-%s", res, output);
200 }
201 EOT
202
203         open(FILE, ">__test2.c");
204         print FILE $test2;
205         close(FILE);
206
207         system "cc $cflags $ldflags -o __test2 __test2.c ";
208         $final = 1 if ($? >> 8);
209
210         unless ($final)
211         {
212                 open(FILE, "./__test2|");
213                 while(<FILE>)
214                 {
215                         $final = 1 if $_ ne "0-idn";
216                 }
217                 close(FILE);
218         }
219         unlink("__test2");
220         unlink("__test2.c");
221         
222         return $result if $final;
223
224         return 2;
225 }
226