File: Makefile.PL

package info (click to toggle)
libhttp-ghttp-perl 1.07-10
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 96 kB
  • ctags: 11
  • sloc: perl: 143; makefile: 56
file content (185 lines) | stat: -rw-r--r-- 4,161 bytes parent folder | download | duplicates (3)
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
# $Id: Makefile.PL,v 1.8 2001/01/17 15:39:41 matt Exp $

use ExtUtils::MakeMaker;
use Config;
use Symbol;

$|=0;

my %config;

while($_ = shift) {
    my ($key, $val) = split(/=/, $_, 2);
    $config{$key} = $val;
}

my $DEBUG = delete $config{DEBUG};

# get libs and inc from gnome-config
eval {
    print "running gnome-config... ";
    $config{LIBS} ||= backtick('gnome-config --libs ghttp');
    $config{INC} ||= backtick('gnome-config --cflags ghttp');
    print "ok\n";
};
if ($@) {
    print "failed\n";
    warn "*** ", $@ if $DEBUG;
    warn "using fallback values for LIBS and INC\n";
    # backtick fails if gnome-config didn't exist...
    $config{LIBS} = '-L/usr/local/lib -L/usr/lib -lghttp';
    $config{INC} = '-I/usr/local/include -I/usr/include';
    
    print <<OPT;
options:
  LIBS='$config{LIBS}'
  INC='$config{INC}'
If this is wrong, Re-run as:
  \$ $^X Makefile.PL LIBS='-L/path/to/lib' INC='-I/path/to/include'

OPT

}

my $LINK = "$Config{ld} -o conftest %s conftest.c %s %s";

if ($config{LIBS} !~ /\-lghttp/) {
    $config{LIBS} .= ' -lghttp';
}

if (!have_library("ghttp")) {
    die <<DEATH;
libghttp not found
Try setting LIBS and INC values on the command line
Or get libghttp from 
  ftp://ftp.gnome.org/pub/GNOME/stable/sources/libghttp/
DEATH
}

have_library("ghttp", "ghttp_get_header_names");

WriteMakefile(
    'NAME'	=> 'HTTP::GHTTP',
    'VERSION_FROM' => 'GHTTP.pm', # finds $VERSION
    'AUTHOR'    => 'Matt Sergeant',
    'ABSTRACT'  => 'Interface to Gnome libghttp HTTP 1.1 client library',
    #'EXE_FILES' => [ 'scripts/g-request' ],
    %config,
);

###################################################################
# Functions
#  - these should really be in MakeMaker... But &shrug;
###################################################################

sub rm_f {
    my @files = @_;
    my @realfiles;
    foreach (@files) {
        push @realfiles, glob($_);
    }
    if (@realfiles) {
        chmod(0777, @realfiles);
        unlink(@realfiles);
    }
}

sub xsystem {
    my $command = shift;
    if ($DEBUG) {
        print $command, "\n";
        if (system($command) != 0) {
            die "system call to '$command' failed";
        }
        return 1;
    }
    open(OLDOUT, ">&STDOUT");
    open(OLDERR, ">&STDERR");
    open(STDOUT, ">/dev/null");
    open(STDERR, ">/dev/null");
    my $retval = system($command);
    open(STDOUT, ">&OLDOUT");
    open(STDERR, ">&OLDERR");
    if ($retval != 0) {
        die "system call to '$command' failed";
    }
    return 1;
}

sub backtick {
    my $command = shift;
    if ($DEBUG) {
        print $command, "\n";
        my $results = `$command`;
        chomp $results;
        if ($? != 0) {
            die "backticks call to '$command' failed";
        }
        return $results;
    }
    open(OLDOUT, ">&STDOUT");
    open(OLDERR, ">&STDERR");
    open(STDOUT, ">/dev/null");
    open(STDERR, ">/dev/null");
    my $results = `$command`;
    my $retval = $?;
    open(STDOUT, ">&OLDOUT");
    open(STDERR, ">&OLDERR");
    if ($retval != 0) {
        die "backticks call to '$command' failed";
    }
    chomp $results;
    return $results;
}

sub try_link0 {
    my ($src, $opt) = @_;
    my $cfile = gensym();
    open($cfile, ">conftest.c") || die "Cannot write to file conftest.c";
    print $cfile $src;
    close($cfile);
    xsystem(sprintf($LINK, $config{INC}, $config{LIBS}, $opt));
}

sub try_link {
    my $result = eval {
        try_link0(@_);
    };
    my $err = $@;
    rm_f("conftest*");
    if ($err) {
        die $err;
    }
    return $result;
}

sub have_library {
    my ($lib, $func) = (@_, "main");
    printf("checking for %s() in -l%s... ", $func, $lib);
    
    my $result;
    if ($func) {
        my $libs = "-l$lib";
        eval {
        $result = try_link(<<"SRC", $libs);
int main() { return 0; }
int t() { ${func}(); return 0; }
SRC
        };
        if ($@) {
            warn $@ if $DEBUG;
        }
    }
    
    unless ($result) {
        print "no\n";
        return 0;
    }
    
    if ($func ne "main") {
        $config{DEFINE} .= uc(" -Dhave_$func");
    }
    
    print "yes\n";
    return 1;
}