diff --git a/main.c b/main.c index 28223a2..e2e305d 100644 --- a/main.c +++ b/main.c @@ -35,11 +35,36 @@ #undef STRICT #endif +char *pcsysrootdir = NULL; +char *pkg_config_pc_path = NULL; + +static int want_my_version = 0; +static int want_version = 0; +static int want_libs = 0; +static int want_cflags = 0; +static int want_l_libs = 0; +static int want_L_libs = 0; +static int want_other_libs = 0; +static int want_I_cflags = 0; +static int want_other_cflags = 0; +static int want_list = 0; +static int want_static_lib_list = ENABLE_INDIRECT_DEPS; +static int want_short_errors = 0; +static int want_uninstalled = 0; +static char *variable_name = NULL; +static int want_exists = 0; +static int want_provides = 0; +static int want_requires = 0; +static int want_requires_private = 0; +static char *required_atleast_version = NULL; +static char *required_exact_version = NULL; +static char *required_max_version = NULL; +static char *required_pkgconfig_version = NULL; +static int want_silence_errors = 0; +static int want_variable_list = 0; static int want_debug_spew = 0; static int want_verbose_errors = 0; static int want_stdout_errors = 0; -char *pcsysrootdir = NULL; -char *pkg_config_pc_path = NULL; void debug_spew (const char *format, ...) @@ -191,33 +216,83 @@ init_pc_path (void) #endif } +static const GOptionEntry options_table[] = { + { "version", 0, 0, G_OPTION_ARG_NONE, &want_my_version, + "output version of pkg-config", NULL }, + { "modversion", 0, 0, G_OPTION_ARG_NONE, &want_version, + "output version for package", NULL }, + { "atleast-pkgconfig-version", 0, 0, G_OPTION_ARG_STRING, + &required_pkgconfig_version, + "require given version of pkg-config", "VERSION" }, + { "libs", 0, 0, G_OPTION_ARG_NONE, &want_libs, + "output all linker flags", NULL }, + { "static", 0, 0, G_OPTION_ARG_NONE, &want_static_lib_list, + "output linker flags for static linking", NULL }, + { "short-errors", 0, 0, G_OPTION_ARG_NONE, &want_short_errors, + "print short errors", NULL }, + { "libs-only-l", 0, 0, G_OPTION_ARG_NONE, &want_l_libs, + "output -l flags", NULL }, + { "libs-only-other", 0, 0, G_OPTION_ARG_NONE, &want_other_libs, + "output other libs (e.g. -pthread)", NULL }, + { "libs-only-L", 0, 0, G_OPTION_ARG_NONE, &want_L_libs, + "output -L flags", NULL }, + { "cflags", 0, 0, G_OPTION_ARG_NONE, &want_cflags, + "output all pre-processor and compiler flags", NULL }, + { "cflags-only-I", 0, 0, G_OPTION_ARG_NONE, &want_I_cflags, + "output -I flags", NULL }, + { "cflags-only-other", 0, 0, G_OPTION_ARG_NONE, &want_other_cflags, + "output cflags not covered by the cflags-only-I option", NULL }, + { "variable", 0, 0, G_OPTION_ARG_STRING, &variable_name, + "get the value of variable named NAME", "NAME" }, + { "define-variable", 0, 0, G_OPTION_ARG_CALLBACK, &define_variable_cb, + "set variable NAME to VALUE", "NAME=VALUE" }, + { "exists", 0, 0, G_OPTION_ARG_NONE, &want_exists, + "return 0 if the module(s) exist", NULL }, + { "print-variables", 0, 0, G_OPTION_ARG_NONE, &want_variable_list, + "output list of variables defined by the module", NULL }, + { "uninstalled", 0, 0, G_OPTION_ARG_NONE, &want_uninstalled, + "return 0 if the uninstalled version of one or more module(s) " + "or their dependencies will be used", NULL }, + { "atleast-version", 0, 0, G_OPTION_ARG_STRING, &required_atleast_version, + "return 0 if the module is at least version VERSION", "VERSION" }, + { "exact-version", 0, 0, G_OPTION_ARG_STRING, &required_exact_version, + "return 0 if the module is at exactly version VERSION", "VERSION" }, + { "max-version", 0, 0, G_OPTION_ARG_STRING, &required_max_version, + "return 0 if the module is at no newer than version VERSION", "VERSION" }, + { "list-all", 0, 0, G_OPTION_ARG_NONE, &want_list, + "list all known packages", NULL }, + { "debug", 0, 0, G_OPTION_ARG_NONE, &want_debug_spew, + "show verbose debug information", NULL }, + { "print-errors", 0, 0, G_OPTION_ARG_NONE, &want_verbose_errors, + "show verbose information about missing or conflicting packages," + "default if --cflags or --libs given on the command line", NULL }, + { "silence-errors", 0, 0, G_OPTION_ARG_NONE, &want_silence_errors, + "be silent about errors (default unless --cflags or --libs" + "given on the command line)", NULL }, + { "errors-to-stdout", 0, 0, G_OPTION_ARG_NONE, &want_stdout_errors, + "print errors from --print-errors to stdout not stderr", NULL }, + { "print-provides", 0, 0, G_OPTION_ARG_NONE, &want_provides, + "print which packages the package provides", NULL }, + { "print-requires", 0, 0, G_OPTION_ARG_NONE, &want_requires, + "print which packages the package requires", NULL }, + { "print-requires-private", 0, 0, G_OPTION_ARG_NONE, &want_requires_private, + "print which packages the package requires for static linking", NULL }, +#ifdef G_OS_WIN32 + { "dont-define-prefix", 0, 0, G_OPTION_ARG_NONE, &dont_define_prefix, + "don't try to override the value of prefix for each .pc file found with " + "a guesstimated value based on the location of the .pc file", NULL }, + { "prefix-variable", 0, 0, G_OPTION_ARG_STRING, &prefix_variable, + "set the name of the variable that pkg-config automatically sets", + "PREFIX" }, + { "msvc-syntax", 0, 0, G_OPTION_ARG_NONE, &msvc_syntax, + "output -l and -L flags for the Microsoft compiler (cl)", NULL }, +#endif + { NULL, 0, 0, 0, NULL, NULL, NULL } +}; + int main (int argc, char **argv) { - static int want_my_version = 0; - static int want_version = 0; - static int want_libs = 0; - static int want_cflags = 0; - static int want_l_libs = 0; - static int want_L_libs = 0; - static int want_other_libs = 0; - static int want_I_cflags = 0; - static int want_other_cflags = 0; - static int want_list = 0; - static int want_static_lib_list = ENABLE_INDIRECT_DEPS; - static int want_short_errors = 0; - static int want_uninstalled = 0; - static char *variable_name = NULL; - static int want_exists = 0; - static int want_provides = 0; - static int want_requires = 0; - static int want_requires_private = 0; - static char *required_atleast_version = NULL; - static char *required_exact_version = NULL; - static char *required_max_version = NULL; - static char *required_pkgconfig_version = NULL; - static int want_silence_errors = 0; - static int want_variable_list = 0; GString *str; GList *packages = NULL; FlagType flags = 0; @@ -228,80 +303,6 @@ main (int argc, char **argv) GError *error = NULL; GOptionContext *opt_context; - GOptionEntry options_table[] = { - { "version", 0, 0, G_OPTION_ARG_NONE, &want_my_version, - "output version of pkg-config", NULL }, - { "modversion", 0, 0, G_OPTION_ARG_NONE, &want_version, - "output version for package", NULL }, - { "atleast-pkgconfig-version", 0, 0, G_OPTION_ARG_STRING, - &required_pkgconfig_version, - "require given version of pkg-config", "VERSION" }, - { "libs", 0, 0, G_OPTION_ARG_NONE, &want_libs, - "output all linker flags", NULL }, - { "static", 0, 0, G_OPTION_ARG_NONE, &want_static_lib_list, - "output linker flags for static linking", NULL }, - { "short-errors", 0, 0, G_OPTION_ARG_NONE, &want_short_errors, - "print short errors", NULL }, - { "libs-only-l", 0, 0, G_OPTION_ARG_NONE, &want_l_libs, - "output -l flags", NULL }, - { "libs-only-other", 0, 0, G_OPTION_ARG_NONE, &want_other_libs, - "output other libs (e.g. -pthread)", NULL }, - { "libs-only-L", 0, 0, G_OPTION_ARG_NONE, &want_L_libs, - "output -L flags", NULL }, - { "cflags", 0, 0, G_OPTION_ARG_NONE, &want_cflags, - "output all pre-processor and compiler flags", NULL }, - { "cflags-only-I", 0, 0, G_OPTION_ARG_NONE, &want_I_cflags, - "output -I flags", NULL }, - { "cflags-only-other", 0, 0, G_OPTION_ARG_NONE, &want_other_cflags, - "output cflags not covered by the cflags-only-I option", NULL }, - { "variable", 0, 0, G_OPTION_ARG_STRING, &variable_name, - "get the value of variable named NAME", "NAME" }, - { "define-variable", 0, 0, G_OPTION_ARG_CALLBACK, &define_variable_cb, - "set variable NAME to VALUE", "NAME=VALUE" }, - { "exists", 0, 0, G_OPTION_ARG_NONE, &want_exists, - "return 0 if the module(s) exist", NULL }, - { "print-variables", 0, 0, G_OPTION_ARG_NONE, &want_variable_list, - "output list of variables defined by the module", NULL }, - { "uninstalled", 0, 0, G_OPTION_ARG_NONE, &want_uninstalled, - "return 0 if the uninstalled version of one or more module(s) " - "or their dependencies will be used", NULL }, - { "atleast-version", 0, 0, G_OPTION_ARG_STRING, &required_atleast_version, - "return 0 if the module is at least version VERSION", "VERSION" }, - { "exact-version", 0, 0, G_OPTION_ARG_STRING, &required_exact_version, - "return 0 if the module is at exactly version VERSION", "VERSION" }, - { "max-version", 0, 0, G_OPTION_ARG_STRING, &required_max_version, - "return 0 if the module is at no newer than version VERSION", "VERSION" }, - { "list-all", 0, 0, G_OPTION_ARG_NONE, &want_list, - "list all known packages", NULL }, - { "debug", 0, 0, G_OPTION_ARG_NONE, &want_debug_spew, - "show verbose debug information", NULL }, - { "print-errors", 0, 0, G_OPTION_ARG_NONE, &want_verbose_errors, - "show verbose information about missing or conflicting packages," - "default if --cflags or --libs given on the command line", NULL }, - { "silence-errors", 0, 0, G_OPTION_ARG_NONE, &want_silence_errors, - "be silent about errors (default unless --cflags or --libs" - "given on the command line)", NULL }, - { "errors-to-stdout", 0, 0, G_OPTION_ARG_NONE, &want_stdout_errors, - "print errors from --print-errors to stdout not stderr", NULL }, - { "print-provides", 0, 0, G_OPTION_ARG_NONE, &want_provides, - "print which packages the package provides", NULL }, - { "print-requires", 0, 0, G_OPTION_ARG_NONE, &want_requires, - "print which packages the package requires", NULL }, - { "print-requires-private", 0, 0, G_OPTION_ARG_NONE, &want_requires_private, - "print which packages the package requires for static linking", NULL }, -#ifdef G_OS_WIN32 - { "dont-define-prefix", 0, 0, G_OPTION_ARG_NONE, &dont_define_prefix, - "don't try to override the value of prefix for each .pc file found with " - "a guesstimated value based on the location of the .pc file", NULL }, - { "prefix-variable", 0, 0, G_OPTION_ARG_STRING, &prefix_variable, - "set the name of the variable that pkg-config automatically sets", - "PREFIX" }, - { "msvc-syntax", 0, 0, G_OPTION_ARG_NONE, &msvc_syntax, - "output -l and -L flags for the Microsoft compiler (cl)", NULL }, -#endif - { NULL, 0, 0, 0, NULL, NULL, NULL } - }; - /* This is here so that we get debug spew from the start, * during arg parsing */