SDL_rtf: Add CMake build script

From ef8e0b90ab1ff43ac87bda69e5ec297bb5014e8b Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Tue, 14 Jun 2022 22:55:41 +0200
Subject: [PATCH] Add CMake build script

---
 CMakeLists.txt                   |  253 +
 Makefile.am                      |   12 +
 Makefile.in                      |  102 +-
 Makefile.os2                     |    5 +-
 SDL2_rtf.pc.in                   |   13 +
 SDL2_rtfConfig.cmake.in          |   17 +
 acinclude/libtool.m4             | 4116 ++++++++-----
 acinclude/ltoptions.m4           |  147 +-
 acinclude/ltsugar.m4             |    8 +-
 acinclude/ltversion.m4           |   16 +-
 acinclude/lt~obsolete.m4         |   18 +-
 aclocal.m4                       |    4 +-
 cmake/CommonFindSDL2.cmake       |   22 +
 cmake/FindSDL2main.cmake         |   24 +
 cmake/PrivateSdlFunctions.cmake  |  243 +
 config.guess                     | 1456 ++---
 config.sub                       |  708 +--
 configure                        | 9606 ++++++++++++++++++------------
 configure.ac                     |   70 +-
 install-sh                       |  148 +-
 ltmain.sh                        | 8086 ++++++++++++++++---------
 sdl2_rtf-config-version.cmake.in |   12 +
 sdl2_rtf-config.cmake.in         |   87 +
 test-versioning.sh               |  115 +
 24 files changed, 15809 insertions(+), 9479 deletions(-)
 create mode 100644 CMakeLists.txt
 create mode 100644 SDL2_rtf.pc.in
 create mode 100644 SDL2_rtfConfig.cmake.in
 create mode 100644 cmake/CommonFindSDL2.cmake
 create mode 100644 cmake/FindSDL2main.cmake
 create mode 100644 cmake/PrivateSdlFunctions.cmake
 create mode 100644 sdl2_rtf-config-version.cmake.in
 create mode 100644 sdl2_rtf-config.cmake.in
 create mode 100755 test-versioning.sh

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..bd18d67
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,253 @@
+cmake_minimum_required(VERSION 3.14)
+
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
+
+# See docs/release_checklist.md
+set(MAJOR_VERSION 2)
+set(MINOR_VERSION 0)
+set(MICRO_VERSION 0)
+set(SDL_REQUIRED_VERSION 2.0.0)
+
+# For historical reasons this is 15.0.0 rather than the expected 1.0.0
+set(DYLIB_COMPATIBILITY_VERSION "1.0.0")
+
+include(PrivateSdlFunctions)
+sdl_calculate_derived_version_variables()
+
+if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
+    message(FATAL_ERROR "Prevented in-tree built. Please create a build directory outside of the SDL_rtf source code and call cmake from there")
+endif()
+
+project(SDL2_rtf
+    LANGUAGES C
+    VERSION "${FULL_VERSION}"
+)
+
+message(STATUS "Configuring ${PROJECT_NAME} ${PROJECT_VERSION}")
+
+# Set defaults preventing destination file conflicts
+set(SDL2RTF_DEBUG_POSTFIX "d"
+    CACHE STRING "Name suffix for debug builds")
+mark_as_advanced(SDL2RTF_DEBUG_POSTFIX)
+
+# Assume MSVC projects don't have a package manager and need vendored dependencies (by default).
+# Most other platforms have some kind of package manager.
+# FIXME: consider a package manager such as conan/vcpkg instead of vendoring
+if(MSVC)
+    set(vendored_default TRUE)
+else()
+    set(vendored_default FALSE)
+endif()
+
+include(CMakePackageConfigHelpers)
+include(GNUInstallDirs)
+
+option(CMAKE_POSITION_INDEPENDENT_CODE "Build static libraries with -fPIC" ON)
+option(BUILD_SHARED_LIBS "Build the library as a shared library" ON)
+
+# Save BUILD_SHARED_LIBS variable
+set(SDL2RTF_BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS}")
+
+option(SDL2RTF_SAMPLES "Build the SDL2_rtf sample program(s)" ON)
+option(SDL2RTF_INSTALL "Enable SDL2_rtf install target" ON)
+
+if(SDL2RTF_BUILD_SHARED_LIBS)
+    set(sdl2_rtf_export_name SDL2_rtf)
+    set(sdl2_rtf_install_name_infix shared)
+    set(sdl2_target_name SDL2::SDL2)
+    set(sdl2ttf_target_name SDL2_ttf::SDL2_ttf)
+else()
+    set(sdl2_rtf_export_name SDL2_rtf-static)
+    set(sdl2_rtf_install_name_infix static)
+    set(sdl2_target_name SDL2::SDL2-static)
+    set(sdl2ttf_target_name SDL2_ttf::SDL2_ttf-static)
+endif()
+
+sdl_find_sdl2(${sdl2_target_name} ${SDL_REQUIRED_VERSION})
+find_package(SDL2_ttf REQUIRED)
+
+add_library(SDL2_rtf
+    rtfactn.c
+    rtfdecl.h
+    rtfreadr.c
+    rtftype.h
+    SDL_rtf.c
+    SDL_rtf.h
+    SDL_rtfreadr.c
+    SDL_rtfreadr.h
+)
+add_library(SDL2_rtf::${sdl2_rtf_export_name} ALIAS SDL2_rtf)
+target_include_directories(SDL2_rtf PUBLIC
+    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
+    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SDL2>"
+)
+target_compile_definitions(SDL2_rtf PRIVATE
+    BUILD_SDL
+    SDL_BUILD_MAJOR_VERSION=${MAJOR_VERSION}
+    SDL_BUILD_MINOR_VERSION=${MINOR_VERSION}
+    SDL_BUILD_MICRO_VERSION=${MICRO_VERSION}
+)
+target_link_libraries(SDL2_rtf PRIVATE $<BUILD_INTERFACE:${sdl2_target_name}> $<BUILD_INTERFACE:${sdl2ttf_target_name}>)
+if(WIN32 AND SDL2RTF_BUILD_SHARED_LIBS)
+    target_sources(SDL2_rtf PRIVATE
+        version.rc
+    )
+endif()
+set_target_properties(SDL2_rtf PROPERTIES
+    DEFINE_SYMBOL DLL_EXPORT
+    PUBLIC_HEADER SDL_rtf.h
+    EXPORT_NAME ${sdl2_rtf_export_name}
+    C_VISIBILITY_PRESET "hidden"
+)
+if(NOT ANDROID)
+    set_target_properties(SDL2_rtf PROPERTIES
+        DEBUG_POSTFIX "${SDL2RTF_DEBUG_POSTFIX}"
+    )
+    if(APPLE)
+        # the SOVERSION property corresponds to the compatibility version and VERSION corresponds to the current version
+        # https://cmake.org/cmake/help/latest/prop_tgt/SOVERSION.html#mach-o-versions
+        set_target_properties(SDL2_rtf PROPERTIES
+            SOVERSION "${DYLIB_COMPATIBILITY_VERSION}"
+            VERSION "${DYLIB_CURRENT_VERSION}"
+        )
+    else()
+        set_target_properties(SDL2_rtf PROPERTIES
+            SOVERSION "${LT_MAJOR}"
+            VERSION "${LT_VERSION}"
+        )
+    endif()
+endif()
+if(SDL2RTF_BUILD_SHARED_LIBS AND (APPLE OR (UNIX AND NOT ANDROID)))
+    add_custom_command(TARGET SDL2_rtf POST_BUILD
+        COMMAND "${CMAKE_COMMAND}" -E create_symlink "$<TARGET_SONAME_FILE_NAME:SDL2_rtf>" "libSDL2_rtf$<$<CONFIG:Debug>:${SDL2RTF_DEBUG_POSTFIX}>$<TARGET_FILE_SUFFIX:SDL2_rtf>"
+        # BYPRODUCTS "libSDL2_rtf$<$<CONFIG:Debug>:${SDL2RTF_DEBUG_POSTFIX}>$<TARGET_FILE_SUFFIX:SDL2_rtf>" # Needs CMake 3.20
+        WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
+    )
+endif()
+if(SDL2RTF_BUILD_SHARED_LIBS)
+    if(WIN32 OR OS2)
+        set_target_properties(SDL2_rtf PROPERTIES
+            PREFIX ""
+        )
+    endif()
+    if(OS2)
+        # OS/2 doesn't support a DLL name longer than 8 characters.
+        set_target_properties(SDL2_rtf PROPERTIES
+            OUTPUT_NAME "SDL2rtf"
+        )
+    elseif(UNIX AND NOT ANDROID)
+        set_target_properties(SDL2_rtf PROPERTIES
+            OUTPUT_NAME "SDL2_rtf-${LT_RELEASE}"
+        )
+    endif()
+endif()
+
+if(SDL2RTF_BUILD_SHARED_LIBS)
+    # Use `Compatible Interface Properties` to ensure a shared SDL2_Rtf is linked to a shared SDL2 library
+    set_property(TARGET SDL2_rtf PROPERTY INTERFACE_SDL2_SHARED ${SDL2RTF_BUILD_SHARED_LIBS})
+    set_property(TARGET SDL2_rtf APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SDL2_SHARED)
+endif()
+
+set(INSTALL_EXTRA_TARGETS)
+set(PC_LIBS)
+set(PC_REQUIRES SDL2_ttf)
+
+if(SDL2RTF_INSTALL)
+    install(
+        TARGETS SDL2_rtf
+        EXPORT SDL2_rtfTargets
+        ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT devel
+        LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT library
+        RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT library
+        PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/SDL2" COMPONENT devel
+    )
+
+    if(WIN32 AND NOT MINGW)
+        set(PKG_PREFIX "cmake")
+    else()
+        set(PKG_PREFIX "${CMAKE_INSTALL_LIBDIR}/cmake/SDL2_rtf")
+    endif()
+
+    configure_package_config_file(SDL2_rtfConfig.cmake.in SDL2_rtfConfig.cmake
+        INSTALL_DESTINATION "${PKG_PREFIX}"
+    )
+    write_basic_package_version_file("${PROJECT_BINARY_DIR}/SDL2_rtfConfigVersion.cmake"
+        VERSION ${FULL_VERSION}
+        COMPATIBILITY AnyNewerVersion
+    )
+    install(
+        FILES
+            "${CMAKE_CURRENT_BINARY_DIR}/SDL2_rtfConfig.cmake"
+            "${CMAKE_CURRENT_BINARY_DIR}/SDL2_rtfConfigVersion.cmake"
+        DESTINATION ${PKG_PREFIX}
+        COMPONENT devel
+    )
+    install(EXPORT SDL2_rtfTargets
+        FILE SDL2_rtf-${sdl2_rtf_install_name_infix}-targets.cmake
+        NAMESPACE SDL2_rtf::
+        DESTINATION "${PKG_PREFIX}"
+        COMPONENT devel
+    )
+
+    if(SDL2RTF_BUILD_SHARED_LIBS)
+        # Only create a .pc file for a shared SDL2_rtf
+        set(prefix "${CMAKE_INSTALL_PREFIX}")
+        set(exec_prefix "\${prefix}")
+        set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
+        set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
+        set(PACKAGE "${PROJECT_NAME}")
+        set(VERSION ${FULL_VERSION})
+        set(SDL_VERSION ${SDL_REQUIRED_VERSION})
+        string(JOIN " " PC_REQUIRES ${PC_REQUIRES})
+        string(JOIN " " PC_LIBS ${PC_LIBS})
+        configure_file("${PROJECT_SOURCE_DIR}/SDL2_rtf.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/SDL2_rtf.pc.intermediate" @ONLY)
+        file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/SDL2_rtf-$<CONFIG>.pc" INPUT "${CMAKE_CURRENT_BINARY_DIR}/SDL2_rtf.pc.intermediate")
+
+        set(PC_DESTDIR)
+        if(CMAKE_SYSTEM_NAME MATCHES FreeBSD)
+            # FreeBSD uses ${PREFIX}/libdata/pkgconfig
+            set(PC_DESTDIR "libdata/pkgconfig")
+        else()
+            set(PC_DESTDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
+        endif()
+        # Only install a SDL2_rtf.pc file in Release mode
+        install(CODE "
+        file(COPY_FILE \"${CMAKE_CURRENT_BINARY_DIR}/SDL2_rtf-$<CONFIG>.pc\"
+            \"${CMAKE_CURRENT_BINARY_DIR}/SDL2_rtf.pc\" ONLY_IF_DIFFERENT)
+        file(INSTALL DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${PC_DESTDIR}\"
+            TYPE FILE
+            FILES \"${CMAKE_CURRENT_BINARY_DIR}/SDL2_rtf.pc\")" CONFIG Release)
+    endif()
+
+    if(SDL2RTF_BUILD_SHARED_LIBS AND (APPLE OR (UNIX AND NOT ANDROID)))
+        install(FILES
+            "${PROJECT_BINARY_DIR}/libSDL2_rtf$<$<CONFIG:Debug>:${SDL2RTF_DEBUG_POSTFIX}>$<TARGET_FILE_SUFFIX:SDL2_rtf>"
+            DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+            COMPONENT devel
+        )
+    endif()
+
+    install(FILES "COPYING.txt"
+        DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/${PROJECT_NAME}"
+        COMPONENT library
+    )
+endif()
+
+if(SDL2RTF_SAMPLES)
+    add_executable(showrtf showrtf.c)
+
+    find_package(SDL2main QUIET)
+
+    foreach(prog showrtf)
+        if(MINGW)
+            target_link_libraries(${prog} PRIVATE mingw32)
+            target_link_options(${prog} PRIVATE -mwindows)
+        endif()
+        target_link_libraries(${prog} PRIVATE SDL2_rtf::${sdl2_rtf_export_name})
+        if(TARGET SDL2::SDL2main)
+            target_link_libraries(${prog} PRIVATE SDL2::SDL2main)
+        endif()
+        target_link_libraries(${prog} PRIVATE ${sdl2_target_name})
+        target_link_libraries(${prog} PRIVATE ${sdl2ttf_target_name})
+    endforeach()
+endif()
diff --git a/Makefile.am b/Makefile.am
index f25f5bd..714e286 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -33,6 +33,9 @@ if USE_VERSION_RC
 libSDL2_rtf_la_DEPENDENCIES = version.o
 endif
 
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = SDL2_rtf.pc
+
 .rc.o:
 	$(RC) $< $@
 
@@ -54,3 +57,12 @@ $(PACKAGE)-$(VERSION).tar.gz: distcheck
 rpm: $(PACKAGE)-$(VERSION).tar.gz
 	rpmbuild -ta $(PACKAGE)-$(VERSION).tar.gz
 
+install-data-local:
+	$(MKDIR_P) $(DESTDIR)$(libdir)/cmake/SDL2_rtf
+	$(INSTALL) -m 644 sdl2_rtf-config.cmake $(DESTDIR)$(libdir)/cmake/SDL2_rtf
+	$(INSTALL) -m 644 sdl2_rtf-config-version.cmake $(DESTDIR)$(libdir)/cmake/SDL2_rtf
+
+uninstall-hook:
+	rm $(DESTDIR)$(libdir)/cmake/SDL2_rtf/sdl2_rtf-config.cmake
+	rm $(DESTDIR)$(libdir)/cmake/SDL2_rtf/sdl2_rtf-config-version.cmake
+	rm -r $(DESTDIR)$(libdir)/cmake/SDL2_rtf
diff --git a/Makefile.in b/Makefile.in
index 2dd34ac..e183be5 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -16,6 +16,7 @@
 
 
 
+
 VPATH = @srcdir@
 am__is_gnu_make = { \
   if test -z '$(MAKELEVEL)'; then \
@@ -108,7 +109,8 @@ DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \
 am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
  configure.lineno config.status.lineno
 mkinstalldirs = $(install_sh) -d
-CONFIG_CLEAN_FILES = SDL2_rtf.spec
+CONFIG_CLEAN_FILES = sdl2_rtf-config.cmake \
+	sdl2_rtf-config-version.cmake SDL2_rtf.spec SDL2_rtf.pc
 CONFIG_CLEAN_VPATH_FILES =
 @HAVE_SDL_TTF_TRUE@am__EXEEXT_1 = showrtf$(EXEEXT)
 PROGRAMS = $(noinst_PROGRAMS)
@@ -139,7 +141,7 @@ am__uninstall_files_from_dir = { \
     || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
          $(am__cd) "$$dir" && rm -f $$files; }; \
   }
-am__installdirs = "$(DESTDIR)$(libdir)" \
+am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgconfigdir)" \
 	"$(DESTDIR)$(libSDL2_rtfincludedir)"
 LTLIBRARIES = $(lib_LTLIBRARIES)
 libSDL2_rtf_la_LIBADD =
@@ -204,6 +206,7 @@ am__can_run_installinfo = \
     n|no|NO) false;; \
     *) (install-info --version) >/dev/null 2>&1;; \
   esac
