From 949e781d8d00e40a1265b158bcf7273a321f02d1 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 25 Nov 2013 18:09:33 +0100 Subject: php-pecl-sdl: 0.9.0 (beta) - New package --- Makefile | 4 ++ example.php | 37 ++++++++++++ php-pecl-sdl.spec | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ sdl-build.patch | 70 ++++++++++++++++++++++ 4 files changed, 287 insertions(+) create mode 100644 Makefile create mode 100644 example.php create mode 100644 php-pecl-sdl.spec create mode 100644 sdl-build.patch diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..13af741 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +SRCDIR := $(shell pwd) +NAME := $(shell basename $(SRCDIR)) +include ../../../common/Makefile + diff --git a/example.php b/example.php new file mode 100644 index 0000000..4ac324e --- /dev/null +++ b/example.php @@ -0,0 +1,37 @@ + + */ + +// require 'common.php'; + +SDL_Init( SDL_INIT_VIDEO ); + +$screen = SDL_SetVideoMode( 640, 480, 16, SDL_HWSURFACE ); +if( null == $screen ) +{ + fprintf( STDERR, 'Error: %s' . PHP_EOL, SDL_GetError() ); +} + +for( $i = 3; $i > 0; $i-- ) +{ + SDL_WM_SetCaption( "Switching to fullscreen mode in $i seconds...", null ); + SDL_Delay( 1000 ); +} + +SDL_WM_ToggleFullscreen( $screen ); + +SDL_Delay( 3000 ); + +SDL_WM_ToggleFullscreen( $screen ); + +SDL_WM_SetCaption( "Back from fullscreen mode. Quitting in 2 seconds...", null ); + +SDL_Delay( 2000 ); + +SDL_FreeSurface( $screen ); + +SDL_Quit(); + diff --git a/php-pecl-sdl.spec b/php-pecl-sdl.spec new file mode 100644 index 0000000..a0056d2 --- /dev/null +++ b/php-pecl-sdl.spec @@ -0,0 +1,176 @@ +# spec file for php-pecl-sdl +# +# Copyright (c) 2013 Remi Collet +# License: CC-BY-SA +# http://creativecommons.org/licenses/by-sa/3.0/ +# +# Please, preserve the changelog entries +# + +%{!?php_inidir: %global php_inidir %{_sysconfdir}/php.d} +%{!?__pecl: %global __pecl %{_bindir}/pecl} +%{!?__php: %global __php %{_bindir}/php} + +%global with_zts 0%{?__ztsphp:1} +%global with_tests %{?_with_tests:1}%{!?_with_tests:0} +%global pecl_name sdl + +Summary: Simple DirectMedia Layer for PHP +Name: php-pecl-sdl +Version: 0.9.0 +Release: 1%{?dist}%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')} +License: PHP +Group: Development/Languages +URL: http://pecl.php.net/package/sdl +Source0: http://pecl.php.net/get/%{pecl_name}-%{version}.tgz + +# From code-examples.tgz +# From http://sourceforge.net/projects/phpsdl/files/ +Source1: example.php + +# Build patch for shared mode (emailed to upstream) +Patch0: %{pecl_name}-build.patch + +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root +BuildRequires: php-devel > 5.2.0 +BuildRequires: php-pear +BuildRequires: SDL-devel + +Requires(post): %{__pecl} +Requires(postun): %{__pecl} +Requires: php(zend-abi) = %{php_zend_api} +Requires: php(api) = %{php_core_api} +Requires: %{__php} +%if %{with_zts} +Requires: %{__ztsphp} +%endif + +Provides: php-%{pecl_name} = %{version} +Provides: php-%{pecl_name}%{?_isa} = %{version} +Provides: php-pecl(%{pecl_name}) = %{version} +Provides: php-pecl(%{pecl_name})%{?_isa} = %{version} + +%if 0%{?fedora} < 20 +# filter private shared +%{?filter_provides_in: %filter_provides_in %{_libdir}/.*\.so$} +%{?filter_setup} +%endif + + +%description +This extension allows you to develop multimedia applications with PHP +using the complete SDL library API. + +Use the "phpsdl" command to launch a SDL application. + + +%prep +%setup -q -c +%patch0 +mv %{pecl_name}-%{version} NTS + + +cat << 'EOF' | tee phpsdl +#!/bin/sh +exec %{__php} -d extension=%{pecl_name}.so "$@" +EOF + +%if %{with_zts} +cat << 'EOF' | tee zts-phpsdl +#!/bin/sh +exec %{__ztsphp} -d extension=%{pecl_name}.so "$@" +EOF + +cp -r NTS ZTS +%endif + +%build + +peclconf() { +%configure \ + --with-sdl \ + --with-php-config=$1 +} +cd NTS +%{_bindir}/phpize +peclconf %{_bindir}/php-config +make %{?_smp_mflags} + +%if %{with_zts} +cd ../ZTS +%{_bindir}/zts-phpize +peclconf %{_bindir}/zts-php-config +make %{?_smp_mflags} +%endif + + +%install +rm -rf %{buildroot} +make -C NTS install INSTALL_ROOT=%{buildroot} + +# Install XML package description +install -Dpm 644 package.xml %{buildroot}%{pecl_xmldir}/%{name}.xml + +# Install the command wrapper +install -Dpm 755 phpsdl %{buildroot}%{_bindir}/phpsdl + +%if %{with_zts} +make -C ZTS install INSTALL_ROOT=%{buildroot} +install -Dpm 755 zts-phpsdl %{buildroot}%{_bindir}/zts-phpsdl +%endif + +# Test & Documentation +cd NTS +for i in $(grep 'role="test"' ../package.xml | sed -e 's/^.*name="//;s/".*$//') +do install -Dpm 644 $i %{buildroot}%{pecl_testdir}/%{pecl_name}/$i +done +for i in %{SOURCE1} $(grep 'role="doc"' ../package.xml | sed -e 's/^.*name="//;s/".*$//') +do install -Dpm 644 $i %{buildroot}%{pecl_docdir}/%{pecl_name}/$i +done + + +%check +: Minimal load test for NTS extension +%{__php} -n -q \ + -d extension=NTS/modules/%{pecl_name}.so \ + --modules | grep -i %{pecl_name} + +%if %{with_zts} +: Minimal load test for ZTS extension +%{__ztsphp} -n -q \ + -d extension=ZTS/modules/%{pecl_name}.so \ + --modules | grep -i %{pecl_name} +%endif + + +%clean +rm -rf %{buildroot} + + +%post +%{pecl_install} %{pecl_xmldir}/%{name}.xml >/dev/null || : + + +%postun +if [ $1 -eq 0 ] ; then + %{pecl_uninstall} %{pecl_name} >/dev/null || : +fi + + +%files +%defattr(-,root,root,-) +%doc %{pecl_docdir}/%{pecl_name} +%doc %{pecl_testdir}/%{pecl_name} +%{_bindir}/phpsdl +%{php_extdir}/%{pecl_name}.so +%{pecl_xmldir}/%{name}.xml + +%if %{with_zts} +%{_bindir}/zts-phpsdl +%{php_ztsextdir}/%{pecl_name}.so +%endif + + +%changelog +* Mon Nov 25 2013 Remi Collet - 0.9.0-1 +- initial package, 0.9.0 (beta) diff --git a/sdl-build.patch b/sdl-build.patch new file mode 100644 index 0000000..de85fe5 --- /dev/null +++ b/sdl-build.patch @@ -0,0 +1,70 @@ +diff -up sdl-0.9.0/config.m4.old sdl-0.9.0/config.m4 +--- sdl-0.9.0/config.m4.old 2013-11-24 21:38:31.000000000 +0100 ++++ sdl-0.9.0/config.m4 2013-11-25 08:21:59.000000000 +0100 +@@ -1,7 +1,7 @@ + dnl $Id$ + dnl config.m4 for extension sdl + +-PHP_ARG_WITH( sdl, for sdl support, [ --with-sdl=DIR Include sdl support ] ) ++PHP_ARG_WITH(sdl, for sdl support, [ --with-sdl=DIR Include sdl support ]) + + if test "$PHP_SDL" != "no"; then + +@@ -34,21 +34,7 @@ if test "$PHP_SDL" != "no"; then + AC_MSG_RESULT(found in $SDL_CONFIG) + + PHP_EVAL_INCLINE(`$SDL_CONFIG --cflags`) +- +- dnl FIXME: support non-shared builds +- SDL_LIBS=`$SDL_CONFIG --libs` +- for i in $SDL_LIBS; do +- case $i in +- -L*) +- tmp=`echo $i | cut -c 3-` +- PHP_ADD_LIBPATH($tmp, SDL_SHARED_LIBADD) +- ;; +- -l*) +- tmp=`echo $i | cut -c 3-` +- PHP_ADD_LIBRARY($tmp, 1, SDL_SHARED_LIBADD) +- ;; +- esac +- done ++ PHP_EVAL_LIBLINE(`$SDL_CONFIG --libs`, SDL_SHARED_LIBADD) + else + AC_MSG_RESULT([not found, trying manual way]) + +@@ -72,14 +58,17 @@ if test "$PHP_SDL" != "no"; then + AC_MSG_RESULT(found below $SDL_DIR/include) + fi + +- if test ! -f "$i/lib/libSDL.so"; then +- AC_MSG_ERROR(Cannot find lib/libSDL.so below $i) ++ if test ! -f "$SDL_DIR/$PHP_LIBDIR/libSDL.$SHLIB_SUFFIX_NAME"; then ++ AC_MSG_ERROR(Cannot find $PHP_LIBDIR/libSDL.$SHLIB_SUFFIX_NAME below $i) + fi + + PHP_ADD_INCLUDE($SDL_DIR/include/SDL) ++ PHP_ADD_LIBRARY_WITH_PATH(SDL, $SDL_DIR/$PHP_LIBDIR, SDL_SHARED_LIBADD) + fi ++ AC_MSG_RESULT(BUILD AS $ext_shared) + +- PHP_NEW_EXTENSION( sdl, php_sdl.c php_sdl_audio.c php_sdl_event.c php_sdl_thread.c php_sdl_wm.c php_sdl_cdrom.c php_sdl_joystick.c php_sdl_time.c, $ext_shared ) ++ PHP_NEW_EXTENSION(sdl, php_sdl.c php_sdl_audio.c php_sdl_event.c php_sdl_thread.c php_sdl_wm.c php_sdl_cdrom.c php_sdl_joystick.c php_sdl_time.c, $ext_shared) ++ PHP_SUBST(SDL_SHARED_LIBADD) + + AC_DEFINE(HAVE_SDL, 1, [ ]) + fi +diff -up sdl-0.9.0/php_sdl.c.old sdl-0.9.0/php_sdl.c +--- sdl-0.9.0/php_sdl.c.old 2013-11-25 08:22:37.000000000 +0100 ++++ sdl-0.9.0/php_sdl.c 2013-11-25 08:23:02.000000000 +0100 +@@ -3318,10 +3318,6 @@ int php_sdl_find_key_with_type(zval *arr + return 1; + } + +-#ifdef COMPILE_DL_SDL +-ZEND_GET_MODULE(sdl) +-#endif +- + /* + * Local variables: + * tab-width: 4 -- cgit