2023-04-27  Juan Manuel Guerrero <juan.guerrero@gmx.de>


	* glib-1.2.10/glib.h [__DJGPP__]: For DJGPP replace the hard coded values for
	G_SEARCHPATH_SEPARATOR and G_SEARCHPATH_SEPARATOR_S by the appropriate values
	taken from string dos_path_separator.

	* glib-1.2.10/tests/string-test.c (main): DJGPP doprnt does not like the
	%10000.10000f format.

	* main.c [G_OS_DJGPP]: For DJGPP add an constructor that will call canonicalize_pkg_paths()
	and sets restore_changed_pkg_paths for atexit().

	* parse.c [G_OS_DJGPP]: For DJGPP replace the call to getc_unlocked, flockfile and
	funlockfile by macros.  These MT file locking functions are not provided by DJGPP.

	* pkg-config-guide.html: Replace POSIX specific paths by DJGPP specific ones.

	* pkg-config.1: Replace POSIX specific paths by DJGPP specific ones.

	* pkg.c [G_OS_DJGPP]: For DJGPP define dos_path_separator, canonicalize_pkg_paths()
	and restore_changed_pkg_paths().

	* pkg.h [G_OS_DJGPP]: For DJGPP provide canonicalize_pkg_paths() and
	restore_changed_pkg_paths() prototypes.

	* popt.c [G_OS_DJGPP]: For DJGPP replace the call to setreuid by a macro.  It does
	nothing than returning without error.






diff -aprNU5 pkg-config-0.25.orig/glib-1.2.10/glib.h pkg-config-0.25/glib-1.2.10/glib.h
--- pkg-config-0.25.orig/glib-1.2.10/glib.h	2001-02-27 03:44:38 +0000
+++ pkg-config-0.25/glib-1.2.10/glib.h	2023-04-27 20:10:22 +0000
@@ -87,17 +87,29 @@
 #define G_SEARCHPATH_SEPARATOR_S ";"
 
 #else  /* !NATIVE_WIN32 */
 
 #ifndef __EMX__
+#ifdef __DJGPP__
+/* DJGPP/MS-DOS/FreeDOS */
+
+extern char dos_path_separator[2];
+
+#define G_DIR_SEPARATOR '/'
+#define G_DIR_SEPARATOR_S "/"
+#define G_SEARCHPATH_SEPARATOR   (dos_path_separator[0])
+#define G_SEARCHPATH_SEPARATOR_S (dos_path_separator)
+
+#else
 /* Unix */
 
 #define G_DIR_SEPARATOR '/'
 #define G_DIR_SEPARATOR_S "/"
 #define G_SEARCHPATH_SEPARATOR ':'
 #define G_SEARCHPATH_SEPARATOR_S ":"
 
+#endif
 #else
 /* EMX/OS2 */
 
 #define G_DIR_SEPARATOR '/'
 #define G_DIR_SEPARATOR_S "/"
