fragment: use forward-merge for static linking (closes #51)

feature/tap-sh
William Pitcock 2013-08-23 03:44:33 +00:00
parent 2a638d4f32
commit 9d960fb9d4
5 changed files with 20 additions and 15 deletions

View File

@ -57,8 +57,11 @@ pkg_fragment_lookup(pkg_list_t *list, pkg_fragment_t *base)
} }
static inline bool 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') if (base->type == 'F')
return false; return false;
@ -66,8 +69,10 @@ pkg_fragment_can_merge_back(pkg_fragment_t *base)
} }
static inline bool 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)) if (!strncmp(base->data, "-framework", 10))
return false; return false;
@ -75,25 +80,25 @@ pkg_fragment_can_merge(pkg_fragment_t *base)
} }
static inline pkg_fragment_t * 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; return NULL;
if (!pkg_fragment_can_merge(base)) if (!pkg_fragment_can_merge(base, flags))
return NULL; return NULL;
return pkg_fragment_lookup(list, base); return pkg_fragment_lookup(list, base);
} }
void 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; 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); 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; return;
frag = calloc(sizeof(pkg_fragment_t), 1); frag = calloc(sizeof(pkg_fragment_t), 1);

8
pkg.c
View File

@ -999,7 +999,7 @@ pkg_cflags_collect(pkg_t *pkg, void *data, unsigned int flags)
{ {
pkg_fragment_t *frag = node->data; 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_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_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_t *frag = node->data;
pkg_fragment_copy(list, frag); pkg_fragment_copy(list, frag, flags);
} }
} }

2
pkg.h
View File

@ -159,7 +159,7 @@ void pkg_argv_free(char **argv);
/* fragment.c */ /* fragment.c */
void pkg_fragment_parse(pkg_list_t *list, pkg_list_t *vars, const char *value); 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_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_delete(pkg_list_t *list, pkg_fragment_t *node);
void pkg_fragment_free(pkg_list_t *list); void pkg_fragment_free(pkg_list_t *list);

View File

@ -1,6 +1,6 @@
Name: private-libs-duplication Name: private-libs-duplication
Version: 1.0 Version: 1.0
Requires: foo Requires: bar
Libs: -lprivate Libs: -lprivate
Libs.private: -lfoo Libs.private: -lfoo

View File

@ -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" \ run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --static --cflags baz" \
'-fPIC' '-I/usr/include/foo' '-DFOO_STATIC' '-fPIC' '-I/usr/include/foo' '-DFOO_STATIC'
run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --static --libs-only-l private-libs-duplication" \ 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 # 4) tests for parser bugs
run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs dos-lineendings" \ run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs dos-lineendings" \