9 #define MY_VERSION "0.22"
20 #define LIB(n, ver, l) { n, ver, NULL, l, NULL }
21 static const struct library all_libs[] = {
22 LIB("libxml-2.0", "2.7.2", "-lxml"),
24 #define N_LIBS (sizeof(all_libs) / sizeof(struct library))
29 OPT_ATLEAST_PKGCONFIG_VERSION,
49 static const struct option opts[] = {
50 { "help", 0, 0, '?' }, // These two must be first
51 { "usage", 0, 0, OPT_USAGE },
53 { "atleast-pkgconfig-version", 1, 0, OPT_ATLEAST_PKGCONFIG_VERSION },
54 { "cflags", 0, 0, OPT_CFLAGS },
55 { "errors-to-stdout", 0, 0, OPT_ERRORS_TO_STDOUT },
56 { "exists", 0, 0, OPT_EXISTS },
57 { "libs", 0, 0, OPT_LIBS },
58 { "libs-only-L", 0, 0, OPT_LIBS_ONLY_L },
59 { "libs-only-l", 0, 0, OPT_LIBS_ONLY_l },
60 { "print-errors", 0, 0, OPT_PRINT_ERRORS },
61 { "short-errors", 0, 0, OPT_SHORT_ERRORS },
62 { "version", 0, 0, OPT_VERSION },
64 { "modversion", 0, 0, OPT_MODVERSION },
65 { "silence-errors", 0, 0, OPT_SILENCE_ERRORS },
66 { "uninstalled", 0, 0, OPT_UNINSTALLED },
67 { "atleast-version", 1, 0, OPT_ATLEAST_VERSION },
68 { "exact-version", 1, 0, OPT_EXACT_VERSION },
69 { "max-version", 1, 0, OPT_MAX_VERSION },
70 { "static", 0, 0, OPT_STATIC },
75 static const char *min_cfg_ver = NULL;
76 static unsigned char cflags, exists, libs, l_args, L_args;
77 static unsigned char error_stdout, print_errors, short_errors;
79 extern void debug(const char *, ...) __attribute__ ((format(printf, 1, 2)));
80 static void msg(const char *fmt, ...) {
87 vfprintf(stderr, fmt, ap);
91 static void usage(const char *pname) {
94 msg("Usage: %s [OPTION...]\n", pname);
95 for (i=2; opts[i].name != 0; i++)
96 msg(" %s\n", opts[i].name);
97 msg("\nHelp options\n");
102 static void usage_hint(const char *pname) {
106 msg("Usage: %s [-?]", pname);
107 for (i=0; opts[i].name != 0; i++) {
108 msg(" [%s", opts[i].name);
123 /* Routine to compare version strings
125 static int compare_versions(char *have, char *want) {
128 while (want != NULL && *want != '\0') {
130 v1 = strtol(have, &have, 10);
133 v2 = strtol(want, &want, 10);
139 while (*have == '.') have++;
140 while (*want == '.') want++;
146 /* Routines to check out version against the desired version.
147 * Return if we're greater of equal versions, exit with an error
150 static void check_version(char *want) {
151 if (compare_versions(MY_VERSION, want))
155 static void process_args(int argc, char *argv[]) {
159 while ((c = getopt_long(argc, argv, "?", opts, &opt_idx)) != -1) {
161 case OPT_CFLAGS: cflags = 1; break;
162 case OPT_ERRORS_TO_STDOUT: error_stdout = 1; break;
163 case OPT_EXISTS: exists = 1; break;
164 case OPT_LIBS: libs = 1; break;
165 case OPT_LIBS_ONLY_L: L_args = 1; break;
166 case OPT_LIBS_ONLY_l: l_args = 1; break;
168 case OPT_PRINT_ERRORS: print_errors = 1; break;
169 case OPT_SHORT_ERRORS: short_errors = 1; break;
171 case OPT_ATLEAST_PKGCONFIG_VERSION:
172 check_version(optarg);
191 /* Found the required libary.
192 * produce whatever output is required.
194 static void output_lib(const struct library *l) {
196 if (l->Iargs != NULL)
197 printf("%s ", l->Iargs);
199 if (l->Largs != NULL)
200 printf("%s ", l->Largs);
202 if (l->largs != NULL)
203 printf("%s ", l->largs);
206 /* Search for the library specified and do what is required with it.
208 static void process_library(const char *lib) {
211 for (i=0; i<N_LIBS; i++)
212 if (strcmp(lib, all_libs[i].name) == 0)
217 msg("No package '%s' found\n", lib);
219 msg("Package %s was not found in the pkg-config search path.\n"
220 "Perhaps you should add the directory containing `%s.pc'\n"
221 "to the PKG_CONFIG_PATH environment variable\n"
222 "No package '%s' found\n", lib, lib, lib);
227 output_lib(all_libs + i);
231 int main(int argc, char *argv[]) {
232 process_args(argc, argv);
234 while (optind < argc)
235 process_library(argv[optind++]);