# $Id: Portfile,v 1.6 2006/06/30 03:57:23 ben Exp $
PortSystem		1.0
name			libsdl-framework
version			1.2.9
categories		devel multimedia
maintainers		darwinports@opendarwin.org
description		Cross-platform multi-media development API
long_description	Simple DirectMedia Layer is a cross-platform \
			multimedia library designed to provide fast access \
			to the graphics framebuffer and audio device. It is \
			used by MPEG playback software, emulators, and many \
			popular games, including the award winning Linux \
			port of "Civilization: Call To Power." Simple \
			DirectMedia Layer supports Linux, Win32, BeOS, \
			MacOS, Solaris, IRIX, and FreeBSD.
platforms		macosx
master_sites		http://www.libsdl.org/release/
distname		SDL-${version}
dist_subdir             libsdl
checksums		md5 80919ef556425ff82a8555ff40a579a0
depends_lib		port:libsdl

configure.args	--enable-shared

set buildindir build

platform darwin 8 {
if {$xcodeversion == "2.1"} {
set buildindir build/Deployment
}
}


variant nostatic {
	configure.args-append	--disable-static
}

post-extract {
	system "cd ${worksrcpath} && tar -xvzf Xcode.tar.gz"
}

post-patch {
	reinplace "s| -I/System/Library/Frameworks/Kernel.framework/Headers/||" \
		${worksrcpath}/src/joystick/darwin/Makefile.in
	reinplace "s|~/Library/Frameworks|./build/Frameworks|g" \
		${worksrcpath}/Xcode/SDL/SDL.pbproj/project.pbxproj
	reinplace "s|build/SDL.framework|${buildindir}/SDL.framework|g" \
		${worksrcpath}/Xcode/SDL/SDL.pbproj/project.pbxproj
	reinplace "s|/Library/Frameworks|../SDL/build/Frameworks|g" \
		${worksrcpath}/Xcode/SDLTest/SDLTest.pbproj/project.pbxproj
}

build.dir		"${worksrcpath}/Xcode/SDL"
build.type		pbx
build.target		-buildstyle Deployment -target Framework

post-build {
	   cd ${worksrcpath}/Xcode/SDL
	   system "install_name_tool -id /Library/Frameworks/SDL.framework/SDL \
	   build/Frameworks/SDL.framework/SDL"
	   build.dir		"${worksrcpath}/Xcode/SDLTest"
	   build.type		pbx
	   build.target	-buildstyle Deployment -target All
	   system "[command build]"
	   cd ${worksrcpath}/Xcode/SDLTest
	   foreach exe [glob ${buildindir}/*.app/Contents/MacOS/*] {
	   	   system "install_name_tool -change @executable_path/../Frameworks/SDL.framework/Versions/A/SDL \
		   	  /Library/Frameworks/SDL.framework/SDL ${exe}"
	   }
}

destroot {
	cd "${worksrcpath}/Xcode/SDL/build/Frameworks"
	xinstall -d -m 0755 ${destroot}/Library/Frameworks
	system "cp -R SDL.framework ${destroot}/Library/Frameworks"
	cd "${worksrcpath}/Xcode/SDLTest/${buildindir}"
	xinstall -d -m 0755 ${destroot}/Developer/Examples/SDL/Tests
	foreach app [glob *.app] {
		system "cp -R ${app} ${destroot}/Developer/Examples/SDL/Tests"
	}
	cd "${worksrcpath}/Xcode/Project Stationary"
	xinstall -d -m 0755 ${destroot}/Developer/Examples/SDL
	system "cp -R * ${destroot}/Developer/Examples/SDL"
}

platform darwin 6 {
	depends_lib-append	lib:libdl:dlcompat
	configure.env		CPPFLAGS="-I${prefix}/include" \
						LDFLAGS="-L${prefix}/lib"
}
