PHP_ARG_WITH(sdl3, [for sdl3 support], [
AS_HELP_STRING([--with-sdl3[=DIR]], [Enable sdl3 support. DIR is the prefix for SDL3 installation.])
])

PHP_ARG_WITH(sdl3_gfx, [for sdl3_gfx support], [
AS_HELP_STRING([--with-sdl3-gfx[=DIR]], [Enable sdl3_gfx support. DIR is the prefix for SDL3_gfx installation.])
])

PHP_ARG_WITH(sdl3_image, [for sdl3_image support], [
AS_HELP_STRING([--with-sdl3-image[=DIR]], [Enable sdl3_image support. DIR is the prefix for SDL3_image installation.])
])

PHP_ARG_WITH(sdl3_ttf, [for sdl3_ttf support], [
AS_HELP_STRING([--with-sdl3-ttf[=DIR]], [Enable sdl3_ttf support. DIR is the prefix for SDL3_ttf installation.])
])

if test "$PHP_SDL3" != "no"; then
  if test -d "$PHP_SDL3"; then
    PKG_CONFIG_PATH="$PHP_SDL3/lib/pkgconfig:$PHP_SDL3/share/pkgconfig:$PKG_CONFIG_PATH"
  fi

  PKG_CHECK_MODULES([SDL3], [sdl3 >= 3.0.0], [
    CFLAGS="$CFLAGS $SDL3_CFLAGS"
    LDFLAGS="$LDFLAGS $SDL3_LIBS"
  ],[
    AC_MSG_ERROR([SDL3 not found. Please check your installation or use --with-sdl3=/path/to/sdl3])
  ])

  if test "$PHP_SDL3_GFX" != "no"; then
    if test -d "$PHP_SDL3_GFX"; then
        PKG_CONFIG_PATH="$PHP_SDL3_GFX/lib/pkgconfig:$PHP_SDL3_GFX/share/pkgconfig:$PKG_CONFIG_PATH"
    fi

    PKG_CHECK_MODULES([SDL3_GFX], [sdl3-gfx >= 1.0.0], [
      CFLAGS="$CFLAGS $SDL3_GFX_CFLAGS"
      LDFLAGS="$LDFLAGS $SDL3_GFX_LIBS"
    ],[
      AC_MSG_ERROR([SDL3_gfx not found. Please check your installation or use --with-sdl3-gfx=/path/to/sdl3_gfx])
    ])
  fi

  if test "$PHP_SDL3_IMAGE" != "no"; then
    if test -d "$PHP_SDL3_IMAGE"; then
        PKG_CONFIG_PATH="$PHP_SDL3_IMAGE/lib/pkgconfig:$PHP_SDL3_IMAGE/share/pkgconfig:$PKG_CONFIG_PATH"
    fi

    PKG_CHECK_MODULES([SDL3_IMAGE], [sdl3-image >= 3.0.0], [
      CFLAGS="$CFLAGS $SDL3_IMAGE_CFLAGS"
      LDFLAGS="$LDFLAGS $SDL3_IMAGE_LIBS"
    ],[
      AC_MSG_ERROR([SDL3_image not found. Please check your installation or use --with-sdl3-image=/path/to/sdl3_image])
    ])
  fi

  if test "$PHP_SDL3_TTF" != "no"; then
    if test -d "$PHP_SDL3_TTF"; then
        PKG_CONFIG_PATH="$PHP_SDL3_TTF/lib/pkgconfig:$PHP_SDL3_TTF/share/pkgconfig:$PKG_CONFIG_PATH"
    fi

    PKG_CHECK_MODULES([SDL3_TTF], [sdl3-ttf >= 3.0.0], [
      CFLAGS="$CFLAGS $SDL3_TTF_CFLAGS"
      LDFLAGS="$LDFLAGS $SDL3_TTF_LIBS"
    ],[
      AC_MSG_ERROR([SDL3_ttf not found. Please check your installation or use --with-sdl3-ttf=/path/to/sdl3_ttf])
    ])
  fi

  SDL_SOURCE_FILES="sdl3.c helper.c sdl3_image.c sdl3_ttf.c sdl3_events.c"

  PHP_NEW_EXTENSION(sdl3, $SDL_SOURCE_FILES, $ext_shared)
fi
