-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile.PL
173 lines (143 loc) · 4.78 KB
/
Makefile.PL
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
use strict;
use warnings;
use ExtUtils::MakeMaker;
my $OGRE_REQ_VERSION = '1.8.0';
my $OIS_REQ_VERSION = '0.05';
main();
exit;
sub main {
my $fixed_args = fixed_args('Ogre');
my $varied_args = varied_args();
my $gpp_warn_args = gpp_warn_args();
WriteMakefile(%$fixed_args, %$varied_args, %$gpp_warn_args);
}
sub gpp_warn_args {
# If you're using gcc >= 4.2, you'd get warnings like this during `make` :
# OIS.c:1835: warning: deprecated conversion from string constant to 'char*'
# The C code generated by `xsubpp` uses literal string constants
# as args to functions expecting char*. This disables those warnings....
if (my_compiler() eq 'g++') {
my $str = `g++ -dumpversion`;
unless ($?) {
chomp $str;
my ($v, $s) = split /\./, $str;
if (($v == 4 && $s >= 2) || $v > 4) {
# http://www.nntp.perl.org/group/perl.perl5.porters/2012/03/msg184347.html
my $ccflags = $Config::Config{ccflags} || '';
return {'CCFLAGS' => "-Wno-write-strings $ccflags"};
}
}
}
# there will be no warnings, or we'll just tolerate them
return {};
}
sub fixed_args {
my ($pkg) = @_;
return {
'NAME' => $pkg,
'VERSION_FROM' => "$pkg.pm",
'ABSTRACT_FROM' => "$pkg.pm",
'AUTHOR' => 'Scott Lanning <[email protected]>',
'LD' => '$(CC)',
'OBJECT' => '$(O_FILES)',
'MAN3PODS' => {},
'XSOPT' => '-C++',
'TYPEMAPS' => ['perlobject.map'],
'META_MERGE' => {
no_index => {
directory => [ qw/t examples genscripts / ],
},
},
};
}
sub varied_args {
my (@errors, @cflags, @libs, @defines) = ();
# Make sure OGRE libs are known by pkg-config
my $pkgname = 'OGRE';
push @errors, check_pkg_config($pkgname, $OGRE_REQ_VERSION);
if (@errors) {
die(map { "$_$/" } @errors);
}
# Get include dirs and defines
push @cflags, pkg_config($pkgname, 'cflags');
# Get lib dirs
push @libs, pkg_config($pkgname, 'libs');
# Check if Gtk+ is installed
$pkgname = 'gtk+-2.0';
@errors = check_pkg_config($pkgname, '2.0.0');
if (@errors) {
print "\nNote: gtk+ support not enabled.\nReasons:\n",
map({ "- $_$/" } @errors);
print "See README.txt for information on enabling Gtk2 support.\n";
}
else {
print "\nEnabling gtk+ support.\n";
push @cflags, pkg_config($pkgname, 'cflags');
push @libs, pkg_config($pkgname, 'libs');
push @defines, '-DPERLOGRE_HAS_GTK2';
}
my %prereqs = (
'Test::More' => 0,
);
# Check if optional Perl modules are installed.
unless (eval { require OIS && $OIS::VERSION >= $OIS_REQ_VERSION }) {
my $msg = "\nNote: the Perl module OIS >= $OIS_REQ_VERSION is not installed,\n"
. "so you won't be able to run some examples\n"
. "or use Ogre::ExampleFrameListener.\n"
. "Installing OIS would be a very good idea\n"
. "unless you have some other way to handle keyboard and mouse input.\n"
. "It's fine to install it after installing Ogre.\n\n"
. "Do you want to install OIS now?";
my $val = ExtUtils::MakeMaker::prompt($msg, 'n');
if ($val =~ /^y/i) {
$prereqs{'OIS'} = $OIS_REQ_VERSION;
print "\nOIS >= $OIS_REQ_VERSION added to prerequisites.\n";
}
}
return {
'PREREQ_PM' => \%prereqs,
'CC' => my_compiler(),
'INC' => join(' ', @cflags),
'LIBS' => join(' ', @libs),
(@defines ? ('DEFINE' => join(' ', @defines)) : ()),
};
}
sub my_compiler {
return $ENV{'CXX'} || 'g++';
}
sub check_pkg_config {
my ($pkg, $required_version) = @_;
my $pc = 'pkg-config';
my @errors = ();
# Check that pkg-config is installed
my $pcver = `$pc --version`;
if ($pcver eq '') {
push @errors, "$pc not found";
}
else {
# Check that pkg-config knows about the package
my $pkgexists = `$pc --exists $pkg`;
if ($?) {
push @errors, "Package $pkg not found by $pc";
}
else {
# Check that the package is the right version
my $pkgver = `$pc --atleast-version='$required_version' $pkg`;
if ($?) {
push @errors, "Package $pkg is not the right version (at least $required_version)";
}
}
}
return @errors;
}
sub pkg_config {
my ($pkg, $option) = @_;
my $str = `pkg-config --$option $pkg`;
if ($?) {
die "pkg-config --$option $pkg: $str\n";
}
else {
chomp $str;
return $str;
}
}