Find SDL libraries in Perl's include/lib path.
[sdlgit/SDL_perl.git] / make / lib / SDL / Build / Darwin.pm
CommitLineData
bfd90409 1#!/usr/bin/env perl
2#
3# Darwin.pm
4#
5# Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
6#
7# ------------------------------------------------------------------------------
8#
9# This library is free software; you can redistribute it and/or
10# modify it under the terms of the GNU Lesser General Public
11# License as published by the Free Software Foundation; either
12# version 2.1 of the License, or (at your option) any later version.
13#
14# This library is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17# Lesser General Public License for more details.
18#
19# You should have received a copy of the GNU Lesser General Public
20# License along with this library; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22#
23# ------------------------------------------------------------------------------
24#
25# Please feel free to send questions, suggestions or improvements to:
26#
27# David J. Goehrig
28# dgoehrig@cpan.org
29#
30
31package SDL::Build::Darwin;
32
33use base 'SDL::Build';
34
35sub fetch_includes
36{
bef74e3b 37 use Config;
38
39 my (@include_path, @lib_path);
40
41 {
42 my %seen;
43 foreach (
44 ($Config{ccflags} =~ /-I(\S+)/g),
45 ($Config{cppflags} =~ /-I(\S+)/g),
46 ) {
47 foreach my $sdl_lib_dir ($_, "$_/SDL") {
48 next unless -f "$sdl_lib_dir/SDL.h";
49 push @include_path, $sdl_lib_dir unless $seen{$sdl_lib_dir}++;
50 }
51 }
52 }
53
54 {
55 my %seen;
56 foreach (
57 ($Config{libpth} =~ /(\S+)/g),
58 ($Config{libsdirs} =~ /(\S+)/g),
59 ($Config{libspath} =~ /(\S+)/g),
60 ($Config{lddlflags} =~ /-I(\S+)/g),
61 ($Config{ldflags} =~ /-I(\S+)/g),
62 ) {
63 next unless -f "$_/libSDL.a";
64 push @lib_path, $_ unless $seen{$_}++;
65 }
66 }
67
68 die "Can't find an SDL library" unless @include_path and @lib_path;
69 warn "Found SDL headers in $include_path[0] and library in $lib_path[0]";
70
bfd90409 71 return (
bef74e3b 72 $include_path[0] => $lib_path[0],
73
74 # Local libraries.
75 '/usr/local/include/smpeg' => '/usr/local/lib',
76 '/usr/local/include/GL' => '/usr/local/lib',
77 '/usr/local/include/gl' => '/usr/local/lib',
78
79 # System libraries.
80 '/usr/include/smpeg' => '/usr/lib',
81 '/usr/include/GL' => '/usr/lib',
82 '/usr/include/gl' => '/usr/lib',
83
84 # System-wide frameworks.
85 '/System/Library/Frameworks/libogg.framework/Headers' => '../../lib',
86 '/System/Library/Frameworks/libvorbis.framework/Headers' => '../../lib',
87 '/System/Library/Frameworks/libvorbisfile.framework/Headers' => '../../lib',
88 '/System/Library/Frameworks/libvorbisenc.framework/Headers' => '../../lib',
89 '/System/Library/Frameworks/OpenGL.framework/Headers' => '/System/Library/Frameworks/OpenGL.framework/Libraries',
90
91 # System libraries.
92 '/System/Library/Frameworks/OpenGL.framework/Headers' => '/System/Library/Frameworks/OpenGL.framework/Libraries',
bfd90409 93 );
94}
95
96sub build_c_sources
97{
98 return [qw/
99 launcher.m
100 /];
101}
102
103sub build_c_source
104{
105 return 'MacOSX';
106}
107
108sub build_install_base
109{
3a32e86d 110 return "SDLPerl.app/Contents/Resources";
bfd90409 111}
112
113sub build_bundle
114{
3a32e86d 115 $bundle_contents="SDLPerl.app/Contents";
bfd90409 116 system "mkdir -p \"$bundle_contents\"";
117 mkdir "$bundle_contents/MacOS",0755;
3a32e86d 118 $cflags = `sdl-config --cflags`;
119 chomp($cflags);
120 $cflags .= ' ' . `perl -MExtUtils::Embed -e ccopts`;
121 chomp($cflags);
122 $libs = `sdl-config --libs`;
123 chomp($libs);
124 $libs .= ' ' . `perl -MExtUtils::Embed -e ldopts`;
bfd90409 125 chomp($libs);
126 $libs =~ s/-lSDLmain//g;
3a32e86d 127 print STDERR "gcc $cflags MacOSX/launcher.m $libs -framework Cocoa -o \"$bundle_contents/MacOS/SDLPerl\"";
128 print STDERR `gcc $cflags MacOSX/launcher.m $libs -framework Cocoa -o \"$bundle_contents/MacOS/SDLPerl\"`;
bfd90409 129 mkdir "$bundle_contents/Resources",0755;
130 system "echo \"APPL????\" > \"$bundle_contents/PkgInfo\"";
131 system "cp MacOSX/Info.plist \"$bundle_contents/\"";
3a32e86d 132 system "cp \"MacOSX/SDLPerl.icns\" \"$bundle_contents/Resources\"";
bfd90409 133}
134
1351;