-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·146 lines (119 loc) · 2.49 KB
/
configure
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
#!/usr/bin/env perl
use strict;
use warnings;
use File::Temp qw(tempfile);
use Getopt::Long;
my $verbose = "";
my $CFLAGS;
my $LDFLAGS;
my $CC;
my %defines = ();
my $define_prefix = "EXCOM_";
my $header_file = "inc/excom/config.h";
if(!defined $ENV{CC}) {
$CC = "cc";
} else {
$CC = $ENV{CC};
}
if(!defined $ENV{CFLAGS}) {
$CFLAGS = "";
} else {
$CFLAGS = "$ENV{CFLAGS} ";
}
if(!defined $ENV{LDFLAGS}) {
$LDFLAGS = "";
} else {
$LDFLAGS = "$ENV{LDFLAGS} ";
}
GetOptions(
"verbose" => \$verbose,
"define-prefix=s" => \$define_prefix,
"header-file=s" => \$header_file
)
or die();
sub compile {
my $body = shift;
my $flags = shift || "";
my ($fh, $filename) = tempfile(SUFFIX => '.c');
my $out = $filename;
$out =~ s/\.c$/.out/;
print $fh $body;
close $fh;
my $command = "$CC $CFLAGS $LDFLAGS $flags -o $out $filename 2>&1";
print "$command\n" if $verbose;
my $output = `$command`;
print "$output\n" if $verbose;
return $? << 8 == 0;
}
sub check_command {
my $command = shift;
print "$command\n" if $verbose;
my $output = `$command`;
print "$output\n" if $verbose;
return $? << 8 == 0;
}
sub command {
my $command = shift;
my $arguments = shift || "";
my $fail = shift || 1;
print "Checking for $command... ";
if (!check_command("$command $arguments")) {
print "no\n";
if($fail)
{
exit 1;
}
} else {
printf "yes\n";
}
}
sub define_header {
my $header_name = shift;
my $define = uc $header_name;
$define =~ s/(\/|\.)/_/g;
$define = "${define_prefix}HAVE_$define";
$defines{$define} = "";
}
sub check_header {
my $header = shift;
my $flags = shift;
my $body = shift || "";
print "Checking for $header... ";
my $src = <<C
#include <stdlib.h>
$body
#include <$header>
int main(){ return 0; }
C
;
if(compile($src, $flags)) {
print "yes\n";
define_header $header;
return 1;
} else {
print "no\n";
return "";
}
}
sub write_header {
my $fh;
open($fh, ">", $header_file) or die("Cannot open $header_file: $!");
my $define_data = "";
foreach my $key (keys %defines) {
$define_data .= "#define $key $defines{$key}\n";
}
print $fh <<CONFIG
#ifndef _${define_prefix}CONFIG_H
#define _${define_prefix}CONFIG_H
$define_data
#endif
CONFIG
;
close($fh) or die("Could not close file: $!");
}
check_header "sys/epoll.h";
check_header "sys/event.h", "", "#include <sys/types.h>";
check_header "poll.h";
command "ragel", "--version";
command "valgrind", "--version";
write_header;