Allow more control of redefined prefix behavior

Currently the native Win32 builds default to redefining the prefix
variable in .pc files based on their installation paths. This behavior
is not always desired when pkg-config is being used in a traditional
fixed path environment (e.g., /mingw like /usr).

Allow the default to be set via configure switch
--enable/disable-define-prefix, and allow it to be set both ways at
runtime through the --[dont-]define-prefix pkg-config option.
This commit is contained in:
Dan Nicholson 2013-04-10 17:59:35 -07:00
parent 636e804ded
commit 409ee76ce1
5 changed files with 40 additions and 14 deletions

View file

@ -161,6 +161,19 @@ if test "$cross_compiling" = yes && test "$native_win32" = yes; then
test "x$WINE" != x && TESTS_PKG_CONFIG='${WINE} '"$TESTS_PKG_CONFIG"
fi
dnl On Windows, the prefix variable in .pc files can be redfined at
dnl runtime. Allow the default behavior to be controlled.
AC_MSG_CHECKING([if prefix should be redefined at runtime])
AC_ARG_ENABLE([define_prefix],
[AS_HELP_STRING([--enable-define-prefix],
[redefine prefix in .pc files @<:@default=yes on Win32@:>@])],
[],
[enable_define_prefix=$native_win32])
AC_MSG_RESULT([$enable_define_prefix])
AC_DEFINE_UNQUOTED([ENABLE_DEFINE_PREFIX],
[`test "x$enable_define_prefix" = xyes && echo TRUE || echo FALSE`],
[Define ${prefix} in .pc files at runtime])
dnl
dnl Find glib or use internal copy. Required version is 2.16 for
dnl g_win32_get_package_installation_directory_of_module().

10
main.c
View file

@ -462,9 +462,13 @@ static const GOptionEntry options_table[] = {
&output_opt_cb, "print which packages the package requires for static "
"linking", NULL },
#ifdef G_OS_WIN32
{ "dont-define-prefix", 0, 0, G_OPTION_ARG_NONE, &dont_define_prefix,
"don't 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 },
{ "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 },
{ "dont-define-prefix", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,
&define_prefix, "don't 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 },
{ "prefix-variable", 0, 0, G_OPTION_ARG_STRING, &prefix_variable,
"set the name of the variable that pkg-config automatically sets",
"PREFIX" },

View file

@ -35,7 +35,7 @@
#include <sys/types.h>
#ifdef G_OS_WIN32
gboolean dont_define_prefix = FALSE;
gboolean define_prefix = ENABLE_DEFINE_PREFIX;
char *prefix_variable = "prefix";
gboolean msvc_syntax = FALSE;
#endif
@ -968,7 +968,7 @@ parse_line (Package *pkg, const char *untrimmed, const char *path,
pkg->vars = g_hash_table_new (g_str_hash, g_str_equal);
#ifdef G_OS_WIN32
if (!dont_define_prefix && strcmp (tag, prefix_variable) == 0)
if (define_prefix && strcmp (tag, prefix_variable) == 0)
{
/* This is the prefix variable. Try to guesstimate a value for it
* for this package from the location of the .pc file.
@ -1025,7 +1025,7 @@ parse_line (Package *pkg, const char *untrimmed, const char *path,
goto cleanup;
}
}
else if (!dont_define_prefix &&
else if (define_prefix &&
orig_prefix != NULL &&
strncmp (p, orig_prefix, strlen (orig_prefix)) == 0 &&
G_IS_DIR_SEPARATOR (p[strlen (orig_prefix)]))

View file

@ -208,14 +208,23 @@ 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
.I "--define-prefix"
.TQ
.I "--dont-define-prefix"
This option is available only on Windows. It prevents \fIpkg-config\fP
from automatically trying to override the value of the variable
"prefix" in each .pc file.
These options are available only on Windows. They control whether
.I pkg-config
overrides the value of the variable "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.
.TP
.I "--prefix-variable=PREFIX"
Also this option is available only on Windows. It sets the name of the
variable that \fIpkg-config\fP automatically sets as described above.
This option is available only on Windows. It sets the name of the
variable that
.I pkg-config
overrides instead of "prefix" when using the \-\-define-prefix feature.
.TP
.I "--static"
Output libraries suitable for static linking. That means including

6
pkg.h
View file

@ -134,9 +134,9 @@ extern char *pcsysrootdir;
extern char *pkg_config_pc_path;
#ifdef G_OS_WIN32
/* If TRUE, do not automatically define "prefix" while
* parsing each .pc file */
extern gboolean dont_define_prefix;
/* 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;