summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2011-03-18 19:47:37 +0000
committerMike Frysinger <vapier@gentoo.org>2011-03-18 19:47:37 +0000
commit35aec29fcd739177647c75fc536a95612b9ba69a (patch)
tree49b63ef13ae4284c067c3076b9e9324299189d29 /sys-devel/gcc-config
parentold (diff)
downloadhistorical-35aec29fcd739177647c75fc536a95612b9ba69a.tar.gz
historical-35aec29fcd739177647c75fc536a95612b9ba69a.tar.bz2
historical-35aec29fcd739177647c75fc536a95612b9ba69a.zip
Stop auto appending CFLAGS_<abi> from the env.
Package-Manager: portage-2.2.0_alpha26/cvs/Linux x86_64
Diffstat (limited to 'sys-devel/gcc-config')
-rw-r--r--sys-devel/gcc-config/ChangeLog8
-rw-r--r--sys-devel/gcc-config/Manifest11
-rw-r--r--sys-devel/gcc-config/files/wrapper-1.5.2.c313
-rw-r--r--sys-devel/gcc-config/gcc-config-1.5-r1.ebuild61
4 files changed, 387 insertions, 6 deletions
diff --git a/sys-devel/gcc-config/ChangeLog b/sys-devel/gcc-config/ChangeLog
index 0d0a11f4ef2a..8dc3d9d7b62a 100644
--- a/sys-devel/gcc-config/ChangeLog
+++ b/sys-devel/gcc-config/ChangeLog
@@ -1,6 +1,12 @@
# ChangeLog for sys-devel/gcc-config
# Copyright 1999-2011 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/sys-devel/gcc-config/ChangeLog,v 1.190 2011/03/07 12:48:15 vapier Exp $
+# $Header: /var/cvsroot/gentoo-x86/sys-devel/gcc-config/ChangeLog,v 1.191 2011/03/18 19:47:37 vapier Exp $
+
+*gcc-config-1.5-r1 (18 Mar 2011)
+
+ 18 Mar 2011; Mike Frysinger <vapier@gentoo.org> +gcc-config-1.5-r1.ebuild,
+ +files/wrapper-1.5.2.c:
+ Stop auto appending CFLAGS_<abi> from the env.
07 Mar 2011; Mike Frysinger <vapier@gentoo.org> files/gcc-config-1.4.1,
files/gcc-config-1.5:
diff --git a/sys-devel/gcc-config/Manifest b/sys-devel/gcc-config/Manifest
index a198991156ef..0000752f8743 100644
--- a/sys-devel/gcc-config/Manifest
+++ b/sys-devel/gcc-config/Manifest
@@ -4,14 +4,15 @@ Hash: SHA256
AUX gcc-config-1.4.1 21703 RMD160 cb01cc5713dec475ff07cfe4f94c038520692a8b SHA1 cae8ea36b179057979dcbe1122ef886d02bae679 SHA256 809e8c3234bf4138d5274ab2934c95e4d281fbea09d89e46ea0f686c4ca23c16
AUX gcc-config-1.5 19395 RMD160 6d4d70fde46c29d7683c13ad33e574f44f599138 SHA1 8074d60e80d65f149f6af40d300a06e843d0df52 SHA256 6a3a31ec500357dff2f6d3aa01ead9de7c186bef415de19fa0ad78bd1a22a1b1
AUX wrapper-1.5.1.c 9788 RMD160 b628944ee01dd772eb917cd08d13dc41bf58409f SHA1 51ac1f9419bc2230a9ce2196e70b5ee4ba61be18 SHA256 991981059fdcd0a9c76d73ff2ce576e553f37ae7d3b378b92ead553963f7339a
+AUX wrapper-1.5.2.c 7968 RMD160 b550c9f5ca378b4aba3ea493093bbb50255edb11 SHA1 8504af6612ba2ae59fe839224865beac1fea910f SHA256 190540ec2c820a6868b4cb3bf4eeda8134071f01ef666c8b405cbaec9130e45d
EBUILD gcc-config-1.4.1.ebuild 1642 RMD160 b6af302e3654e7dbf5aa808e0c037c66df810ae8 SHA1 b5853c35cf17285d852ef424f12bb1eb0f1b19ab SHA256 5ad070e899901f17a57a515829d83a243ae79ffe5dbe46999328139e13cc9d23
-EBUILD gcc-config-1.5.ebuild 1643 RMD160 e67c71ef5b9824e7d1394dad39a09312992e19e8 SHA1 051ff48881a19aec0b635ec4413c89116e4cb8c0 SHA256 4972b0ce2511fe468e0772801214c3e90c2b53bc54b42dda119a666f285875ae
-MISC ChangeLog 34204 RMD160 d6ee23e1f0543d23b776e5b9214336385ea660b6 SHA1 cc983c710cca080e923cab0d3a7e07f3c3997323 SHA256 a3b819bf06a4f70b01e1f7dd24a550a68770dbf7b07c9ad079938a95033e8398
+EBUILD gcc-config-1.5-r1.ebuild 1646 RMD160 8cb85f46321682f6314dae0eb0d88edf4d4a399c SHA1 748986759f14006326a2e35da4e27a82c5617261 SHA256 bc1e4b67d12a02e3f357b3d3f4a983df248c41ba6917eac99dfb031c4245dd36
+MISC ChangeLog 34391 RMD160 885a06d966a7aaac265a69515e5a170a347a0654 SHA1 fab1583912d7e42a0c5c1db86289b3c25d861dff SHA256 ff2b485b9a66fdbc5f73622da8c608d36d52b599b128e87e70dbc48a1badf2d5
MISC metadata.xml 162 RMD160 d002486a43522f2116b1d9d59828c484956d66e2 SHA1 d6b4923897f6ae673b4f93646f5b4ba61d5a2c3c SHA256 65a915d44de1f01d4b7f72d313b4192c38374a9835d24988c00c1e73dca5805a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (GNU/Linux)
-iF4EAREIAAYFAk101AEACgkQaC/OocHi7JaF3wD+MJipDiiY6JCdndv8IUm33MAx
-fnZDvgOIToZ0El00bQ8A/AgEhMDZrp8rtMjLJ38qK1Xtn+uSeL+uXnd/4X+C7oyJ
-=0aNf
+iF4EAREIAAYFAk2Dtt4ACgkQaC/OocHi7JaMOQD+OFDOJlB773cnDTMWkN0MZkIM
+qSctVMGCY/4mRudsyOUA/RQME/gVeF82BfkBqcZR8j3ht0lkRxXtNV578fvfnMTb
+=8gm7
-----END PGP SIGNATURE-----
diff --git a/sys-devel/gcc-config/files/wrapper-1.5.2.c b/sys-devel/gcc-config/files/wrapper-1.5.2.c
new file mode 100644
index 000000000000..d3e64f009d98
--- /dev/null
+++ b/sys-devel/gcc-config/files/wrapper-1.5.2.c
@@ -0,0 +1,313 @@
+/*
+ * Copyright 1999-2011 Gentoo Foundation
+ * Distributed under the terms of the GNU General Public License v2
+ * $Header: /var/cvsroot/gentoo-x86/sys-devel/gcc-config/files/wrapper-1.5.2.c,v 1.1 2011/03/18 19:47:37 vapier Exp $
+ * Author: Martin Schlemmer <azarah@gentoo.org>
+ * az's lackey: Mike Frysinger <vapier@gentoo.org>
+ */
+
+#ifdef DEBUG
+# define USE_DEBUG 1
+#else
+# define USE_DEBUG 0
+#endif
+
+#include <errno.h>
+#include <libgen.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#define GCC_CONFIG "/usr/bin/gcc-config"
+#define ENVD_BASE "/etc/env.d/05gcc"
+
+#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
+
+/* basename(3) is allowed to modify memory */
+#undef basename
+#define basename(path) \
+({ \
+ char *__path = path; \
+ char *__ret = strrchr(__path, '/'); \
+ __ret ? __ret + 1 : __path; \
+})
+
+struct wrapper_data {
+ char *name, *fullname, *bin, *path;
+};
+
+static const struct {
+ char *alias;
+ char *target;
+} wrapper_aliases[] = {
+ { "cc", "gcc" },
+ { "f77", "g77" },
+};
+
+#define wrapper_warn(fmt, ...) fprintf(stderr, "%s" fmt "\n", "gcc-config: ", ## __VA_ARGS__)
+#define wrapper_err(fmt, ...) ({ wrapper_warn("%s" fmt, "error: ", ## __VA_ARGS__); exit(1); })
+#define wrapper_errp(fmt, ...) wrapper_err(fmt ": %s", ## __VA_ARGS__, strerror(errno))
+#define wrapper_dbg(fmt, ...) ({ if (USE_DEBUG) wrapper_warn(fmt, ## __VA_ARGS__); })
+
+#define xmemwrap(func, proto, use) \
+static void *x ## func proto \
+{ \
+ void *ret = func use; \
+ if (!ret) \
+ wrapper_err(#func "%s", ": out of memory"); \
+ return ret; \
+}
+xmemwrap(malloc, (size_t size), (size))
+xmemwrap(strdup, (const char *s), (s))
+
+/* check_for_target checks in path for the file we are seeking
+ * it returns 1 if found (with data->bin setup), 0 if not and
+ * negative on error
+ */
+static int check_for_target(char *path, struct wrapper_data *data)
+{
+ struct stat sbuf;
+ char str[PATH_MAX + 1];
+ size_t path_len = strlen(path);
+ size_t len = path_len + strlen(data->name) + 2;
+
+ if (sizeof(str) < len)
+ wrapper_warn("path too long: %s", path);
+
+ strcpy(str, path);
+ str[path_len] = '/';
+ str[path_len+1] = '\0';
+ strcat(str, data->name);
+
+ /* Stat possible file to check that
+ * 1) it exist and is a regular file, and
+ * 2) it is not the wrapper itself, and
+ * 3) it is in a /gcc-bin/ directory tree
+ */
+ if (strcmp(str, data->fullname) != 0 &&
+ strstr(str, "/gcc-bin/") != NULL &&
+ stat(str, &sbuf) == 0 &&
+ (S_ISREG(sbuf.st_mode) || S_ISLNK(sbuf.st_mode)))
+ {
+ wrapper_dbg("%s: found in %s", data->name, path);
+ data->bin = xstrdup(str);
+ return 1;
+ }
+
+ wrapper_dbg("%s: did not find in %s", data->name, path);
+ return 0;
+}
+
+static int find_target_in_path(struct wrapper_data *data)
+{
+ char *token = NULL, *state = NULL;
+ char *str;
+
+ if (data->path == NULL)
+ return 0;
+
+ /* Make a copy since strtok_r will modify path */
+ str = xstrdup(data->path);
+
+ /* Find the first file with suitable name in PATH. The idea here is
+ * that we do not want to bind ourselfs to something static like the
+ * default profile, or some odd environment variable, but want to be
+ * able to build something with a non default gcc by just tweaking
+ * the PATH ... */
+ token = strtok_r(str, ":", &state);
+ while (token != NULL) {
+ if (check_for_target(token, data))
+ return 1;
+ token = strtok_r(NULL, ":", &state);
+ }
+
+ wrapper_dbg("%s: did not find in PATH", data->name);
+ return 0;
+}
+
+/* find_target_in_envd parses /etc/env.d/05gcc, and tries to
+ * extract PATH, which is set to the current profile's bin
+ * directory ...
+ */
+static int find_target_in_envd(struct wrapper_data *data, int cross_compile)
+{
+ FILE *envfile = NULL;
+ char *token = NULL, *state;
+ char str[PATH_MAX + 1];
+ char *strp = str;
+ char envd_file[PATH_MAX + 1];
+
+ if (!cross_compile) {
+ /* for the sake of speed, we'll keep a symlink around for
+ * the native compiler. #190260
+ */
+ snprintf(envd_file, sizeof(envd_file)-1, "/etc/env.d/gcc/.NATIVE");
+ } else {
+ char *ctarget, *end = strrchr(data->name, '-');
+ if (end == NULL)
+ return 0;
+ ctarget = xstrdup(data->name);
+ ctarget[end - data->name] = '\0';
+ snprintf(envd_file, PATH_MAX, "%s-%s", ENVD_BASE, ctarget);
+ free(ctarget);
+ }
+
+ envfile = fopen(envd_file, "r");
+ if (envfile == NULL)
+ return 0;
+
+ while (fgets(strp, PATH_MAX, envfile) != NULL) {
+ /* Keep reading ENVD_FILE until we get a line that
+ * starts with 'GCC_PATH=' ... keep 'PATH=' around
+ * for older gcc versions.
+ */
+ if (strncmp(strp, "GCC_PATH=", strlen("GCC_PATH=")) &&
+ strncmp(strp, "PATH=", strlen("PATH=")))
+ continue;
+
+ token = strtok_r(strp, "=", &state);
+ if ((token != NULL) && token[0])
+ /* The second token should be the value of PATH .. */
+ token = strtok_r(NULL, "=", &state);
+ else
+ goto bail;
+
+ if ((token != NULL) && token[0]) {
+ strp = token;
+ /* A bash variable may be unquoted, quoted with " or
+ * quoted with ', so extract the value without those ..
+ */
+ token = strtok(strp, "\n\"\'");
+
+ while (token != NULL) {
+ if (check_for_target(token, data)) {
+ fclose(envfile);
+ return 1;
+ }
+
+ token = strtok(NULL, "\n\"\'");
+ }
+ }
+
+ strp = str;
+ }
+
+ bail:
+ fclose(envfile);
+ return (cross_compile ? 0 : find_target_in_envd(data, 1));
+}
+
+static void find_wrapper_target(struct wrapper_data *data)
+{
+ if (find_target_in_path(data))
+ return;
+
+ if (find_target_in_envd(data, 0))
+ return;
+
+ /* Only our wrapper is in PATH, so get the CC path using
+ * gcc-config and execute the real binary in there ...
+ */
+ FILE *inpipe = popen(GCC_CONFIG " --get-bin-path", "r");
+ if (inpipe == NULL)
+ wrapper_errp("could not open pipe");
+
+ char str[PATH_MAX + 1];
+ if (fgets(str, PATH_MAX, inpipe) == 0)
+ wrapper_errp("could not get compiler binary path");
+
+ /* chomp! */
+ size_t plen = strlen(str);
+ if (str[plen-1] == '\n')
+ str[plen-1] = '\0';
+
+ data->bin = xmalloc(plen + 1 + strlen(data->name) + 1);
+ sprintf(data->bin, "%s/%s", str, data->name);
+
+ pclose(inpipe);
+}
+
+/* This function modifies PATH to have gcc's bin path appended */
+static void modify_path(struct wrapper_data *data)
+{
+ char *newpath = NULL, *token = NULL, *state;
+ char dname_data[PATH_MAX + 1], str[PATH_MAX + 1];
+ char *str2 = dname_data, *dname = dname_data;
+ size_t len = 0;
+
+ if (data->bin == NULL)
+ return;
+
+ if (data->path == NULL)
+ return;
+
+ snprintf(str2, PATH_MAX + 1, "%s", data->bin);
+
+ if ((dname = dirname(str2)) == NULL)
+ return;
+
+ /* Make a copy since strtok_r will modify path */
+ snprintf(str, PATH_MAX + 1, "%s", data->path);
+
+ token = strtok_r(str, ":", &state);
+
+ /* Check if we already appended our bin location to PATH */
+ if ((token != NULL) && token[0])
+ if (!strcmp(token, dname))
+ return;
+
+ len = strlen(dname) + strlen(data->path) + 2 + strlen("PATH") + 1;
+
+ newpath = xmalloc(len);
+ memset(newpath, 0, len);
+
+ snprintf(newpath, len, "PATH=%s:%s", dname, data->path);
+ putenv(newpath);
+}
+
+int main(int argc, char *argv[])
+{
+ struct wrapper_data data;
+
+ memset(&data, 0, sizeof(data));
+
+ if (getenv("PATH"))
+ data.path = xstrdup(getenv("PATH"));
+
+ /* What should we find ? */
+ data.name = basename(argv[0]);
+
+ /* Allow for common compiler names like cc->gcc */
+ size_t i;
+ for (i = 0; i < ARRAY_SIZE(wrapper_aliases); ++i)
+ if (!strcmp(data.name, wrapper_aliases[i].alias))
+ data.name = wrapper_aliases[i].target;
+
+ /* What is the full name of our wrapper? */
+ data.fullname = xmalloc(strlen(data.name) + sizeof("/usr/bin/") + 1);
+ sprintf(data.fullname, "/usr/bin/%s", data.name);
+
+ find_wrapper_target(&data);
+
+ modify_path(&data);
+
+ free(data.path);
+ data.path = NULL;
+
+ /* Set argv[0] to the correct binary, else gcc can't find internal headers
+ * http://bugs.gentoo.org/8132
+ */
+ argv[0] = data.bin;
+
+ /* Ok, lets do it one more time ... */
+ execv(data.bin, argv);
+
+ /* shouldn't have made it here if things worked ... */
+ wrapper_err("could not run/locate '%s'", data.name);
+
+ return 123;
+}
diff --git a/sys-devel/gcc-config/gcc-config-1.5-r1.ebuild b/sys-devel/gcc-config/gcc-config-1.5-r1.ebuild
new file mode 100644
index 000000000000..c151ad7655dc
--- /dev/null
+++ b/sys-devel/gcc-config/gcc-config-1.5-r1.ebuild
@@ -0,0 +1,61 @@
+# Copyright 1999-2011 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/sys-devel/gcc-config/gcc-config-1.5-r1.ebuild,v 1.1 2011/03/18 19:47:37 vapier Exp $
+
+inherit flag-o-matic toolchain-funcs multilib
+
+# Version of .c wrapper to use
+W_VER="1.5.2"
+
+DESCRIPTION="Utility to change the gcc compiler being used"
+HOMEPAGE="http://www.gentoo.org/"
+SRC_URI=""
+
+LICENSE="GPL-2"
+SLOT="0"
+#KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~sparc-fbsd ~x86-fbsd"
+IUSE=""
+
+RDEPEND="!app-admin/eselect-compiler"
+
+S=${WORKDIR}
+
+src_unpack() {
+ cp "${FILESDIR}"/wrapper-${W_VER}.c "${S}"/wrapper.c || die
+}
+
+src_compile() {
+ strip-flags
+ emake CC="$(tc-getCC)" wrapper || die "compile wrapper"
+}
+
+src_install() {
+ newbin "${FILESDIR}"/${PN}-${PV} ${PN} || die "install gcc-config"
+ sed -i \
+ -e "s:@GENTOO_LIBDIR@:$(get_libdir):g" \
+ "${D}"/usr/bin/${PN}
+
+ exeinto /usr/$(get_libdir)/misc
+ newexe wrapper gcc-config || die "install wrapper"
+}
+
+pkg_postinst() {
+ # Scrub eselect-compiler remains
+ if [[ -e ${ROOT}/etc/env.d/05compiler ]] ; then
+ rm -f "${ROOT}"/etc/env.d/05compiler
+ fi
+
+ # Make sure old versions dont exist #79062
+ rm -f "${ROOT}"/usr/sbin/gcc-config
+
+ # We not longer use the /usr/include/g++-v3 hacks, as
+ # it is not needed ...
+ [[ -L ${ROOT}/usr/include/g++ ]] && rm -f "${ROOT}"/usr/include/g++
+ [[ -L ${ROOT}/usr/include/g++-v3 ]] && rm -f "${ROOT}"/usr/include/g++-v3
+
+ # Do we have a valid multi ver setup ?
+ local x
+ for x in $(gcc-config -C -l 2>/dev/null | awk '$NF == "*" { print $2 }') ; do
+ gcc-config ${x}
+ done
+}