forked from ariadne/pkgconf
main: expand into something more useful, add --cflags and --libs printer selectors to poptOptions
parent
b55a4ce39f
commit
3a36809567
3
Makefile
3
Makefile
|
@ -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
|
||||||
|
|
||||||
|
|
49
main.c
49
main.c
|
@ -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,12 +50,21 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wanted_something)
|
||||||
printf("\n");
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue