diff -durp pkg-config-0.27.1.orig/main.c pkg-config-0.27.1/main.c --- pkg-config-0.27.1.orig/main.c 2012-08-15 14:38:13.000000000 +0200 +++ pkg-config-0.27.1/main.c 2012-11-02 21:57:55.801842274 +0100 @@ -740,9 +740,17 @@ main (int argc, char **argv) if (want_l_libs) { - char *str = packages_get_l_libs (packages); + char *str; + + str = packages_get_l_libs (packages); printf ("%s ", str); g_free (str); + + str = packages_get_l_libs_wa (packages); + if (str) + printf ("-Wl,--whole-archive %s -Wl,--no-whole-archive ", str); + g_free (str); + need_newline = TRUE; } else if (want_L_libs) diff -durp pkg-config-0.27.1.orig/parse.c pkg-config-0.27.1/parse.c --- pkg-config-0.27.1.orig/parse.c 2012-08-20 22:17:58.000000000 +0200 +++ pkg-config-0.27.1/parse.c 2012-11-02 21:58:28.690026920 +0100 @@ -661,7 +661,8 @@ static char *strdup_escape_shell(const c static void _do_parse_libs (Package *pkg, int argc, char **argv) { - int i; + int i, whole_archive, n_whole_archive; + GSList **l_libs; #ifdef G_OS_WIN32 char *L_flag = (msvc_syntax ? "/libpath:" : "-L"); char *l_flag = (msvc_syntax ? "" : "-l"); @@ -673,6 +674,9 @@ static void _do_parse_libs (Package *pkg #endif i = 0; + whole_archive = 0; + n_whole_archive = 0; + l_libs = &pkg->l_libs; while (i < argc) { char *tmp = trim_string (argv[i]); @@ -691,9 +695,21 @@ static void _do_parse_libs (Package *pkg while (*p && isspace ((guchar)*p)) ++p; - pkg->l_libs = g_slist_prepend (pkg->l_libs, + *l_libs = g_slist_prepend (*l_libs, g_strconcat (l_flag, p, lib_suffix, NULL)); + if (whole_archive) + n_whole_archive++; + } + else if (strcmp("-Wl,--whole-archive",arg) == 0) + { + whole_archive = 1; + l_libs = &pkg->l_libs_wa; + } + else if (strcmp("-Wl,--no-whole-archive",arg) == 0) + { + whole_archive = 0; + l_libs = &pkg->l_libs; } else if (p[0] == '-' && p[1] == 'L') @@ -731,7 +747,14 @@ static void _do_parse_libs (Package *pkg ++i; } - + if (pkg->l_libs_wa) + { + if (n_whole_archive == 0) + { + g_slist_free_full(pkg->l_libs_wa, g_free); + pkg->l_libs_wa = NULL; + } + } } diff -durp pkg-config-0.27.1.orig/pkg.c pkg-config-0.27.1/pkg.c --- pkg-config-0.27.1.orig/pkg.c 2012-08-15 14:38:13.000000000 +0200 +++ pkg-config-0.27.1/pkg.c 2012-11-02 21:54:28.064670039 +0100 @@ -479,6 +479,12 @@ get_l_libs (Package *pkg) } static GSList * +get_l_libs_wa (Package *pkg) +{ + return pkg->l_libs_wa; +} + +static GSList * get_L_libs (Package *pkg) { return pkg->L_libs; @@ -1036,6 +1042,26 @@ packages_get_l_libs (GSList *pkgs) } char * +package_get_l_libs_wa (Package *pkg) +{ + /* We don't want these in search path order, rather in dependency + * order, so static linking works. + */ + if (pkg->l_libs_wa_merged == NULL) + pkg->l_libs_wa_merged = get_merged_from_back (pkg, get_l_libs_wa, FALSE, + !ignore_private_libs); + + return pkg->l_libs_wa_merged; +} + +char * +packages_get_l_libs_wa (GSList *pkgs) +{ + return get_multi_merged_from_back (pkgs, get_l_libs_wa, FALSE, + !ignore_private_libs); +} + +char * package_get_L_libs (Package *pkg) { /* We want these in search path order so the -L flags don't override PKG_CONFIG_PATH */ @@ -1072,6 +1098,7 @@ char * packages_get_all_libs (GSList *pkgs) { char *l_libs; + char *l_libs_wa; char *L_libs; char *other_libs; GString *str; @@ -1082,6 +1109,7 @@ packages_get_all_libs (GSList *pkgs) other_libs = packages_get_other_libs (pkgs); L_libs = packages_get_L_libs (pkgs); l_libs = packages_get_l_libs (pkgs); + l_libs_wa = packages_get_l_libs_wa (pkgs); if (other_libs) g_string_append (str, other_libs); @@ -1092,6 +1120,14 @@ packages_get_all_libs (GSList *pkgs) if (l_libs) g_string_append (str, l_libs); + if (l_libs_wa) + { + g_string_append (str, "-Wl,--whole-archive "); + g_string_append (str, l_libs_wa); + g_string_append (str, "-Wl,--no-whole-archive "); + } + + g_free (l_libs_wa); g_free (l_libs); g_free (L_libs); g_free (other_libs); diff -durp pkg-config-0.27.1.orig/pkg.h pkg-config-0.27.1/pkg.h --- pkg-config-0.27.1.orig/pkg.h 2012-08-15 14:38:13.000000000 +0200 +++ pkg-config-0.27.1/pkg.h 2012-11-02 21:30:56.567105810 +0100 @@ -56,6 +56,8 @@ struct _Package GSList *requires_private; GSList *l_libs; char *l_libs_merged; + GSList *l_libs_wa; + char *l_libs_wa_merged; GSList *L_libs; char *L_libs_merged; GSList *other_libs; @@ -77,6 +79,8 @@ Package *get_package (cons Package *get_package_quiet (const char *name); char * package_get_l_libs (Package *pkg); char * packages_get_l_libs (GSList *pkgs); +char * package_get_l_libs_wa (Package *pkg); +char * packages_get_l_libs_wa (GSList *pkgs); char * package_get_L_libs (Package *pkg); char * packages_get_L_libs (GSList *pkgs); char * package_get_other_libs (Package *pkg);