SDL/sdl2-config.in

71 lines
2.1 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# Get the canonical path of the folder containing this script
bindir=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)")
# Calculate the canonical path of the prefix, relative to the folder of this script
prefix=$(cd -P -- "$bindir/@bin_prefix_relpath@" && printf '%s\n' "$(pwd -P)")
exec_prefix=@exec_prefix@
exec_prefix_set=no
libdir=@libdir@
@ENABLE_STATIC_FALSE@usage="\
@ENABLE_STATIC_FALSE@Usage: $0 [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]"
@ENABLE_STATIC_TRUE@usage="\
@ENABLE_STATIC_TRUE@Usage: $0 [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs] [--static-libs]"
if test $# -eq 0; then
echo "${usage}" 1>&2
exit 1
fi
sdl2-config.in: Deprecate sdl2-config Library-specific foo-config scripts duplicate very similar logic across various different projects, and tend to break cross-compiling, multilib (gcc -m32), Debian/Ubuntu multiarch and so on by only being able to have one sdl2-config at a time as the first one in the PATH. The direct replacement is pkg-config(1) or a compatible reimplementation like pkgconf(1), which relies on each library installing declarative metadata, like SDL's sdl2.pc (available since at least 2.0.0) and centralizes the logic into the pkg-config/pkgconf tool. Most uses of `sdl2-config --foo` can be replaced by something similar to `${PKG_CONFIG:-pkg-config} --foo sdl2`. Instead of adding a custom sdl2-config to the PATH or using its --prefix or --exec-prefix options, users of a custom installation prefix can use any of pkg-config's non-SDL-specific ways to influence the result, for example setting PKG_CONFIG_PATH, PKG_CONFIG_SYSROOT_DIR or PKG_CONFIG_LIBDIR environment variables, or setting the PKG_CONFIG environment variable to point to a wrapper script. For Autotools specifically, the replacement for AM_PATH_SDL2 (which will be officially deprecated in a subsequent commit) is PKG_CHECK_MODULES. CMake has its own semi-declarative mechanism for dependency discovery, "config packages", and the SDL build already installs a config package. There's a good example of using a config package to discover SDL in `cmake/test/`. Meson natively supports pkg-config, and already uses it in preference to sdl2-config. Other build systems can run pkg-config instead of sdl2-config, preferably checking the PKG_CONFIG environment variable first. https://github.com/ioquake/ioq3 is a good example of a project doing this correctly. Helps: #6140, #3516 Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-31 06:05:36 -06:00
echo "sdl2-config: This script is deprecated" >&2
echo "sdl2-config: In Autotools builds, use PKG_CHECK_MODULES([SDL], [sdl2 >= 2.x.y])" >&2
echo "sdl2-config: In CMake builds, use find_package(SDL2 CONFIG)" >&2
echo "sdl2-config: In other build systems, look for 'sdl2' with pkg-config(1) or pkgconf(1)" >&2
while test $# -gt 0; do
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
case $1 in
--prefix=*)
prefix=$optarg
if test $exec_prefix_set = no ; then
exec_prefix=$optarg
fi
;;
--prefix)
echo $prefix
;;
--exec-prefix=*)
exec_prefix=$optarg
exec_prefix_set=yes
;;
--exec-prefix)
echo $exec_prefix
;;
--version)
echo @SDL_VERSION@
;;
--cflags)
echo -I@includedir@/SDL2 @SDL_CFLAGS@
;;
@ENABLE_SHARED_TRUE@ --libs)
@ENABLE_SHARED_TRUE@ echo -L@libdir@ @SDL_RLD_FLAGS@ @SDL_LIBS@
@ENABLE_SHARED_TRUE@ ;;
@ENABLE_STATIC_TRUE@@ENABLE_SHARED_TRUE@ --static-libs)
@ENABLE_STATIC_TRUE@@ENABLE_SHARED_FALSE@ --libs|--static-libs)
@ENABLE_STATIC_TRUE@ sdl_static_libs=$(echo "@SDL_LIBS@ @SDL_STATIC_LIBS@" | sed -E "s#-lSDL2[ $]#$libdir/libSDL2.a #g")
@ENABLE_STATIC_TRUE@ echo -L@libdir@ $sdl_static_libs
@ENABLE_STATIC_TRUE@ ;;
*)
echo "${usage}" 1>&2
exit 1
;;
esac
shift
done