summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Nicholson <dbn.lists@gmail.com>2012-11-19 08:19:48 -0800
committerDan Nicholson <dbn.lists@gmail.com>2012-12-04 13:04:57 -0800
commit9bf6277b9c4f1980e3449ddc164e748d9b762200 (patch)
treeda1e9e4a8f0c69d22d412fb32b8cb08e90335ac0
parent05f319d3e5a2e37788d6aa6d92c39991e4c567df (diff)
downloadpkg-config-9bf6277b9c4f1980e3449ddc164e748d9b762200.tar.gz
Keep Libs and Cflags together to maintain ordering
Instead of splitting to -l/-L/other and -I/other, keep the args together and mark each argument with its type. Then we can maintain order all the way through.
-rw-r--r--parse.c86
-rw-r--r--pkg.c114
-rw-r--r--pkg.h14
3 files changed, 112 insertions, 102 deletions
diff --git a/parse.c b/parse.c
index c5b730c..eafba83 100644
--- a/parse.c
+++ b/parse.c
@@ -615,6 +615,7 @@ static void _do_parse_libs (Package *pkg, int argc, char **argv)
i = 0;
while (i < argc)
{
+ Flag *flag = g_new (Flag, 1);
char *tmp = trim_string (argv[i]);
char *arg = strdup_escape_shell(tmp);
char *p;
@@ -631,9 +632,9 @@ static void _do_parse_libs (Package *pkg, int argc, char **argv)
while (*p && isspace ((guchar)*p))
++p;
- pkg->l_libs = g_list_prepend (pkg->l_libs,
- g_strconcat (l_flag, p, lib_suffix, NULL));
-
+ flag->type = LIBS_l;
+ flag->arg = g_strconcat (l_flag, p, lib_suffix, NULL);
+ pkg->libs = g_list_prepend (pkg->libs, flag);
}
else if (p[0] == '-' &&
p[1] == 'L')
@@ -641,8 +642,10 @@ static void _do_parse_libs (Package *pkg, int argc, char **argv)
p += 2;
while (*p && isspace ((guchar)*p))
++p;
- pkg->L_libs = g_list_prepend (pkg->L_libs,
- g_strconcat (L_flag, p, NULL));
+
+ flag->type = LIBS_L;
+ flag->arg = g_strconcat (L_flag, p, lib_suffix, NULL);
+ pkg->libs = g_list_prepend (pkg->libs, flag);
}
else if (strcmp("-framework",p) == 0 && i+1 < argc)
{
@@ -653,19 +656,23 @@ static void _do_parse_libs (Package *pkg, int argc, char **argv)
*/
gchar *framework, *tmp = trim_string (argv[i+1]);
- framework = strdup_escape_shell(tmp);
- pkg->other_libs = g_list_prepend (pkg->other_libs,
- g_strconcat(arg, " ", framework, NULL));
+ framework = strdup_escape_shell(tmp);
+ flag->type = LIBS_OTHER;
+ flag->arg = g_strconcat (arg, " ", framework, NULL);
+ pkg->libs = g_list_prepend (pkg->libs, flag);
i++;
- g_free(framework);
- g_free(tmp);
+ g_free (framework);
+ g_free (tmp);
}
- else
+ else if (*arg != '\0')
{
- if (*arg != '\0')
- pkg->other_libs = g_list_prepend (pkg->other_libs,
- g_strdup (arg));
+ flag->type = LIBS_OTHER;
+ flag->arg = g_strdup (arg);
+ pkg->libs = g_list_prepend (pkg->libs, flag);
}
+ else
+ /* flag wasn't used */
+ g_free (flag);
g_free (arg);
@@ -765,7 +772,7 @@ parse_cflags (Package *pkg, const char *str, const char *path)
GError *error = NULL;
int i;
- if (pkg->I_cflags || pkg->other_cflags)
+ if (pkg->cflags)
{
verbose_error ("Cflags field occurs twice in '%s'\n", path);
@@ -785,6 +792,7 @@ parse_cflags (Package *pkg, const char *str, const char *path)
i = 0;
while (i < argc)
{
+ Flag *flag = g_new (Flag, 1);
char *tmp = trim_string (argv[i]);
char *arg = strdup_escape_shell(tmp);
char *p = arg;
@@ -797,22 +805,32 @@ parse_cflags (Package *pkg, const char *str, const char *path)
while (*p && isspace ((guchar)*p))
++p;
- pkg->I_cflags = g_list_prepend (pkg->I_cflags,
- g_strconcat ("-I", p, NULL));
-
- } else {
- if (*arg != '\0')
- pkg->other_cflags = g_list_prepend (pkg->other_cflags,
- g_strdup (arg));
- if (strcmp("-idirafter", arg) == 0) {
- char *n;
+ flag->type = CFLAGS_I;
+ flag->arg = g_strconcat ("-I", p, NULL);
+ pkg->cflags = g_list_prepend (pkg->cflags, flag);
+ }
+ else if (strcmp("-idirafter", arg) == 0 && i+1 < argc)
+ {
+ char *dirafter, *tmp;
- tmp = trim_string(argv[++i]);
- n = strdup_escape_shell(tmp);
- pkg->other_cflags = g_list_prepend (pkg->other_cflags, n);
- g_free(tmp);
- }
- }
+ tmp = trim_string (argv[i+1]);
+ dirafter = strdup_escape_shell (tmp);
+ flag->type = CFLAGS_OTHER;
+ flag->arg = g_strconcat (arg, " ", dirafter, NULL);
+ pkg->cflags = g_list_prepend (pkg->cflags, flag);
+ i++;
+ g_free (dirafter);
+ g_free (tmp);
+ }
+ else if (*arg != '\0')
+ {
+ flag->type = CFLAGS_OTHER;
+ flag->arg = g_strdup (arg);
+ pkg->cflags = g_list_prepend (pkg->cflags, flag);
+ }
+ else
+ /* flag wasn't used */
+ g_free (flag);
g_free (arg);
@@ -1092,12 +1110,8 @@ parse_package_file (const char *path, gboolean ignore_requires,
g_string_free (str, TRUE);
fclose(f);
- pkg->I_cflags = g_list_reverse (pkg->I_cflags);
- pkg->other_cflags = g_list_reverse (pkg->other_cflags);
-
- pkg->l_libs = g_list_reverse (pkg->l_libs);
- pkg->L_libs = g_list_reverse (pkg->L_libs);
- pkg->other_libs = g_list_reverse (pkg->other_libs);
+ pkg->cflags = g_list_reverse (pkg->cflags);
+ pkg->libs = g_list_reverse (pkg->libs);
return pkg;
}
diff --git a/pkg.c b/pkg.c
index 5625827..68a1cbe 100644
--- a/pkg.c
+++ b/pkg.c
@@ -425,7 +425,7 @@ get_package_quiet (const char *name)
}
static GList *
-string_list_strip_duplicates (GList *list, gboolean forward)
+flag_list_strip_duplicates (GList *list, gboolean forward)
{
GHashTable *table;
GList *tmp;
@@ -435,26 +435,30 @@ string_list_strip_duplicates (GList *list, gboolean forward)
tmp != NULL;
tmp = forward ? g_list_next (tmp) : g_list_previous (tmp))
{
- if (!g_hash_table_lookup_extended (table, tmp->data, NULL, NULL))
+ Flag *flag = tmp->data;
+
+ debug_spew ("Seeing if arg %s is duplicate\n", flag->arg);
+
+ if (!g_hash_table_lookup_extended (table, flag->arg, NULL, NULL))
{
- /* Unique string. Track it and and move to the next. */
- g_hash_table_replace (table, tmp->data, tmp->data);
+ /* Unique flag. Track it and and move to the next. */
+ g_hash_table_replace (table, flag->arg, flag->arg);
}
else
{
GList *dup = tmp;
- /* Remove the duplicate string from the list and move to the last
+ /* Remove the duplicate flag from the list and move to the last
* element to prepare for the next iteration. */
if (forward)
{
- debug_spew (" removing duplicate \"%s\"\n", tmp->data);
+ debug_spew (" removing duplicate \"%s\"\n", flag->arg);
tmp = g_list_previous (tmp);
}
else
{
debug_spew (" removing duplicate (from back) \"%s\"\n",
- tmp->data);
+ flag->arg);
tmp = g_list_next (tmp);
}
list = g_list_remove_link (list, dup);
@@ -466,7 +470,7 @@ string_list_strip_duplicates (GList *list, gboolean forward)
}
static char *
-string_list_to_string (GList *list)
+flag_list_to_string (GList *list)
{
GList *tmp;
GString *str = g_string_new ("");
@@ -474,11 +478,10 @@ string_list_to_string (GList *list)
tmp = list;
while (tmp != NULL) {
- char *tmpstr = (char*) tmp->data;
- if (pcsysrootdir != NULL &&
- tmpstr[0] == '-' &&
- (tmpstr[1] == 'I' ||
- tmpstr[1] == 'L')) {
+ Flag *flag = tmp->data;
+ char *tmpstr = flag->arg;
+
+ if (pcsysrootdir != NULL && flag->type & (CFLAGS_I | LIBS_L)) {
g_string_append_c (str, '-');
g_string_append_c (str, tmpstr[1]);
g_string_append (str, pcsysrootdir);
@@ -578,41 +581,23 @@ merge_flag_lists (GList *packages, FlagType type)
for (; packages != NULL; packages = g_list_next (packages))
{
Package *pkg = packages->data;
- GList *flags;
-
- /* fetch the appropriate flags */
- switch (type)
- {
- case CFLAGS_OTHER:
- flags = pkg->other_cflags;
- break;
- case CFLAGS_I:
- flags = pkg->I_cflags;
- break;
- case LIBS_OTHER:
- flags = pkg->other_libs;
- break;
- case LIBS_L:
- flags = pkg->L_libs;
- break;
- case LIBS_l:
- flags = pkg->l_libs;
- break;
- default:
- g_assert_not_reached ();
- break;
- }
+ GList *flags = (type & LIBS_ANY) ? pkg->libs : pkg->cflags;
/* manually copy the elements so we can keep track of the end */
for (; flags != NULL; flags = g_list_next (flags))
{
- if (last == NULL)
+ Flag *flag = flags->data;
+
+ if (flag->type & type)
{
- merged = g_list_prepend (NULL, flags->data);
- last = merged;
+ if (last == NULL)
+ {
+ merged = g_list_prepend (NULL, flags->data);
+ last = merged;
+ }
+ else
+ last = g_list_next (g_list_append (last, flags->data));
}
- else
- last = g_list_next (g_list_append (last, flags->data));
}
}
@@ -850,15 +835,19 @@ verify_package (Package *pkg)
}
count = 0;
- iter = pkg->I_cflags;
- while (iter != NULL)
+ for (iter = pkg->cflags; iter != NULL; iter = g_list_next (iter))
{
gint offset = 0;
+ Flag *flag = iter->data;
+
+ if (!(flag->type & CFLAGS_I))
+ continue;
+
/* we put things in canonical -I/usr/include (vs. -I /usr/include) format,
* but if someone changes it later we may as well be robust
*/
- if (((strncmp (iter->data, "-I", 2) == 0) && (offset = 2))||
- ((strncmp (iter->data, "-I ", 3) == 0) && (offset = 3)))
+ if (((strncmp (flag->arg, "-I", 2) == 0) && (offset = 2))||
+ ((strncmp (flag->arg, "-I ", 3) == 0) && (offset = 3)))
{
if (offset == 0)
{
@@ -870,29 +859,28 @@ verify_package (Package *pkg)
while (system_dir_iter != NULL)
{
if (strcmp (system_dir_iter->data,
- ((char*)iter->data) + offset) == 0)
+ ((char*)flag->arg) + offset) == 0)
{
- debug_spew ("Package %s has %s in Cflags\n",
- pkg->key, (gchar *)iter->data);
+ debug_spew ("Package %s has %s in Cflags\n",
+ pkg->key, (gchar *)flag->arg);
if (g_getenv ("PKG_CONFIG_ALLOW_SYSTEM_CFLAGS") == NULL)
{
- debug_spew ("Removing %s from cflags for %s\n", iter->data, pkg->key);
+ debug_spew ("Removing %s from cflags for %s\n",
+ flag->arg, pkg->key);
++count;
iter->data = NULL;
-
+
break;
}
}
system_dir_iter = system_dir_iter->next;
}
}
-
- iter = iter->next;
}
while (count)
{
- pkg->I_cflags = g_list_remove (pkg->I_cflags, NULL);
+ pkg->cflags = g_list_remove (pkg->cflags, NULL);
--count;
}
@@ -911,15 +899,18 @@ verify_package (Package *pkg)
system_directories = add_env_variable_to_list (system_directories, search_path);
count = 0;
- iter = pkg->L_libs;
- while (iter != NULL)
+ for (iter = pkg->libs; iter != NULL; iter = g_list_next (iter))
{
GList *system_dir_iter = system_directories;
+ Flag *flag = iter->data;
+
+ if (!(flag->type & LIBS_L))
+ continue;
while (system_dir_iter != NULL)
{
gboolean is_system = FALSE;
- const char *linker_arg = iter->data;
+ const char *linker_arg = flag->arg;
const char *system_libpath = system_dir_iter->data;
if (strncmp (linker_arg, "-L ", 3) == 0 &&
@@ -936,7 +927,8 @@ verify_package (Package *pkg)
{
iter->data = NULL;
++count;
- debug_spew ("Removing -L %s from libs for %s\n", system_libpath, pkg->key);
+ debug_spew ("Removing -L %s from libs for %s\n",
+ system_libpath, pkg->key);
break;
}
}
@@ -948,7 +940,7 @@ verify_package (Package *pkg)
while (count)
{
- pkg->L_libs = g_list_remove (pkg->L_libs, NULL);
+ pkg->libs = g_list_remove (pkg->libs, NULL);
--count;
}
}
@@ -968,8 +960,8 @@ get_multi_merged (GList *pkgs, FlagType type, gboolean in_path_order,
char *retval;
list = fill_list (pkgs, type, in_path_order, include_private);
- list = string_list_strip_duplicates (list, in_path_order);
- retval = string_list_to_string (list);
+ list = flag_list_strip_duplicates (list, in_path_order);
+ retval = flag_list_to_string (list);
g_list_free (list);
return retval;
diff --git a/pkg.h b/pkg.h
index a28c406..95c114a 100644
--- a/pkg.h
+++ b/pkg.h
@@ -45,9 +45,16 @@ typedef enum
ALWAYS_MATCH
} ComparisonType;
+typedef struct _Flag Flag;
typedef struct _Package Package;
typedef struct _RequiredVersion RequiredVersion;
+struct _Flag
+{
+ FlagType type;
+ char *arg;
+};
+
struct _RequiredVersion
{
char *name;
@@ -68,11 +75,8 @@ struct _Package
GList *requires;
GList *requires_private_entries;
GList *requires_private;
- GList *l_libs;
- GList *L_libs;
- GList *other_libs;
- GList *I_cflags;
- GList *other_cflags;
+ GList *libs;
+ GList *cflags;
GHashTable *vars;
GHashTable *required_versions; /* hash from name to RequiredVersion */
GList *conflicts; /* list of RequiredVersion */