4 * Copyright (C) 2010 - Johannes Schmid
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <libanjuta/anjuta-pkg-config.h>
24 #include <libanjuta/anjuta-utils.h>
25 #include <libanjuta/anjuta-debug.h>
27 /* Blacklist for packages that shouldn't be parsed. Those packages
28 * usually contain the same include paths as their top-level package
29 * Checked with g_str_has_prefix() so partial names are ok!
31 const gchar
* ignore_packages
[] =
38 remove_includes (GList
* includes
, GList
* dependencies
)
41 for (dir
= dependencies
; dir
!= NULL
; dir
= g_list_next (dir
))
43 GList
* find
= g_list_find_custom (includes
, dir
->data
, (GCompareFunc
)strcmp
);
47 includes
= g_list_delete_link (includes
, find
);
55 anjuta_pkg_config_list_dependencies (const gchar
* package
, GError
** error
)
63 cmd
= g_strdup_printf ("pkg-config --print-requires --print-requires-private %s",
65 if (g_spawn_command_line_sync (cmd
, &out
, &err
, &status
, error
))
67 gchar
** depends
= g_strsplit (out
, "\n", -1);
71 for (depend
= depends
; *depend
!= NULL
; depend
++)
73 if (strlen (*depend
) && !anjuta_pkg_config_ignore_package (*depend
))
75 deps
= g_list_append (deps
, g_strdup (*depend
));
88 anjuta_pkg_config_get_directories (const gchar
* pkg_name
, gboolean no_deps
, GError
** error
)
96 cmd
= g_strdup_printf ("pkg-config --cflags-only-I %s", pkg_name
);
98 if (g_spawn_command_line_sync (cmd
, &out
, &err
, &status
, error
))
102 flags
= g_strsplit (out
, " ", -1);
108 for (flag
= flags
; *flag
!= NULL
; flag
++)
110 if (g_regex_match_simple ("\\.*/include/\\w+", *flag
, 0, 0) == TRUE
)
112 dirs
= g_list_prepend (dirs
, g_strdup (*flag
+ 2));
123 GList
* pkgs
= anjuta_pkg_config_list_dependencies (pkg_name
, error
);
125 for (pkg
= pkgs
; pkg
!= NULL
; pkg
= g_list_next (pkg
))
127 GList
* dep_dirs
= anjuta_pkg_config_get_directories (pkg
->data
, FALSE
, NULL
);
128 dirs
= remove_includes (dirs
, dep_dirs
);
129 anjuta_util_glist_strings_free (dep_dirs
);
131 anjuta_util_glist_strings_free (pkgs
);
138 anjuta_pkg_config_ignore_package (const gchar
* name
)
141 for (pkg
= ignore_packages
; *pkg
!= NULL
; pkg
++)
143 if (g_str_has_prefix (name
, *pkg
))
150 * anjuta_pkg_config_get_version:
151 * @package: Name of the package
153 * This does sync io, call from a thread if necessary
155 * Returns: (transfer full) the version of the package or NULL
157 gchar
* anjuta_pkg_config_get_version (const gchar
* package
)
165 cmd
= g_strdup_printf ("pkg-config --modversion %s", package
);
167 if (g_spawn_command_line_sync (cmd
, &out
, &err
, &status
, &error
))
180 DEBUG_PRINT ("Could query package version: %s", error
->message
);
181 g_error_free (error
);