summaryrefslogtreecommitdiff
authorPekka Paalanen <ppaalanen@gmail.com>2012-08-22 06:00:44 (GMT)
committer Pekka Paalanen <ppaalanen@gmail.com>2012-08-22 07:12:37 (GMT)
commit3c775f8f16573fb33b56140f1ca7672865c6cbc7 (patch) (side-by-side diff)
tree21bd06e17b190cf43c51afa82baacd6351462585
parenta47a8849aba89482b27636bb8f8c5e35e410be91 (diff)
downloadandrogenizer-3c775f8f16573fb33b56140f1ca7672865c6cbc7.tar.gz
androgenizer-3c775f8f16573fb33b56140f1ca7672865c6cbc7.tar.bz2
rewrite ldflag dropping logic
The result does not change, just collect the flags in an array.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--common.h6
-rw-r--r--library.c43
-rw-r--r--library.h2
-rw-r--r--options.c11
4 files changed, 56 insertions, 6 deletions
diff --git a/common.h b/common.h
index f4d297e..332c463 100644
--- a/common.h
+++ b/common.h
@@ -56,6 +56,12 @@ enum tags {
TAG_DEBUG = 16
};
+enum flag_action {
+ FLAG_USE,
+ FLAG_SKIP,
+ FLAG_SKIP_WITH_ARG
+};
+
struct generator {
};
diff --git a/library.c b/library.c
index e3e9caa..3517b56 100644
--- a/library.c
+++ b/library.c
@@ -45,3 +45,46 @@ enum library_type library_scope(char *name)
return LIBRARY_EXTERNAL;
}
+enum flag_arg {
+ FLAG_ARG_NO,
+ FLAG_ARG_YES,
+};
+
+struct flag_exclusion {
+ const char *name;
+ enum flag_arg arg;
+};
+
+static const struct flag_exclusion dropped_ldflags[] = {
+ { "-pthread", FLAG_ARG_NO },
+ { "-lpthread", FLAG_ARG_NO },
+ { "-lrt", FLAG_ARG_NO },
+ { "-no-undefined", FLAG_ARG_NO },
+ { "-dlopen", FLAG_ARG_YES },
+ { "-version-info", FLAG_ARG_YES },
+ { NULL, 0 }
+};
+
+enum flag_action ldflag_action(const char *flag)
+{
+ const struct flag_exclusion *fe;
+
+ for (fe = &dropped_ldflags[0]; fe->name; fe++) {
+ if (strcmp(flag, fe->name) != 0)
+ continue;
+
+ switch (fe->arg) {
+ case FLAG_ARG_NO:
+ return FLAG_SKIP;
+ case FLAG_ARG_YES:
+ return FLAG_SKIP_WITH_ARG;
+ /* case FLAG_ARG_JOINED:
+ If an argument is immediately in this flag,
+ return FLAG_SKIP, otherwise there must be
+ an argument as the next word, so return
+ FLAG_SKIP_WITH_ARG. */
+ }
+ }
+
+ return FLAG_USE;
+}
diff --git a/library.h b/library.h
index 004e314..e8ca9bb 100644
--- a/library.h
+++ b/library.h
@@ -20,4 +20,6 @@
enum library_type library_scope(char *name);
+enum flag_action ldflag_action(const char *flag);
+
#endif /* __LIBRARY_H__ */
diff --git a/options.c b/options.c
index 33e02b8..15e5585 100644
--- a/options.c
+++ b/options.c
@@ -375,6 +375,7 @@ static void add_library(struct module *m, char *name, enum library_type ltype)
static int add_ldflag(struct module *m, char *flag, enum build_type btype)
{
enum library_type ltype;
+ enum flag_action action;
int len = strlen(flag);
if (len < 2) {/* this is probably a WTF condition... */
@@ -391,18 +392,16 @@ static int add_ldflag(struct module *m, char *flag, enum build_type btype)
free(flag);
return 0;
}
- if ((strcmp(flag, "-pthread") == 0) ||
- (strcmp(flag, "-lpthread") == 0) ||
- (strcmp(flag, "-lrt") == 0) ||
- (strcmp(flag, "-no-undefined") == 0)) {
+ action = ldflag_action(flag);
+ if (action == FLAG_SKIP) {
free(flag);
return 0;
}
- if ((strcmp(flag, "-dlopen") == 0) ||
- (strcmp(flag, "-version-info") == 0)) {
+ if (action == FLAG_SKIP_WITH_ARG) {
free(flag);
return 1;
}
+ /* otherwise we have FLAG_USE */
if (flag[1] == 'l') {/* actually figure out what libtype... */
ltype = library_scope(flag + 2);
add_library(m, strdup(flag+2), ltype);