[PATCH 5/8] Make the --define-prefix feature available on all platforms
Dan Nicholson
dbn.lists at gmail.com
Sat Apr 20 07:42:22 PDT 2013
Allowing pkg-config to override the prefix variable in .pc files is a
useful feature for making packages relocatable. There's nothing Windows
specific about it.
Freedesktop #63602 (https://bugs.freedesktop.org/show_bug.cgi?id=63602)
---
main.c | 2 +-
parse.c | 5 ++---
pkg-config.1 | 46 +++++++++++++++++++++++-----------------------
pkg.h | 4 +---
4 files changed, 27 insertions(+), 30 deletions(-)
diff --git a/main.c b/main.c
index f76ac87..8991479 100644
--- a/main.c
+++ b/main.c
@@ -461,7 +461,6 @@ static const GOptionEntry options_table[] = {
{ "print-requires-private", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
&output_opt_cb, "print which packages the package requires for static "
"linking", NULL },
-#ifdef G_OS_WIN32
{ "define-prefix", 0, 0, G_OPTION_ARG_NONE, &define_prefix,
"try to override the value of prefix for each .pc file found with a "
"guesstimated value based on the location of the .pc file", NULL },
@@ -472,6 +471,7 @@ static const GOptionEntry options_table[] = {
{ "prefix-variable", 0, 0, G_OPTION_ARG_STRING, &prefix_variable,
"set the name of the variable that pkg-config automatically sets",
"PREFIX" },
+#ifdef G_OS_WIN32
{ "msvc-syntax", 0, 0, G_OPTION_ARG_NONE, &msvc_syntax,
"output -l and -L flags for the Microsoft compiler (cl)", NULL },
#endif
diff --git a/parse.c b/parse.c
index 0b98be5..64399e6 100644
--- a/parse.c
+++ b/parse.c
@@ -34,9 +34,10 @@
#endif
#include <sys/types.h>
-#ifdef G_OS_WIN32
gboolean define_prefix = ENABLE_DEFINE_PREFIX;
char *prefix_variable = "prefix";
+
+#ifdef G_OS_WIN32
gboolean msvc_syntax = FALSE;
#endif
@@ -943,7 +944,6 @@ parse_line (Package *pkg, const char *untrimmed, const char *path,
if (pkg->vars == NULL)
pkg->vars = g_hash_table_new (g_str_hash, g_str_equal);
-#ifdef G_OS_WIN32
if (define_prefix && strcmp (tag, prefix_variable) == 0)
{
/* This is the prefix variable. Try to guesstimate a value for it
@@ -1006,7 +1006,6 @@ parse_line (Package *pkg, const char *untrimmed, const char *path,
p + strlen (pkg->orig_prefix), NULL);
g_free (oldstr);
}
-#endif
if (g_hash_table_lookup (pkg->vars, tag))
{
diff --git a/pkg-config.1 b/pkg-config.1
index 5efb486..427bf76 100644
--- a/pkg-config.1
+++ b/pkg-config.1
@@ -211,20 +211,37 @@ for the linker, and should be placed on the cl command line after a
.I "--define-prefix"
.TQ
.I "--dont-define-prefix"
-These options are available only on Windows. They control whether
+These options control whether
.I pkg-config
-overrides the value of the variable "prefix" in each .pc file. With
-\-\-define-prefix,
+overrides the value of the variable
+.I prefix
+in each .pc file. With \-\-define-prefix,
.I pkg-config
uses the installed location of the .pc file to determine the
prefix. \-\-dont-define-prefix prevents this behavior. The default is
usually \-\-define-prefix.
+
+When this feature is enabled and a .pc file is found in a directory named
+.IR pkgconfig ,
+the prefix for that package is assumed to be the grandparent of the
+directory where the file was found, and the
+.I prefix
+variable is overridden for that file accordingly.
+
+If the value of a variable in a .pc file begins with the original,
+non-overridden, value of the
+.I prefix
+variable, then the overridden value of
+.I prefix
+is used instead. This allows the feature to work even when the variables
+have been expanded in the .pc file.
.TP
.I "--prefix-variable=PREFIX"
-This option is available only on Windows. It sets the name of the
-variable that
+Set the name of the variable that
.I pkg-config
-overrides instead of "prefix" when using the \-\-define-prefix feature.
+overrides instead of
+.I prefix
+when using the \-\-define-prefix feature.
.TP
.I "--static"
Output libraries suitable for static linking. That means including
@@ -314,23 +331,6 @@ and
.IR share\epkgconfig .
This can be augmented or replaced using the standard environment
variables described above.
-
-If a .pc file is found in a directory named
-.IR pkgconfig ,
-the prefix for that package is assumed to be the grandparent of the
-directory where the file was found, and the
-.I prefix
-variable is overridden for that file accordingly.
-
-If the value of a variable in a .pc file begins with the original,
-non-overridden, value of the
-.I prefix
-variable, then the overridden value of
-.I prefix
-is used instead. This allows the feature to work even when the variables
-have been expanded in the .pc file.
-
-See the \-\-dont-define-prefix option for disabling this feature.
.\"
.SH AUTOCONF MACROS
.TP
diff --git a/pkg.h b/pkg.h
index fe50e87..328ac26 100644
--- a/pkg.h
+++ b/pkg.h
@@ -85,9 +85,7 @@ struct _Package
int libs_num; /* Number of times the "Libs" header has been seen */
int libs_private_num; /* Number of times the "Libs.private" header has been seen */
gboolean in_requires_chain; /* package is in current Requires chain */
-#ifdef G_OS_WIN32
char *orig_prefix; /* original prefix value before redefinition */
-#endif
};
Package *get_package (const char *name);
@@ -136,13 +134,13 @@ extern char *pcsysrootdir;
*/
extern char *pkg_config_pc_path;
-#ifdef G_OS_WIN32
/* If TRUE, define "prefix" in .pc files at runtime. */
extern gboolean define_prefix;
/* The name of the variable that acts as prefix, unless it is "prefix" */
extern char *prefix_variable;
+#ifdef G_OS_WIN32
/* If TRUE, output flags in MSVC syntax. */
extern gboolean msvc_syntax;
#endif
--
1.8.1.4
More information about the pkg-config
mailing list