+DATA = $(pkgconfig_DATA)
 HEADERS = $(libSDL2_rtfinclude_HEADERS)
 am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
 # Read a list of newline-separated strings from the standard input,
@@ -223,9 +226,11 @@ am__define_uniq_tagged_files = \
     if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
   done | $(am__uniquify_input)`
 AM_RECURSIVE_TARGETS = cscope
-am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/SDL2_rtf.spec.in \
-	compile config.guess config.sub depcomp install-sh ltmain.sh \
-	missing
+am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/SDL2_rtf.pc.in \
+	$(srcdir)/SDL2_rtf.spec.in \
+	$(srcdir)/sdl2_rtf-config-version.cmake.in \
+	$(srcdir)/sdl2_rtf-config.cmake.in compile config.guess \
+	config.sub depcomp install-sh ltmain.sh missing
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 distdir = $(PACKAGE)-$(VERSION)
 top_distdir = $(distdir)
@@ -254,11 +259,9 @@ AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
-BINARY_AGE = @BINARY_AGE@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
-CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CSCOPE = @CSCOPE@
 CTAGS = @CTAGS@
@@ -281,7 +284,6 @@ INSTALL_DATA = @INSTALL_DATA@
 INSTALL_PROGRAM = @INSTALL_PROGRAM@
 INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
-INTERFACE_AGE = @INTERFACE_AGE@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
 LIBOBJS = @LIBOBJS@
@@ -295,8 +297,10 @@ LT_CURRENT = @LT_CURRENT@
 LT_EXTRA = @LT_EXTRA@
 LT_RELEASE = @LT_RELEASE@
 LT_REVISION = @LT_REVISION@
+LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
 MAJOR_VERSION = @MAJOR_VERSION@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MICRO_VERSION = @MICRO_VERSION@
 MINOR_VERSION = @MINOR_VERSION@
 MKDIR_P = @MKDIR_P@
@@ -314,6 +318,8 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
 PACKAGE_URL = @PACKAGE_URL@
 PACKAGE_VERSION = @PACKAGE_VERSION@
 PATH_SEPARATOR = @PATH_SEPARATOR@
+PC_LIBS = @PC_LIBS@
+PC_REQUIRES = @PC_REQUIRES@
 PKG_CONFIG = @PKG_CONFIG@
 PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
 PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
@@ -324,6 +330,7 @@ SDLTTF_CFLAGS = @SDLTTF_CFLAGS@
 SDLTTF_LIBS = @SDLTTF_LIBS@
 SDL_CFLAGS = @SDL_CFLAGS@
 SDL_LIBS = @SDL_LIBS@
+SDL_VERSION = @SDL_VERSION@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
@@ -333,6 +340,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
 am__include = @am__include@
@@ -347,6 +355,7 @@ build_cpu = @build_cpu@
 build_os = @build_os@
 build_vendor = @build_vendor@
 builddir = @builddir@
+cmake_prefix_relpath = @cmake_prefix_relpath@
 datadir = @datadir@
 datarootdir = @datarootdir@
 docdir = @docdir@
@@ -365,7 +374,6 @@ libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 oldincludedir = @oldincludedir@
@@ -413,6 +421,8 @@ libSDL2_rtf_la_LDFLAGS = \
 	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) $(LT_EXTRA)
 
 @USE_VERSION_RC_TRUE@libSDL2_rtf_la_DEPENDENCIES = version.o
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = SDL2_rtf.pc
 @HAVE_SDL_TTF_FALSE@EXAMPLES = 
 @HAVE_SDL_TTF_TRUE@EXAMPLES = showrtf
 showrtf_SOURCES = showrtf.c
@@ -455,8 +465,14 @@ $(top_srcdir)/configure:  $(am__configure_deps)
 $(ACLOCAL_M4):  $(am__aclocal_m4_deps)
 	$(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
 $(am__aclocal_m4_deps):
+sdl2_rtf-config.cmake: $(top_builddir)/config.status $(srcdir)/sdl2_rtf-config.cmake.in
+	cd $(top_builddir) && $(SHELL) ./config.status $@
+sdl2_rtf-config-version.cmake: $(top_builddir)/config.status $(srcdir)/sdl2_rtf-config-version.cmake.in
+	cd $(top_builddir) && $(SHELL) ./config.status $@
 SDL2_rtf.spec: $(top_builddir)/config.status $(srcdir)/SDL2_rtf.spec.in
 	cd $(top_builddir) && $(SHELL) ./config.status $@
+SDL2_rtf.pc: $(top_builddir)/config.status $(srcdir)/SDL2_rtf.pc.in
+	cd $(top_builddir) && $(SHELL) ./config.status $@
 
 clean-noinstPROGRAMS:
 	@list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \
@@ -570,6 +586,27 @@ clean-libtool:
 
 distclean-libtool:
 	-rm -f libtool config.lt
+install-pkgconfigDATA: $(pkgconfig_DATA)
+	@$(NORMAL_INSTALL)
+	@list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \
+	if test -n "$$list"; then \
+	  echo " $(MKDIR_P) '$(DESTDIR)$(pkgconfigdir)'"; \
+	  $(MKDIR_P) "$(DESTDIR)$(pkgconfigdir)" || exit 1; \
+	fi; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pkgconfigdir)'"; \
+	  $(INSTALL_DATA) $$files "$(DESTDIR)$(pkgconfigdir)" || exit $$?; \
+	done
+
+uninstall-pkgconfigDATA:
+	@$(NORMAL_UNINSTALL)
+	@list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	dir='$(DESTDIR)$(pkgconfigdir)'; $(am__uninstall_files_from_dir)
 install-libSDL2_rtfincludeHEADERS: $(libSDL2_rtfinclude_HEADERS)
 	@$(NORMAL_INSTALL)
 	@list='$(libSDL2_rtfinclude_HEADERS)'; test -n "$(libSDL2_rtfincludedir)" || list=; \
@@ -824,9 +861,9 @@ distcleancheck: distclean
 	       exit 1; } >&2
 check-am: all-am
 check: check-am
-all-am: Makefile $(PROGRAMS) $(LTLIBRARIES) $(HEADERS)
+all-am: Makefile $(PROGRAMS) $(LTLIBRARIES) $(DATA) $(HEADERS)
 installdirs:
-	for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(libSDL2_rtfincludedir)"; do \
+	for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgconfigdir)" "$(DESTDIR)$(libSDL2_rtfincludedir)"; do \
 	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
 	done
 install: install-am
@@ -887,7 +924,8 @@ info: info-am
 
 info-am:
 
-install-data-am: install-libSDL2_rtfincludeHEADERS
+install-data-am: install-data-local install-libSDL2_rtfincludeHEADERS \
+	install-pkgconfigDATA
 
 install-dvi: install-dvi-am
 
@@ -940,9 +978,10 @@ ps: ps-am
 ps-am:
 
 uninstall-am: uninstall-libLTLIBRARIES \
-	uninstall-libSDL2_rtfincludeHEADERS
-
-.MAKE: install-am install-strip
+	uninstall-libSDL2_rtfincludeHEADERS uninstall-pkgconfigDATA
+	@$(NORMAL_INSTALL)
+	$(MAKE) $(AM_MAKEFLAGS) uninstall-hook
+.MAKE: install-am install-strip uninstall-am
 
 .PHONY: CTAGS GTAGS TAGS all all-am am--depfiles am--refresh check \
 	check-am clean clean-cscope clean-generic clean-libLTLIBRARIES \
@@ -952,17 +991,18 @@ uninstall-am: uninstall-libLTLIBRARIES \
 	distclean distclean-compile distclean-generic \
 	distclean-libtool distclean-tags distcleancheck distdir \
 	distuninstallcheck dvi dvi-am html html-am info info-am \
-	install install-am install-data install-data-am install-dvi \
-	install-dvi-am install-exec install-exec-am install-html \
-	install-html-am install-info install-info-am \
-	install-libLTLIBRARIES install-libSDL2_rtfincludeHEADERS \
-	install-man install-pdf install-pdf-am install-ps \
-	install-ps-am install-strip installcheck installcheck-am \
-	installdirs maintainer-clean maintainer-clean-generic \
-	mostlyclean mostlyclean-compile mostlyclean-generic \
-	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
-	uninstall-am uninstall-libLTLIBRARIES \
-	uninstall-libSDL2_rtfincludeHEADERS
+	install install-am install-data install-data-am \
+	install-data-local install-dvi install-dvi-am install-exec \
+	install-exec-am install-html install-html-am install-info \
+	install-info-am install-libLTLIBRARIES \
+	install-libSDL2_rtfincludeHEADERS install-man install-pdf \
+	install-pdf-am install-pkgconfigDATA install-ps install-ps-am \
+	install-strip installcheck installcheck-am installdirs \
+	maintainer-clean maintainer-clean-generic mostlyclean \
+	mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
+	pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am \
+	uninstall-hook uninstall-libLTLIBRARIES \
+	uninstall-libSDL2_rtfincludeHEADERS uninstall-pkgconfigDATA
 
 .PRECIOUS: Makefile
 
@@ -977,6 +1017,16 @@ $(PACKAGE)-$(VERSION).tar.gz: distcheck
 rpm: $(PACKAGE)-$(VERSION).tar.gz
 	rpmbuild -ta $(PACKAGE)-$(VERSION).tar.gz
 
+install-data-local:
+	$(MKDIR_P) $(DESTDIR)$(libdir)/cmake/SDL2_rtf
+	$(INSTALL) -m 644 sdl2_rtf-config.cmake $(DESTDIR)$(libdir)/cmake/SDL2_rtf
+	$(INSTALL) -m 644 sdl2_rtf-config-version.cmake $(DESTDIR)$(libdir)/cmake/SDL2_rtf
+
+uninstall-hook:
+	rm $(DESTDIR)$(libdir)/cmake/SDL2_rtf/sdl2_rtf-config.cmake
+	rm $(DESTDIR)$(libdir)/cmake/SDL2_rtf/sdl2_rtf-config-version.cmake
+	rm -r $(DESTDIR)$(libdir)/cmake/SDL2_rtf
+
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
diff --git a/Makefile.os2 b/Makefile.os2
index 2ce415c..4f8e8bf 100644
--- a/Makefile.os2
+++ b/Makefile.os2
@@ -5,7 +5,10 @@
 # your own environment!.
 
 LIBNAME = SDL2rtf
-VERSION = 2.0.0
+MAJOR_VERSION = 2
+MINOR_VERSION = 0
+MICRO_VERSION = 0
+VERSION = $(MAJOR_VERSION).$(MINOR_VERSION).$(MICRO_VERSION)
 
 TITLENAME = $(LIBNAME) $(VERSION)
 
diff --git a/SDL2_rtf.pc.in b/SDL2_rtf.pc.in
new file mode 100644
index 0000000..7cff4bb
--- /dev/null
+++ b/SDL2_rtf.pc.in
@@ -0,0 +1,13 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: SDL2_rtf
+Description: Support for Rich Text Format (.rtf) files with Simple Directmedia Layer
+Version: @VERSION@
+Requires: sdl2 >= @SDL_VERSION@
+Libs: -L${libdir} -lSDL2_rtf
+Cflags: -I${includedir}/SDL2
+Requires.private: @PC_REQUIRES@
+Libs.private: @PC_LIBS@
diff --git a/SDL2_rtfConfig.cmake.in b/SDL2_rtfConfig.cmake.in
new file mode 100644
index 0000000..22675d7
--- /dev/null
+++ b/SDL2_rtfConfig.cmake.in
@@ -0,0 +1,17 @@
+# sdl2_rtf cmake project-config input for CMakeLists.txt script
+
+include(FeatureSummary)
+set_package_properties(SDL2_rtf PROPERTIES
+    URL "https://www.libsdl.org/projects/SDL_rtf/"
+    DESCRIPTION "Support for Rich Text Format (.rtf) files with Simple Directmedia Layer"
+)
+
+set(SDL2_rtf_FOUND ON)
+
+if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL2_rtf-shared-targets.cmake")
+    include("${CMAKE_CURRENT_LIST_DIR}/SDL2_rtf-shared-targets.cmake")
+endif()
+
+if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL2_rtf-static-targets.cmake")
+    include("${CMAKE_CURRENT_LIST_DIR}/SDL2_rtf-static-targets.cmake")
+endif()
diff --git a/acinclude/libtool.m4 b/acinclude/libtool.m4
index 94a5a73..a644432 100644
--- a/acinclude/libtool.m4
+++ b/acinclude/libtool.m4
@@ -1,9 +1,6 @@
-##############################################################################
-# Based on libtool-2.2.6a.
 # libtool.m4 - Configure libtool for the host system. -*-Autoconf-*-
 #
-#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
-#                 2006, 2007, 2008 Free Software Foundation, Inc.
+#   Copyright (C) 1996-2001, 2003-2015 Free Software Foundation, Inc.
 #   Written by Gordon Matzigkeit, 1996
 #
 # This file is free software; the Free Software Foundation gives
@@ -11,35 +8,30 @@
 # modifications, as long as this notice is preserved.
 
 m4_define([_LT_COPYING], [dnl
-#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
-#                 2006, 2007, 2008 Free Software Foundation, Inc.
-#   Written by Gordon Matzigkeit, 1996
-#
-#   This file is part of GNU Libtool.
+# Copyright (C) 2014 Free Software Foundation, Inc.
+# This is free software; see the source for copying conditions.  There is NO
+# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# GNU Libtool is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of of the License, or
+# (at your option) any later version.
 #
-# GNU Libtool is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program or library that is built
+# using GNU Libtool, you may include this file under the  same
+# distribution terms that you use for the rest of that program.
 #
-# As a special exception to the GNU General Public License,
-# if you distribute this file as part of a program or library that
-# is built using GNU Libtool, you may include this file under the
-# same distribution terms that you use for the rest of that program.
-#
-# GNU Libtool is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# GNU Libtool is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with GNU Libtool; see the file COPYING.  If not, a copy
-# can be downloaded from http://www.gnu.org/licenses/gpl.html, or
-# obtained by writing to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ])
 
-# serial 56 LT_INIT
+# serial 58 LT_INIT
 
 
 # LT_PREREQ(VERSION)
@@ -67,7 +59,8 @@ esac
 # LT_INIT([OPTIONS])
 # ------------------
 AC_DEFUN([LT_INIT],
-[AC_PREREQ([2.58])dnl We use AC_INCLUDES_DEFAULT
+[AC_PREREQ([2.62])dnl We use AC_PATH_PROGS_FEATURE_CHECK
+AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
 AC_BEFORE([$0], [LT_LANG])dnl
 AC_BEFORE([$0], [LT_OUTPUT])dnl
 AC_BEFORE([$0], [LTDL_INIT])dnl
@@ -84,11 +77,13 @@ AC_REQUIRE([LTVERSION_VERSION])dnl
 AC_REQUIRE([LTOBSOLETE_VERSION])dnl
 m4_require([_LT_PROG_LTMAIN])dnl
 
+_LT_SHELL_INIT([SHELL=${CONFIG_SHELL-/bin/sh}])
+
 dnl Parse OPTIONS
 _LT_SET_OPTIONS([$0], [$1])
 
 # This can be used to rebuild libtool when needed
-LIBTOOL_DEPS="$ltmain"
+LIBTOOL_DEPS=$ltmain
 
 # Always use our own libtool.
 LIBTOOL='$(SHELL) $(top_builddir)/libtool'
@@ -108,26 +103,43 @@ dnl AC_DEFUN([AC_PROG_LIBTOOL], [])
 dnl AC_DEFUN([AM_PROG_LIBTOOL], [])
 
 
+# _LT_PREPARE_CC_BASENAME
+# -----------------------
+m4_defun([_LT_PREPARE_CC_BASENAME], [
+# Calculate cc_basename.  Skip known compiler wrappers and cross-prefix.
+func_cc_basename ()
+{
+    for cc_temp in @S|@*""; do
+      case $cc_temp in
+        compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;;
+        distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;;
+        \-*) ;;
+        *) break;;
+      esac
+    done
+    func_cc_basename_result=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"`
+}
+])# _LT_PREPARE_CC_BASENAME
+
+
 # _LT_CC_BASENAME(CC)
 # -------------------
