sdl12-compat: Added a replacement sdl-config script.

From fe1f41acbf1f9751949d259a08ca6c326d3a2138 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 1 Jun 2021 12:54:41 -0400
Subject: [PATCH] Added a replacement sdl-config script.

This is more or less a copy/paste from SDL2.

Fixes #66.
---
 CMakeLists.txt | 28 +++++++++++++++++++--
 sdl-config.in  | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+), 2 deletions(-)
 create mode 100755 sdl-config.in

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9aa894c..fe9e8ec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,6 +7,8 @@ project(sdl12_compat
         VERSION 0.0.1
         LANGUAGES C)
 
+set(SDL12_COMPAT_VERSION_STR "1.2.50")
+
 option(SDL12TESTS "Enable to build SDL-1.2 test programs" ON)
 option(SDL12DEVEL "Enable installing SDL-1.2 development headers" ON)
 
@@ -56,12 +58,12 @@ if(APPLE)
     )
 elseif(UNIX AND NOT ANDROID)
     set_target_properties(SDL PROPERTIES
-        VERSION "1.2.50"
+        VERSION "${SDL12_COMPAT_VERSION_STR}"
         SOVERSION "0"
         OUTPUT_NAME "SDL-1.2")
 else()
     set_target_properties(SDL PROPERTIES
-        VERSION "1.2.50"
+        VERSION "${SDL12_COMPAT_VERSION_STR}"
         SOVERSION "0"
       OUTPUT_NAME "SDL")
 endif()
@@ -153,4 +155,26 @@ if(SDL12DEVEL)
   install(FILES ${CMAKE_BINARY_DIR}/sdl12_compat.pc
     DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
   )
+
+  # !!! FIXME: lots of these sdl-config vars probably need more customization.
+
+  # !!! FIXME: do we _want_ static builds?
+  set(ENABLE_STATIC_TRUE "")
+  set(ENABLE_STATIC_FALSE "#")
+  set(ENABLE_SHARED_TRUE "")
+  set(ENABLE_SHARED_FALSE "#")
+
+  set(SDL_VERSION "${SDL12_COMPAT_VERSION_STR}")
+  set(SDL_CFLAGS "-D_GNU_SOURCE=1 -D_REENTRANT")
+  set(SDL_RLD_FLAGS "")  # !!! FIXME: this forces rpath, which we might want?
+  set(SDL_LIBS "-lSDL")
+  set(SDL_STATIC_LIBS "-lm -ldl -lpthread")
+  set(prefix ${CMAKE_INSTALL_PREFIX})
+  set(exec_prefix "\${prefix}")
+  set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
+  set(bindir "\${exec_prefix}/bin")
+  set(includedir "\${prefix}/include")
+  configure_file("${CMAKE_SOURCE_DIR}/sdl-config.in" "${CMAKE_BINARY_DIR}/sdl-config" @ONLY)
+  install(PROGRAMS "${CMAKE_BINARY_DIR}/sdl-config" DESTINATION bin)
 endif()
+
diff --git a/sdl-config.in b/sdl-config.in
new file mode 100755
index 0000000..f7895c2
--- /dev/null
+++ b/sdl-config.in
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+# This is a replacement for SDL 1.2's sdl-config script. You only need this
+#  if you are trying to build something uses SDL 1.2. If you have something
+#  already built that you want to drop sdl12-compat into, just replace
+#  the copy of SDL 1.2 with a build of sdl12-compat in the appropriate way.
+
+# Copied and modified from SDL2's sdl2-compat.
+
+prefix=@prefix@
+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
+
+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@      echo -L@libdir@ @SDL_LIBS@ @SDL_STATIC_LIBS@
+@ENABLE_STATIC_TRUE@      ;;
+    *)
+      echo "${usage}" 1>&2
+      exit 1
+      ;;
+  esac
+  shift
+done