diff options
Diffstat (limited to 'pkgtools/cwrappers/files')
-rw-r--r-- | pkgtools/cwrappers/files/bin/base-wrapper.c | 9 | ||||
-rw-r--r-- | pkgtools/cwrappers/files/bin/common.c | 70 | ||||
-rw-r--r-- | pkgtools/cwrappers/files/bin/common.h | 16 | ||||
-rw-r--r-- | pkgtools/cwrappers/files/bin/normalise-cc.c | 32 | ||||
-rw-r--r-- | pkgtools/cwrappers/files/bin/normalise-ld.c | 21 | ||||
-rw-r--r-- | pkgtools/cwrappers/files/doc/configuration.txt | 18 | ||||
-rw-r--r-- | pkgtools/cwrappers/files/doc/normalise-ld.txt | 5 | ||||
-rw-r--r-- | pkgtools/cwrappers/files/doc/normalise.txt | 10 |
8 files changed, 162 insertions, 19 deletions
diff --git a/pkgtools/cwrappers/files/bin/base-wrapper.c b/pkgtools/cwrappers/files/bin/base-wrapper.c index 788752280f7..b15ea6068fc 100644 --- a/pkgtools/cwrappers/files/bin/base-wrapper.c +++ b/pkgtools/cwrappers/files/bin/base-wrapper.c @@ -1,7 +1,7 @@ -/* $NetBSD: base-wrapper.c,v 1.4 2017/01/12 14:56:35 joerg Exp $ */ +/* $NetBSD: base-wrapper.c,v 1.5 2017/06/11 19:34:43 joerg Exp $ */ /*- - * Copyright (c) 2007 Joerg Sonnenberger <joerg@NetBSD.org>. + * Copyright (c) 2007, 2017 Joerg Sonnenberger <joerg@NetBSD.org>. * All rights reserved. * * This code was developed as part of Google's Summer of Code 2007 program. @@ -128,6 +128,11 @@ main(int argc, char **argv) goto skip_transforms; #endif +#if defined(WRAPPER_LD) + operation_mode_ld(&args); +#else + operation_mode_cc(&args); +#endif arglist_apply_config(&args); #if defined(WRAPPER_LD) normalise_ld(&args); diff --git a/pkgtools/cwrappers/files/bin/common.c b/pkgtools/cwrappers/files/bin/common.c index 5c0692dbd8c..4b704e1ae98 100644 --- a/pkgtools/cwrappers/files/bin/common.c +++ b/pkgtools/cwrappers/files/bin/common.c @@ -1,7 +1,7 @@ -/* $NetBSD: common.c,v 1.6 2016/12/09 22:25:28 joerg Exp $ */ +/* $NetBSD: common.c,v 1.7 2017/06/11 19:34:43 joerg Exp $ */ /*- - * Copyright (c) 2009 Joerg Sonnenberger <joerg@NetBSD.org>. + * Copyright (c) 2009, 2017 Joerg Sonnenberger <joerg@NetBSD.org>. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -49,9 +49,18 @@ char *exec_path; char *exec_name; char *wrksrc; int debug; +enum operation_mode current_operation_mode = mode_unknown; static struct arglist prepend_args = TAILQ_HEAD_INITIALIZER(prepend_args); static struct arglist append_args = TAILQ_HEAD_INITIALIZER(append_args); +static struct arglist prepend_executable_args = + TAILQ_HEAD_INITIALIZER(prepend_executable_args); +static struct arglist append_executable_args = + TAILQ_HEAD_INITIALIZER(append_executable_args); +static struct arglist prepend_shared_args = + TAILQ_HEAD_INITIALIZER(prepend_shared_args); +static struct arglist append_shared_args = + TAILQ_HEAD_INITIALIZER(append_shared_args); struct argument *prepend_after; const char library_name_chars[] = @@ -135,29 +144,56 @@ arglist_from_argc(struct arglist *args, int argc, char **argv) } } -void -arglist_apply_config(struct arglist *args) +static void +arglist_prepend_list(struct arglist *args, struct arglist *prepends) { struct argument *arg, *arg2; if (prepend_after) { - TAILQ_FOREACH(arg, &prepend_args, link) { + TAILQ_FOREACH(arg, prepends, link) { arg2 = argument_copy(arg->val); TAILQ_INSERT_AFTER(args, prepend_after, arg2, link); } } else { - TAILQ_FOREACH_REVERSE(arg, &prepend_args, arglist, link) { + TAILQ_FOREACH_REVERSE(arg, prepends, arglist, link) { arg2 = argument_copy(arg->val); TAILQ_INSERT_HEAD(args, arg2, link); } } - TAILQ_FOREACH(arg, &append_args, link) { +} + +static void +arglist_append_list(struct arglist *args, struct arglist *appends) +{ + struct argument *arg, *arg2; + + TAILQ_FOREACH(arg, appends, link) { arg2 = argument_copy(arg->val); TAILQ_INSERT_TAIL(args, arg2, link); } } void +arglist_apply_config(struct arglist *args) +{ + arglist_prepend_list(args, &prepend_args); + arglist_append_list(args, &append_args); + + switch (current_operation_mode) { + default: + break; + case mode_link_executable: + arglist_prepend_list(args, &prepend_executable_args); + arglist_append_list(args, &append_executable_args); + break; + case mode_link_shared: + arglist_prepend_list(args, &prepend_shared_args); + arglist_append_list(args, &prepend_shared_args); + break; + } +} + +void argument_unlink(struct arglist *args, struct argument **argp) { struct argument *arg; @@ -233,6 +269,26 @@ parse_config(const char *wrapper) arg = argument_copy(line + 7); TAILQ_INSERT_TAIL(&append_args, arg, link); } + if (strncmp(line, "prepend_executable=", 19) == 0) { + struct argument *arg; + arg = argument_copy(line + 19); + TAILQ_INSERT_TAIL(&prepend_executable_args, arg, link); + } + if (strncmp(line, "append_executable=", 18) == 0) { + struct argument *arg; + arg = argument_copy(line + 18); + TAILQ_INSERT_TAIL(&append_executable_args, arg, link); + } + if (strncmp(line, "prepend_shared=", 15) == 0) { + struct argument *arg; + arg = argument_copy(line + 15); + TAILQ_INSERT_TAIL(&prepend_shared_args, arg, link); + } + if (strncmp(line, "append_shared=", 14) == 0) { + struct argument *arg; + arg = argument_copy(line + 14); + TAILQ_INSERT_TAIL(&append_shared_args, arg, link); + } if (strncmp(line, "wrksrc=", 7) == 0) { free(wrksrc); wrksrc = xstrdup(line + 7); diff --git a/pkgtools/cwrappers/files/bin/common.h b/pkgtools/cwrappers/files/bin/common.h index e9ae43430c1..a1c22a7b6fd 100644 --- a/pkgtools/cwrappers/files/bin/common.h +++ b/pkgtools/cwrappers/files/bin/common.h @@ -1,7 +1,7 @@ -/* $NetBSD: common.h,v 1.5 2016/11/27 11:46:45 joerg Exp $ */ +/* $NetBSD: common.h,v 1.6 2017/06/11 19:34:43 joerg Exp $ */ /*- - * Copyright (c) 2009 Joerg Sonnenberger <joerg@NetBSD.org>. + * Copyright (c) 2009, 2017 Joerg Sonnenberger <joerg@NetBSD.org>. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -44,6 +44,16 @@ extern char *exec_name; extern char *wrksrc; extern int debug; +enum operation_mode { + mode_unknown, + mode_preprocess, + mode_assemble, + mode_compile, + mode_link_executable, + mode_link_shared +}; +extern enum operation_mode current_operation_mode; + TAILQ_HEAD(arglist, argument); struct argument { @@ -84,6 +94,7 @@ void *xrealloc(void *, size_t); char *xstrdup(const char *); char *xstrndup(const char *, size_t); +void operation_mode_cc(struct arglist *); void normalise_cc(struct arglist *); void cleanup_cc(struct arglist *args); void transform_cc(struct arglist *args); @@ -95,6 +106,7 @@ void init_generic_transform(void); void register_generic_transform(const char *); void generic_transform_cc(struct arglist *); +void operation_mode_ld(struct arglist *); void normalise_ld(struct arglist *); void generic_transform_ld(struct arglist *); diff --git a/pkgtools/cwrappers/files/bin/normalise-cc.c b/pkgtools/cwrappers/files/bin/normalise-cc.c index 5e69833188b..51a28de8412 100644 --- a/pkgtools/cwrappers/files/bin/normalise-cc.c +++ b/pkgtools/cwrappers/files/bin/normalise-cc.c @@ -1,7 +1,7 @@ -/* $NetBSD: normalise-cc.c,v 1.4 2016/09/15 17:08:14 joerg Exp $ */ +/* $NetBSD: normalise-cc.c,v 1.5 2017/06/11 19:34:43 joerg Exp $ */ /*- - * Copyright (c) 2009 Joerg Sonnenberger <joerg@NetBSD.org>. + * Copyright (c) 2009, 2017 Joerg Sonnenberger <joerg@NetBSD.org>. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -61,6 +61,34 @@ normalise_path_list(struct arglist *args, struct argument *arg, } void +operation_mode_cc(struct arglist *args) +{ + struct argument *arg; + + current_operation_mode = mode_link_executable; + TAILQ_FOREACH(arg, args, link) { + if (arg->val[0] != '-') + continue; + if (strcmp(arg->val, "-E") == 0) { + current_operation_mode = mode_preprocess; + continue; + } + if (strcmp(arg->val, "-S") == 0) { + current_operation_mode = mode_assemble; + continue; + } + if (strcmp(arg->val, "-c") == 0) { + current_operation_mode = mode_compile; + continue; + } + if (strcmp(arg->val, "-shared") == 0) { + current_operation_mode = mode_link_shared; + continue; + } + } +} + +void normalise_cc(struct arglist *args) { struct argument *arg, *arg2, *arg3; diff --git a/pkgtools/cwrappers/files/bin/normalise-ld.c b/pkgtools/cwrappers/files/bin/normalise-ld.c index aefcad07e5d..666a84d0dee 100644 --- a/pkgtools/cwrappers/files/bin/normalise-ld.c +++ b/pkgtools/cwrappers/files/bin/normalise-ld.c @@ -1,7 +1,7 @@ -/* $NetBSD: normalise-ld.c,v 1.2 2015/04/19 14:30:07 jperkin Exp $ */ +/* $NetBSD: normalise-ld.c,v 1.3 2017/06/11 19:34:43 joerg Exp $ */ /*- - * Copyright (c) 2009 Joerg Sonnenberger <joerg@NetBSD.org>. + * Copyright (c) 2009, 2017 Joerg Sonnenberger <joerg@NetBSD.org>. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,6 +36,23 @@ #include "common.h" void +operation_mode_ld(struct arglist *args) +{ + struct argument *arg; + + current_operation_mode = mode_link_executable; + TAILQ_FOREACH(arg, args, link) { + if (arg->val[0] != '-') + continue; + if (strcmp(arg->val, "-shared") == 0 || + strcmp(arg->val, "-Bshareable") == 0) { + current_operation_mode = mode_link_shared; + continue; + } + } +} + +void normalise_ld(struct arglist *args) { struct argument *arg, *arg2, *arg3; diff --git a/pkgtools/cwrappers/files/doc/configuration.txt b/pkgtools/cwrappers/files/doc/configuration.txt index 715c6055fdb..2794dce3b72 100644 --- a/pkgtools/cwrappers/files/doc/configuration.txt +++ b/pkgtools/cwrappers/files/doc/configuration.txt @@ -1,4 +1,4 @@ -$NetBSD: configuration.txt,v 1.2 2014/11/27 20:36:43 joerg Exp $ +$NetBSD: configuration.txt,v 1.3 2017/06/11 19:34:44 joerg Exp $ The configuration of the wrapper framework depends on two variables. The environment variable CWRAPPERS_CONFIG_DIR points to a directory @@ -22,7 +22,21 @@ transform: Specify a transformation rule. See generic-transform.txt for the details. prepend: Prepend an option directly after logging the original command. -The options are inserted in the order of the config file. +The options are inserted in the order of the config file. In libtool mode, +the options are inserted after the first argument, if that argument itself is +not an option. append: Append an option directly after logging the original command. The options are inserted in the order of the config file. + +prepend_executable: Like prepend, but applied only if the operation mode is +link-executable. + +append_executable: Like append, but applied only if the operation mode is +link-executable. + +prepend_shared: Like prepend, but applied only if the operation mode is +link-shared. + +append_shared: Like append, but applied only if the operation mode is +link-shared. diff --git a/pkgtools/cwrappers/files/doc/normalise-ld.txt b/pkgtools/cwrappers/files/doc/normalise-ld.txt index 875071c8323..f62601fcaca 100644 --- a/pkgtools/cwrappers/files/doc/normalise-ld.txt +++ b/pkgtools/cwrappers/files/doc/normalise-ld.txt @@ -1,4 +1,4 @@ -$NetBSD: normalise-ld.txt,v 1.1 2014/09/17 12:40:56 joerg Exp $ +$NetBSD: normalise-ld.txt,v 1.2 2017/06/11 19:34:44 joerg Exp $ The first phase of wrapper processing for ld-ish wrappers is argument normalisation. This simplifies processing in latter steps. @@ -19,3 +19,6 @@ to the form "-rpath foo". "/lib([a-zA-Z0-9_-])*\.s[ol](\.[0-9][^/]*)$ are replaced by "-Ldir -l\1" with "dir" being the base name of the argument. This is not done for arguments to -o, --dynamic-linker or -Wl,--dynamic-linker. + +If "-shared" or "-Bshareable" is present, the operation mode is considered +to be link-shared, otherwise the output mode is link-executable. diff --git a/pkgtools/cwrappers/files/doc/normalise.txt b/pkgtools/cwrappers/files/doc/normalise.txt index ac999588ad3..abc0c9b87cb 100644 --- a/pkgtools/cwrappers/files/doc/normalise.txt +++ b/pkgtools/cwrappers/files/doc/normalise.txt @@ -1,4 +1,4 @@ -$NetBSD: normalise.txt,v 1.1 2014/09/17 12:40:56 joerg Exp $ +$NetBSD: normalise.txt,v 1.2 2017/06/11 19:34:44 joerg Exp $ The first phase of wrapper processing for cc-ish wrappers is argument normalisation. This simplifies processing in latter steps. @@ -30,3 +30,11 @@ path (e.g. not starting with /) are dropped. "/lib([a-zA-Z0-9_-])*\.s[ol](\.[0-9][^/]*)$ are replaced by "-Ldir -l\1" with "dir" being the base name of the argument. This is not done for arguments to -o, --dynamic-linker or -Wl,--dynamic-linker. + +The last option in the following set is used to set the operation mode: +- "-E" -> preprocess +- "-S" -> assemble +- "-c" -> compile +- "-shared" -> link-shared +and the default operation mode is link-executable. Note that the operation mode +is not necessarily determined correctly for the libtool wrapper. |