diff -aprNU5 pkg-config-0.25.orig/glib-1.2.10/tests/string-test.c pkg-config-0.25/glib-1.2.10/tests/string-test.c
--- pkg-config-0.25.orig/glib-1.2.10/tests/string-test.c	1999-02-24 06:14:24 +0000
+++ pkg-config-0.25/glib-1.2.10/tests/string-test.c	2023-04-27 20:10:22 +0000
@@ -101,11 +101,11 @@ main (int   argc,
     g_string_append_c (string1, 'a'+(i%26));
 
   g_assert((strlen("hi pete!") + 10000) == string1->len);
   g_assert((strlen("hi pete!") + 10000) == strlen(string1->str));
 
-#if !(defined (_MSC_VER) || defined (__LCC__))
+#if !(defined (_MSC_VER) || defined (__LCC__) || defined (__DJGPP__))
   /* MSVC and LCC use the same run-time C library, which doesn't like
      the %10000.10000f format... */
   g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%10000.10000f",
 		    "this pete guy sure is a wuss, like he's the number ",
 		    1,
diff -aprNU5 pkg-config-0.25.orig/main.c pkg-config-0.25/main.c
--- pkg-config-0.25.orig/main.c	2010-05-10 17:58:56 +0000
+++ pkg-config-0.25/main.c	2023-04-27 20:10:22 +0000
@@ -169,10 +169,35 @@ print_hashtable_key (gpointer key,
                      gpointer user_data)
 {
   printf("%s\n", (gchar*)key);
 }
 
+#ifdef G_OS_DJGPP
+/* This is called before `main' to cononicalize all paths
+   in the environment and to get the path separator.
+   For DJGPP the path separator is infered at run-time by inspection
+   of the PATH_SEPARATOR enviroinment variable or assuming a default.  */
+static void __attribute__((constructor))
+djgpp_pkg_config_startup (void)
+{
+  char *paths[NUMBER_OF_PKG_PATHS] = {
+    /*  Paths from environment.  */
+    "PKG_CONFIG_PATH",
+    "PKG_CONFIG_LIBDIR",
+    "PKG_CONFIG_SYSROOT_DIR",
+    "PKG_CONFIG_TOP_BUILD_DIR",
+    NULL,
+
+    /*  Hard coded paths at compile time.  */
+    PKG_CONFIG_PC_PATH,
+    NULL
+  };
+  canonicalize_pkg_paths (paths);
+  atexit (restore_changed_pkg_paths);
+}
+#endif
+
 int
 main (int argc, char **argv)
 {
   static int want_my_version = 0;
   static int want_version = 0;
diff -aprNU5 pkg-config-0.25.orig/parse.c pkg-config-0.25/parse.c
--- pkg-config-0.25.orig/parse.c	2010-05-27 20:21:36 +0000
+++ pkg-config-0.25/parse.c	2023-04-27 20:10:22 +0000
@@ -44,10 +44,26 @@ int msvc_syntax = FALSE;
 #ifndef G_IS_DIR_SEPARATOR
 #define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/')
 #endif
 #endif
 
+#ifdef G_OS_DJGPP
+/*  DJGPP does not provide neither of these.  */
+# undef  getc_unlocked
+# define getc_unlocked(filehandle)    \
+  (__gnuc_extension__                 \
+    ({                                \
+       int __c = getc((filehandle));  \
+       __c;                           \
+    })                                \
+  )
+# undef  flockfile
+# define flockfile(filehandle)    /* void */
+# undef  funlockfile
+# define funlockfile(filehandle)  /* void */
+#endif
+
 /**
  * Read an entire line from a file into a buffer. Lines may
  * be delimited with '\n', '\r', '\n\r', or '\r\n'. The delimiter
  * is not written into the buffer. Text after a '#' character is treated as
  * a comment and skipped. '\' can be used to escape a # character.
diff -aprNU5 pkg-config-0.25.orig/pkg-config-guide.html pkg-config-0.25/pkg-config-guide.html
--- pkg-config-0.25.orig/pkg-config-guide.html	2010-05-08 20:29:14 +0000
+++ pkg-config-0.25/pkg-config-guide.html	2023-04-27 20:10:22 +0000
@@ -82,11 +82,11 @@ with this program; if not, write to the
   <tt>pkg-config</tt> tool. This will be described in more detail later.</p>
 
   <p>The file format contains predefined metadata keywords and freeform
   variables. An example may be illustrative:<p>
 
-<pre>prefix=/usr/local
+<pre>prefix=/dev/env/DJDIR
 exec_prefix=${prefix}
 includedir=${prefix}/include
 libdir=${exec_prefix}/lib
 
 Name: foo
@@ -178,11 +178,11 @@ Libs: -L${libdir} -lfoo</pre>
   demonstrate variable definitions. The most common usage is to define the
   installation paths so that they don't clutter the metadata fields. Since
   the variables are expanded recursively, this is very helpful when used in
   conjunction with autoconf derived paths.</p>
 
-<pre>prefix=/usr/local
+<pre>prefix=/dev/env/DJDIR
 includedir=${prefix}/include
 
 Cflags: -I${includedir}/foo</pre>
 
   <p>The most important <tt>pkg-config</tt> metadata fields are
@@ -229,11 +229,11 @@ Cflags: -I${includedir}/foo</pre>
 
   <p>Consider a system with two modules, <tt>foo</tt> and <tt>bar</tt>.
   Their <tt>.pc</tt> files might look like this:</p>
 
 <pre>foo.pc:
-prefix=/usr
+prefix=/dev/env/DJDIR
 exec_prefix=${prefix}
 includedir=${prefix}/include
 libdir=${exec_prefix}/lib
 
 Name: foo
@@ -241,11 +241,11 @@ Description: The foo library
 Version: 1.0.0
 Cflags: -I${includedir}/foo
 Libs: -L${libdir} -lfoo
 
 bar.pc:
-prefix=/usr
+prefix=/dev/env/DJDIR
 exec_prefix=${prefix}
 includedir=${prefix}/include
 libdir=${exec_prefix}/lib
 
 Name: bar
@@ -331,11 +331,11 @@ No package 'xoxo' found</pre>
 <pre>$ pkg-config --modversion hello
 Package hello was not found in the pkg-config search path.
 Perhaps you should add the directory containing `hello.pc'
 to the PKG_CONFIG_PATH environment variable
 No package 'hello' found
-$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
+$ export PKG_CONFIG_PATH=/dev/env/DJDIR/lib/pkgconfig
 $ pkg-config --modversion hello
 1.0.0</pre>
 
   <p>A few <a href="http://www.gnu.org/software/autoconf/">autoconf</a> macros
   are also provided to ease integration of <tt>pkg-config</tt> modules into
diff -aprNU5 pkg-config-0.25.orig/pkg-config.1 pkg-config-0.25/pkg-config.1
--- pkg-config-0.25.orig/pkg-config.1	2010-05-27 20:42:42 +0000
+++ pkg-config-0.25/pkg-config.1	2023-04-27 21:38:12 +0000
@@ -53,16 +53,23 @@ program: program.c
 .I pkg-config
 retrieves information about packages from special metadata
 files. These files are named after the package, and has a
 .I .pc
 extension.  On most systems, \fIpkg-config\fP looks in
-.I/usr/lib/pkgconfig, /usr/share/pkgconfig, /usr/local/lib/pkgconfig
+.I /usr/lib/pkgconfig, /usr/share/pkgconfig, /usr/local/lib/pkgconfig
 and
-.I/usr/local/share/pkgconfig
+.I /usr/local/share/pkgconfig
  for these files.  It will additionally look in the colon-separated
 (on Windows, semicolon-separated) list of directories specified by the
 PKG_CONFIG_PATH environment variable.
+On DJGPP, the value of the PATH_SEPARATOR environment variable defines
+if a colon or a semicolon is used to separate the directories.
+On DJGPP, \fIpkg-config\fP looks in
+.I /dev/env/DJDIR/lib/pkgconfig
+and
+.I /dev/env/DJDIR/share/pkgconfig
+for these files.
 .PP
 The package name specified on the \fIpkg-config\fP command line is
 defined to be the name of the metadata file, minus the \fI.pc\fP
 extension. If a library can install multiple versions simultaneously,
 it must give each version its own name (for example, GTK 1.2 might
@@ -201,11 +208,11 @@ Remember to use \-\-print-errors if you
 .TP
 .I "--msvc-syntax"
 This option is available only on Windows. It causes \fIpkg-config\fP
 to output -l and -L flags in the form recognized by the Microsoft
 Visual C++ command-line compiler, \fIcl\fP. Specifically, instead of
-.I-Lx:/some/path
+.I -Lx:/some/path
 it prints \fI/libpath:x/some/path\fP, and instead of \fI-lfoo\fP it
 prints \fIfoo.lib\fP. Note that the --libs output consists of flags
 for the linker, and should be placed on the cl command line after a
 /link switch.
 .TP
@@ -280,10 +287,11 @@ the new system root. this means that a -
 become -I/var/target/usr/include/libfoo with a PKG_CONFIG_SYSROOT_DIR
 equal to /var/target (same rule apply to -L)
 .TP
 .I "PKG_CONFIG_LIBDIR"
 Replaces the default \fIpkg-config\fP search directory, usually \fI/usr/lib/pkgconfig\fP
+or \fI/dev/env/DJDIR/lib/pkgconfig\fP on DJGPP
 .\"
 .SH QUERYING PKG-CONFIG'S DEFAULTS
 .I pkg-config\fP can be used to query itself for the default search path, version number and other information, for instance using:
 .nf
   $ pkg-config --variable pc_path pkg-config
diff -aprNU5 pkg-config-0.25.orig/pkg.c pkg-config-0.25/pkg.c
--- pkg-config-0.25.orig/pkg.c	2010-05-08 20:14:16 +0000
+++ pkg-config-0.25/pkg.c	2023-04-27 20:10:22 +0000
@@ -60,10 +60,133 @@ static int scanned_dir_count = 0;
 gboolean disable_uninstalled = FALSE;
 gboolean ignore_requires = FALSE;
 gboolean ignore_requires_private = TRUE;
 gboolean ignore_private_libs = TRUE;
 
+#ifdef G_OS_DJGPP
+const char *orig_paths[NUMBER_OF_PKG_PATHS][2];
+char dos_path_separator[2];
+
+#define COLON_SEPARATOR       (0)
+#define SEMI_COLON_SEPARATOR  (1)
+#define GET_PATH_SEPARATOR(dos_path_separator)                          \
+ (__gnuc_extension__                                                    \
+   ({                                                                   \
+      int _type;                                                        \
+      char *_path_separator = getenv("PATH_SEPARATOR");                 \
+      if (!_path_separator)                                             \
+        _type = (SEMI_COLON_SEPARATOR);                                 \
+      else                                                              \
+      if (_path_separator[0] == ':' && _path_separator[1] == '\0')      \
+        _type = (COLON_SEPARATOR);                                      \
+      else                                                              \
+        _type = (SEMI_COLON_SEPARATOR);                                 \
+      (dos_path_separator)[0] = _type = (COLON_SEPARATOR) ? ':' : ';';  \
+      (dos_path_separator)[1] = '\0';                                   \
+   })                                                                   \
+ )
+
+void
+canonicalize_pkg_paths (char *paths[NUMBER_OF_PKG_PATHS])
+{
+#define PATH_LENGTH  1024
+  char real_path[PATH_LENGTH], **search_dirs, **iter;
+  int i;
+
+  GET_PATH_SEPARATOR (dos_path_separator);
+
+  /* Create full expanded paths with x: replaced by /dev/x
+     and backslashes replaced by slashes from environment variables.  */
+  for (i = 0; paths[i]; i++)
+    {
+      char *path = getenv (orig_paths[i][0] = paths[i]);
+      if (path)
+        {
+          char *real_dir = real_path;
+          int changed = 0;
+
+          search_dirs = g_strsplit (path, dos_path_separator, -1);
+          for (iter = search_dirs; *iter; iter++)
+            {
+              char *begin = realpath (*iter, real_dir);
+              if (begin)
+                {
+                  changed = 1;
+                  for (; *real_dir; real_dir++)
+                    ;
+                  if (PATH_LENGTH > (int)(real_dir - real_path))
+                    {
+                      *real_dir = dos_path_separator[0];
+                      if (begin[1] == ':')
+                        {
+#define OFFSET  sizeof("/dev")
+                          char drive = begin[0];
+                          char *src = real_dir, *dst = real_dir + OFFSET - 1;
+
+                          while (*src != ':')
+                            *dst-- = *src--;
+                          *dst-- = drive;
+                          *dst-- = '/';
+                          *dst-- = 'v';
+                          *dst-- = 'e';
+                          *dst-- = 'd';
+                          *dst-- = '/';
+                          real_dir += OFFSET;
+#undef OFFSET
+                        }
+                    }
+                }
+            }
+          if ((int)(real_dir - real_path) > 0)
+            *--real_dir = '\0';
+
+          if (changed)
+            {
+              orig_paths[i][1] = g_strdup (path);
+              setenv (paths[i], real_path, 1);
+            }
+          else
+            orig_paths[i][1] = NULL;
+
+          real_path[0] = '\0';
+
+          g_strfreev (search_dirs);
+        }
+    }
+
+  /* Create full expanded paths with x: replaced by /dev/x
+     and backslashes replaced by slashes from hard coded variables.  */
+  char path_sep = dos_path_separator[0] == ';' ? ':' : ';';
+  for (i++; paths[i]; i++)
+    {
+      int n;
+      for (n = 0; paths[i][n]; n++)
+        {
+          if (paths[i][n] == path_sep)
+            paths[i][n] = dos_path_separator[0];
+          else
+          if (paths[i][n] == '\\')
+            paths[i][n] = '/';
+       }
+    }
+}
+#undef GET_PATH_SEPARATOR
+#undef SEMI_COLON_SEPARATOR
+#undef COLON_SEPARATOR
+
+void
+restore_changed_pkg_paths (void)
+{
+  int i;
+  for (i = 0; i < NUMBER_OF_PKG_PATHS; i++)
+    {
+      if (orig_paths[i][1])
+        setenv (orig_paths[i][0], orig_paths[i][1], 1);
+    }
+}
+#endif /* G_OS_DJGPP */
+
 void
 add_search_dir (const char *path)
 {
   search_dirs = g_slist_append (search_dirs, g_strdup (path));
 }
diff -aprNU5 pkg-config-0.25.orig/pkg.h pkg-config-0.25/pkg.h
--- pkg-config-0.25.orig/pkg.h	2009-08-15 19:44:18 +0000
+++ pkg-config-0.25/pkg.h	2023-04-27 20:10:22 +0000
@@ -133,10 +133,16 @@ void disable_private_libs(void);
 void enable_requires(void);
 void disable_requires(void);
 void enable_requires_private(void);
 void disable_requires_private(void);
 
+#ifdef G_OS_DJGPP
+#define NUMBER_OF_PKG_PATHS (5 + 2)
+void canonicalize_pkg_paths (char *paths[NUMBER_OF_PKG_PATHS]);
+void restore_changed_pkg_paths (void);
+#endif
+
 /* If TRUE, do not automatically prefer uninstalled versions */
 extern gboolean disable_uninstalled;
 
 extern char *pcsysrootdir;
 
diff -aprNU5 pkg-config-0.25.orig/popt/popt.c pkg-config-0.25/popt/popt.c
--- pkg-config-0.25.orig/popt/popt.c	2010-05-09 08:22:02 +0000
+++ pkg-config-0.25/popt/popt.c	2023-04-27 20:10:22 +0000
@@ -46,10 +46,23 @@
 
 #include "findme.h"
 #include "popt.h"
 #include "poptint.h"
 
+#ifdef G_OS_DJGPP
+/*  DJGPP does not provide this.  */
+# undef  setreuid
+# define setreuid(ruid, euid)  \
+  (__gnuc_extension__          \
+    ({                         \
+       int __c = 0;            \
+       errno = 0;              \
+       __c;                    \
+    })                         \
+  )
+#endif
+
 void poptSetExecPath(poptContext con, const char * path, int allowAbsolute) {
     if (con->execPath) free(con->execPath);
     con->execPath = strdup(path);
     con->execAbsolute = allowAbsolute;
 }
