mirror of
https://gitlab.freedesktop.org/pkg-config/pkg-config.git
synced 2025-12-20 06:40:03 +01:00
Allow all combinations of --cflags and --libs variants
Use a bitmask to keep track of what Libs/Cflags to output. This makes it simple to handle any combination of --cflags and --libs option variants. A lot of excess code is removed in the process as all the flags options can now be carried around in a single variable. Freedesktop #54388 (https://bugs.freedesktop.org/show_bug.cgi?id=54388)
This commit is contained in:
parent
d630bf3c75
commit
90ed8f193f
7 changed files with 184 additions and 143 deletions
|
|
@ -4,6 +4,7 @@ TESTS_ENVIRONMENT = PKG_CONFIG='$(TESTS_PKG_CONFIG)' $(TESTS_SHELL)
|
|||
TESTS = \
|
||||
check-cflags \
|
||||
check-libs \
|
||||
check-mixed-flags \
|
||||
check-non-l-flags \
|
||||
check-define-variable \
|
||||
check-libs-private \
|
||||
|
|
|
|||
|
|
@ -18,3 +18,11 @@ run_test --cflags-only-I other
|
|||
|
||||
RESULT="-DOTHER"
|
||||
run_test --cflags-only-other other
|
||||
|
||||
# Try various mixed combinations
|
||||
RESULT="-DOTHER -I/other/include"
|
||||
run_test --cflags-only-I --cflags-only-other other
|
||||
run_test --cflags-only-other --cflags-only-I other
|
||||
run_test --cflags --cflags-only-I --cflags-only-other other
|
||||
run_test --cflags --cflags-only-I other
|
||||
run_test --cflags --cflags-only-other other
|
||||
|
|
|
|||
|
|
@ -25,3 +25,23 @@ run_test --libs-only-L other
|
|||
|
||||
RESULT="-Wl,--as-needed"
|
||||
run_test --libs-only-other other
|
||||
|
||||
# Try various mixed combinations
|
||||
RESULT="-L/other/lib -lother"
|
||||
run_test --libs-only-l --libs-only-L other
|
||||
run_test --libs-only-L --libs-only-l other
|
||||
|
||||
RESULT="-Wl,--as-needed -lother"
|
||||
run_test --libs-only-l --libs-only-other other
|
||||
run_test --libs-only-other --libs-only-l other
|
||||
|
||||
RESULT="-Wl,--as-needed -L/other/lib"
|
||||
run_test --libs-only-L --libs-only-other other
|
||||
run_test --libs-only-other --libs-only-L other
|
||||
|
||||
RESULT="-Wl,--as-needed -L/other/lib -lother"
|
||||
run_test --libs-only-l --libs-only-L --libs-only-other other
|
||||
run_test --libs --libs-only-l --libs-only-L --libs-only-other other
|
||||
run_test --libs --libs-only-l other
|
||||
run_test --libs --libs-only-L other
|
||||
run_test --libs --libs-only-other other
|
||||
|
|
|
|||
79
check/check-mixed-flags
Executable file
79
check/check-mixed-flags
Executable file
|
|
@ -0,0 +1,79 @@
|
|||
#! /bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
. ${srcdir}/common
|
||||
|
||||
RESULT="-DOTHER -I/other/include -Wl,--as-needed -L/other/lib -lother"
|
||||
run_test --cflags --libs other
|
||||
run_test --libs --cflags other
|
||||
run_test --cflags-only-I --cflags-only-other --libs-only-l --libs-only-L \
|
||||
--libs-only-other other
|
||||
|
||||
RESULT="-I/other/include -lother"
|
||||
run_test --cflags-only-I --libs-only-l other
|
||||
run_test --libs-only-l --cflags-only-I other
|
||||
|
||||
RESULT="-DOTHER -lother"
|
||||
run_test --cflags-only-other --libs-only-l other
|
||||
run_test --libs-only-l --cflags-only-other other
|
||||
|
||||
RESULT="-I/other/include -L/other/lib"
|
||||
run_test --cflags-only-I --libs-only-L other
|
||||
run_test --libs-only-L --cflags-only-I other
|
||||
|
||||
RESULT="-DOTHER -L/other/lib"
|
||||
run_test --cflags-only-other --libs-only-L other
|
||||
run_test --libs-only-L --cflags-only-other other
|
||||
|
||||
RESULT="-I/other/include -Wl,--as-needed"
|
||||
run_test --cflags-only-I --libs-only-other other
|
||||
run_test --libs-only-other --cflags-only-I other
|
||||
|
||||
RESULT="-DOTHER -Wl,--as-needed"
|
||||
run_test --cflags-only-other --libs-only-other other
|
||||
run_test --libs-only-other --cflags-only-other other
|
||||
|
||||
RESULT="-I/other/include -L/other/lib -lother"
|
||||
run_test --cflags-only-I --libs-only-L --libs-only-l other
|
||||
run_test --libs-only-l --libs-only-L --cflags-only-I other
|
||||
|
||||
RESULT="-DOTHER -L/other/lib -lother"
|
||||
run_test --cflags-only-other --libs-only-L --libs-only-l other
|
||||
run_test --libs-only-l --libs-only-L --cflags-only-other other
|
||||
|
||||
RESULT="-I/other/include -Wl,--as-needed -lother"
|
||||
run_test --cflags-only-I --libs-only-other --libs-only-l other
|
||||
run_test --libs-only-l --libs-only-other --cflags-only-I other
|
||||
|
||||
RESULT="-DOTHER -Wl,--as-needed -lother"
|
||||
run_test --cflags-only-other --libs-only-other --libs-only-l other
|
||||
run_test --libs-only-l --libs-only-other --cflags-only-other other
|
||||
|
||||
RESULT="-I/other/include -Wl,--as-needed -L/other/lib"
|
||||
run_test --cflags-only-I --libs-only-other --libs-only-L other
|
||||
run_test --libs-only-L --libs-only-other --cflags-only-I other
|
||||
|
||||
RESULT="-DOTHER -Wl,--as-needed -L/other/lib"
|
||||
run_test --cflags-only-other --libs-only-other --libs-only-L other
|
||||
run_test --libs-only-L --libs-only-other --cflags-only-other other
|
||||
|
||||
RESULT="-DOTHER -I/other/include -lother"
|
||||
run_test --cflags --libs-only-l other
|
||||
run_test --cflags-only-I --cflags-only-other --libs-only-l other
|
||||
|
||||
RESULT="-DOTHER -I/other/include -L/other/lib"
|
||||
run_test --cflags --libs-only-L other
|
||||
run_test --cflags-only-I --cflags-only-other --libs-only-L other
|
||||
|
||||
RESULT="-DOTHER -I/other/include -Wl,--as-needed"
|
||||
run_test --cflags --libs-only-other other
|
||||
run_test --cflags-only-I --cflags-only-other --libs-only-other other
|
||||
|
||||
RESULT="-I/other/include -Wl,--as-needed -L/other/lib -lother"
|
||||
run_test --cflags-only-I --libs other
|
||||
run_test --cflags-only-I --libs-only-l --libs-only-L --libs-only-other other
|
||||
|
||||
RESULT="-DOTHER -Wl,--as-needed -L/other/lib -lother"
|
||||
run_test --cflags-only-other --libs other
|
||||
run_test --cflags-only-other --libs-only-l --libs-only-L --libs-only-other other
|
||||
65
main.c
65
main.c
|
|
@ -220,6 +220,7 @@ main (int argc, char **argv)
|
|||
static int want_variable_list = 0;
|
||||
GString *str;
|
||||
GSList *packages = NULL;
|
||||
FlagType flags = 0;
|
||||
char *search_path;
|
||||
char *pcbuilddir;
|
||||
gboolean need_newline;
|
||||
|
|
@ -374,6 +375,21 @@ main (int argc, char **argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/* construct Libs/Cflags mask */
|
||||
if (want_cflags)
|
||||
flags |= CFLAGS_ANY;
|
||||
if (want_I_cflags)
|
||||
flags |= CFLAGS_I;
|
||||
if (want_other_cflags)
|
||||
flags |= CFLAGS_OTHER;
|
||||
if (want_libs)
|
||||
flags |= LIBS_ANY;
|
||||
if (want_l_libs)
|
||||
flags |= LIBS_l;
|
||||
if (want_L_libs)
|
||||
flags |= LIBS_L;
|
||||
if (want_other_libs)
|
||||
flags |= LIBS_OTHER;
|
||||
|
||||
/* Error printing is determined as follows:
|
||||
* - for --cflags, --libs, etc. it's on by default
|
||||
|
|
@ -716,53 +732,10 @@ main (int argc, char **argv)
|
|||
need_newline = TRUE;
|
||||
}
|
||||
|
||||
if (want_I_cflags)
|
||||
if (flags != 0)
|
||||
{
|
||||
char *str = packages_get_I_cflags (packages);
|
||||
printf ("%s ", str);
|
||||
g_free (str);
|
||||
need_newline = TRUE;
|
||||
}
|
||||
else if (want_other_cflags)
|
||||
{
|
||||
char *str = packages_get_other_cflags (packages);
|
||||
printf ("%s ", str);
|
||||
g_free (str);
|
||||
need_newline = TRUE;
|
||||
}
|
||||
else if (want_cflags)
|
||||
{
|
||||
char *str = packages_get_all_cflags (packages);
|
||||
printf ("%s ", str);
|
||||
g_free (str);
|
||||
need_newline = TRUE;
|
||||
}
|
||||
|
||||
if (want_l_libs)
|
||||
{
|
||||
char *str = packages_get_l_libs (packages);
|
||||
printf ("%s ", str);
|
||||
g_free (str);
|
||||
need_newline = TRUE;
|
||||
}
|
||||
else if (want_L_libs)
|
||||
{
|
||||
char *str = packages_get_L_libs (packages);
|
||||
printf ("%s ", str);
|
||||
g_free (str);
|
||||
need_newline = TRUE;
|
||||
}
|
||||
else if (want_other_libs)
|
||||
{
|
||||
char *str = packages_get_other_libs (packages);
|
||||
printf ("%s ", str);
|
||||
g_free (str);
|
||||
need_newline = TRUE;
|
||||
}
|
||||
else if (want_libs)
|
||||
{
|
||||
char *str = packages_get_all_libs (packages);
|
||||
printf ("%s ", str);
|
||||
char *str = packages_get_flags (packages, flags);
|
||||
printf ("%s", str);
|
||||
g_free (str);
|
||||
need_newline = TRUE;
|
||||
}
|
||||
|
|
|
|||
139
pkg.c
139
pkg.c
|
|
@ -1018,102 +1018,57 @@ get_multi_merged_from_back (GSList *pkgs, GetListFunc func,
|
|||
}
|
||||
|
||||
char *
|
||||
packages_get_l_libs (GSList *pkgs)
|
||||
packages_get_flags (GSList *pkgs, FlagType flags)
|
||||
{
|
||||
return get_multi_merged_from_back (pkgs, get_l_libs, FALSE,
|
||||
GString *str;
|
||||
char *cur;
|
||||
|
||||
str = g_string_new (NULL);
|
||||
|
||||
|
||||
/* sort flags from beginning and in forward direction except for -l */
|
||||
if (flags & CFLAGS_OTHER)
|
||||
{
|
||||
cur = get_multi_merged (pkgs, get_other_cflags, TRUE, TRUE);
|
||||
debug_spew ("adding CFLAGS_OTHER string \"%s\"\n", cur);
|
||||
g_string_append (str, cur);
|
||||
g_free (cur);
|
||||
}
|
||||
if (flags & CFLAGS_I)
|
||||
{
|
||||
cur = get_multi_merged (pkgs, get_I_cflags, TRUE, TRUE);
|
||||
debug_spew ("adding CFLAGS_I string \"%s\"\n", cur);
|
||||
g_string_append (str, cur);
|
||||
g_free (cur);
|
||||
}
|
||||
if (flags & LIBS_OTHER)
|
||||
{
|
||||
cur = get_multi_merged (pkgs, get_other_libs, TRUE,
|
||||
!ignore_private_libs);
|
||||
debug_spew ("adding LIBS_OTHER string \"%s\"\n", cur);
|
||||
g_string_append (str, cur);
|
||||
g_free (cur);
|
||||
}
|
||||
if (flags & LIBS_L)
|
||||
{
|
||||
cur = get_multi_merged (pkgs, get_L_libs, TRUE, !ignore_private_libs);
|
||||
debug_spew ("adding LIBS_L string \"%s\"\n", cur);
|
||||
g_string_append (str, cur);
|
||||
g_free (cur);
|
||||
}
|
||||
if (flags & LIBS_l)
|
||||
{
|
||||
cur = get_multi_merged_from_back (pkgs, get_l_libs, FALSE,
|
||||
!ignore_private_libs);
|
||||
debug_spew ("adding LIBS_l string \"%s\"\n", cur);
|
||||
g_string_append (str, cur);
|
||||
g_free (cur);
|
||||
}
|
||||
|
||||
debug_spew ("returning flags string \"%s\"\n", str->str);
|
||||
return g_string_free (str, FALSE);
|
||||
}
|
||||
|
||||
char *
|
||||
packages_get_L_libs (GSList *pkgs)
|
||||
{
|
||||
return get_multi_merged (pkgs, get_L_libs, TRUE, !ignore_private_libs);
|
||||
}
|
||||
|
||||
char *
|
||||
packages_get_other_libs (GSList *pkgs)
|
||||
{
|
||||
return get_multi_merged (pkgs, get_other_libs, TRUE, !ignore_private_libs);
|
||||
}
|
||||
|
||||
char *
|
||||
packages_get_all_libs (GSList *pkgs)
|
||||
{
|
||||
char *l_libs;
|
||||
char *L_libs;
|
||||
char *other_libs;
|
||||
GString *str;
|
||||
char *retval;
|
||||
|
||||
str = g_string_new ("");
|
||||
|
||||
other_libs = packages_get_other_libs (pkgs);
|
||||
L_libs = packages_get_L_libs (pkgs);
|
||||
l_libs = packages_get_l_libs (pkgs);
|
||||
|
||||
if (other_libs)
|
||||
g_string_append (str, other_libs);
|
||||
|
||||
if (L_libs)
|
||||
g_string_append (str, L_libs);
|
||||
|
||||
if (l_libs)
|
||||
g_string_append (str, l_libs);
|
||||
|
||||
g_free (l_libs);
|
||||
g_free (L_libs);
|
||||
g_free (other_libs);
|
||||
|
||||
retval = str->str;
|
||||
|
||||
g_string_free (str, FALSE);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
char *
|
||||
packages_get_I_cflags (GSList *pkgs)
|
||||
{
|
||||
/* sort by path position so PKG_CONFIG_PATH affects -I flag order */
|
||||
return get_multi_merged (pkgs, get_I_cflags, TRUE, TRUE);
|
||||
}
|
||||
|
||||
char *
|
||||
packages_get_other_cflags (GSList *pkgs)
|
||||
{
|
||||
return get_multi_merged (pkgs, get_other_cflags, TRUE, TRUE);
|
||||
}
|
||||
|
||||
char *
|
||||
packages_get_all_cflags (GSList *pkgs)
|
||||
{
|
||||
char *I_cflags;
|
||||
char *other_cflags;
|
||||
GString *str;
|
||||
char *retval;
|
||||
|
||||
str = g_string_new ("");
|
||||
|
||||
other_cflags = packages_get_other_cflags (pkgs);
|
||||
I_cflags = packages_get_I_cflags (pkgs);
|
||||
|
||||
if (other_cflags)
|
||||
g_string_append (str, other_cflags);
|
||||
|
||||
if (I_cflags)
|
||||
g_string_append (str, I_cflags);
|
||||
|
||||
g_free (I_cflags);
|
||||
g_free (other_cflags);
|
||||
|
||||
retval = str->str;
|
||||
|
||||
g_string_free (str, FALSE);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
define_global_variable (const char *varname,
|
||||
const char *varval)
|
||||
|
|
|
|||
23
pkg.h
23
pkg.h
|
|
@ -22,6 +22,18 @@
|
|||
|
||||
#include <glib.h>
|
||||
|
||||
typedef guint8 FlagType; /* bit mask for flag types */
|
||||
|
||||
#define LIBS_l (1 << 0)
|
||||
#define LIBS_L (1 << 1)
|
||||
#define LIBS_OTHER (1 << 2)
|
||||
#define CFLAGS_I (1 << 3)
|
||||
#define CFLAGS_OTHER (1 << 4)
|
||||
|
||||
#define LIBS_ANY (LIBS_l | LIBS_L | LIBS_OTHER)
|
||||
#define CFLAGS_ANY (CFLAGS_I | CFLAGS_OTHER)
|
||||
#define FLAGS_ANY (LIBS_ANY | CFLAGS_ANY)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LESS_THAN,
|
||||
|
|
@ -72,19 +84,13 @@ struct _Package
|
|||
|
||||
Package *get_package (const char *name);
|
||||
Package *get_package_quiet (const char *name);
|
||||
char * packages_get_l_libs (GSList *pkgs);
|
||||
char * packages_get_L_libs (GSList *pkgs);
|
||||
char * packages_get_other_libs (GSList *pkgs);
|
||||
char * packages_get_all_libs (GSList *pkgs);
|
||||
char * packages_get_I_cflags (GSList *pkgs);
|
||||
char * packages_get_other_cflags (GSList *pkgs);
|
||||
char * packages_get_all_cflags (GSList *pkgs);
|
||||
char * packages_get_flags (GSList *pkgs,
|
||||
FlagType flags);
|
||||
char * package_get_var (Package *pkg,
|
||||
const char *var);
|
||||
char * packages_get_var (GSList *pkgs,
|
||||
const char *var);
|
||||
|
||||
|
||||
void add_search_dir (const char *path);
|
||||
void add_search_dirs (const char *path, const char *separator);
|
||||
void package_init (void);
|
||||
|
|
@ -134,4 +140,3 @@ extern int msvc_syntax;
|
|||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue