summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorjoerg <joerg@pkgsrc.org>2014-09-17 12:40:56 +0000
committerjoerg <joerg@pkgsrc.org>2014-09-17 12:40:56 +0000
commiteed6611b55d6775ac51eab96cda7471a2c78e83a (patch)
tree7b86f87ea67d008616a375422ae26ebcab7e7cc2 /pkgtools
parentf50151c182fc0530d5734d41dceac825b231c59e (diff)
downloadpkgsrc-eed6611b55d6775ac51eab96cda7471a2c78e83a.tar.gz
Add cwrappers-20100308 with minimal compat changes. Developed as part of
GSoC 2007, initial test suite parts from schmonz@, nagging by jperkin, approval for addition during freeze by agc@.
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/cwrappers/DESCR4
-rw-r--r--pkgtools/cwrappers/Makefile30
-rw-r--r--pkgtools/cwrappers/PLIST10
-rw-r--r--pkgtools/cwrappers/files/bin/Makefile45
-rw-r--r--pkgtools/cwrappers/files/bin/alloc.c95
-rw-r--r--pkgtools/cwrappers/files/bin/as-wrapper.c4
-rw-r--r--pkgtools/cwrappers/files/bin/base-wrapper.c179
-rw-r--r--pkgtools/cwrappers/files/bin/c++-wrapper.c4
-rw-r--r--pkgtools/cwrappers/files/bin/cc-wrapper.c4
-rw-r--r--pkgtools/cwrappers/files/bin/cleanup-cc.c80
-rw-r--r--pkgtools/cwrappers/files/bin/common.c359
-rw-r--r--pkgtools/cwrappers/files/bin/common.h109
-rw-r--r--pkgtools/cwrappers/files/bin/cpp-wrapper.c4
-rw-r--r--pkgtools/cwrappers/files/bin/f77-wrapper.c4
-rw-r--r--pkgtools/cwrappers/files/bin/fixup-libtool.c411
-rw-r--r--pkgtools/cwrappers/files/bin/generic-transform-cc.c451
-rw-r--r--pkgtools/cwrappers/files/bin/generic-transform-ld.c3
-rw-r--r--pkgtools/cwrappers/files/bin/generic-transform-libtool.c3
-rw-r--r--pkgtools/cwrappers/files/bin/getline.c51
-rw-r--r--pkgtools/cwrappers/files/bin/imake-wrapper.c4
-rw-r--r--pkgtools/cwrappers/files/bin/ld-wrapper.c4
-rw-r--r--pkgtools/cwrappers/files/bin/libtool-wrapper.c4
-rw-r--r--pkgtools/cwrappers/files/bin/mi_vector_hash.c179
-rw-r--r--pkgtools/cwrappers/files/bin/normalise-cc.c204
-rw-r--r--pkgtools/cwrappers/files/bin/normalise-ld.c68
-rw-r--r--pkgtools/cwrappers/files/bin/reorder-cc.c108
-rwxr-xr-xpkgtools/cwrappers/files/bin/rules2src.awk94
-rw-r--r--pkgtools/cwrappers/files/bin/shlibtool-wrapper.c4
-rw-r--r--pkgtools/cwrappers/files/bin/transform-cc.c112
-rw-r--r--pkgtools/cwrappers/files/bin/transform-gcc-rules172
-rw-r--r--pkgtools/cwrappers/files/bin/transform-gcc.c172
-rw-r--r--pkgtools/cwrappers/files/doc/cleanup.txt16
-rw-r--r--pkgtools/cwrappers/files/doc/configuration.txt28
-rw-r--r--pkgtools/cwrappers/files/doc/fixup-libtool.txt1
-rw-r--r--pkgtools/cwrappers/files/doc/generic-transform-ld.txt6
-rw-r--r--pkgtools/cwrappers/files/doc/generic-transform.txt38
-rw-r--r--pkgtools/cwrappers/files/doc/normalise-ld.txt21
-rw-r--r--pkgtools/cwrappers/files/doc/normalise.txt32
-rw-r--r--pkgtools/cwrappers/files/doc/reorder.txt13
-rw-r--r--pkgtools/cwrappers/files/doc/transform.txt13
-rw-r--r--pkgtools/cwrappers/files/doc/unimplemented.txt44
-rw-r--r--pkgtools/cwrappers/files/test/Makefile29
-rw-r--r--pkgtools/cwrappers/files/test/TODO5
-rw-r--r--pkgtools/cwrappers/files/test/setup_common.sh25
-rw-r--r--pkgtools/cwrappers/files/test/test-include_pkgdir.sh45
-rw-r--r--pkgtools/cwrappers/files/test/test-include_usr_include.sh45
-rw-r--r--pkgtools/cwrappers/files/test/test-lib_expand.sh20
-rw-r--r--pkgtools/cwrappers/files/test/test-libdir_pkgdir.sh45
-rw-r--r--pkgtools/cwrappers/files/test/test-libdir_usr_lib.sh45
-rw-r--r--pkgtools/cwrappers/files/test/test-libpath.sh58
-rw-r--r--pkgtools/cwrappers/files/test/test-no_abspath.sh19
-rw-r--r--pkgtools/cwrappers/files/test/test-option.sh32
-rw-r--r--pkgtools/cwrappers/files/test/test-quoted_arg.sh19
-rw-r--r--pkgtools/cwrappers/files/test/test-remove_dir.sh19
-rw-r--r--pkgtools/cwrappers/files/test/test-repeated_arg.sh19
-rw-r--r--pkgtools/cwrappers/files/test/test-rpath_merge.sh26
-rw-r--r--pkgtools/cwrappers/files/test/test-rpath_pkgdir.sh66
-rw-r--r--pkgtools/cwrappers/files/test/test-rpath_split.sh26
-rw-r--r--pkgtools/cwrappers/files/test/test-rpath_usr_lib.sh52
59 files changed, 3782 insertions, 0 deletions
diff --git a/pkgtools/cwrappers/DESCR b/pkgtools/cwrappers/DESCR
new file mode 100644
index 00000000000..082b16095c4
--- /dev/null
+++ b/pkgtools/cwrappers/DESCR
@@ -0,0 +1,4 @@
+The cwrappers package implements the compiler wrappers for pkgsrc.
+They are the fundation of the buildlink framework. They also allow
+various transformations of arguments to simplify
+cross-platform portability.
diff --git a/pkgtools/cwrappers/Makefile b/pkgtools/cwrappers/Makefile
new file mode 100644
index 00000000000..e71fabe8f79
--- /dev/null
+++ b/pkgtools/cwrappers/Makefile
@@ -0,0 +1,30 @@
+# $NetBSD: Makefile,v 1.1 2014/09/17 12:40:56 joerg Exp $
+
+PKGNAME= cwrappers-20100308
+CATEGORIES= pkgtools sysutils
+
+MAINTAINER= joerg@NetBSD.org
+HOMEPAGE= http://www.NetBSD.org/
+COMMENT= pkgsrc compiler wrappers
+LICENSE= modified-bsd
+
+USE_BSD_MAKEFILE= yes
+USE_FEATURES= nbcompat
+
+INSTALLATION_DIRS= libexec/cwrappers
+
+.include "../../mk/bsd.prefs.mk"
+
+.if ${OPSYS} != "NetBSD" || !empty(MACHINE_PLATFORM:MNetBSD-[0-5].*)
+MAKE_ENV+= NEED_MI_VECTOR_HASH=1
+.endif
+.if !empty(MACHINE_PLATFORM:MDarwin-10.*)
+MAKE_ENV+= NEED_GETLINE=1
+.endif
+
+CFLAGS.Linux+= -D_GNU_SOURCE=1
+
+do-extract:
+ ${CP} -R ${FILESDIR}/bin ${WRKSRC}
+
+.include "../../mk/bsd.pkg.mk"
diff --git a/pkgtools/cwrappers/PLIST b/pkgtools/cwrappers/PLIST
new file mode 100644
index 00000000000..1661832a12a
--- /dev/null
+++ b/pkgtools/cwrappers/PLIST
@@ -0,0 +1,10 @@
+@comment $NetBSD: PLIST,v 1.1 2014/09/17 12:40:56 joerg Exp $
+libexec/cwrappers/as-wrapper
+libexec/cwrappers/c++-wrapper
+libexec/cwrappers/cc-wrapper
+libexec/cwrappers/cpp-wrapper
+libexec/cwrappers/f77-wrapper
+libexec/cwrappers/imake-wrapper
+libexec/cwrappers/ld-wrapper
+libexec/cwrappers/libtool-wrapper
+libexec/cwrappers/shlibtool-wrapper
diff --git a/pkgtools/cwrappers/files/bin/Makefile b/pkgtools/cwrappers/files/bin/Makefile
new file mode 100644
index 00000000000..3a4ab8640e6
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/Makefile
@@ -0,0 +1,45 @@
+PROGS= as-wrapper cc-wrapper c++-wrapper cpp-wrapper f77-wrapper \
+ imake-wrapper ld-wrapper libtool-wrapper shlibtool-wrapper
+
+LIB_SRCS= alloc.c cleanup-cc.c common.c reorder-cc.c
+
+.ifdef NEED_MI_VECTOR_HASH
+LIB_SRCS+= mi_vector_hash.c
+CPPFLAGS+= -DNEED_MI_VECTOR_HASH
+.endif
+.ifdef NEED_GETLINE
+LIB_SRCS+= getline.c
+CPPFLAGS+= -DNEED_GETLINE
+.endif
+
+LDADD+= -lnbcompat
+
+CC_SRCS= ${LIB_SRCS} generic-transform-cc.c normalise-cc.c
+
+SRCS.as-wrapper= ${CC_SRCS} as-wrapper.c
+SRCS.cc-wrapper= ${CC_SRCS} cc-wrapper.c transform-cc.c
+SRCS.c++-wrapper= ${CC_SRCS} c++-wrapper.c transform-cc.c
+SRCS.cpp-wrapper= ${CC_SRCS} cpp-wrapper.c
+SRCS.f77-wrapper= ${CC_SRCS} f77-wrapper.c
+SRCS.imake-wrapper= ${CC_SRCS} imake-wrapper.c
+SRCS.ld-wrapper= ${LIB_SRCS} generic-transform-ld.c \
+ normalise-ld.c ld-wrapper.c
+SRCS.libtool-wrapper= ${LIB_SRCS} generic-transform-libtool.c \
+ normalise-cc.c libtool-wrapper.c fixup-libtool.c
+SRCS.shlibtool-wrapper= ${LIB_SRCS} generic-transform-libtool.c \
+ normalise-cc.c shlibtool-wrapper.c fixup-libtool.c
+
+WARNS= 4
+NOMAN=
+
+CLEANFILES+= .work-new.log \
+ transform-gcc-rules-fixed.map \
+ transform-gcc-rules-fixed1.c \
+ transform-gcc-rules-fixed2.c
+
+transform-cc.c: transform-gcc.c
+
+transform-gcc.c: transform-gcc-rules rules2src.awk
+ awk -v output=transform-gcc.c -f rules2src.awk transform-gcc-rules
+
+.include <bsd.prog.mk>
diff --git a/pkgtools/cwrappers/files/bin/alloc.c b/pkgtools/cwrappers/files/bin/alloc.c
new file mode 100644
index 00000000000..9e35173f7bb
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/alloc.c
@@ -0,0 +1,95 @@
+/* $NetBSD: alloc.c,v 1.1 2014/09/17 12:40:56 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2007 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * All rights reserved.
+ *
+ * This code was developed as part of Google's Summer of Code 2007 program.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <err.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "common.h"
+
+char *
+xasprintf(const char *fmt, ...)
+{
+ va_list ap;
+ char *buf;
+
+ va_start(ap, fmt);
+ if (vasprintf(&buf, fmt, ap) == -1)
+ err(1, "asprintf failed");
+ va_end(ap);
+ return buf;
+}
+
+void *
+xmalloc(size_t len)
+{
+ void *ptr;
+
+ if ((ptr = malloc(len)) == NULL)
+ err(1, "malloc failed");
+ return ptr;
+}
+
+void *
+xrealloc(void *buf, size_t len)
+{
+ void *ptr;
+
+ if ((ptr = realloc(buf, len)) == NULL)
+ err(1, "realloc failed");
+ return ptr;
+}
+
+char *
+xstrdup(const char *str)
+{
+ char *buf;
+
+ if ((buf = strdup(str)) == NULL)
+ err(1, "strdup failed");
+ return buf;
+}
+
+char *
+xstrndup(const char *str, size_t len)
+{
+ char *buf;
+
+ buf = xmalloc(len + 1);
+ strncpy(buf, str, len);
+ buf[len] = '\0';
+
+ return buf;
+}
diff --git a/pkgtools/cwrappers/files/bin/as-wrapper.c b/pkgtools/cwrappers/files/bin/as-wrapper.c
new file mode 100644
index 00000000000..6102181d359
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/as-wrapper.c
@@ -0,0 +1,4 @@
+#define WRAPPER_AS
+#define WRAPPER_NAME "as"
+
+#include "base-wrapper.c"
diff --git a/pkgtools/cwrappers/files/bin/base-wrapper.c b/pkgtools/cwrappers/files/bin/base-wrapper.c
new file mode 100644
index 00000000000..ac04d776b35
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/base-wrapper.c
@@ -0,0 +1,179 @@
+/* $NetBSD: base-wrapper.c,v 1.1 2014/09/17 12:40:56 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2007 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * All rights reserved.
+ *
+ * This code was developed as part of Google's Summer of Code 2007 program.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/wait.h>
+#include <err.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+
+static const char wrapper_name[] = WRAPPER_NAME;
+
+#if !defined(WRAPPER_LIBTOOL) && !defined(WRAPPER_SHLIBTOOL)
+void
+register_unwrap(const char *rule)
+{
+}
+#endif
+
+#if defined(WRAPPER_LIBTOOL) || defined(WRAPPER_SHLIBTOOL)
+static int
+libtool_mode(struct arglist *args)
+{
+ struct argument *arg;
+ const char *mode = NULL;
+
+ mode = NULL;
+ TAILQ_FOREACH(arg, args, link) {
+ if (arg->val[0] != '-') {
+ prepend_after = arg;
+ break;
+ }
+ if (strncmp(arg->val, "--mode=", 7) == 0) {
+ mode = arg->val + 7;
+ continue;
+ }
+ if (strcmp(arg->val, "--mode") == 0) {
+ arg = TAILQ_NEXT(arg, link);
+ if (arg == NULL || *arg->val == '-')
+ errx(255, "Misssing --mode argument");
+ mode = arg->val;
+ continue;
+ }
+ if (strcmp(arg->val, "--finish") == 0) {
+ mode = arg->val + 2;
+ continue;
+ }
+ if (strcmp(arg->val, "--tag") == 0) {
+ arg = TAILQ_NEXT(arg, link);
+ if (arg == NULL || *arg->val == '-')
+ errx(255, "Misssing --tag argument");
+ continue;
+ }
+ }
+ if (arg == NULL)
+ return 1;
+ if (mode == NULL)
+ errx(255, "Misssing --mode=XXX");
+
+ if (strcmp(mode, "compile") == 0 ||
+ strcmp(mode, "link") == 0)
+ return 0;
+ else
+ return 1;
+}
+#endif
+
+int
+main(int argc, char **argv)
+{
+ int do_fork, rv;
+ FILE *fp;
+ struct arglist args;
+ struct argument *arg;
+ char **argv2;
+
+ init_generic_transform();
+
+ parse_config(wrapper_name);
+
+ if (argc == 2 && strcmp(argv[1], "--wrappee-name") == 0) {
+ puts(exec_name);
+ return 0;
+ }
+
+ arglist_from_argc(&args, argc, argv);
+
+ fp = worklog_open();
+ worklog_cmd(fp, "[*]", wrapper_name, &args);
+
+#if defined(WRAPPER_LIBTOOL) || defined(WRAPPER_SHLIBTOOL)
+ if (libtool_mode(&args))
+ goto skip_transforms;
+#endif
+
+ arglist_apply_config(&args);
+#if defined(WRAPPER_LD)
+ normalise_ld(&args);
+#else
+ normalise_cc(&args);
+#endif
+ cleanup_cc(&args);
+#if defined(WRAPPER_LD)
+ generic_transform_ld(&args);
+#else
+ generic_transform_cc(&args);
+#endif
+ reorder_cc(&args);
+#if defined(WRAPPER_CC) || defined(WRAPPER_CXX)
+ transform_cc(&args);
+#endif
+ cleanup_cc(&args);
+
+#if defined(WRAPPER_LIBTOOL) || defined(WRAPPER_SHLIBTOOL)
+skip_transforms:
+#endif
+
+ argc = 1;
+ TAILQ_FOREACH(arg, &args, link)
+ ++argc;
+
+ argv2 = xmalloc(sizeof(void *) * argc);
+ argv2[0] = exec_name;
+ argv = argv2 + 1;
+ TAILQ_FOREACH(arg, &args, link)
+ *argv++ = arg->val;
+
+ worklog_cmd(fp, "<.>", exec_name, &args);
+
+ fclose(fp);
+
+#if defined(WRAPPER_LIBTOOL) || defined(WRAPPER_SHLIBTOOL)
+ do_fork = 1;
+#else
+ do_fork = 0;
+#endif
+
+ rv = command_exec(&args, do_fork);
+
+#if defined(WRAPPER_LIBTOOL) || defined(WRAPPER_SHLIBTOOL)
+ if (rv == 0)
+ fixup_libtool(&args);
+#endif
+
+ return rv;
+}
diff --git a/pkgtools/cwrappers/files/bin/c++-wrapper.c b/pkgtools/cwrappers/files/bin/c++-wrapper.c
new file mode 100644
index 00000000000..bed6417bc44
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/c++-wrapper.c
@@ -0,0 +1,4 @@
+#define WRAPPER_CXX
+#define WRAPPER_NAME "c++"
+
+#include "base-wrapper.c"
diff --git a/pkgtools/cwrappers/files/bin/cc-wrapper.c b/pkgtools/cwrappers/files/bin/cc-wrapper.c
new file mode 100644
index 00000000000..a29293121f0
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/cc-wrapper.c
@@ -0,0 +1,4 @@
+#define WRAPPER_CC
+#define WRAPPER_NAME "cc"
+
+#include "base-wrapper.c"
diff --git a/pkgtools/cwrappers/files/bin/cleanup-cc.c b/pkgtools/cwrappers/files/bin/cleanup-cc.c
new file mode 100644
index 00000000000..515949b370c
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/cleanup-cc.c
@@ -0,0 +1,80 @@
+/* $NetBSD: cleanup-cc.c,v 1.1 2014/09/17 12:40:56 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2009 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+
+#include <err.h>
+#include <stdlib.h>
+#include <string.h>
+#include "common.h"
+
+#define CLEANUP_HASH 256
+
+void
+cleanup_cc(struct arglist *args)
+{
+ struct argument *arg, *arg2, *arg3;
+ struct arglist hashtab[CLEANUP_HASH];
+ size_t i;
+
+ for (i = 0; i < CLEANUP_HASH; ++i)
+ TAILQ_INIT(hashtab + i);
+
+ TAILQ_FOREACH_SAFE(arg, args, link, arg2) {
+ if (arg->val[0] != '-')
+ continue;
+ if (strncmp(arg->val, "-Wl,-rpath,", 11) == 0) {
+ if (arg->val[11] == '/')
+ continue;
+ argument_unlink(args, &arg);
+ continue;
+ }
+ if (arg2 != NULL && strncmp(arg->val, "-l", 2) == 0 &&
+ strcmp(arg->val, arg2->val) == 0) {
+ argument_unlink(args, &arg);
+ continue;
+ }
+ if (strncmp(arg->val, "-I", 2) == 0 ||
+ strncmp(arg->val, "-L", 2) == 0 ||
+ strncmp(arg->val, "-Wl,-rpath,", 11) == 0 ||
+ strncmp(arg->val, "-Wl,-rpath-link,", 15) == 0) {
+ i = wrapper_hash(arg->val) & (CLEANUP_HASH - 1);
+ TAILQ_FOREACH(arg3, hashtab + i, tmp_link) {
+ if (strcmp(arg->val, arg3->val) == 0) {
+ argument_unlink(args, &arg);
+ break;
+ }
+ }
+ if (arg3 == NULL)
+ TAILQ_INSERT_TAIL(hashtab + i, arg, tmp_link);
+ continue;
+ }
+ }
+}
diff --git a/pkgtools/cwrappers/files/bin/common.c b/pkgtools/cwrappers/files/bin/common.c
new file mode 100644
index 00000000000..bdad8e0c5d8
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/common.c
@@ -0,0 +1,359 @@
+/* $NetBSD: common.c,v 1.1 2014/09/17 12:40:56 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2009 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <nbcompat.h>
+#include <sys/wait.h>
+#include <nbcompat/err.h>
+#include <nbcompat/stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+
+static char *worklog_path;
+static char *real_path;
+char *exec_name;
+char *wrksrc;
+int debug;
+
+static struct arglist prepend_args = TAILQ_HEAD_INITIALIZER(prepend_args);
+static struct arglist append_args = TAILQ_HEAD_INITIALIZER(append_args);
+struct argument *prepend_after;
+
+const char library_name_chars[] =
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "01234567890-_";
+
+char *
+concat(const char *s1, const char *s2)
+{
+ size_t len1, len2;
+ char *output;
+
+ len1 = strlen(s1);
+ len2 = strlen(s2);
+
+ output = xmalloc(len1 + len2 + 1);
+ memcpy(output, s1, len1);
+ memcpy(output + len1, s2, len2);
+ output[len1 + len2] = '\0';
+
+ return output;
+}
+
+char *
+concat2(const char *s1, const char *s2, size_t len2)
+{
+ size_t len1;
+ char *output;
+
+ len1 = strlen(s1);
+
+ output = xmalloc(len1 + len2 + 1);
+ memcpy(output, s1, len1);
+ memcpy(output + len1, s2, len2);
+ output[len1 + len2] = '\0';
+
+ return output;
+}
+
+struct argument *
+argument_new(char *str)
+{
+ struct argument *arg;
+
+ arg = xmalloc(sizeof(*arg));
+ arg->val = str;
+
+ return arg;
+}
+
+struct argument *
+argument_copy(const char *str)
+{
+ struct argument *arg;
+
+ arg = xmalloc(sizeof(*arg));
+ arg->val = xstrdup(str);
+
+ return arg;
+}
+
+void
+argument_update(struct argument *arg, char *str)
+{
+ free(arg->val);
+ arg->val = str;
+}
+
+void
+arglist_from_argc(struct arglist *args, int argc, char **argv)
+{
+ struct argument *arg;
+
+ TAILQ_INIT(args);
+
+ for (--argc, ++argv; argc; --argc, ++argv) {
+ if (**argv == '\0')
+ continue;
+ arg = argument_copy(*argv);
+ TAILQ_INSERT_TAIL(args, arg, link);
+ }
+}
+
+void
+arglist_apply_config(struct arglist *args)
+{
+ struct argument *arg, *arg2;
+
+ if (prepend_after) {
+ TAILQ_FOREACH(arg, &prepend_args, link) {
+ arg2 = argument_copy(arg->val);
+ TAILQ_INSERT_AFTER(args, prepend_after, arg2, link);
+ }
+ } else {
+ TAILQ_FOREACH_REVERSE(arg, &prepend_args, arglist, link) {
+ arg2 = argument_copy(arg->val);
+ TAILQ_INSERT_HEAD(args, arg2, link);
+ }
+ }
+ TAILQ_FOREACH(arg, &append_args, link) {
+ arg2 = argument_copy(arg->val);
+ TAILQ_INSERT_TAIL(args, arg2, link);
+ }
+}
+
+void
+argument_unlink(struct arglist *args, struct argument **argp)
+{
+ struct argument *arg;
+
+ arg = *argp;
+ *argp = TAILQ_NEXT(arg, link);
+
+ TAILQ_REMOVE(args, arg, link);
+ free(arg->val);
+ free(arg);
+}
+
+void
+parse_config(const char *wrapper)
+{
+ const char *config_dir;
+ char *config_file, *line;
+ size_t len;
+ ssize_t llen;
+ FILE *fp;
+
+ config_dir = getenv("WRAPPER_CONFIG_DIR");
+ if (config_dir == NULL)
+ errx(255, "WRAPPER_CONFIG_DIR is missing from environment");
+
+ config_file = xasprintf("%s/%s", config_dir, wrapper);
+ fp = fopen(config_file, "r");
+ if (fp == NULL)
+ errx(255, "Failed to open wrapper config file `%s'",
+ config_file);
+
+ for (len = 0, line = NULL; (llen = getline(&line, &len, fp)) > 0;
+ free(line), line = NULL, len = 0) {
+ if (line[llen - 1] == '\n') {
+ line[llen - 1] = '\0';
+ --llen;
+ }
+ if (strncmp(line, "worklog=", 8) == 0) {
+ free(worklog_path);
+ worklog_path = xstrdup(line + 8);
+ continue;
+ }
+ if (strncmp(line, "path=", 5) == 0) {
+ free(real_path);
+ real_path = xstrdup(line + 5);
+ continue;
+ }
+ if (strncmp(line, "exec=", 5) == 0) {
+ free(exec_name);
+ exec_name = xstrdup(line + 5);
+ continue;
+ }
+ if (strncmp(line, "reorder=", 8) == 0) {
+ register_reorder(line + 8);
+ continue;
+ }
+ if (strncmp(line, "transform=", 10) == 0) {
+ register_generic_transform(line + 10);
+ continue;
+ }
+ if (strncmp(line, "prepend=", 8) == 0) {
+ struct argument *arg;
+ arg = argument_copy(line + 8);
+ TAILQ_INSERT_TAIL(&prepend_args, arg, link);
+ }
+ if (strncmp(line, "append=", 7) == 0) {
+ struct argument *arg;
+ arg = argument_copy(line + 7);
+ TAILQ_INSERT_TAIL(&append_args, arg, link);
+ }
+ if (strncmp(line, "wrksrc=", 7) == 0) {
+ free(wrksrc);
+ wrksrc = xstrdup(line + 7);
+ continue;
+ }
+ if (strncmp(line, "unwrap=", 7) == 0) {
+ register_unwrap(line + 7);
+ continue;
+ }
+ if (strncmp(line, "debug=", 6) == 0) {
+ debug = atoi(line + 6);
+ continue;
+ }
+ }
+
+ fclose(fp);
+
+ if (worklog_path == NULL)
+ errx(255, "worklog path has not been set");
+ if (exec_name == NULL)
+ errx(255, "executable name has not been set");
+}
+
+FILE *
+worklog_open(void)
+{
+ FILE *fp;
+
+ fp = fopen(worklog_path, "a");
+ if (fp == NULL)
+ err(255, "Could not open %s", worklog_path);
+
+ return fp;
+}
+
+void
+worklog_cmd(FILE *worklog, const char *prefix, const char *cmd,
+ struct arglist *args)
+{
+ static const char safe_chars[] =
+ "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "01234567890-_/:.,+=";
+ struct argument *arg;
+ size_t len, buflen;
+ char *buf;
+
+ fprintf(worklog, "%s %s", prefix, cmd);
+
+ buf = NULL;
+ buflen = 0;
+ TAILQ_FOREACH(arg, args, link) {
+ len = strlen(arg->val);
+ if (len == 0) {
+ fputs(" ''", worklog);
+ continue;
+ }
+ if (strspn(arg->val, safe_chars) == len) {
+ fputc(' ', worklog);
+ fputs(arg->val, worklog);
+ continue;
+ }
+ len = shquote(arg->val, buf, buflen);
+ if (len >= buflen) {
+ buflen = len + 1;
+ free(buf);
+ buf = xmalloc(buflen);
+ shquote(arg->val, buf, buflen);
+ }
+ fputc(' ', worklog);
+ fputs(buf, worklog);
+ }
+
+ fputc('\n', worklog);
+
+ if (buf)
+ free(buf);
+}
+
+int
+command_exec(struct arglist *args, int do_fork)
+{
+ struct argument *arg;
+ static const char failed_exec_msg[] = "exec failed\n";
+ char **argv, **argv2;
+ int argc, status;
+ pid_t child;
+
+ argc = 2;
+ TAILQ_FOREACH(arg, args, link)
+ ++argc;
+
+ argv2 = xmalloc(sizeof(void *) * argc);
+ argv2[0] = exec_name;
+ argv = argv2 + 1;
+ TAILQ_FOREACH(arg, args, link)
+ *argv++ = arg->val;
+ *argv = NULL;
+
+ if (real_path)
+ setenv("PATH", real_path, 1);
+
+ if (do_fork)
+ child = vfork();
+ else
+ child = 0;
+
+ switch (child) {
+ case 0:
+ execvp(exec_name, argv2);
+ status = write(STDERR_FILENO, failed_exec_msg,
+ sizeof(failed_exec_msg) - 1);
+ _exit(255 | status);
+ case -1:
+ err(255, "fork failed");
+ default:
+ waitpid(child, &status, 0);
+ return WEXITSTATUS(status);
+ }
+}
+
+size_t
+wrapper_hash(const char *str)
+{
+ return wrapper_hash2(str, strlen(str));
+}
+
+size_t
+wrapper_hash2(const char *str, size_t len)
+{
+ uint32_t hashes[3];
+
+ mi_vector_hash(str, len, 0xdeadbeef, hashes);
+ return hashes[0];
+}
diff --git a/pkgtools/cwrappers/files/bin/common.h b/pkgtools/cwrappers/files/bin/common.h
new file mode 100644
index 00000000000..aa1b7465423
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/common.h
@@ -0,0 +1,109 @@
+/* $NetBSD: common.h,v 1.1 2014/09/17 12:40:56 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2009 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef COMMON_H
+#define COMMON_H
+
+#include <nbcompat/types.h>
+#include <nbcompat/queue.h>
+#include <inttypes.h>
+#include <stdio.h>
+
+extern const char library_name_chars[];
+extern char *exec_name;
+extern char *wrksrc;
+extern int debug;
+
+TAILQ_HEAD(arglist, argument);
+
+struct argument {
+ TAILQ_ENTRY(argument) link;
+ TAILQ_ENTRY(argument) tmp_link;
+ char *val;
+};
+
+extern struct argument *prepend_after;
+
+char *concat(const char *, const char *);
+char *concat2(const char *, const char *, size_t);
+void arglist_from_argc(struct arglist *, int, char **);
+void arglist_apply_config(struct arglist *);
+int command_exec(struct arglist *, int);
+size_t wrapper_hash(const char *);
+size_t wrapper_hash2(const char *, size_t);
+
+void argument_unlink(struct arglist *, struct argument **);
+struct argument *argument_new(char *);
+struct argument *argument_copy(const char *);
+void argument_update(struct argument *, char *);
+
+void parse_config(const char *);
+
+FILE *worklog_open(void);
+void worklog_cmd(FILE *, const char *, const char *, struct arglist *);
+
+#if defined(__GNUC__) && __GNUC__ >= 2
+char *xasprintf(const char *, ...)
+ __attribute__((__format__(__printf__, 1, 2)));
+#else
+char *xasprintf(const char *, ...);
+#endif
+
+void *xmalloc(size_t);
+void *xrealloc(void *, size_t);
+char *xstrdup(const char *);
+char *xstrndup(const char *, size_t);
+
+void normalise_cc(struct arglist *);
+void cleanup_cc(struct arglist *args);
+void transform_cc(struct arglist *args);
+
+void register_reorder(const char *);
+void reorder_cc(struct arglist *);
+
+void init_generic_transform(void);
+void register_generic_transform(const char *);
+void generic_transform_cc(struct arglist *);
+
+void normalise_ld(struct arglist *);
+void generic_transform_ld(struct arglist *);
+
+void register_unwrap(const char *);
+void fixup_libtool(struct arglist *);
+
+#ifdef NEED_MI_VECTOR_HASH
+void mi_vector_hash(const void *, size_t, uint32_t, uint32_t[3]);
+#endif
+#ifdef NEED_GETLINE
+ssize_t getline(char **, size_t *, FILE *);
+#endif
+
+#endif
diff --git a/pkgtools/cwrappers/files/bin/cpp-wrapper.c b/pkgtools/cwrappers/files/bin/cpp-wrapper.c
new file mode 100644
index 00000000000..906a925f8af
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/cpp-wrapper.c
@@ -0,0 +1,4 @@
+#define WRAPPER_CPP
+#define WRAPPER_NAME "cpp"
+
+#include "base-wrapper.c"
diff --git a/pkgtools/cwrappers/files/bin/f77-wrapper.c b/pkgtools/cwrappers/files/bin/f77-wrapper.c
new file mode 100644
index 00000000000..7c05c94fbce
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/f77-wrapper.c
@@ -0,0 +1,4 @@
+#define WRAPPER_F77
+#define WRAPPER_NAME "f77"
+
+#include "base-wrapper.c"
diff --git a/pkgtools/cwrappers/files/bin/fixup-libtool.c b/pkgtools/cwrappers/files/bin/fixup-libtool.c
new file mode 100644
index 00000000000..18418c2f6db
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/fixup-libtool.c
@@ -0,0 +1,411 @@
+/* $NetBSD: fixup-libtool.c,v 1.1 2014/09/17 12:40:56 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2009 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/stat.h>
+#include <err.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "common.h"
+
+#define LIBPATH_HASH 256
+
+struct unwrap_rule {
+ TAILQ_ENTRY(unwrap_rule) link;
+ char *src;
+ char *dst;
+ size_t src_len;
+};
+
+TAILQ_HEAD(unwrap_ruleset, unwrap_rule);
+
+static struct unwrap_ruleset unwrap_rules =
+ TAILQ_HEAD_INITIALIZER(unwrap_rules);
+
+void
+register_unwrap(const char *rule)
+{
+ const char *sep;
+ struct unwrap_rule *r;
+
+ sep = strchr(rule, ':');
+ if (sep == NULL)
+ goto failure;
+ if (strchr(sep + 1, ':') != NULL)
+ goto failure;
+
+ r = xmalloc(sizeof(*r));
+ r->src = xstrndup(rule, sep - rule);
+ if (sep[1])
+ r->dst = xstrdup(sep + 1);
+ else
+ r->dst = NULL;
+ r->src_len = sep - rule;
+
+ TAILQ_INSERT_TAIL(&unwrap_rules, r, link);
+
+ return;
+
+failure:
+ errx(255, "Invalid transform rule: %s", rule);
+}
+
+struct processing_option {
+ FILE *output;
+ const char *lafile;
+ struct arglist hashtab[LIBPATH_HASH];
+ int first;
+ int in_lai;
+ int in_relink;
+ const char *last_opt;
+ size_t last_len;
+};
+
+static void
+process_option(struct processing_option *opt, const char *line, size_t len)
+{
+ struct unwrap_rule *r;
+ struct argument *arg;
+ char *tmp;
+ const char *eol;
+ size_t i, wlen;
+
+ if (opt->in_lai && opt->last_opt && opt->last_len == len &&
+ strncmp(opt->last_opt, line, len) == 0)
+ return;
+ if (len >= 11 && strncmp(line, "-Wl,-rpath,", 11) == 0)
+ return; /* No rpath... */
+ if (len >= 15 && strncmp(line, "-Wl,-rpath-link,", 15) == 0)
+ return; /* Still no rpath... */
+ if (len > 2 && strncmp(line, "-D", 2) == 0)
+ return; /* No preprocessor options */
+ if (len > 2 && strncmp(line, "-I", 2) == 0)
+ return; /* No preprocessor options */
+
+ if (len >= 2 && strncmp(line, "-L", 2) == 0) {
+ if (opt->in_lai) {
+ TAILQ_FOREACH(r, &unwrap_rules, link) {
+ if (len - 2 < r->src_len)
+ continue;
+ if (strncmp(line + 2, r->src, r->src_len))
+ continue;
+ if (line[r->src_len + 2] != '/' &&
+ len != r->src_len + 2)
+ continue;
+ line += r->src_len + 2;
+ len -= r->src_len + 2;
+ tmp = xasprintf("-L%s%*.*s", r->dst,
+ (int)len, (int)len, line);
+ process_option(opt, tmp, strlen(tmp));
+ free(tmp);
+ return;
+ }
+ if (wrksrc) {
+ wlen = strlen(wrksrc);
+
+ if (wlen <= len - 2 &&
+ strncmp(line + 2, wrksrc, wlen) == 0 &&
+ (line[wlen + 2] == '/' || wlen + 2 == len))
+ return;
+ /* XXX Check for DEPOTBASE */
+ }
+ }
+ i = wrapper_hash2(line, len) & (LIBPATH_HASH - 1);
+ TAILQ_FOREACH(arg, opt->hashtab + i, link) {
+ if (strncmp(arg->val, line, len) == 0 &&
+ arg->val[len] == '\0')
+ break;
+ }
+ if (arg != NULL)
+ return;
+
+ arg = argument_new(xstrndup(line, len));
+ TAILQ_INSERT_TAIL(opt->hashtab + i, arg, link);
+
+ goto print_option;
+ }
+
+ opt->last_opt = line;
+ opt->last_len = len;
+
+ if (len < 3 || strncmp(line + len - 3, ".la", 3))
+ goto print_option;
+
+ for (eol = line + len - 3; eol > line; --eol) {
+ if (*eol == '/')
+ break;
+ }
+
+ if (opt->in_lai && *eol == '/') {
+ TAILQ_FOREACH(r, &unwrap_rules, link) {
+ if (eol < line + r->src_len)
+ continue;
+ if (strncmp(line, r->src, r->src_len))
+ continue;
+ if (line[r->src_len] != '/')
+ continue;
+ line += r->src_len;
+ len -= r->src_len;
+ if (strncmp(eol + 1, "lib", 3) == 0) {
+ tmp = xasprintf("-L%s%*.*s", r->dst,
+ (int)(eol - line), (int)(eol - line), line);
+ process_option(opt, tmp, strlen(tmp));
+ free(tmp);
+ eol += 4;
+ len = line + len - eol - 3;
+ fprintf(opt->output, " -l%*.*s", (int)len, (int)len,
+ eol);
+ } else {
+ tmp = xasprintf("%s%*.*s", r->dst,
+ (int)len, (int)len, line);
+ process_option(opt, tmp, strlen(tmp));
+ free(tmp);
+ }
+ return;
+ }
+ }
+
+ if (!opt->in_relink)
+ goto print_option;
+
+ if (opt->lafile && strncmp(opt->lafile, line, len) == 0 &&
+ len == strlen(opt->lafile))
+ goto print_option;
+
+ if (*line != '/' && line == eol) {
+ process_option(opt, "-L./.libs", 9);
+ goto print_option;
+ }
+
+ if (*line != '/') {
+ tmp = xasprintf("-L%*.*s/.libs", (int)(eol - line),
+ (int)(eol - line), line);
+ process_option(opt, tmp, strlen(tmp));
+ free(tmp);
+ goto print_option;
+ }
+
+ if (wrksrc == NULL)
+ goto print_option;
+
+ wlen = strlen(wrksrc);
+ if (wlen > len ||
+ (wlen != len && line[wlen] != '/') ||
+ strncmp(wrksrc, line, wlen))
+ goto print_option;
+
+ tmp = xasprintf("-L%*.*s/.libs", (int)(eol - line),
+ (int)(eol - line), line);
+ process_option(opt, tmp, strlen(tmp));
+ free(tmp);
+
+print_option:
+ if (opt->first)
+ opt->first = 0;
+ else
+ putc(' ', opt->output);
+ fwrite(line, len, 1, opt->output);
+}
+
+static void
+process_variable(FILE *output, const char *lafile, const char *line,
+ int in_lai, int in_relink)
+{
+ struct processing_option opt;
+ size_t len, len2;
+ struct argument *arg;
+ size_t i;
+ const char *command;
+
+ for (i = 0; i < LIBPATH_HASH; ++i)
+ TAILQ_INIT(opt.hashtab + i);
+
+ opt.output = output;
+ opt.lafile = lafile;
+ opt.in_lai = in_lai;
+ opt.in_relink = in_relink;
+ opt.last_opt = NULL;
+ opt.last_len = 0;
+
+ if (in_relink) {
+ command = strchr(line, ';');
+ if (command == NULL)
+ errx(255, "Unrecognizable relink format");
+ ++command;
+ fwrite(line, command - line, 1, output);
+ fputs(" libtool", output); /* XXX Use full path here? */
+
+ /* XXX document this logic */
+ line = command + 1;
+ len = strspn(line, " \t");
+ line += len;
+ len2 = len = strcspn(line, " \t");
+ command = line;
+ if (len == 0)
+ errx(255, "Unrecognizable relink format");
+ line += len;
+ len = strspn(line, " \t");
+ line += len;
+ if (len2 != 7 || strncmp(command, "libtool", 7)) {
+ len = strcspn(line, " \t");
+ if (len == 0)
+ errx(255, "Unrecognizable relink format");
+ line += len;
+ len = strspn(line, " \t");
+ line += len;
+ }
+ }
+
+ for (opt.first = !in_relink; *line ; line += len) {
+ len = strspn(line, " \t");
+ line += len;
+ len = strcspn(line, " \t");
+ if (len == 0)
+ break;
+ process_option(&opt, line, len);
+ }
+
+ for (i = 0; i < LIBPATH_HASH; ++i) {
+ while ((arg = TAILQ_FIRST(opt.hashtab + i)) != NULL)
+ argument_unlink(opt.hashtab + i, &arg);
+ }
+}
+
+static void
+fixup_libtool_la(const char *lafile, int in_lai)
+{
+ static const char dep_lib[] = "dependency_libs='";
+ static const char relink_cmd[] = "relink_command=\"";
+ struct stat st;
+ FILE *fp, *output;
+ char *line, *opt_start, *tmp_name;
+ const char *pass_lafile, *cur_option;
+ int in_relink;
+ char delimiter;
+ size_t len;
+ ssize_t cur;
+
+ fp = fopen(lafile, "r");
+ if (fp == NULL)
+ return;
+ if (fstat(fileno(fp), &st))
+ err(255, "fstat('%s') failed", lafile);
+ if ((st.st_mode & S_IFMT) != S_IFREG) {
+ fclose(fp);
+ return;
+ }
+
+ tmp_name = concat(lafile, ".tmp");
+ output = fopen(tmp_name, "w");
+ if (output == NULL)
+ err(255, "fopen('%s') failed", tmp_name);
+
+ line = NULL;
+ len = 0;
+ while ((cur = getline(&line, &len, fp)) > 0) {
+ if (strncmp(line, relink_cmd, sizeof(relink_cmd) - 1) == 0) {
+ cur_option = relink_cmd;
+ opt_start = line + sizeof(relink_cmd) - 1;
+ pass_lafile = lafile;
+ delimiter='\"';
+ in_relink = 1;
+ } else if (strncmp(line, dep_lib, sizeof(dep_lib) - 1) == 0) {
+ cur_option = dep_lib;
+ opt_start = line + sizeof(dep_lib) - 1;
+ pass_lafile = NULL;
+ delimiter='\'';
+ in_relink = 0;
+ } else {
+ fwrite(line, 1, cur, output);
+ continue;
+ }
+
+ if (line[cur - 2] != delimiter || line[cur - 1] != '\n')
+ errx(255, "corrupted libtool archive '%s'", lafile);
+ if (debug) {
+ fputs("# buildlink modification, original:\n# ",
+ output);
+ fwrite(line, 1, cur, output);
+ } else {
+ fputs("# buildlink modification\n", output);
+ }
+ fputs(cur_option, output);
+ line[cur - 2] = '\0';
+ process_variable(output, pass_lafile, opt_start, in_lai,
+ in_relink);
+ fprintf(output, "%c\n", delimiter);
+ }
+ free(line);
+
+ fclose(fp);
+ if (ferror(fp) || fclose(output) || rename(tmp_name, lafile)) {
+ unlink(tmp_name);
+ err(255, "output processing failed");
+ }
+}
+
+void
+fixup_libtool(struct arglist *args)
+{
+ struct argument *arg, *arg2;
+ const char *slash;
+ char *laifile;
+ size_t len;
+
+ TAILQ_FOREACH(arg, args, link) {
+ if (strcmp(arg->val, "-o"))
+ continue;
+ arg2 = TAILQ_NEXT(arg, link);
+ if (arg2 == NULL || arg2->val[0] == '-')
+ errx(255, "Missing argument for option -o");
+ arg = arg2;
+ len = strlen(arg->val);
+ if (len < 3)
+ continue;
+ if (strcmp(arg->val + len - 3, ".la") == 0)
+ break;
+ }
+ if (arg == NULL)
+ return;
+
+ fixup_libtool_la(arg->val, 0);
+ slash = strrchr(arg->val, '/');
+ if (slash == NULL)
+ laifile = xasprintf("./.libs/%si", arg->val);
+ else
+ laifile = xasprintf("%*.*s/.libs/%si",
+ (int)(slash - arg->val), (int)(slash - arg->val),
+ arg->val, slash + 1);
+ fixup_libtool_la(laifile, 1);
+ free(laifile);
+}
diff --git a/pkgtools/cwrappers/files/bin/generic-transform-cc.c b/pkgtools/cwrappers/files/bin/generic-transform-cc.c
new file mode 100644
index 00000000000..e61bada054d
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/generic-transform-cc.c
@@ -0,0 +1,451 @@
+/* $NetBSD: generic-transform-cc.c,v 1.1 2014/09/17 12:40:56 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2009 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(WRAPPER_LIBTOOL)
+#include <sys/stat.h>
+#endif
+
+#include <err.h>
+#include <stdlib.h>
+#include <string.h>
+#include "common.h"
+
+#if defined(WRAPPER_LD)
+#define generic_transform_cc generic_transform_ld
+#endif
+
+#define OPT_HASH 256
+
+struct transform_rule {
+ TAILQ_ENTRY(transform_rule) link;
+ char *src;
+ char *dst;
+ size_t src_len;
+};
+
+struct lib_transform_rule {
+ TAILQ_ENTRY(lib_transform_rule) link;
+ char *src;
+ char **dst;
+ size_t src_len;
+};
+
+TAILQ_HEAD(transform_ruleset, transform_rule);
+TAILQ_HEAD(lib_transform_ruleset, lib_transform_rule);
+
+static struct transform_ruleset opt_rules[OPT_HASH];
+
+#if !defined(WRAPPER_LD)
+static struct transform_ruleset include_rules =
+ TAILQ_HEAD_INITIALIZER(include_rules);
+#endif
+static struct transform_ruleset lib_rules =
+ TAILQ_HEAD_INITIALIZER(lib_rules);
+static struct transform_ruleset rpath_rules =
+ TAILQ_HEAD_INITIALIZER(rpath_rules);
+#if defined(WRAPPER_LIBTOOL)
+static struct transform_ruleset libpath_rules =
+ TAILQ_HEAD_INITIALIZER(libpath_rules);
+#endif
+
+static struct lib_transform_ruleset libname_rules =
+ TAILQ_HEAD_INITIALIZER(libname_rules);
+
+void
+init_generic_transform(void)
+{
+ size_t i;
+
+ for (i = 0; i < OPT_HASH; ++i)
+ TAILQ_INIT(opt_rules + i);
+}
+
+static void
+register_generic_transform_path(const char *orig_rule, const char *rule,
+ struct transform_ruleset *ruleset)
+{
+ const char *sep;
+ struct transform_rule *r;
+
+ sep = strchr(rule, ':');
+ if (sep == NULL)
+ goto failure;
+ if (strchr(sep + 1, ':') != NULL)
+ goto failure;
+
+ r = xmalloc(sizeof(*r));
+ r->src = xstrndup(rule, sep - rule);
+ if (sep[1])
+ r->dst = xstrdup(sep + 1);
+ else
+ r->dst = NULL;
+ r->src_len = sep - rule;
+
+ TAILQ_INSERT_TAIL(ruleset, r, link);
+
+ return;
+
+failure:
+ errx(255, "Invalid transform rule: %s", orig_rule);
+}
+
+static void
+register_generic_transform_lib(const char *orig_rule, const char *rule)
+{
+ struct lib_transform_rule *r;
+ const char *sep;
+ size_t count;
+
+ sep = strchr(rule, ':');
+ if (sep == NULL)
+ goto failure;
+
+ r = xmalloc(sizeof(*r));
+ r->src = concat2("-l", rule, sep - rule);
+ r->src_len = sep - rule + 2;
+ rule = sep;
+ for (count = 0; sep != NULL; ++count)
+ sep = strchr(sep + 1, ':');
+
+ r->dst = xmalloc(sizeof(char *) * (count + 1));
+ for (count = 0; rule != NULL; ++count, rule = sep) {
+ ++rule;
+ sep = strchr(rule, ':');
+ if (sep == rule || *rule == '\0')
+ goto failure;
+ if (sep)
+ r->dst[count] = concat2("-l", rule, sep - rule);
+ else
+ r->dst[count] = concat("-l", rule);
+ }
+ r->dst[count] = NULL;
+
+ TAILQ_INSERT_TAIL(&libname_rules, r, link);
+
+ return;
+failure:
+ errx(255, "Invalid transform rule: %s", orig_rule);
+}
+
+static void
+register_opt_transform(const char *orig_rule, const char *rule)
+{
+ const char *sep;
+ struct transform_rule *r;
+ size_t i;
+
+ sep = strchr(rule, ':');
+ if (sep == NULL)
+ goto failure;
+ if (strchr(sep + 1, ':') != NULL)
+ goto failure;
+
+ r = xmalloc(sizeof(*r));
+ r->src = xstrndup(rule, sep - rule);
+ if (sep[1])
+ r->dst = xstrdup(sep + 1);
+ else
+ r->dst = NULL;
+ r->src_len = sep - rule;
+
+ i = wrapper_hash(r->src) & (OPT_HASH - 1);
+
+ TAILQ_INSERT_TAIL(opt_rules + i, r, link);
+
+ return;
+
+failure:
+ errx(255, "Invalid transform rule: %s", orig_rule);
+}
+
+static void
+register_rm_transform(const char *orig_rule, const char *rule)
+{
+ struct transform_rule *r;
+ size_t i;
+
+ if (strchr(rule, ':') != NULL)
+ goto failure;
+
+ r = xmalloc(sizeof(*r));
+ r->src = xstrdup(rule);
+ r->dst = NULL;
+ r->src_len = strlen(r->src);
+
+ i = wrapper_hash(r->src) & (OPT_HASH - 1);
+
+ TAILQ_INSERT_TAIL(opt_rules + i, r, link);
+
+ return;
+
+failure:
+ errx(255, "Invalid transform rule: %s", orig_rule);
+}
+
+void
+register_generic_transform(const char *rule)
+{
+ if (strncmp(rule, "I:", 2) == 0) {
+#if !defined(WRAPPER_LD)
+ register_generic_transform_path(rule, rule + 2,
+ &include_rules);
+#endif
+ } else if (strncmp(rule, "L:", 2) == 0) {
+ register_generic_transform_path(rule, rule + 2,
+ &lib_rules);
+ } else if (strncmp(rule, "R:", 2) == 0) {
+ register_generic_transform_path(rule, rule + 2,
+ &rpath_rules);
+ } else if (strncmp(rule, "l:", 2) == 0) {
+ register_generic_transform_lib(rule, rule + 2);
+ } else if (strncmp(rule, "P:", 2) == 0) {
+#if defined(WRAPPER_LIBTOOL)
+ register_generic_transform_path(rule, rule + 2,
+ &libpath_rules);
+#endif
+ } else if (strncmp(rule, "opt:", 4) == 0) {
+ register_opt_transform(rule, rule + 4);
+ } else if (strncmp(rule, "rm:", 3) == 0) {
+ register_rm_transform(rule, rule + 3);
+ } else
+ errx(255, "Unknown transform rule: %s", rule);
+}
+
+#if defined(WRAPPER_LIBTOOL)
+static void
+generic_transform_cc_absolute(struct arglist *args, struct argument *arg)
+{
+ struct transform_rule *rule;
+ const char *fname, *iter;
+ size_t len;
+
+ fname = strrchr(arg->val, '/');
+ if (strncmp(fname + 1, "lib", 3))
+ return;
+ iter = fname + 4;
+ len = strspn(iter, library_name_chars);
+ if (len == 0)
+ return;
+ iter += len;
+ if (strcmp(iter, ".la") && strcmp(iter, ".a"))
+ return;
+
+ len = fname - arg->val;
+
+ TAILQ_FOREACH(rule, &libpath_rules, link) {
+ if (rule->src_len > len)
+ continue;
+ if (arg->val[rule->src_len] != '/')
+ continue;
+ if (strncmp(arg->val, rule->src, rule->src_len))
+ continue;
+ argument_update(arg, concat(rule->dst, arg->val + rule->src_len));
+ break;
+ }
+}
+
+static int
+generic_transform_libtool_lib(struct arglist *args, struct argument *arg)
+{
+ struct argument *arg2;
+ struct stat sb;
+ char *fname;
+ int rv;
+ size_t len;
+
+ TAILQ_FOREACH(arg2, args, link) {
+ if (arg == arg2)
+ break;
+ if (strncmp(arg2->val, "-L", 2))
+ continue;
+ len = strlen(arg2->val);
+ if (len >= 6 && strcmp(arg2->val + len - 6, "/.libs") == 0)
+ continue;
+ fname = xasprintf("%s/lib%s.la", arg2->val + 2, arg->val + 2);
+ rv = stat(fname, &sb);
+ if (rv == -1 ||
+ !(S_ISREG(sb.st_mode) || S_ISLNK(sb.st_mode))) {
+ free(fname);
+ continue;
+ }
+ if (arg2->val[2] == '/') {
+ if (wrksrc == NULL)
+ return 0;
+ if (strncmp(arg2->val + 2, wrksrc, len))
+ return 0;
+ }
+ argument_update(arg, fname);
+ return 1;
+ }
+ return 0;
+}
+#endif
+
+void
+generic_transform_cc(struct arglist *args)
+{
+ struct argument *arg, *arg2, *opt_arg;
+ struct transform_rule *rule;
+ struct transform_ruleset *ruleset;
+ struct lib_transform_rule *lib_rule;
+ const char *path, *prefix;
+ char *transformed;
+ int rpath_mode;
+ size_t i, len;
+
+ TAILQ_FOREACH_SAFE(arg, args, link, arg2) {
+ len = strlen(arg->val);
+ i = wrapper_hash2(arg->val, len) & (OPT_HASH - 1);
+ rpath_mode = 0;
+ TAILQ_FOREACH(rule, opt_rules + i, link) {
+ if (rule->src_len == len &&
+ strcmp(rule->src, arg->val) == 0)
+ break;
+ }
+ if (rule != NULL) {
+ if (rule->dst == NULL) {
+ argument_unlink(args, &arg);
+ continue;
+ }
+ argument_update(arg, xstrdup(rule->dst));
+ len = strlen(rule->dst);
+ }
+
+#if defined(WRAPPER_LIBTOOL)
+ if (strncmp(arg->val, "-l", 2) == 0 &&
+ generic_transform_libtool_lib(args, arg))
+ continue;
+#endif
+
+ if (arg->val[0] == '/') {
+#if defined(WRAPPER_LIBTOOL)
+ generic_transform_cc_absolute(args, arg);
+#endif
+ continue;
+ }
+#if !defined(WRAPPER_LD)
+ else if (strncmp(arg->val, "-I", 2) == 0) {
+ len -= 2;
+ prefix = "-I";
+ path = arg->val + 2;
+ ruleset = &include_rules;
+ opt_arg = NULL;
+ }
+#endif
+ else if (strncmp(arg->val, "-L", 2) == 0) {
+ len -= 2;
+ prefix = "-L";
+ path = arg->val + 2;
+ ruleset = &lib_rules;
+ opt_arg = NULL;
+ }
+#if !defined(WRAPPER_LD)
+ else if (strncmp(arg->val, "-Wl,-rpath,", 11) == 0) {
+ len -= 11;
+ prefix = "-Wl,-rpath,";
+ path = arg->val + 11;
+ ruleset = &rpath_rules;
+ opt_arg = NULL;
+ rpath_mode = 1;
+ } else if (strncmp(arg->val, "-Wl,-rpath-link,", 15) == 0) {
+ len -= 15;
+ prefix = "-Wl,-rpath-link,";
+ path = arg->val + 15;
+ ruleset = &rpath_rules;
+ opt_arg = NULL;
+ rpath_mode = 1;
+ }
+#else
+ else if (strcmp(arg->val, "-rpath") == 0 ||
+ strcmp(arg->val, "-rpath-link") == 0) {
+ opt_arg = arg;
+ arg = arg2;
+ if (arg == NULL || arg->val[0] == '-') {
+ errx(255, "Missing argument for %s",
+ opt_arg->val);
+ }
+ ruleset = &rpath_rules;
+ arg2 = TAILQ_NEXT(arg, link);
+ len = strlen(arg->val);
+ prefix = "";
+ path = arg->val;
+ rpath_mode = 1;
+ }
+#endif
+ else if (strncmp(arg->val, "-l", 2) == 0) {
+ TAILQ_FOREACH(lib_rule, &libname_rules, link) {
+ if (lib_rule->src_len != len)
+ continue;
+ if (strcmp(lib_rule->src, arg->val) == 0)
+ break;
+ }
+ if (lib_rule == NULL)
+ continue;
+ argument_unlink(args, &arg);
+ for (i = 0; lib_rule->dst[i] != NULL; ++i) {
+ arg = argument_copy(lib_rule->dst[i]);
+ if (arg2 == NULL)
+ TAILQ_INSERT_TAIL(args, arg, link);
+ else
+ TAILQ_INSERT_BEFORE(arg2, arg, link);
+ }
+ continue;
+ } else
+ continue;
+
+ if (*path != '/')
+ continue;
+
+ TAILQ_FOREACH(rule, ruleset, link) {
+ if (rule->src_len > len)
+ continue;
+ if (path[rule->src_len] != '\0' &&
+ path[rule->src_len] != '/')
+ continue;
+ if (strncmp(path, rule->src, rule->src_len) == 0)
+ break;
+ }
+ if (rule == NULL || rule->dst == NULL) {
+ if (rpath_mode) {
+ if (len >= 6 &&
+ strcmp(path + len - 6, "/.libs") == 0)
+ continue;
+ }
+ if (opt_arg)
+ argument_unlink(args, &opt_arg);
+ argument_unlink(args, &arg);
+ continue;
+ }
+ transformed = xasprintf("%s%s%s", prefix, rule->dst,
+ path + rule->src_len);
+ argument_update(arg, transformed);
+ }
+}
diff --git a/pkgtools/cwrappers/files/bin/generic-transform-ld.c b/pkgtools/cwrappers/files/bin/generic-transform-ld.c
new file mode 100644
index 00000000000..c99be3afefa
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/generic-transform-ld.c
@@ -0,0 +1,3 @@
+#define WRAPPER_LD
+
+#include "generic-transform-cc.c"
diff --git a/pkgtools/cwrappers/files/bin/generic-transform-libtool.c b/pkgtools/cwrappers/files/bin/generic-transform-libtool.c
new file mode 100644
index 00000000000..1c3cc573025
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/generic-transform-libtool.c
@@ -0,0 +1,3 @@
+#define WRAPPER_LIBTOOL
+
+#include "generic-transform-cc.c"
diff --git a/pkgtools/cwrappers/files/bin/getline.c b/pkgtools/cwrappers/files/bin/getline.c
new file mode 100644
index 00000000000..543a15c25eb
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/getline.c
@@ -0,0 +1,51 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+
+ssize_t
+getline(char **lineptr, size_t *len, FILE *fp)
+{
+ char *iter, *eos;
+ int ch;
+
+ if (*len == 1) {
+ free(*lineptr);
+ *len = 0;
+ }
+ if (*len == 0) {
+ *lineptr = malloc(128);
+ if (*lineptr == NULL)
+ return -1;
+ *len = 128;
+ }
+
+ iter = *lineptr;
+ for (;;) {
+ eos = *lineptr + *len - 1;
+
+ while (iter < eos) {
+ ch = getc_unlocked(fp);
+ if (ch == -1)
+ break;
+ *iter++ = ch;
+ if (ch == '\n') {
+ *iter = '\0';
+ return iter - *lineptr;
+ }
+ }
+ if (iter == *lineptr)
+ return -1;
+ if (iter < eos) {
+ *iter = '\0';
+ return iter - *lineptr;
+ }
+
+ iter = realloc(*lineptr, *len * 2);
+ if (iter == NULL)
+ return -1;
+ *lineptr = iter;
+ iter += *len - 1;
+ *len *= 2;
+ }
+}
diff --git a/pkgtools/cwrappers/files/bin/imake-wrapper.c b/pkgtools/cwrappers/files/bin/imake-wrapper.c
new file mode 100644
index 00000000000..97e4425b055
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/imake-wrapper.c
@@ -0,0 +1,4 @@
+#define WRAPPER_IMAKE
+#define WRAPPER_NAME "imake"
+
+#include "base-wrapper.c"
diff --git a/pkgtools/cwrappers/files/bin/ld-wrapper.c b/pkgtools/cwrappers/files/bin/ld-wrapper.c
new file mode 100644
index 00000000000..6feab101890
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/ld-wrapper.c
@@ -0,0 +1,4 @@
+#define WRAPPER_LD
+#define WRAPPER_NAME "ld"
+
+#include "base-wrapper.c"
diff --git a/pkgtools/cwrappers/files/bin/libtool-wrapper.c b/pkgtools/cwrappers/files/bin/libtool-wrapper.c
new file mode 100644
index 00000000000..1858cdcf72f
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/libtool-wrapper.c
@@ -0,0 +1,4 @@
+#define WRAPPER_LIBTOOL
+#define WRAPPER_NAME "libtool"
+
+#include "base-wrapper.c"
diff --git a/pkgtools/cwrappers/files/bin/mi_vector_hash.c b/pkgtools/cwrappers/files/bin/mi_vector_hash.c
new file mode 100644
index 00000000000..12886ab4cc6
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/mi_vector_hash.c
@@ -0,0 +1,179 @@
+/* $NetBSD: mi_vector_hash.c,v 1.1 2014/09/17 12:40:56 joerg Exp $ */
+/*-
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Joerg Sonnenberger.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * See http://burtleburtle.net/bob/hash/doobs.html for the full description
+ * and the original version of the code. This version differs by exposing
+ * the full internal state and avoiding byte operations in the inner loop
+ * if the key is aligned correctly.
+ */
+
+#include <nbcompat.h>
+#include <nbcompat/cdefs.h>
+__RCSID("$NetBSD: mi_vector_hash.c,v 1.1 2014/09/17 12:40:56 joerg Exp $");
+
+#include <nbcompat/endian.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "common.h"
+
+static uint16_t
+my_le16dec(const void *buf)
+{
+ const uint8_t *p = (const uint8_t *)buf;
+
+ return (p[0] | ((uint16_t)p[1] << 8));
+}
+
+static uint32_t
+my_le32dec(const void *buf)
+{
+ const uint8_t *p = (const uint8_t *)buf;
+
+ return (my_le16dec(p) | ((uint32_t)my_le16dec(p + 2) << 16));
+}
+
+#define mix(a, b, c) do { \
+ a -= b; a -= c; a ^= (c >> 13); \
+ b -= c; b -= a; b ^= (a << 8); \
+ c -= a; c -= b; c ^= (b >> 13); \
+ a -= b; a -= c; a ^= (c >> 12); \
+ b -= c; b -= a; b ^= (a << 16); \
+ c -= a; c -= b; c ^= (b >> 5); \
+ a -= b; a -= c; a ^= (c >> 3); \
+ b -= c; b -= a; b ^= (a << 10); \
+ c -= a; c -= b; c ^= (b >> 15); \
+} while (/* CONSTCOND */0)
+
+#define FIXED_SEED 0x9e3779b9 /* Golden ratio, arbitrary constant */
+
+void
+mi_vector_hash(const void *key, size_t len, uint32_t seed, uint32_t hashes[3])
+{
+ static const uint32_t mask[4] = {
+ 0x000000ff, 0x0000ffff, 0x00ffffff, 0xffffffff
+ };
+ uint32_t orig_len, a, b, c;
+ const uint8_t *k;
+
+ orig_len = (uint32_t)len;
+
+ a = b = FIXED_SEED;
+ c = seed;
+
+ if ((uintptr_t)key & 3) {
+ k = key;
+ while (len >= 12) {
+ a += my_le32dec(k);
+ b += my_le32dec(k + 4);
+ c += my_le32dec(k + 8);
+ mix(a, b, c);
+ k += 12;
+ len -= 12;
+ }
+ c += orig_len;
+
+ if (len > 8) {
+ switch (len) {
+ case 11:
+ c += (uint32_t)k[10] << 24;
+ /* FALLTHROUGH */
+ case 10:
+ c += (uint32_t)k[9] << 16;
+ /* FALLTHROUGH */
+ case 9:
+ c += (uint32_t)k[8] << 8;
+ /* FALLTHROUGH */
+ }
+ b += my_le32dec(k + 4);
+ a += my_le32dec(k);
+ } else if (len > 4) {
+ switch (len) {
+ case 8:
+ b += (uint32_t)k[7] << 24;
+ /* FALLTHROUGH */
+ case 7:
+ b += (uint32_t)k[6] << 16;
+ /* FALLTHROUGH */
+ case 6:
+ b += (uint32_t)k[5] << 8;
+ /* FALLTHROUGH */
+ case 5:
+ b += k[4];
+ /* FALLTHROUGH */
+ }
+ a += my_le32dec(k);
+ } else if (len) {
+ switch (len) {
+ case 4:
+ a += (uint32_t)k[3] << 24;
+ /* FALLTHROUGH */
+ case 3:
+ a += (uint32_t)k[2] << 16;
+ /* FALLTHROUGH */
+ case 2:
+ a += (uint32_t)k[1] << 8;
+ /* FALLTHROUGH */
+ case 1:
+ a += k[0];
+ /* FALLTHROUGH */
+ }
+ }
+ } else {
+ const uint32_t *key32 = key;
+ while (len >= 12) {
+ a += le32toh(key32[0]);
+ b += le32toh(key32[1]);
+ c += le32toh(key32[2]);
+ mix(a, b, c);
+ key32 += 3;
+ len -= 12;
+ }
+ c += orig_len;
+
+ if (len > 8) {
+ c += (le32toh(key32[2]) & mask[len - 9]) << 8;
+ b += le32toh(key32[1]);
+ a += le32toh(key32[0]);
+ } else if (len > 4) {
+ b += le32toh(key32[1]) & mask[len - 5];
+ a += le32toh(key32[0]);
+ } else if (len)
+ a += le32toh(key32[0]) & mask[len - 1];
+ }
+ mix(a, b, c);
+ hashes[0] = a;
+ hashes[1] = b;
+ hashes[2] = c;
+}
diff --git a/pkgtools/cwrappers/files/bin/normalise-cc.c b/pkgtools/cwrappers/files/bin/normalise-cc.c
new file mode 100644
index 00000000000..ac2b773e0e5
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/normalise-cc.c
@@ -0,0 +1,204 @@
+/* $NetBSD: normalise-cc.c,v 1.1 2014/09/17 12:40:56 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2009 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+
+#include <err.h>
+#include <stdlib.h>
+#include <string.h>
+#include "common.h"
+
+static void
+normalise_path_list(struct arglist *args, struct argument *arg,
+ const char *prefix, const char *val, int strip_relative)
+{
+ const char *sep;
+ struct argument *arg2;
+
+ while ((sep = strchr(val, ':')) != NULL) {
+ if (sep == val || (strip_relative && val[0] != '/')) {
+ val = sep + 1;
+ continue;
+ }
+ arg2 = argument_new(concat2(prefix, val, sep - val));
+ TAILQ_INSERT_AFTER(args, arg, arg2, link);
+ arg = arg2;
+ val = sep + 1;
+ }
+ if (val[0] == '\0' || (strip_relative && val[0] != '/'))
+ return;
+ arg2 = argument_new(concat(prefix, val));
+ TAILQ_INSERT_AFTER(args, arg, arg2, link);
+ arg = arg2;
+}
+
+void
+normalise_cc(struct arglist *args)
+{
+ struct argument *arg, *arg2, *arg3;
+ const char *next, *last;
+ size_t len;
+
+ TAILQ_FOREACH_SAFE(arg, args, link, arg2) {
+ if (arg->val[0] != '-')
+ continue;
+ if (strcmp(arg->val, "-Xlinker") == 0) {
+ if (arg2 == NULL)
+ errx(255, "Missing argument for %s", arg->val);
+ if (strncmp(arg2->val, "-Wl,", 4) == 0) {
+ argument_unlink(args, &arg);
+ continue;
+ }
+ argument_update(arg2, concat("-Wl,", arg2->val));
+ argument_unlink(args, &arg);
+ continue;
+ }
+ if (strncmp(arg->val, "-Wl,", 4) == 0 &&
+ (next = strchr(arg->val + 4, ',')) != NULL) {
+ last = arg->val + 4;
+ do {
+ arg3 = argument_new(concat2("-Wl,", last,
+ next - last));
+ if (arg2 != NULL)
+ TAILQ_INSERT_BEFORE(arg2, arg3, link);
+ else
+ TAILQ_INSERT_TAIL(args, arg3, link);
+ last = next + 1;
+ } while ((next = strchr(last, ',')) != NULL);
+ arg3 = argument_new(concat("-Wl,", last));
+ if (arg2 != NULL)
+ TAILQ_INSERT_BEFORE(arg2, arg3, link);
+ else
+ TAILQ_INSERT_TAIL(args, arg3, link);
+ argument_unlink(args, &arg);
+ continue;
+ }
+ }
+
+ TAILQ_FOREACH_SAFE(arg, args, link, arg2) {
+ if (strcmp(arg->val, "-o") == 0 ||
+ strcmp(arg->val, "--dynamic-linker") == 0) {
+ if (arg2 == NULL || arg2->val[0] == '-')
+ errx(255, "Missing argument for %s", arg->val);
+ arg2 = TAILQ_NEXT(arg2, link);
+ continue;
+ }
+ if (arg->val[0] == '/') {
+ next = strrchr(arg->val, '/');
+ ++next;
+ if (strncmp(next, "lib", 3))
+ continue;
+ next += 3;
+ len = strspn(next, library_name_chars);
+ if (len == 0)
+ continue;
+ last = next + len;
+ if (strncmp(last, ".so", 3) &&
+ strncmp(last, ".sl", 3))
+ continue;
+ if (last[3] &&
+ (last[3] != '.' || last[4] < '0' || last[4] > '9'))
+ continue;
+ arg3 = argument_new(xasprintf("-l%*.*s", (int)len,
+ (int)len, next));
+ next = strrchr(arg->val, '/');
+ len = next - arg->val;
+ argument_update(arg, xasprintf("-L%*.*s", (int)len,
+ (int)len, arg->val));
+ TAILQ_INSERT_AFTER(args, arg, arg3, link);
+ continue;
+ }
+ if (arg->val[0] != '-')
+ continue;
+ if (strcmp(arg->val, "-I") == 0 ||
+ strcmp(arg->val, "-D") == 0 ||
+ strcmp(arg->val, "-L") == 0) {
+ if (arg2 == NULL || arg2->val[0] == '-')
+ errx(255, "Missing argument for %s", arg->val);
+ argument_update(arg, concat(arg->val, arg2->val));
+ argument_unlink(args, &arg2);
+ continue;
+ }
+ if (strcmp(arg->val, "-Wl,-L") == 0) {
+ if (arg2 == NULL || strncmp(arg2->val, "-Wl,", 4))
+ errx(255, "Missing argument for %s", arg->val);
+ argument_update(arg, concat("-L", arg2->val + 4));
+ argument_unlink(args, &arg2);
+ continue;
+ }
+ if (strcmp(arg->val, "-Wl,-rpath-link") == 0) {
+ if (arg2 == NULL || strncmp(arg2->val, "-Wl,", 4))
+ errx(255, "Missing argument for %s", arg->val);
+ normalise_path_list(args, arg, "-Wl,-rpath-link,",
+ arg2->val + 4, 0);
+ argument_unlink(args, &arg);
+ argument_unlink(args, &arg2);
+ continue;
+ }
+ if (strcmp(arg->val, "-R") == 0) {
+ if (arg2 == NULL || arg2->val[0] == '-')
+ errx(255, "Missing argument for %s", arg->val);
+ normalise_path_list(args, arg, "-Wl,-rpath,",
+ arg2->val, 1);
+ argument_unlink(args, &arg);
+ argument_unlink(args, &arg2);
+ continue;
+ }
+ if (strcmp(arg->val, "-Wl,-R") == 0 ||
+ strcmp(arg->val, "-Wl,-rpath") == 0 ||
+ strcmp(arg->val, "-Wl,--rpath") == 0) {
+ if (arg2 == NULL || strncmp(arg2->val, "-Wl,", 4))
+ errx(255, "Missing argument for %s", arg->val);
+ normalise_path_list(args, arg, "-Wl,-rpath,",
+ arg2->val + 4, 1);
+ argument_unlink(args, &arg);
+ argument_unlink(args, &arg2);
+ continue;
+ }
+ if (strncmp(arg->val, "-Wl,-R", 6) == 0) {
+ normalise_path_list(args, arg, "-Wl,-rpath,",
+ arg->val + 6, 1);
+ argument_unlink(args, &arg);
+ continue;
+ }
+ if (strncmp(arg->val, "-R", 2) == 0) {
+ normalise_path_list(args, arg, "-Wl,-rpath,",
+ arg->val + 2, 1);
+ argument_unlink(args, &arg);
+ continue;
+ }
+ if (strncmp(arg->val, "-Wl,-rpath,", 10) == 0) {
+ normalise_path_list(args, arg, "-Wl,-rpath,",
+ arg->val + 10, 1);
+ argument_unlink(args, &arg);
+ continue;
+ }
+ }
+}
diff --git a/pkgtools/cwrappers/files/bin/normalise-ld.c b/pkgtools/cwrappers/files/bin/normalise-ld.c
new file mode 100644
index 00000000000..fbb6617e2d2
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/normalise-ld.c
@@ -0,0 +1,68 @@
+/* $NetBSD: normalise-ld.c,v 1.1 2014/09/17 12:40:56 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2009 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+
+#include <err.h>
+#include <stdlib.h>
+#include <string.h>
+#include "common.h"
+
+void
+normalise_ld(struct arglist *args)
+{
+ struct argument *arg, *arg2, *arg3;
+
+ TAILQ_FOREACH_SAFE(arg, args, link, arg2) {
+ if (arg->val[0] != '-')
+ continue;
+ if (strncmp(arg->val, "-Wl,", 4) == 0)
+ argument_update(arg, xstrdup(arg->val + 4));
+ if (strcmp(arg->val, "-L") == 0) {
+ if (arg2 == NULL || arg2->val[0] == '-')
+ errx(255, "Missing argument for %s", arg->val);
+ argument_update(arg, concat(arg->val, arg2->val));
+ continue;
+ }
+ if (strcmp(arg->val, "-R") == 0 ||
+ strcmp(arg->val, "--rpath") == 0) {
+ if (arg2 == NULL || arg2->val[0] == '-')
+ errx(255, "Missing argument for %s", arg->val);
+ argument_update(arg, xstrdup("-rpath"));
+ continue;
+ }
+ if (strncmp(arg->val, "-R", 2) == 0) {
+ argument_update(arg, xstrdup(arg->val + 2));
+ arg3 = argument_copy("-rpath");
+ TAILQ_INSERT_BEFORE(arg, arg3, link);
+ continue;
+ }
+ }
+}
diff --git a/pkgtools/cwrappers/files/bin/reorder-cc.c b/pkgtools/cwrappers/files/bin/reorder-cc.c
new file mode 100644
index 00000000000..a608d9b2b76
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/reorder-cc.c
@@ -0,0 +1,108 @@
+/* $NetBSD: reorder-cc.c,v 1.1 2014/09/17 12:40:56 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2009 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <err.h>
+#include <stdlib.h>
+#include <string.h>
+#include "common.h"
+
+struct reorder_rule {
+ TAILQ_ENTRY(reorder_rule) link;
+ char *lib;
+ char *lib2;
+};
+
+static TAILQ_HEAD(, reorder_rule) reorder_rules =
+ TAILQ_HEAD_INITIALIZER(reorder_rules);
+
+void
+register_reorder(const char *rule)
+{
+ struct reorder_rule *r;
+ const char *orig_rule = rule;
+ size_t len;
+
+ if (strncmp(rule, "l:", 2))
+ goto failed;
+ rule += 2;
+
+ r = xmalloc(sizeof(*r));
+
+ len = strspn(rule, library_name_chars);
+ if (len == 0)
+ goto failed;
+ r->lib = concat2("-l", rule, len);
+ rule +=len;
+
+ if (*rule != ':')
+ goto failed;
+ ++rule;
+
+ len = strspn(rule, library_name_chars);
+ if (len == 0 || rule[len] != '\0')
+ goto failed;
+ r->lib2 = concat2("-l", rule, len);
+
+ TAILQ_INSERT_TAIL(&reorder_rules, r, link);
+
+ return;
+
+failed:
+ errx(255, "Invalid reorder rule: %s", orig_rule);
+}
+
+void
+reorder_cc(struct arglist *args)
+{
+ struct reorder_rule *rule;
+ struct argument *arg, *arg2, *arg3;
+ struct arglist matches;
+
+ TAILQ_FOREACH(rule, &reorder_rules, link) {
+ TAILQ_INIT(&matches);
+
+ TAILQ_FOREACH(arg, args, link) {
+ if (strcmp(arg->val, rule->lib2) == 0)
+ break;
+ if (strcmp(arg->val, rule->lib) == 0)
+ TAILQ_INSERT_TAIL(&matches, arg, tmp_link);
+ }
+ if (arg == NULL || (arg3 = TAILQ_FIRST(&matches)) == NULL)
+ continue;
+
+ TAILQ_REMOVE(args, arg3, link);
+ TAILQ_INSERT_AFTER(args, arg, arg3, link);
+
+ TAILQ_REMOVE(&matches, arg3, tmp_link);
+ TAILQ_FOREACH_SAFE(arg, &matches, tmp_link, arg2)
+ argument_unlink(args, &arg);
+ }
+}
diff --git a/pkgtools/cwrappers/files/bin/rules2src.awk b/pkgtools/cwrappers/files/bin/rules2src.awk
new file mode 100755
index 00000000000..a049cce8a03
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/rules2src.awk
@@ -0,0 +1,94 @@
+#!/usr/bin/awk -f
+BEGIN {
+ cur_fixed = 0
+ cur_variable = 0
+}
+
+/^#/ { next }
+/^[[:space:]]*$/ { next }
+{
+ if ($2 == "") {
+ f = "transform_pass"
+ a = "NULL"
+ if (NF > 1) {
+ print "Too many fields for pass rule"
+ exit 1
+ }
+ } else if ($2 == "==>") {
+ f = "transform_replace"
+ a = "\"" $3 "\""
+ if (a == "") {
+ print "Missing argument in line ", FNR
+ exit 1
+ }
+ if (NF > 3) {
+ print "Too many fields for replace rule"
+ exit 1
+ }
+ } else if ($2 == "==!") {
+ f = "transform_pass_with_warning"
+ a = "NULL"
+ if (NF > 2) {
+ print "Too many fields for warning rule"
+ exit 1
+ }
+ } else if ($2 == "==|") {
+ f = "transform_discard"
+ a = "NULL"
+ if (NF > 2) {
+ print "Too many fields for discard rule"
+ exit 1
+ }
+ } else {
+ print "Unsupported transformation type"
+ exit 1
+ }
+
+ if ($1 ~ /\*$/) {
+ $1 = substr($1, 1, length($1) - 1)
+ variable_transforms[cur_variable++] = \
+ sprintf("{ \"%s\", %d, %s, %s }", $1, length($1), f, a)
+ } else {
+ fixed_transforms[cur_fixed] = \
+ sprintf("{ \"%s\", %d, %s, %s }", $1, length($1), f, a)
+ fixed_keys[cur_fixed++] = $1
+ }
+}
+
+END {
+ print ARGV[1]
+
+ ruleset = ARGV[1]
+ fname = "transform_cc_fixed"
+ output_c1 = ruleset "-fixed1.c"
+ output_c2 = ruleset "-fixed2.c"
+ output_c = ruleset "-fixed.c"
+ output_map = ruleset "-fixed.map"
+ nbperf = sprintf("nbperf -s -n %s -a chm -o %s -m %s",
+ fname, output_c1, output_map)
+ for (i = 0; i < cur_fixed; ++i)
+ print fixed_keys[i] | nbperf
+ close(nbperf)
+ for (i = 0; i < cur_fixed; ++i) {
+ getline out < output_map
+ fixed_order[out] = i
+ }
+ close(output_map)
+
+ print "" > output_c2
+ print "static struct transformation fixed_transforms[] = {" > output_c2
+ for (i = 0; i < cur_fixed; ++i) {
+ j = fixed_order[i]
+ print "\t" fixed_transforms[j] "," > output_c2
+ }
+ print "};" > output_c2
+ print "" > output_c2
+ print "static struct transformation var_transforms[] = {" > output_c2
+ for (i = 0; i < cur_variable; ++i) {
+ print "\t" variable_transforms[i] "," > output_c2
+ }
+ print "\t{ NULL, 0, NULL, NULL }," > output_c2
+ print "};" > output_c2
+ close(output_c2)
+ system(sprintf("cat %s %s > %s", output_c1, output_c2, output))
+}
diff --git a/pkgtools/cwrappers/files/bin/shlibtool-wrapper.c b/pkgtools/cwrappers/files/bin/shlibtool-wrapper.c
new file mode 100644
index 00000000000..db4c3df4565
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/shlibtool-wrapper.c
@@ -0,0 +1,4 @@
+#define WRAPPER_SHLIBTOOL
+#define WRAPPER_NAME "shlibtool"
+
+#include "base-wrapper.c"
diff --git a/pkgtools/cwrappers/files/bin/transform-cc.c b/pkgtools/cwrappers/files/bin/transform-cc.c
new file mode 100644
index 00000000000..3d7cd027dcf
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/transform-cc.c
@@ -0,0 +1,112 @@
+/* $NetBSD: transform-cc.c,v 1.1 2014/09/17 12:40:56 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2009 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <err.h>
+#include <string.h>
+#include "common.h"
+
+struct transformation {
+ const char *pattern;
+ size_t len;
+ struct argument *(*transform)(struct arglist *, struct argument *,
+ const char *);
+ const char *opt;
+};
+
+static struct argument *transform_pass(struct arglist *,
+ struct argument *, const char *);
+static struct argument *transform_pass_with_warning(struct arglist *,
+ struct argument *, const char *);
+static struct argument *transform_discard(struct arglist *,
+ struct argument *, const char *);
+static struct argument *transform_replace(struct arglist *,
+ struct argument *, const char *);
+
+#include "transform-gcc.c"
+
+static struct argument *
+transform_pass(struct arglist *args, struct argument *arg, const char *opt)
+{
+ return TAILQ_NEXT(arg, link);
+}
+
+static struct argument *
+transform_pass_with_warning(struct arglist *args, struct argument *arg,
+ const char *opt)
+{
+ warnx("Unsupported option: %s", arg->val);
+
+ return TAILQ_NEXT(arg, link);
+}
+
+static struct argument *
+transform_discard(struct arglist *args, struct argument *arg, const char *opt)
+{
+ argument_unlink(args, &arg);
+ return arg;
+}
+
+static struct argument *
+transform_replace(struct arglist *args, struct argument *arg, const char *opt)
+{
+ argument_update(arg, xstrdup(opt));
+
+ return TAILQ_NEXT(arg, link);
+}
+
+void
+transform_cc(struct arglist *args)
+{
+ struct argument *arg, *arg2;
+ size_t len;
+ struct transformation *t;
+
+ TAILQ_FOREACH_SAFE(arg, args, link, arg2) {
+ if (arg->val[0] != '-')
+ continue;
+
+ len = strlen(arg->val);
+ t = fixed_transforms + transform_cc_fixed(arg->val, len);
+ if (t->len == len && strcmp(t->pattern, arg->val) == 0) {
+ arg2 = (*t->transform)(args, arg, t->opt);
+ continue;
+ }
+ for (t = var_transforms; t->pattern != NULL; ++t) {
+ if (t->len > len &&
+ strncmp(t->pattern, arg->val, t->len) == 0)
+ break;
+ }
+ if (t->pattern != NULL) {
+ arg2 = (*t->transform)(args, arg, t->opt);
+ continue;
+ }
+ }
+}
diff --git a/pkgtools/cwrappers/files/bin/transform-gcc-rules b/pkgtools/cwrappers/files/bin/transform-gcc-rules
new file mode 100644
index 00000000000..1397a9f7abd
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/transform-gcc-rules
@@ -0,0 +1,172 @@
+# $NetBSD: transform-gcc-rules,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+# Copyright (c) 2009 Joerg Sonnenberger <joerg@NetBSD.org>.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# Lines starting with # are comments.
+# Single word options are options to pass.
+# "foo ==|" means that option "foo" should be discarded.
+# "foo ==!" means that option "foo" should be passed, but give a warning.
+# "foo ==> bar" means that "foo" should be translated into "bar".
+#
+# Common compiler options
+-D*
+-E
+-I*
+-L*
+-O
+-O0
+-O1
+-U*
+-c
+-g
+-o
+-s
+# Used by GNU configure scripts
+-V
+-v
+--version
+# GCC extensions
+-
+-dynamic
+-export-dynamic
+-falign-functions=*
+-falign-loops=*
+-falign-jumps=*
+-fexpensive-options
+-ffast-math
+-ffloat-store
+-finline-functions
+-fno-builtin
+-fno-builtin-*
+-fno-common
+-fno-implicit-templates
+-fno-inline-functions
+-fno-strict-aliasing
+-fomit-frame-pointer
+-fPIC
+-fpic
+-fpcc-struct-return
+-freg-struct-return
+-fsigned-char
+-funroll-loops
+-funsigned-char
+-ggdb
+-M
+-MD
+-MF
+-MM
+-MMD
+-MP
+-MT
+-m32
+-m64
+-mabi=*
+-march=*
+-mcpu=*
+-mieee-fp
+-O2
+-O3
+-Os
+-pedantic
+-pedantic-errors
+-pipe
+-pthread
+-print-prog-name=*
+-print-search-dirs
+-S
+-shared
+-static
+-std=c99
+-std=gnu89
+-std=gnu99
+-W
+-WL,*
+-WS,*
+-Wall
+-Wc,*
+-Wcast-align
+-Wcast-qual
+-Wchar-subscripts
+-Wconversion
+-Wextra
+-Werror
+-Werror-implicit-function-declaration
+-Wformat=0
+-Wformat=1
+-Wformat=2
+-Wl,*
+-Wmissing-declarations
+-Wmissing-format-attribute
+-Wmissing-prototypes
+-Wnested-externs
+-Wno-error
+-Wno-format-y2k
+-Wno-format-zero-length
+-Wno-implicit-int
+-Wno-import
+-Wno-inline
+-Wno-long-long
+-Wno-sign-compare
+-Wno-traditional
+-Wno-undef
+-Wno-uninitialized
+-Wno-unused
+-Wno-unused-parameter
+-Wno-write-strings
+-Wparentheses
+-Wpointer-arith
+-Wreturn-type
+-Wshadow
+-Wsign-compare
+-Wstrict-aliasing
+-Wstrict-prototypes
+-Wswitch
+-Wunused
+-Wundef
+-Wwrite-strings
+# Do not suppress warnings
+-w ==|
+# Options specific to g++
+-fexceptions
+-fmessage-length=*
+-fno-check-new
+-fno-exceptions
+-fno-rtti
+-ftemplate-depth=*
+-Wno-non-virtual-dtor
+# Options specific to Objective C
+-fconstant-string-class=*
+-fgnu-runtime
+# Compatibility with other compilers
+-Kpic ==> -fPIC
+-kpic ==> -fPIC
+-KPIC ==> -fPIC
+-kPIC ==> -fPIC
+-mt ==> -threads
+-64 ==> -m64
+-* ==!
diff --git a/pkgtools/cwrappers/files/bin/transform-gcc.c b/pkgtools/cwrappers/files/bin/transform-gcc.c
new file mode 100644
index 00000000000..b97c5d64a6e
--- /dev/null
+++ b/pkgtools/cwrappers/files/bin/transform-gcc.c
@@ -0,0 +1,172 @@
+#include <stdlib.h>
+
+static uint32_t
+transform_cc_fixed(const void * __restrict key, size_t keylen)
+{
+ static const uint8_t g[221] = {
+ 0x00, 0x6b, 0x00, 0x3d, 0x12, 0x21, 0x67, 0x16, 0x0d, 0x0b,
+ 0x00, 0x1e, 0x00, 0x45, 0x0a, 0x0b, 0x00, 0x52, 0x00, 0x00,
+ 0x00, 0x4a, 0x00, 0x2a, 0x00, 0x00, 0x5c, 0x2a, 0x45, 0x68,
+ 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x2a,
+ 0x12, 0x57, 0x00, 0x43, 0x2f, 0x29, 0x00, 0x00, 0x00, 0x38,
+ 0x67, 0x00, 0x00, 0x00, 0x00, 0x36, 0x50, 0x04, 0x00, 0x08,
+ 0x32, 0x52, 0x00, 0x00, 0x3e, 0x67, 0x1f, 0x45, 0x00, 0x0f,
+ 0x5b, 0x00, 0x00, 0x00, 0x00, 0x50, 0x58, 0x62, 0x00, 0x00,
+ 0x17, 0x6b, 0x29, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x46, 0x00,
+ 0x69, 0x00, 0x47, 0x19, 0x27, 0x00, 0x00, 0x00, 0x00, 0x2e,
+ 0x00, 0x00, 0x2e, 0x00, 0x00, 0x39, 0x19, 0x68, 0x64, 0x00,
+ 0x36, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x40, 0x00, 0x06, 0x43,
+ 0x00, 0x00, 0x00, 0x6b, 0x00, 0x5f, 0x3f, 0x3c, 0x00, 0x51,
+ 0x00, 0x00, 0x00, 0x39, 0x00, 0x04, 0x00, 0x41, 0x3e, 0x5e,
+ 0x00, 0x00, 0x00, 0x56, 0x4b, 0x00, 0x17, 0x00, 0x00, 0x00,
+ 0x47, 0x40, 0x00, 0x00, 0x00, 0x11, 0x0e, 0x00, 0x59, 0x33,
+ 0x3f, 0x52, 0x00, 0x18, 0x42, 0x14, 0x00, 0x00, 0x00, 0x00,
+ 0x18, 0x00, 0x00, 0x00, 0x68, 0x6b, 0x00, 0x00, 0x00, 0x2c,
+ 0x1a, 0x00, 0x12, 0x00, 0x31, 0x00, 0x00, 0x16, 0x4a, 0x00,
+ 0x00, 0x1a, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x3a, 0x00,
+ 0x00, 0x00, 0x54, 0x4b, 0x00, 0x4c, 0x53, 0x1c, 0x00, 0x00,
+ 0x00, 0x6d, 0x00, 0x00, 0x6b, 0x24, 0x00, 0x00, 0x22, 0x00,
+ 0x00,
+ };
+ uint32_t h[3];
+
+ mi_vector_hash(key, keylen, 0xcee3bdd8U, h);
+ return (g[h[0] % 221] + g[h[1] % 221]) % 110;
+}
+
+static struct transformation fixed_transforms[] = {
+ { "-E", 2, transform_pass, NULL },
+ { "-O", 2, transform_pass, NULL },
+ { "-O0", 3, transform_pass, NULL },
+ { "-O1", 3, transform_pass, NULL },
+ { "-c", 2, transform_pass, NULL },
+ { "-g", 2, transform_pass, NULL },
+ { "-o", 2, transform_pass, NULL },
+ { "-s", 2, transform_pass, NULL },
+ { "-V", 2, transform_pass, NULL },
+ { "-v", 2, transform_pass, NULL },
+ { "--version", 9, transform_pass, NULL },
+ { "-", 1, transform_pass, NULL },
+ { "-dynamic", 8, transform_pass, NULL },
+ { "-export-dynamic", 15, transform_pass, NULL },
+ { "-fexpensive-options", 19, transform_pass, NULL },
+ { "-ffast-math", 11, transform_pass, NULL },
+ { "-ffloat-store", 13, transform_pass, NULL },
+ { "-finline-functions", 18, transform_pass, NULL },
+ { "-fno-builtin", 12, transform_pass, NULL },
+ { "-fno-common", 11, transform_pass, NULL },
+ { "-fno-implicit-templates", 23, transform_pass, NULL },
+ { "-fno-inline-functions", 21, transform_pass, NULL },
+ { "-fno-strict-aliasing", 20, transform_pass, NULL },
+ { "-fomit-frame-pointer", 20, transform_pass, NULL },
+ { "-fPIC", 5, transform_pass, NULL },
+ { "-fpic", 5, transform_pass, NULL },
+ { "-fpcc-struct-return", 19, transform_pass, NULL },
+ { "-freg-struct-return", 19, transform_pass, NULL },
+ { "-fsigned-char", 13, transform_pass, NULL },
+ { "-funroll-loops", 14, transform_pass, NULL },
+ { "-funsigned-char", 15, transform_pass, NULL },
+ { "-ggdb", 5, transform_pass, NULL },
+ { "-M", 2, transform_pass, NULL },
+ { "-MD", 3, transform_pass, NULL },
+ { "-MF", 3, transform_pass, NULL },
+ { "-MM", 3, transform_pass, NULL },
+ { "-MMD", 4, transform_pass, NULL },
+ { "-MP", 3, transform_pass, NULL },
+ { "-MT", 3, transform_pass, NULL },
+ { "-m32", 4, transform_pass, NULL },
+ { "-m64", 4, transform_pass, NULL },
+ { "-mieee-fp", 9, transform_pass, NULL },
+ { "-O2", 3, transform_pass, NULL },
+ { "-O3", 3, transform_pass, NULL },
+ { "-Os", 3, transform_pass, NULL },
+ { "-pedantic", 9, transform_pass, NULL },
+ { "-pedantic-errors", 16, transform_pass, NULL },
+ { "-pipe", 5, transform_pass, NULL },
+ { "-pthread", 8, transform_pass, NULL },
+ { "-print-search-dirs", 18, transform_pass, NULL },
+ { "-S", 2, transform_pass, NULL },
+ { "-shared", 7, transform_pass, NULL },
+ { "-static", 7, transform_pass, NULL },
+ { "-std=c99", 8, transform_pass, NULL },
+ { "-std=gnu89", 10, transform_pass, NULL },
+ { "-std=gnu99", 10, transform_pass, NULL },
+ { "-W", 2, transform_pass, NULL },
+ { "-Wall", 5, transform_pass, NULL },
+ { "-Wcast-align", 12, transform_pass, NULL },
+ { "-Wcast-qual", 11, transform_pass, NULL },
+ { "-Wchar-subscripts", 17, transform_pass, NULL },
+ { "-Wconversion", 12, transform_pass, NULL },
+ { "-Wextra", 7, transform_pass, NULL },
+ { "-Werror", 7, transform_pass, NULL },
+ { "-Werror-implicit-function-declaration", 37, transform_pass, NULL },
+ { "-Wformat=0", 10, transform_pass, NULL },
+ { "-Wformat=1", 10, transform_pass, NULL },
+ { "-Wformat=2", 10, transform_pass, NULL },
+ { "-Wmissing-declarations", 22, transform_pass, NULL },
+ { "-Wmissing-format-attribute", 26, transform_pass, NULL },
+ { "-Wmissing-prototypes", 20, transform_pass, NULL },
+ { "-Wnested-externs", 16, transform_pass, NULL },
+ { "-Wno-error", 10, transform_pass, NULL },
+ { "-Wno-format-y2k", 15, transform_pass, NULL },
+ { "-Wno-format-zero-length", 23, transform_pass, NULL },
+ { "-Wno-implicit-int", 17, transform_pass, NULL },
+ { "-Wno-import", 11, transform_pass, NULL },
+ { "-Wno-inline", 11, transform_pass, NULL },
+ { "-Wno-long-long", 14, transform_pass, NULL },
+ { "-Wno-sign-compare", 17, transform_pass, NULL },
+ { "-Wno-traditional", 16, transform_pass, NULL },
+ { "-Wno-undef", 10, transform_pass, NULL },
+ { "-Wno-uninitialized", 18, transform_pass, NULL },
+ { "-Wno-unused", 11, transform_pass, NULL },
+ { "-Wno-unused-parameter", 21, transform_pass, NULL },
+ { "-Wno-write-strings", 18, transform_pass, NULL },
+ { "-Wparentheses", 13, transform_pass, NULL },
+ { "-Wpointer-arith", 15, transform_pass, NULL },
+ { "-Wreturn-type", 13, transform_pass, NULL },
+ { "-Wshadow", 8, transform_pass, NULL },
+ { "-Wsign-compare", 14, transform_pass, NULL },
+ { "-Wstrict-aliasing", 17, transform_pass, NULL },
+ { "-Wstrict-prototypes", 19, transform_pass, NULL },
+ { "-Wswitch", 8, transform_pass, NULL },
+ { "-Wunused", 8, transform_pass, NULL },
+ { "-Wundef", 7, transform_pass, NULL },
+ { "-Wwrite-strings", 15, transform_pass, NULL },
+ { "-w", 2, transform_discard, NULL },
+ { "-fexceptions", 12, transform_pass, NULL },
+ { "-fno-check-new", 14, transform_pass, NULL },
+ { "-fno-exceptions", 15, transform_pass, NULL },
+ { "-fno-rtti", 9, transform_pass, NULL },
+ { "-Wno-non-virtual-dtor", 21, transform_pass, NULL },
+ { "-fgnu-runtime", 13, transform_pass, NULL },
+ { "-Kpic", 5, transform_replace, "-fPIC" },
+ { "-kpic", 5, transform_replace, "-fPIC" },
+ { "-KPIC", 5, transform_replace, "-fPIC" },
+ { "-kPIC", 5, transform_replace, "-fPIC" },
+ { "-mt", 3, transform_replace, "-threads" },
+ { "-64", 3, transform_replace, "-m64" },
+};
+
+static struct transformation var_transforms[] = {
+ { "-D", 2, transform_pass, NULL },
+ { "-I", 2, transform_pass, NULL },
+ { "-L", 2, transform_pass, NULL },
+ { "-U", 2, transform_pass, NULL },
+ { "-falign-functions=", 18, transform_pass, NULL },
+ { "-falign-loops=", 14, transform_pass, NULL },
+ { "-falign-jumps=", 14, transform_pass, NULL },
+ { "-fno-builtin-", 13, transform_pass, NULL },
+ { "-mabi=", 6, transform_pass, NULL },
+ { "-march=", 7, transform_pass, NULL },
+ { "-mcpu=", 6, transform_pass, NULL },
+ { "-print-prog-name=", 17, transform_pass, NULL },
+ { "-WL,", 4, transform_pass, NULL },
+ { "-WS,", 4, transform_pass, NULL },
+ { "-Wc,", 4, transform_pass, NULL },
+ { "-Wl,", 4, transform_pass, NULL },
+ { "-fmessage-length=", 17, transform_pass, NULL },
+ { "-ftemplate-depth=", 17, transform_pass, NULL },
+ { "-fconstant-string-class=", 24, transform_pass, NULL },
+ { "-", 1, transform_pass_with_warning, NULL },
+ { NULL, 0, NULL, NULL },
+};
diff --git a/pkgtools/cwrappers/files/doc/cleanup.txt b/pkgtools/cwrappers/files/doc/cleanup.txt
new file mode 100644
index 00000000000..3042006e16f
--- /dev/null
+++ b/pkgtools/cwrappers/files/doc/cleanup.txt
@@ -0,0 +1,16 @@
+$NetBSD: cleanup.txt,v 1.1 2014/09/17 12:40:56 joerg Exp $
+
+The second phase of wrapper processing for cc-ish wrappers is removal of
+broken or redundant arguments. This helps platforms with small argv
+limit. The cleanup phase is repeated after all other transformations
+are done.
+
+Transformations done in this phase:
+
+1. Remove rpath options with relative path. This is just a bug and they
+should never end up in the final binary. -Wl,-rpath-link is not dropped
+as it only affects the linker.
+
+2. Unify consecutive identical -l options.
+
+3. Drop duplicate -I, -L, -Wl,-rpath and -Wl,-rpath-link.
diff --git a/pkgtools/cwrappers/files/doc/configuration.txt b/pkgtools/cwrappers/files/doc/configuration.txt
new file mode 100644
index 00000000000..49f8b59fc61
--- /dev/null
+++ b/pkgtools/cwrappers/files/doc/configuration.txt
@@ -0,0 +1,28 @@
+$NetBSD: configuration.txt,v 1.1 2014/09/17 12:40:56 joerg Exp $
+
+The configuration of the wrapper framework depends on two variables.
+The environment variable WRAPPER_CONFIG_DIR points to a directory
+with one configuration file per wrapper.
+
+The configuration file consists of simple key=value pairs. It is
+case-sensitive and all spaces are considered part of the value.
+
+Lists of keys:
+
+worklog: Name of logfile to append to.
+
+exec: Name of the target command to exec(2).
+
+path: Override current value of the environmental variable PATH before
+calling the wrappee.
+
+reorder: Specify a reorder rule. See reorder.txt for the details.
+
+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.
+
+append: Append an option directly after logging the original command.
+The options are inserted in the order of the config file.
diff --git a/pkgtools/cwrappers/files/doc/fixup-libtool.txt b/pkgtools/cwrappers/files/doc/fixup-libtool.txt
new file mode 100644
index 00000000000..0e82df1734b
--- /dev/null
+++ b/pkgtools/cwrappers/files/doc/fixup-libtool.txt
@@ -0,0 +1 @@
+XXX libtool-fix-la
diff --git a/pkgtools/cwrappers/files/doc/generic-transform-ld.txt b/pkgtools/cwrappers/files/doc/generic-transform-ld.txt
new file mode 100644
index 00000000000..80a978c46d7
--- /dev/null
+++ b/pkgtools/cwrappers/files/doc/generic-transform-ld.txt
@@ -0,0 +1,6 @@
+Like generic-transform.txt with the following changes:
+
+1. No processing of -I.
+
+2. Instead of "-Wl,-rpath,foo" and "-Wl,-rpath-link,foo", "-rpath foo"
+and "-rpath-link foo" are used.
diff --git a/pkgtools/cwrappers/files/doc/generic-transform.txt b/pkgtools/cwrappers/files/doc/generic-transform.txt
new file mode 100644
index 00000000000..07a9eda632e
--- /dev/null
+++ b/pkgtools/cwrappers/files/doc/generic-transform.txt
@@ -0,0 +1,38 @@
+$NetBSD: generic-transform.txt,v 1.1 2014/09/17 12:40:56 joerg Exp $
+
+The third phase of the wrapper processing is the general transformation
+phase. This phase is the core of the wrapper framework and implements
+the visibility transformations.
+
+Transformations done in this phase:
+
+1. All opt:src:dst and rm:src rules are matched against the argument. If
+there is a match and it was a rm:src rule or a opt:src: rule without
+dst, it is removed. Otherwise it is replaced with dst. The order in which
+rules are matched is unspecified.
+
+2. -I, -Wl,-rpath and -L options with a relative path are skipped.
+
+3. For the remaining -I, -Wl,-rpath and -L options a corresponding
+transform rule (transform=I:src:dst, transform=R:src:dst,
+transform=L:src:dst) rule is searched for, so that the path is equal to
+or below src. If this is a -Wl,-rpath option and the path ends in /.libs,
+it is assume be to handled by libtool internally and implicitly allowed.
+If no such rule is found or dst is empty, the argument is dropped.
+Otherwise the src part of the path name is replaced with dst.
+No further transformation is done for this argument in this phase.
+
+4. libtool/shlibtool wrapper only:
+For -l options search for the matching libtool archive, e.g. for -ldst
+look for libdst.la in the include search path.
+
+5. For -l options a corresponding transform rule
+(transform=l:src:dst[:dst2...]) is searched for. If such a rule exists
+(e.g. the option is -lsrc), it will be replaced with -ldst [-ldst2...].
+No further transformation is done for this argument in this phase.
+
+6. libtool/shlibtool wrapper only:
+For absolute path names as options search for a corresponding
+transform rule (transform=P:src:dst) to translate libfoo.a and libfoo.la
+below the directory src into a path with src replaced by dst.
+No further transformation is done for this argument in this phase.
diff --git a/pkgtools/cwrappers/files/doc/normalise-ld.txt b/pkgtools/cwrappers/files/doc/normalise-ld.txt
new file mode 100644
index 00000000000..875071c8323
--- /dev/null
+++ b/pkgtools/cwrappers/files/doc/normalise-ld.txt
@@ -0,0 +1,21 @@
+$NetBSD: normalise-ld.txt,v 1.1 2014/09/17 12:40:56 joerg Exp $
+
+The first phase of wrapper processing for ld-ish wrappers is argument
+normalisation. This simplifies processing in latter steps.
+
+Transformations done in this phase:
+
+1. Empty arguments are suppressed.
+
+2. Arguments of the "-Wl,foo" are converted to "foo".
+
+3. Arguments of the form "-L foo" are converted to the single argument
+form "-Lfoo".
+
+7. Arguments of the form "-Rfoo", "-R foo" or "--rpath foo" are converted
+to the form "-rpath foo".
+
+8. Full path names that end up in
+"/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.
diff --git a/pkgtools/cwrappers/files/doc/normalise.txt b/pkgtools/cwrappers/files/doc/normalise.txt
new file mode 100644
index 00000000000..ac999588ad3
--- /dev/null
+++ b/pkgtools/cwrappers/files/doc/normalise.txt
@@ -0,0 +1,32 @@
+$NetBSD: normalise.txt,v 1.1 2014/09/17 12:40:56 joerg Exp $
+
+The first phase of wrapper processing for cc-ish wrappers is argument
+normalisation. This simplifies processing in latter steps.
+
+Transformations done in this phase:
+
+1. Empty arguments are suppressed.
+
+2. Arguments of the form "-Xlinker -Wl,foo" are converted to "-Wl,foo".
+All other arguments of the form "-Xlinker foo" are converted to "-Wl,foo".
+
+3. Arguments of the form "-Wl,*,*" are split into separate -Wl options.
+
+4. Arguments of the form "-I foo", "-D foo", "-L foo" or
+"-Wl,-L -Wl,foo" are converted to the single argument form "-Ifoo",
+"-Dfoo", "-Lfoo" and "-Wl,-Lfoo" respectively.
+
+5. Arguments of the form "-Wl,-L,foo" are converted to "-Lfoo".
+
+6. Arguments of the form "-Wl,-rpath-link -Wl,foo" are converted to
+the single argument form "-Wl,-rpath-link,foo".
+
+7. Arguments of the form "-Rfoo", "-R foo", "-Wl,-Rfoo", "-Wl,-R -Wl,foo",
+"-Wl,-rpath -Wl,foo" or "--Wl,-rpath -Wl,foo" are converted to the single
+canonical argument form "-Wl,-rpath,foo". All -Wl,-rpath options with relative
+path (e.g. not starting with /) are dropped.
+
+8. Full path names that end up in
+"/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.
diff --git a/pkgtools/cwrappers/files/doc/reorder.txt b/pkgtools/cwrappers/files/doc/reorder.txt
new file mode 100644
index 00000000000..f9a56038f30
--- /dev/null
+++ b/pkgtools/cwrappers/files/doc/reorder.txt
@@ -0,0 +1,13 @@
+$NetBSD: reorder.txt,v 1.1 2014/09/17 12:40:56 joerg Exp $
+
+The fourth phase of the wrapper processing can reorder libraries
+according to platform specific dependencies. Each rule has the
+form "l:lib1:lib2". It ensures that all -llib1 options before -llib2
+are moved directly after the latter.
+
+The rules are processed in order to all arguments at once. Cycle
+reorder rules effectively result in the last rule winning.
+
+The reorder rules may interact badly with -Wl,-Bdynamic and
+-Wl,-Bstatic. If this options are in use, the correct ordering
+should be used without depending on the wrapper.
diff --git a/pkgtools/cwrappers/files/doc/transform.txt b/pkgtools/cwrappers/files/doc/transform.txt
new file mode 100644
index 00000000000..0c09afb2c71
--- /dev/null
+++ b/pkgtools/cwrappers/files/doc/transform.txt
@@ -0,0 +1,13 @@
+$NetBSD: transform.txt,v 1.1 2014/09/17 12:40:56 joerg Exp $
+
+The fifth phase of the wrapper processing is the platform
+transformation support. The aim here is to translate GCC
+options (and some other compiler frontends) into the options
+of the target compiler.
+
+Translations for GCC are:
+- Drop "-w"
+- Translate "-mt" to "-threads", "-64" to "-m64" and
+ "-Kpic", "-kpic", "-KPIC" and "-kPIC" to "-fPIC".
+
+It can warn about options during translation as well.
diff --git a/pkgtools/cwrappers/files/doc/unimplemented.txt b/pkgtools/cwrappers/files/doc/unimplemented.txt
new file mode 100644
index 00000000000..e1aca412bd2
--- /dev/null
+++ b/pkgtools/cwrappers/files/doc/unimplemented.txt
@@ -0,0 +1,44 @@
+Mode detection:
+
+-E preprocess-only
+-S assembly-only
+-c compile-only
+
+--> Consider to drop the various linker options
+
+Cleanup:
+
+- Remove redundant -D options. Should keep -U in mind.
+
+Library path resorting:
+
+- Reorder -l to be after all -L options, duplicate -Wl,-dynamic / -Wl,-static
+ options in the library list. Should this also take -Wl,-rpath-link into
+ account?
+
+Scan:
+
+- Append extra_args only if -v is not used
+
+Scan for ld:
+
+- Strip -Wl,
+- Silently drop -pthread
+
+Platform specific processing:
+
+- All platforms but Darwin have _USE_RPATH=yes. Shouldn't Darwin just
+ filter out the rpath rules in a platform specific transformation phase?
+
+Transform:
+
+- opt:foo:bar: Replace all options matching foo with bar. foo might be
+ fnmatch expression. Earlier than other transformations. If bar is empty,
+ option is dropped.
+
+Libtool:
+
+- Drop -L, -l, -Wl,* if not in link mode
+ -> see first point
+
+- pkgviews support
diff --git a/pkgtools/cwrappers/files/test/Makefile b/pkgtools/cwrappers/files/test/Makefile
new file mode 100644
index 00000000000..4b4777fe538
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/Makefile
@@ -0,0 +1,29 @@
+# $NetBSD: Makefile,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+
+.SUFFIXES: .sh .atf
+.sh.atf: setup_common.sh
+ atf-compile -o ${.TARGET} ${.IMPSRC}
+
+TESTS!= echo test-*.sh
+TESTFILES= ${TESTS:S/.sh$/.atf/g}
+ALLFILES= Atffile ${TESTFILES}
+
+ATF_REPORT?= atf-report
+
+all: ${ALLFILES}
+
+test: all
+ atf-run | ${ATF_REPORT}
+
+clean:
+ rm -f ${ALLFILES}
+
+Atffile:
+ @echo 'Content-Type: application/X-atf-atffile; version="1"' > Atffile
+ @echo >> Atffile
+ @echo 'prop: test-suite = "regress-buildlink-transform"' >> Atffile
+ @echo >> Atffile
+. for i in ${TESTFILES}
+ @echo "tp: ${i}" >> Atffile
+. endfor
diff --git a/pkgtools/cwrappers/files/test/TODO b/pkgtools/cwrappers/files/test/TODO
new file mode 100644
index 00000000000..e3d5926705d
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/TODO
@@ -0,0 +1,5 @@
+* Set WRAPPER_CONFIG_DIR to a test location, then look at work.log.
+* Hook in these old GSoC pkgsrc/pkgtools/wrapper tests.
+* Convert them to atf-c-api(3).
+* Add more tests for the rules described in doc/{cleanup,normalise}.txt.
+* When implementing new behaviors, write accompanying tests -- ideally, first!
diff --git a/pkgtools/cwrappers/files/test/setup_common.sh b/pkgtools/cwrappers/files/test/setup_common.sh
new file mode 100644
index 00000000000..258da9460b8
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/setup_common.sh
@@ -0,0 +1,25 @@
+wrapper_test_setup() {
+ local _wrappee
+ _wrappee=$1; shift
+
+ # variables available to tests
+ WRAPPER="$(atf_get_srcdir)/../bin/${_wrappee}-wrapper"
+ WRAPPER_CONFIG_DIR=wrapperconfig; export WRAPPER_CONFIG_DIR
+ mkdir ${WRAPPER_CONFIG_DIR}
+ LOCALBASE=/local/base
+ BUILDLINK_DIR=/wrksrc/build/link
+ COMPILER_RPATH_FLAG="-Wl,-R" # or -L on Darwin, or...
+
+ # minimal config file for test purposes
+ cat > ${WRAPPER_CONFIG_DIR}/${_wrappee} << EOF
+worklog=/dev/null
+exec=echo
+transform=I:${LOCALBASE}:${BUILDLINK_DIR}
+EOF
+ # plus any requested transforms
+ while [ $# -gt 0 ]; do
+ echo "transform=$1" >> ${WRAPPER_CONFIG_DIR}/${_wrappee}
+ shift
+ done
+
+}
diff --git a/pkgtools/cwrappers/files/test/test-include_pkgdir.sh b/pkgtools/cwrappers/files/test/test-include_pkgdir.sh
new file mode 100644
index 00000000000..740ece7b033
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/test-include_pkgdir.sh
@@ -0,0 +1,45 @@
+# $NetBSD: test-include_pkgdir.sh,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+
+atf_test_case include_pkgdir
+include_pkgdir_head() {
+ atf_set 'descr' 'XXX autoconverted from include-pkgdir.mk'
+}
+include_pkgdir_body() {
+ wrapper_test_setup cc
+ input="-I${LOCALBASE}/include"
+ echo "-I${BUILDLINK_DIR}/include" > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_test_case include_pkgdir_slashdot
+include_pkgdir_slashdot_head() {
+ atf_set 'descr' 'Checks that trailing /. is elided from includes'
+}
+include_pkgdir_slashdot_body() {
+ wrapper_test_setup cc
+ input="-I${LOCALBASE}/include/."
+ echo "-I${BUILDLINK_DIR}/include" > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_test_case include_pkgsubdir
+include_pkgsubdir_head() {
+ atf_set 'descr' 'XXX autoconverted from include-pkgsubdir.mk'
+}
+include_pkgsubdir_body() {
+ wrapper_test_setup cc
+ input="-I${LOCALBASE}/include/krb5"
+ echo "-I${BUILDLINK_DIR}/include/krb5" > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_init_test_cases() {
+ . $(atf_get_srcdir)/setup_common.sh
+ atf_add_test_case include_pkgdir
+ atf_add_test_case include_pkgdir_slashdot
+ atf_add_test_case include_pkgsubdir
+}
diff --git a/pkgtools/cwrappers/files/test/test-include_usr_include.sh b/pkgtools/cwrappers/files/test/test-include_usr_include.sh
new file mode 100644
index 00000000000..4a11f9870e3
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/test-include_usr_include.sh
@@ -0,0 +1,45 @@
+# $NetBSD: test-include_usr_include.sh,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+
+atf_test_case include_usr_include
+include_usr_include_head() {
+ atf_set 'descr' 'XXX autoconverted from include-usr-include.mk'
+}
+include_usr_include_body() {
+ wrapper_test_setup cc
+ input="-I/usr/include"
+ echo > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_test_case include_usr_include_slashdot
+include_usr_include_slashdot_head() {
+ atf_set 'descr' 'XXX autoconverted from include-usr-include-slashdot.mk'
+}
+include_usr_include_slashdot_body() {
+ wrapper_test_setup cc
+ input="-I/usr/include/."
+ echo > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_test_case include_usr_include_subdir
+include_usr_include_subdir_head() {
+ atf_set 'descr' 'XXX autoconverted from include-usr-include-subdir.mk'
+}
+include_usr_include_subdir_body() {
+ wrapper_test_setup cc
+ input="-I/usr/include/krb5"
+ echo "-I/usr/include/krb5" > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_init_test_cases() {
+ . $(atf_get_srcdir)/setup_common.sh
+ atf_add_test_case include_usr_include
+ atf_add_test_case include_usr_include_slashdot
+ atf_add_test_case include_usr_include_subdir
+}
diff --git a/pkgtools/cwrappers/files/test/test-lib_expand.sh b/pkgtools/cwrappers/files/test/test-lib_expand.sh
new file mode 100644
index 00000000000..df20d59e69d
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/test-lib_expand.sh
@@ -0,0 +1,20 @@
+# $NetBSD: test-lib_expand.sh,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+
+atf_test_case lib_expand
+lib_expand_head() {
+ atf_set 'descr' 'Checks that one -llib can be expanded into several'
+}
+lib_expand_body() {
+ wrapper_test_setup cc \
+ l:readline:edit:termcap:m
+ input="-lreadline -lreadline"
+ echo "-ledit -ltermcap -lm" > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_init_test_cases() {
+ . $(atf_get_srcdir)/setup_common.sh
+ atf_add_test_case lib_expand
+}
diff --git a/pkgtools/cwrappers/files/test/test-libdir_pkgdir.sh b/pkgtools/cwrappers/files/test/test-libdir_pkgdir.sh
new file mode 100644
index 00000000000..c217ecccaec
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/test-libdir_pkgdir.sh
@@ -0,0 +1,45 @@
+# $NetBSD: test-libdir_pkgdir.sh,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+
+atf_test_case libdir_pkgdir
+libdir_pkgdir_head() {
+ atf_set 'descr' 'XXX autoconverted from libdir-pkgdir.mk'
+}
+libdir_pkgdir_body() {
+ wrapper_test_setup cc
+ input="-L${LOCALBASE}/lib"
+ echo "-L${BUILDLINK_DIR}/lib" > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_test_case libdir_pkgdir_slashdot
+libdir_pkgdir_slashdot_head() {
+ atf_set 'descr' 'XXX autoconverted from libdir-pkgdir-slashdot.mk'
+}
+libdir_pkgdir_slashdot_body() {
+ wrapper_test_setup cc
+ input="-L${LOCALBASE}/lib/."
+ echo "-L${BUILDLINK_DIR}/lib" > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_test_case libdir_pkgsubdir
+libdir_pkgsubdir_head() {
+ atf_set 'descr' 'XXX autoconverted from libdir-pkgsubdir.mk'
+}
+libdir_pkgsubdir_body() {
+ wrapper_test_setup cc
+ input="-L${LOCALBASE}/lib/mysql"
+ echo "-L${BUILDLINK_DIR}/lib/mysql" > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_init_test_cases() {
+ . $(atf_get_srcdir)/setup_common.sh
+ atf_add_test_case libdir_pkgdir
+ atf_add_test_case libdir_pkgdir_slashdot
+ atf_add_test_case libdir_pkgsubdir
+}
diff --git a/pkgtools/cwrappers/files/test/test-libdir_usr_lib.sh b/pkgtools/cwrappers/files/test/test-libdir_usr_lib.sh
new file mode 100644
index 00000000000..89376f3a4c0
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/test-libdir_usr_lib.sh
@@ -0,0 +1,45 @@
+# $NetBSD: test-libdir_usr_lib.sh,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+
+atf_test_case libdir_usr_lib
+libdir_usr_lib_head() {
+ atf_set 'descr' 'XXX autoconverted from libdir-usr-lib.mk'
+}
+libdir_usr_lib_body() {
+ wrapper_test_setup cc
+ input="-L/usr/lib"
+ echo > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_test_case libdir_usr_lib_slashdot
+libdir_usr_lib_slashdot_head() {
+ atf_set 'descr' 'XXX autoconverted from libdir-usr-lib-slashdot.mk'
+}
+libdir_usr_lib_slashdot_body() {
+ wrapper_test_setup cc
+ input="-L/usr/lib/."
+ echo > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_test_case libdir_usr_lib_subdir
+libdir_usr_lib_subdir_head() {
+ atf_set 'descr' 'XXX autoconverted from libdir-usr-lib-subdir.mk'
+}
+libdir_usr_lib_subdir_body() {
+ wrapper_test_setup cc
+ input="-L/usr/lib/i18n"
+ echo "-L/usr/lib/i18n" > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_init_test_cases() {
+ . $(atf_get_srcdir)/setup_common.sh
+ atf_add_test_case libdir_usr_lib
+ atf_add_test_case libdir_usr_lib_slashdot
+ atf_add_test_case libdir_usr_lib_subdir
+}
diff --git a/pkgtools/cwrappers/files/test/test-libpath.sh b/pkgtools/cwrappers/files/test/test-libpath.sh
new file mode 100644
index 00000000000..d839d4fbf08
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/test-libpath.sh
@@ -0,0 +1,58 @@
+# $NetBSD: test-libpath.sh,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+
+atf_test_case libpath
+libpath_head() {
+ atf_set 'descr' 'XXX autoconverted from libpath.mk'
+}
+libpath_body() {
+ wrapper_test_setup cc
+ input="${LOCALBASE}/lib/libfoo.la"
+ echo "${BUILDLINK_DIR}/lib/libfoo.la" > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_test_case libpath_in_define
+libpath_in_define_head() {
+ atf_set 'descr' 'XXX autoconverted from libpath-in-define.mk'
+}
+libpath_in_define_body() {
+ wrapper_test_setup cc
+ input="-DFOO=\"${LOCALBASE}/lib/libfoo.la\""
+ echo "-DFOO=\"${LOCALBASE}/lib/libfoo.la\"" > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_test_case libpath_shlib
+libpath_shlib_head() {
+ atf_set 'descr' 'XXX autoconverted from libpath-shlib.mk'
+}
+libpath_shlib_body() {
+ wrapper_test_setup cc
+ input="${LOCALBASE}/lib/libfoo.so"
+ echo "-L${BUILDLINK_DIR}/lib -lfoo" > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_test_case libpath_shmod
+libpath_shmod_head() {
+ atf_set 'descr' 'XXX autoconverted from libpath-shmod.mk'
+}
+libpath_shmod_body() {
+ wrapper_test_setup cc
+ input="${LOCALBASE}/lib/module/foo.so"
+ echo "${LOCALBASE}/lib/module/foo.so" > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_init_test_cases() {
+ . $(atf_get_srcdir)/setup_common.sh
+ atf_add_test_case libpath
+ atf_add_test_case libpath_in_define
+ atf_add_test_case libpath_shlib
+ atf_add_test_case libpath_shmod
+}
diff --git a/pkgtools/cwrappers/files/test/test-no_abspath.sh b/pkgtools/cwrappers/files/test/test-no_abspath.sh
new file mode 100644
index 00000000000..e33649186d7
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/test-no_abspath.sh
@@ -0,0 +1,19 @@
+# $NetBSD: test-no_abspath.sh,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+
+atf_test_case no_abspath
+no_abspath_head() {
+ atf_set 'descr' 'XXX autoconverted from no-abspath.mk'
+}
+no_abspath_body() {
+ wrapper_test_setup cc
+ input="-L/bad/path/lib -I/bad/path/include ${COMPILER_RPATH_FLAG}/bad/path/lib"
+ echo > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_init_test_cases() {
+ . $(atf_get_srcdir)/setup_common.sh
+ atf_add_test_case no_abspath
+}
diff --git a/pkgtools/cwrappers/files/test/test-option.sh b/pkgtools/cwrappers/files/test/test-option.sh
new file mode 100644
index 00000000000..785ddf86b75
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/test-option.sh
@@ -0,0 +1,32 @@
+# $NetBSD: test-option.sh,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+
+atf_test_case preserve_option
+preserve_option_head() {
+ atf_set 'descr' 'XXX autoconverted from preserve-option.mk'
+}
+preserve_option_body() {
+ wrapper_test_setup cc
+ input="-O2ABC"
+ echo "-O2ABC" > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_test_case remove_option
+remove_option_head() {
+ atf_set 'descr' 'XXX autoconverted from remove-option.mk'
+}
+remove_option_body() {
+ wrapper_test_setup cc
+ input="-O2 -O5 -O9"
+ echo > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_init_test_cases() {
+ . $(atf_get_srcdir)/setup_common.sh
+ atf_add_test_case preserve_option
+ atf_add_test_case remove_option
+}
diff --git a/pkgtools/cwrappers/files/test/test-quoted_arg.sh b/pkgtools/cwrappers/files/test/test-quoted_arg.sh
new file mode 100644
index 00000000000..2360c8e616a
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/test-quoted_arg.sh
@@ -0,0 +1,19 @@
+# $NetBSD: test-quoted_arg.sh,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+
+atf_test_case quoted_arg
+quoted_arg_head() {
+ atf_set 'descr' 'Checks that quoted arguments pass unmolested'
+}
+quoted_arg_body() {
+ wrapper_test_setup cc
+ input='-D"DEFAULT_MODULE_PATH=\"${LOCALBASE}/lib/security/\""'
+ echo "${input}" > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_init_test_cases() {
+ . $(atf_get_srcdir)/setup_common.sh
+ atf_add_test_case quoted_arg
+}
diff --git a/pkgtools/cwrappers/files/test/test-remove_dir.sh b/pkgtools/cwrappers/files/test/test-remove_dir.sh
new file mode 100644
index 00000000000..0c88479fce5
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/test-remove_dir.sh
@@ -0,0 +1,19 @@
+# $NetBSD: test-remove_dir.sh,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+
+atf_test_case remove_dir
+remove_dir_head() {
+ atf_set 'descr' 'Checks that undesirable link/include dirs are removed'
+}
+remove_dir_body() {
+ wrapper_test_setup cc
+ input="-L/opt/schily/lib -I/opt/schily/include"
+ echo > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_init_test_cases() {
+ . $(atf_get_srcdir)/setup_common.sh
+ atf_add_test_case remove_dir
+}
diff --git a/pkgtools/cwrappers/files/test/test-repeated_arg.sh b/pkgtools/cwrappers/files/test/test-repeated_arg.sh
new file mode 100644
index 00000000000..3ea18897051
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/test-repeated_arg.sh
@@ -0,0 +1,19 @@
+# $NetBSD: test-repeated_arg.sh,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+
+atf_test_case repeated_arg
+repeated_arg_head() {
+ atf_set 'descr' 'XXX autoconverted from repeated-arg.mk'
+}
+repeated_arg_body() {
+ wrapper_test_setup cc
+ input="-L${LOCALBASE}/lib -L${LOCALBASE}/lib"
+ echo "-L${BUILDLINK_DIR}/lib" > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_init_test_cases() {
+ . $(atf_get_srcdir)/setup_common.sh
+ atf_add_test_case repeated_arg
+}
diff --git a/pkgtools/cwrappers/files/test/test-rpath_merge.sh b/pkgtools/cwrappers/files/test/test-rpath_merge.sh
new file mode 100644
index 00000000000..f73fe809db8
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/test-rpath_merge.sh
@@ -0,0 +1,26 @@
+# $NetBSD: test-rpath_merge.sh,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+
+atf_test_case rpath_merge
+rpath_merge_head() {
+ atf_set 'descr' 'XXX autoconverted from rpath-merge.mk'
+}
+rpath_merge_body() {
+ wrapper_test_setup cc
+ input="${COMPILER_RPATH_FLAG:S/,$//} -Wl,${LOCALBASE}/lib:${LOCALBASE}/lib/foo"
+ case "${_USE_RPATH}" in
+ [yY][eE][sS])
+ echo "${COMPILER_RPATH_FLAG}${LOCALBASE}/lib ${COMPILER_RPATH_FLAG}${LOCALBASE}/lib/foo" > expout
+ ;;
+ *)
+ echo > expout
+ ;;
+ esac
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_init_test_cases() {
+ . $(atf_get_srcdir)/setup_common.sh
+ atf_add_test_case rpath_merge
+}
diff --git a/pkgtools/cwrappers/files/test/test-rpath_pkgdir.sh b/pkgtools/cwrappers/files/test/test-rpath_pkgdir.sh
new file mode 100644
index 00000000000..be613303435
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/test-rpath_pkgdir.sh
@@ -0,0 +1,66 @@
+# $NetBSD: test-rpath_pkgdir.sh,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+
+atf_test_case rpath_pkgdir
+rpath_pkgdir_head() {
+ atf_set 'descr' 'XXX autoconverted from rpath-pkgdir.mk'
+}
+rpath_pkgdir_body() {
+ wrapper_test_setup cc
+ input="${COMPILER_RPATH_FLAG}${LOCALBASE}/lib"
+ case "${_USE_RPATH}" in
+ [yY][eE][sS])
+ echo "${COMPILER_RPATH_FLAG}${LOCALBASE}/lib" > expout
+ ;;
+ *)
+ echo > expout
+ ;;
+ esac
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_test_case rpath_pkgdir_slashdot
+rpath_pkgdir_slashdot_head() {
+ atf_set 'descr' 'XXX autoconverted from rpath-pkgdir-slashdot.mk'
+}
+rpath_pkgdir_slashdot_body() {
+ wrapper_test_setup cc
+ input="${COMPILER_RPATH_FLAG}${LOCALBASE}/lib/."
+ case "${_USE_RPATH}" in
+ [yY][eE][sS])
+ echo "${COMPILER_RPATH_FLAG}${LOCALBASE}/lib" > expout
+ ;;
+ *)
+ echo > expout
+ ;;
+ esac
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_test_case rpath_pkgsubdir
+rpath_pkgsubdir_head() {
+ atf_set 'descr' 'XXX autoconverted from rpath-pkgsubdir.mk'
+}
+rpath_pkgsubdir_body() {
+ wrapper_test_setup cc
+ input="${COMPILER_RPATH_FLAG}${LOCALBASE}/lib/mysql"
+ case "${_USE_RPATH}" in
+ [yY][eE][sS])
+ echo "${COMPILER_RPATH_FLAG}${LOCALBASE}/lib/mysql" > expout
+ ;;
+ *)
+ echo > expout
+ ;;
+ esac
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_init_test_cases() {
+ . $(atf_get_srcdir)/setup_common.sh
+ atf_add_test_case rpath_pkgdir
+ atf_add_test_case rpath_pkgdir_slashdot
+ atf_add_test_case rpath_pkgsubdir
+}
diff --git a/pkgtools/cwrappers/files/test/test-rpath_split.sh b/pkgtools/cwrappers/files/test/test-rpath_split.sh
new file mode 100644
index 00000000000..add6563e567
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/test-rpath_split.sh
@@ -0,0 +1,26 @@
+# $NetBSD: test-rpath_split.sh,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+
+atf_test_case rpath_split
+rpath_split_head() {
+ atf_set 'descr' 'XXX autoconverted from rpath-split.mk'
+}
+rpath_split_body() {
+ wrapper_test_setup cc
+ input="${COMPILER_RPATH_FLAG}${LOCALBASE}/lib:${LOCALBASE}/lib/foo"
+ case "${_USE_RPATH}" in
+ [yY][eE][sS])
+ echo "${COMPILER_RPATH_FLAG}${LOCALBASE}/lib ${COMPILER_RPATH_FLAG}${LOCALBASE}/lib/foo" > expout
+ ;;
+ *)
+ echo > expout
+ ;;
+ esac
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_init_test_cases() {
+ . $(atf_get_srcdir)/setup_common.sh
+ atf_add_test_case rpath_split
+}
diff --git a/pkgtools/cwrappers/files/test/test-rpath_usr_lib.sh b/pkgtools/cwrappers/files/test/test-rpath_usr_lib.sh
new file mode 100644
index 00000000000..118cb2a7287
--- /dev/null
+++ b/pkgtools/cwrappers/files/test/test-rpath_usr_lib.sh
@@ -0,0 +1,52 @@
+# $NetBSD: test-rpath_usr_lib.sh,v 1.1 2014/09/17 12:40:56 joerg Exp $
+#
+
+atf_test_case rpath_usr_lib
+rpath_usr_lib_head() {
+ atf_set 'descr' 'XXX autoconverted from rpath-usr-lib.mk'
+}
+rpath_usr_lib_body() {
+ wrapper_test_setup cc
+ input="${COMPILER_RPATH_FLAG}/usr/lib"
+ echo > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_test_case rpath_usr_lib_slashdot
+rpath_usr_lib_slashdot_head() {
+ atf_set 'descr' 'XXX autoconverted from rpath-usr-lib-slashdot.mk'
+}
+rpath_usr_lib_slashdot_body() {
+ wrapper_test_setup cc
+ input="${COMPILER_RPATH_FLAG}/usr/lib/."
+ echo > expout
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_test_case rpath_usr_lib_subdir
+rpath_usr_lib_subdir_head() {
+ atf_set 'descr' 'XXX autoconverted from rpath-usr-lib-subdir.mk'
+}
+rpath_usr_lib_subdir_body() {
+ wrapper_test_setup cc
+ input="${COMPILER_RPATH_FLAG}/usr/lib/i18n"
+ case "${_USE_RPATH}" in # XXX do we want this?
+ [yY][eE][sS])
+ echo "${COMPILER_RPATH_FLAG}/usr/lib/i18n" > expout
+ ;;
+ *)
+ echo > expout
+ ;;
+ esac
+ atf-check -s eq:0 -o file:expout -e ignore ${WRAPPER} ${input} \
+ || atf_fail 'XXX no reason'
+}
+
+atf_init_test_cases() {
+ . $(atf_get_srcdir)/setup_common.sh
+ atf_add_test_case rpath_usr_lib
+ atf_add_test_case rpath_usr_lib_slashdot
+ atf_add_test_case rpath_usr_lib_subdir
+}