From 1c658f0383f6bf0225808c521bcfdf26878e9cc1 Mon Sep 17 00:00:00 2001 From: Tony Theodore Date: Wed, 14 Aug 2013 15:36:43 +1000 Subject: [PATCH] add Cflags.private fragment --- pkg.c | 25 +++++++++++++++++++++++++ pkg.h | 1 + tests/lib1/foo.pc | 1 + tests/run.sh.in | 2 ++ 4 files changed, 29 insertions(+) diff --git a/pkg.c b/pkg.c index 58eed08..86311ba 100644 --- a/pkg.c +++ b/pkg.c @@ -248,6 +248,8 @@ pkg_new_from_file(const char *filename, FILE *f, unsigned int flags) pkg->version = pkg_tuple_parse(&pkg->vars, value); else if (!strcasecmp(key, "CFLAGS")) pkg_fragment_parse(&pkg->cflags, &pkg->vars, value); + else if (!strcasecmp(key, "CFLAGS.private")) + pkg_fragment_parse(&pkg->cflags_private, &pkg->vars, value); else if (!strcasecmp(key, "LIBS")) pkg_fragment_parse(&pkg->libs, &pkg->vars, value); else if (!strcasecmp(key, "LIBS.private")) @@ -295,6 +297,7 @@ pkg_free(pkg_t *pkg) pkg_dependency_free(&pkg->conflicts); pkg_fragment_free(&pkg->cflags); + pkg_fragment_free(&pkg->cflags_private); pkg_fragment_free(&pkg->libs); pkg_fragment_free(&pkg->libs_private); @@ -1000,6 +1003,21 @@ pkg_cflags_collect(pkg_t *pkg, void *data, unsigned int flags) } } +static void +pkg_cflags_private_collect(pkg_t *pkg, void *data, unsigned int flags) +{ + pkg_list_t *list = data; + pkg_node_t *node; + (void) flags; + + PKG_FOREACH_LIST_ENTRY(pkg->cflags_private.head, node) + { + pkg_fragment_t *frag = node->data; + + pkg_fragment_copy(list, frag); + } +} + int pkg_cflags(pkg_t *root, pkg_list_t *list, int maxdepth, unsigned int flags) { @@ -1009,6 +1027,13 @@ pkg_cflags(pkg_t *root, pkg_list_t *list, int maxdepth, unsigned int flags) if (eflag != PKG_ERRF_OK) pkg_fragment_free(list); + if (flags & PKGF_MERGE_PRIVATE_FRAGMENTS) + { + eflag = pkg_traverse(root, pkg_cflags_private_collect, list, maxdepth, flags); + if (eflag != PKG_ERRF_OK) + pkg_fragment_free(list); + } + return eflag; } diff --git a/pkg.h b/pkg.h index 4e2c31c..f398bda 100644 --- a/pkg.h +++ b/pkg.h @@ -95,6 +95,7 @@ struct pkg_ { pkg_list_t libs; pkg_list_t libs_private; pkg_list_t cflags; + pkg_list_t cflags_private; pkg_list_t requires; pkg_list_t requires_private; diff --git a/tests/lib1/foo.pc b/tests/lib1/foo.pc index 5974fbe..a8d448f 100644 --- a/tests/lib1/foo.pc +++ b/tests/lib1/foo.pc @@ -8,3 +8,4 @@ Description: A testing pkg-config file Version: 1.2.3 Libs: -L${libdir} -lfoo Cflags: -fPIC -I${includedir}/foo +Cflags.private: -DFOO_STATIC diff --git a/tests/run.sh.in b/tests/run.sh.in index 5cac694..b0cf04f 100644 --- a/tests/run.sh.in +++ b/tests/run.sh.in @@ -114,6 +114,8 @@ run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --static --libs baz" \ '-lfoo' '-lbaz' '-lzee' run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --static --libs argv-parse-2" \ '-pthread ' +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --static --cflags baz" \ + '-fPIC' '-I/usr/include/foo' '-DFOO_STATIC' # 4) tests for parser bugs run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs dos-lineendings" \