main: expand into something more useful, add --cflags and --libs printer selectors to poptOptions

pull/1/merge
William Pitcock 2011-07-25 00:06:37 -05:00
parent b55a4ce39f
commit 3a36809567
2 changed files with 48 additions and 6 deletions

View File

@ -1,9 +1,10 @@
PROG = pkgconf${PROG_SUFFIX} PROG = pkgconf${PROG_SUFFIX}
SRCS = main.c parse.c pkg.c SRCS = main.c parse.c pkg.c
LIBS = -lpopt
include buildsys.mk include buildsys.mk
LIBS = -lpopt
install-extra: install-extra:
${LN} ${bindir}/pkgconf ${DESTDIR}/${bindir}/pkg-config ${LN} ${bindir}/pkgconf ${DESTDIR}/${bindir}/pkg-config

51
main.c
View File

@ -21,10 +21,12 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <popt.h>
#include "pkg.h" #include "pkg.h"
static int want_cflags = 1; static int want_cflags = 0;
static int want_libs = 1; static int want_libs = 0;
static void static void
print_cflags(pkg_t *pkg, void *unused) print_cflags(pkg_t *pkg, void *unused)
@ -48,13 +50,22 @@ handle_package(const char *package)
pkg = pkg_find(package); pkg = pkg_find(package);
if (pkg) if (pkg)
{ {
int wanted_something = 0;
if (want_cflags) if (want_cflags)
{
wanted_something++;
pkg_traverse(pkg, print_cflags, NULL); pkg_traverse(pkg, print_cflags, NULL);
}
if (want_libs) if (want_libs)
{
wanted_something++;
pkg_traverse(pkg, print_libs, NULL); pkg_traverse(pkg, print_libs, NULL);
}
printf("\n"); if (wanted_something)
printf("\n");
} }
else else
{ {
@ -66,6 +77,36 @@ handle_package(const char *package)
int int
main(int argc, const char *argv[]) main(int argc, const char *argv[])
{ {
handle_package(argv[1]); int ret;
return 0; poptContext opt_context;
struct poptOption options[] = {
{ "libs", 0, POPT_ARG_NONE, &want_libs, 0, "output all linker flags" },
{ "cflags", 0, POPT_ARG_NONE, &want_cflags, 0, "output all compiler flags" },
POPT_AUTOHELP
{ NULL, 0, 0, NULL, 0 }
};
opt_context = poptGetContext(NULL, argc, argv, options, 0);
ret = poptGetNextOpt(opt_context);
if (ret != -1)
{
fprintf(stderr, "%s: %s\n",
poptBadOption(opt_context, POPT_BADOPTION_NOALIAS),
poptStrerror(ret));
return EXIT_FAILURE;
}
while (1)
{
const char *package = poptGetArg(opt_context);
if (package == NULL)
break;
handle_package(package);
}
poptFreeContext(opt_context);
return EXIT_SUCCESS;
} }