-# Calculate cc_basename.  Skip known compiler wrappers and cross-prefix.
+# It would be clearer to call AC_REQUIREs from _LT_PREPARE_CC_BASENAME,
+# but that macro is also expanded into generated libtool script, which
+# arranges for $SED and $ECHO to be set by different means.
 m4_defun([_LT_CC_BASENAME],
-[for cc_temp in $1""; do
-  case $cc_temp in
-    compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;;
-    distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;;
-    \-*) ;;
-    *) break;;
-  esac
-done
-cc_basename=`$ECHO "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
+[m4_require([_LT_PREPARE_CC_BASENAME])dnl
+AC_REQUIRE([_LT_DECL_SED])dnl
+AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH])dnl
+func_cc_basename $1
+cc_basename=$func_cc_basename_result
 ])
 
 
 # _LT_FILEUTILS_DEFAULTS
 # ----------------------
 # It is okay to use these file commands and assume they have been set
-# sensibly after `m4_require([_LT_FILEUTILS_DEFAULTS])'.
+# sensibly after 'm4_require([_LT_FILEUTILS_DEFAULTS])'.
 m4_defun([_LT_FILEUTILS_DEFAULTS],
 [: ${CP="cp -f"}
 : ${MV="mv -f"}
@@ -140,6 +152,11 @@ m4_defun([_LT_FILEUTILS_DEFAULTS],
 m4_defun([_LT_SETUP],
 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
 AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+AC_REQUIRE([_LT_PREPARE_SED_QUOTE_VARS])dnl
+AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH])dnl
+
+_LT_DECL([], [PATH_SEPARATOR], [1], [The PATH separator for the build system])dnl
+dnl
 _LT_DECL([], [host_alias], [0], [The host system])dnl
 _LT_DECL([], [host], [0])dnl
 _LT_DECL([], [host_os], [0])dnl
@@ -162,68 +179,54 @@ _LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl
 dnl
 m4_require([_LT_FILEUTILS_DEFAULTS])dnl
 m4_require([_LT_CHECK_SHELL_FEATURES])dnl
+m4_require([_LT_PATH_CONVERSION_FUNCTIONS])dnl
 m4_require([_LT_CMD_RELOAD])dnl
 m4_require([_LT_CHECK_MAGIC_METHOD])dnl
+m4_require([_LT_CHECK_SHAREDLIB_FROM_LINKLIB])dnl
 m4_require([_LT_CMD_OLD_ARCHIVE])dnl
 m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl
+m4_require([_LT_WITH_SYSROOT])dnl
+m4_require([_LT_CMD_TRUNCATE])dnl
 
 _LT_CONFIG_LIBTOOL_INIT([
-# See if we are running on zsh, and set the options which allow our
+# See if we are running on zsh, and set the options that allow our
 # commands through without removal of \ escapes INIT.
-if test -n "\${ZSH_VERSION+set}" ; then
+if test -n "\${ZSH_VERSION+set}"; then
    setopt NO_GLOB_SUBST
 fi
 ])
-if test -n "${ZSH_VERSION+set}" ; then
+if test -n "${ZSH_VERSION+set}"; then
    setopt NO_GLOB_SUBST
 fi
 
 _LT_CHECK_OBJDIR
 
 m4_require([_LT_TAG_COMPILER])dnl
-_LT_PROG_ECHO_BACKSLASH
 
 case $host_os in
 aix3*)
   # AIX sometimes has problems with the GCC collect2 program.  For some
   # reason, if we set the COLLECT_NAMES environment variable, the problems
   # vanish in a puff of smoke.
-  if test "X${COLLECT_NAMES+set}" != Xset; then
+  if test set != "${COLLECT_NAMES+set}"; then
     COLLECT_NAMES=
     export COLLECT_NAMES
   fi
   ;;
 esac
 
-# Sed substitution that helps us do robust quoting.  It backslashifies
-# metacharacters that are still active within double-quoted strings.
-sed_quote_subst='s/\([["`$\\]]\)/\\\1/g'
-
-# Same as above, but do not quote variable references.
-double_quote_subst='s/\([["`\\]]\)/\\\1/g'
-
-# Sed substitution to delay expansion of an escaped shell variable in a
-# double_quote_subst'ed string.
-delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
-
-# Sed substitution to delay expansion of an escaped single quote.
-delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g'
-
-# Sed substitution to avoid accidental globbing in evaled expressions
-no_glob_subst='s/\*/\\\*/g'
-
 # Global v

(Patch may be truncated, please check the link at the top of this post.)