From 9d960fb9d4c0e8c02e856dc4245ed540da38b5a4 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 23 Aug 2013 03:44:33 +0000 Subject: [PATCH] fragment: use forward-merge for static linking (closes #51) --- fragment.c | 21 +++++++++++++-------- pkg.c | 8 ++++---- pkg.h | 2 +- tests/lib1/private-libs-duplication.pc | 2 +- tests/run.sh.in | 2 +- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/fragment.c b/fragment.c index 845e448..6832e0d 100644 --- a/fragment.c +++ b/fragment.c @@ -57,8 +57,11 @@ pkg_fragment_lookup(pkg_list_t *list, pkg_fragment_t *base) } static inline bool -pkg_fragment_can_merge_back(pkg_fragment_t *base) +pkg_fragment_can_merge_back(pkg_fragment_t *base, unsigned int flags) { + if ((flags & PKGF_MERGE_PRIVATE_FRAGMENTS) && base->type == 'l') + return false; + if (base->type == 'F') return false; @@ -66,8 +69,10 @@ pkg_fragment_can_merge_back(pkg_fragment_t *base) } static inline bool -pkg_fragment_can_merge(pkg_fragment_t *base) +pkg_fragment_can_merge(pkg_fragment_t *base, unsigned int flags) { + (void) flags; + if (!strncmp(base->data, "-framework", 10)) return false; @@ -75,25 +80,25 @@ pkg_fragment_can_merge(pkg_fragment_t *base) } static inline pkg_fragment_t * -pkg_fragment_exists(pkg_list_t *list, pkg_fragment_t *base) +pkg_fragment_exists(pkg_list_t *list, pkg_fragment_t *base, unsigned int flags) { - if (!pkg_fragment_can_merge_back(base)) + if (!pkg_fragment_can_merge_back(base, flags)) return NULL; - if (!pkg_fragment_can_merge(base)) + if (!pkg_fragment_can_merge(base, flags)) return NULL; return pkg_fragment_lookup(list, base); } void -pkg_fragment_copy(pkg_list_t *list, pkg_fragment_t *base) +pkg_fragment_copy(pkg_list_t *list, pkg_fragment_t *base, unsigned int flags) { pkg_fragment_t *frag; - if ((frag = pkg_fragment_exists(list, base)) != NULL) + if ((frag = pkg_fragment_exists(list, base, flags)) != NULL) pkg_fragment_delete(list, frag); - else if (!pkg_fragment_can_merge_back(base) && (pkg_fragment_lookup(list, base) != NULL)) + else if (!pkg_fragment_can_merge_back(base, flags) && (pkg_fragment_lookup(list, base) != NULL)) return; frag = calloc(sizeof(pkg_fragment_t), 1); diff --git a/pkg.c b/pkg.c index 86311ba..7b3534c 100644 --- a/pkg.c +++ b/pkg.c @@ -999,7 +999,7 @@ pkg_cflags_collect(pkg_t *pkg, void *data, unsigned int flags) { pkg_fragment_t *frag = node->data; - pkg_fragment_copy(list, frag); + pkg_fragment_copy(list, frag, flags); } } @@ -1014,7 +1014,7 @@ pkg_cflags_private_collect(pkg_t *pkg, void *data, unsigned int flags) { pkg_fragment_t *frag = node->data; - pkg_fragment_copy(list, frag); + pkg_fragment_copy(list, frag, flags); } } @@ -1048,7 +1048,7 @@ pkg_libs_collect(pkg_t *pkg, void *data, unsigned int flags) { pkg_fragment_t *frag = node->data; - pkg_fragment_copy(list, frag); + pkg_fragment_copy(list, frag, flags); } } @@ -1063,7 +1063,7 @@ pkg_libs_private_collect(pkg_t *pkg, void *data, unsigned int flags) { pkg_fragment_t *frag = node->data; - pkg_fragment_copy(list, frag); + pkg_fragment_copy(list, frag, flags); } } diff --git a/pkg.h b/pkg.h index f398bda..176f4cd 100644 --- a/pkg.h +++ b/pkg.h @@ -159,7 +159,7 @@ void pkg_argv_free(char **argv); /* fragment.c */ void pkg_fragment_parse(pkg_list_t *list, pkg_list_t *vars, const char *value); void pkg_fragment_add(pkg_list_t *list, const char *string); -void pkg_fragment_copy(pkg_list_t *list, pkg_fragment_t *base); +void pkg_fragment_copy(pkg_list_t *list, pkg_fragment_t *base, unsigned int flags); void pkg_fragment_delete(pkg_list_t *list, pkg_fragment_t *node); void pkg_fragment_free(pkg_list_t *list); diff --git a/tests/lib1/private-libs-duplication.pc b/tests/lib1/private-libs-duplication.pc index f8a4741..aa5fa90 100644 --- a/tests/lib1/private-libs-duplication.pc +++ b/tests/lib1/private-libs-duplication.pc @@ -1,6 +1,6 @@ Name: private-libs-duplication Version: 1.0 -Requires: foo +Requires: bar Libs: -lprivate Libs.private: -lfoo diff --git a/tests/run.sh.in b/tests/run.sh.in index 2066eef..0883666 100644 --- a/tests/run.sh.in +++ b/tests/run.sh.in @@ -117,7 +117,7 @@ run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --static --libs argv-parse-2" \ run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --static --cflags baz" \ '-fPIC' '-I/usr/include/foo' '-DFOO_STATIC' run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --static --libs-only-l private-libs-duplication" \ - '-lprivate-libs-duplication -lfoo' + '-lprivate -lbar -lfoo' # 4) tests for parser bugs run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs dos-lineendings" \