setup-sdl: Export environent variables for sdl2-config and pkg-config

From a91f14a5b7cd898037135c5e1f46e916ac7b8a09 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Fri, 30 Jun 2023 20:45:02 +0200
Subject: [PATCH] Export environent variables for sdl2-config and pkg-config

---
 action.yml      |  2 +-
 packed/index.js | 16 +++++++++++++++-
 src/main.ts     | 16 ++++++++++++++++
 3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/action.yml b/action.yml
index 99e1a12..f25653f 100644
--- a/action.yml
+++ b/action.yml
@@ -1,5 +1,5 @@
 name: "Setup SDL"
-description: "Set up SDL and add the path of SDL2.dll to the PATH."
+description: "Set up SDL"
 inputs:
   version:
     description: "Minimum required version of SDL (2.x.y, 2-any, 2-latest, 2-head, 3-head), or git hash"
diff --git a/packed/index.js b/packed/index.js
index 734d5ae..80cab11 100644
--- a/packed/index.js
+++ b/packed/index.js
@@ -347,7 +347,7 @@ function get_cmake_toolchain_path() {
 }
 function run() {
     return __awaiter(this, void 0, void 0, function () {
-        var SDL_BUILD_PLATFORM, SETUP_SDL_ROOT, IGNORED_SHELLS, shell_in, SHELL, REQUESTED_VERSION_TYPE, CMAKE_BUILD_TYPE, CMAKE_BUILD_TYPES, git_branch_hash, requested_version, requested_type, github_releases, release_db, sdl_release, GIT_HASH, CMAKE_TOOLCHAIN_FILE, STATE_HASH, PACKAGE_DIR, CACHE_KEY, CACHE_PATHS, sdl_from_cache, SOURCE_DIR, BUILD_DIR, USE_NINJA, cmake_configure_args, SDL_VERSION;
+        var SDL_BUILD_PLATFORM, SETUP_SDL_ROOT, IGNORED_SHELLS, shell_in, SHELL, REQUESTED_VERSION_TYPE, CMAKE_BUILD_TYPE, CMAKE_BUILD_TYPES, git_branch_hash, requested_version, requested_type, github_releases, release_db, sdl_release, GIT_HASH, CMAKE_TOOLCHAIN_FILE, STATE_HASH, PACKAGE_DIR, CACHE_KEY, CACHE_PATHS, sdl_from_cache, SOURCE_DIR, BUILD_DIR, USE_NINJA, cmake_configure_args, SDL_VERSION, pkg_config_path, sdl2_config;
         var _this = this;
         return __generator(this, function (_a) {
             switch (_a.label) {
@@ -501,6 +501,20 @@ function run() {
                     if (core.getBooleanInput("add-to-environment")) {
                         (0, platform_1.export_environent_variables)(SDL_BUILD_PLATFORM, PACKAGE_DIR);
                     }
+                    pkg_config_path = process.env.PKG_CONFIG_PATH;
+                    if (pkg_config_path) {
+                        pkg_config_path += path.delimiter;
+                    }
+                    else {
+                        pkg_config_path = "";
+                    }
+                    pkg_config_path += path.join(PACKAGE_DIR, "lib", "pkgconfig").replace("\\", "/");
+                    core.exportVariable("PKG_CONFIG_PATH", pkg_config_path);
+                    // Set SDL2_CONFIG environment variable
+                    if (SDL_VERSION.major == 2) {
+                        sdl2_config = path.join(PACKAGE_DIR, "bin", "sdl2-config").replace("\\", "/");
+                        core.exportVariable("SDL2_CONFIG", sdl2_config);
+                    }
                     core.exportVariable("SDL".concat(SDL_VERSION.major, "_ROOT"), PACKAGE_DIR);
                     core.setOutput("prefix", PACKAGE_DIR);
                     core.setOutput("version", SDL_VERSION.toString());
diff --git a/src/main.ts b/src/main.ts
index 89f2805..55fe088 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -414,6 +414,22 @@ async function run() {
     export_environent_variables(SDL_BUILD_PLATFORM, PACKAGE_DIR);
   }
 
+  // Append <prefix>/lib/pkgconfig to PKG_CONFIG_PATH
+  let pkg_config_path = process.env.PKG_CONFIG_PATH;
+  if (pkg_config_path) {
+    pkg_config_path += path.delimiter;
+  } else {
+    pkg_config_path = ""
+  }
+  pkg_config_path += path.join(PACKAGE_DIR, "lib", "pkgconfig").replace("\\", "/");
+  core.exportVariable("PKG_CONFIG_PATH", pkg_config_path);
+
+  // Set SDL2_CONFIG environment variable
+  if (SDL_VERSION.major == 2) {
+    const sdl2_config = path.join(PACKAGE_DIR, "bin", "sdl2-config").replace("\\", "/");
+    core.exportVariable(`SDL2_CONFIG`, sdl2_config);
+  }
+
   core.exportVariable(`SDL${SDL_VERSION.major}_ROOT`, PACKAGE_DIR);
   core.setOutput("prefix", PACKAGE_DIR);
   core.setOutput("version", SDL_VERSION.toString());