summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schlemmer <azarah@gentoo.org>2003-01-15 00:25:33 +0000
committerMartin Schlemmer <azarah@gentoo.org>2003-01-15 00:25:33 +0000
commit6a1e12ebdebcff204e37fc5d2343a3ad529e1de1 (patch)
tree84288e1a6fc00714fe17c94a4b9cf8d95568a173
parentchange usage screen; bug #13005. (diff)
downloadgcc-config-6a1e12ebdebcff204e37fc5d2343a3ad529e1de1.tar.gz
gcc-config-6a1e12ebdebcff204e37fc5d2343a3ad529e1de1.tar.bz2
gcc-config-6a1e12ebdebcff204e37fc5d2343a3ad529e1de1.zip
add wrappers to ~x86v1.2.8
-rwxr-xr-xgcc-config147
-rw-r--r--wrapper.c125
2 files changed, 169 insertions, 103 deletions
diff --git a/gcc-config b/gcc-config
index abb99fa..0bb30fa 100755
--- a/gcc-config
+++ b/gcc-config
@@ -2,7 +2,7 @@
# Copyright 1999-2002 Gentoo Foundation
# Distributed under the terms of the GNU General Public License
# Author: Martin Schlemmer <azarah@gentoo.org>
-# $Header: gentoo-x86/sys-devel/gcc-config/files/gcc-config-1.2.7,v 1.2 2003/01/02 21:40:41 azarah Exp $
+# $Header: gentoo-x86/sys-devel/gcc-config/files/gcc-config-1.2.8,v 1.1 2003/01/15 00:25:33 azarah Exp $
source /etc/init.d/functions.sh || {
@@ -12,8 +12,8 @@ source /etc/init.d/functions.sh || {
usage() {
cat << "USAGE_END"
-Usage: gcc-config [Option] [GCC Profile]
-Change the current gcc profile, or give info about profiles.
+Usage: gcc-config [Option] [CC Profile]
+Change the current cc/gcc profile, or give info about profiles.
Options:
@@ -61,7 +61,7 @@ fi
cmd_setup() {
- # Sourcing /etc/env.d/gcc/${GCC_COMP} is going to mess up
+ # Sourcing /etc/env.d/gcc/${CC_COMP} is going to mess up
# PATH among things...
CP="$(find_path cp)"
RM="$(find_path rm)"
@@ -89,34 +89,12 @@ find_path() {
done
}
-gen_wrapper() {
- ${CAT} > $1 << END
-#!/bin/sh
-
-# This is part of sys-devel/gcc-config
-
-CPP="\`which cpp 2> /dev/null\`"
-
-# Setup PATH if we cannot find the cpp binary, or if the one
-# we find is the wrapper script ...
-if [ ! -x "\${CPP}" -o "\${CPP}" == "/usr/bin/cpp" ]
-then
- PATH="\`/usr/sbin/gcc-config --get-bin-path\`:\${PATH}"
-fi
-
-$2 "\$@"
-END
-
- ${CHMOD} 0755 $1
-}
-
-GCC_COMP=""
+CC_COMP=""
REAL_CHOST="$(/usr/bin/python -c 'import portage; print portage.settings["CHOST"];')"
switch_profile() {
local MY_LDPATH=""
local GCC_PROFILES=""
- local REPLACED_CPP="no"
if [ "$(id -u)" -ne 0 ]
then
@@ -124,9 +102,9 @@ switch_profile() {
exit 1
fi
- ebegin "Switching to ${GCC_COMP} compiler"
+ ebegin "Switching to ${CC_COMP} compiler"
- # Sourcing /etc/env.d/gcc/${GCC_COMP} is going to mess up
+ # Sourcing /etc/env.d/gcc/${CC_COMP} is going to mess up
# PATH among things...
cmd_setup
@@ -136,8 +114,8 @@ switch_profile() {
# compilers for default CHOST will be used to compile stuff,
# and thus we want all their lib paths in /etc/ld.so.conf ...
GCC_PROFILES="$(${FIND} /etc/env.d/gcc/ -name "${REAL_CHOST}-*")"
- GCC_PROFILES="${GCC_PROFILES/\/etc\/env.d\/gcc\/${GCC_COMP}}"
- GCC_PROFILES="/etc/env.d/gcc/${GCC_COMP} ${GCC_PROFILES}"
+ GCC_PROFILES="${GCC_PROFILES/\/etc\/env.d\/gcc\/${CC_COMP}}"
+ GCC_PROFILES="/etc/env.d/gcc/${CC_COMP} ${GCC_PROFILES}"
# Extract all LDPATH's for our CHOST
for x in ${GCC_PROFILES}
@@ -162,77 +140,38 @@ switch_profile() {
done
# Setup things properly again for this profile
- source /etc/env.d/gcc/${GCC_COMP}
-
- # Add support for colorgcc
- if [ -x /usr/bin/colorgcc ]
- then
- echo "PATH=\"/usr/bin/wrappers:${PATH}\"" > /etc/env.d/05gcc
- echo "ROOTPATH=\"/usr/bin/wrappers:${PATH}\"" >> /etc/env.d/05gcc
- echo "CCBINPATH=\"${PATH}\"" >> /etc/env.d/05gcc
- else
- echo "PATH=\"${PATH}\"" > /etc/env.d/05gcc
- echo "ROOTPATH=\"${PATH}\"" >> /etc/env.d/05gcc
- fi
+ source /etc/env.d/gcc/${CC_COMP}
# Setup /etc/env.d/05gcc
- ${AWK} '!/^(PATH|ROOTPATH)=|^STDCXX_INCDIR=|^LDPATH=/ {print $0}' \
- /etc/env.d/gcc/${GCC_COMP} >> /etc/env.d/05gcc
+ ${AWK} '!/^STDCXX_INCDIR=|^LDPATH=/ {print $0}' \
+ /etc/env.d/gcc/${CC_COMP} > /etc/env.d/05gcc
# Add our custom LDPATH
echo "LDPATH=\"${MY_LDPATH}\"" >> /etc/env.d/05gcc
- # Create /lib/cpp if missing or a symlink
- if [ -L /lib/cpp -o ! -f /lib/cpp ]
- then
- ${RM} -f /lib/cpp
- gen_wrapper /lib/cpp cpp
- # Make sure it are not unmerged by mistake
- ${TOUCH} /lib/cpp
- fi
- # Create /usr/bin/cc if missing or a symlink
- if [ -L /usr/bin/cc -o ! -f /usr/bin/cc ]
- then
- ${RM} -f /usr/bin/cc
- gen_wrapper /usr/bin/cc gcc
- # Make sure it are not unmerged by mistake
- ${TOUCH} /usr/bin/cc
- fi
- # Create /usr/bin/cpp if missing or a symlink (used by XFree86 for one)
- if [ -L /usr/bin/cpp -o ! -f /usr/bin/cpp ] || \
- [ -f /usr/bin/cpp -a ! -f /usr/bin/cpp0 ]
- then
- # In some cases we hava an old binary that was not unmerged, and breaks
- # things, thus remove it and replace with proper wrapper ...
- if [ -f /usr/bin/cpp ] && \
- [ -z "$(${GREP} "This is part of sys-devel\/gcc-config" /usr/bin/cpp)" ]
- then
- REPLACED_CPP="yes"
- ${MV} -f /usr/bin/cpp /usr/bin/cpp.orig
- fi
-
- ${RM} -f /usr/bin/cpp
- gen_wrapper /usr/bin/cpp cpp
- # Make sure it are not unmerged by mistake
- ${TOUCH} /usr/bin/cpp
- fi
+ # Make sure we do not recreate /lib/cpp and /usr/bin/cc ...
+# echo "DISABLE_GEN_GCC_WRAPPERS=\"yes\"" >> /etc/env.d/05gcc
- echo "CURRENT=${GCC_COMP}" > /etc/env.d/gcc/config
+ echo "CURRENT=${CC_COMP}" > /etc/env.d/gcc/config
source /etc/profile
+ # These might not be installed, and we want to update the mtime
+ # for ccache and distcc anyhow ...
+ ${RM} -f /lib/cpp
+ ${CP} -f /usr/lib/gcc-config/wrapper /lib/cpp
+ for x in gcc cpp cc c++ g++ ${CHOST}-gcc ${CHOST}-c++ ${CHOST}-g++
+ do
+ ${RM} -f /usr/bin/${x}
+ ${CP} -f /usr/lib/gcc-config/wrapper /usr/bin/${x}
+ ${TOUCH} -m /usr/bin/${x}
+ done
+
+
${ENV_UPDATE} &> /dev/null
eend 0
- if [ "${REPLACED_CPP}" = "yes" ]
- then
- echo
- ewarn "Sanity check of /usr/bin/cpp failed, backing up to /usr/bin/cpp.orig"
- ewarn "and replacing with wrapper script! If you have problems, replace it"
- ewarn "with the original, or submit a bugreport."
- fi
-
return 0
}
@@ -275,7 +214,7 @@ list_profiles() {
print_environ() {
local OLDPATH="${PATH}"
- source /etc/env.d/gcc/${GCC_COMP}
+ source /etc/env.d/gcc/${CC_COMP}
echo "export PATH=\"${PATH}:${OLDPATH}\""
@@ -291,7 +230,7 @@ print_environ() {
}
get_bin_path() {
- source /etc/env.d/gcc/${GCC_COMP}
+ source /etc/env.d/gcc/${CC_COMP}
echo "${PATH}"
@@ -299,7 +238,7 @@ get_bin_path() {
}
get_lib_path() {
- source /etc/env.d/gcc/${GCC_COMP}
+ source /etc/env.d/gcc/${CC_COMP}
echo "${LDPATH}"
@@ -307,7 +246,7 @@ get_lib_path() {
}
get_stdcxx_incdir() {
- source /etc/env.d/gcc/${GCC_COMP}
+ source /etc/env.d/gcc/${CC_COMP}
echo "${LDPATH}/include/${STDCXX_INCDIR}"
@@ -325,7 +264,7 @@ do
--use-old)
if get_current_profile &> /dev/null
then
- GCC_COMP="$(get_current_profile)"
+ CC_COMP="$(get_current_profile)"
fi
;;
--use-portage-chost)
@@ -374,38 +313,40 @@ do
fi
;;
*)
- if [ -z "${GCC_COMP}" ]
+ if [ -z "${CC_COMP}" ]
then
- GCC_COMP="${x}"
+ CC_COMP="${x}"
fi
;;
esac
done
-if [ "${DOIT}" = "switch_profile" -a -z "${GCC_COMP}" ]
+if [ "${DOIT}" = "switch_profile" -a -z "${CC_COMP}" ]
then
usage
fi
-if [ -z "${GCC_COMP}" ]
+if [ -z "${CC_COMP}" ]
then
if get_current_profile &> /dev/null
then
- GCC_COMP="$(get_current_profile)"
+ CC_COMP="$(get_current_profile)"
else
- usage
+ eerror "$0: No default profile setup!"
+ exit 1
fi
fi
-if [ ! -d /usr/lib/gcc-lib/${GCC_COMP%-*}/${GCC_COMP##*-} -o \
- ! -f /etc/env.d/gcc/${GCC_COMP} ]
+if [ ! -d /usr/lib/gcc-lib/${CC_COMP%-*}/${CC_COMP##*-} -o \
+ ! -f /etc/env.d/gcc/${CC_COMP} ]
then
- usage
+ eerror "$0: Profile does not exist!"
+ exit 1
fi
# Chosen CHOST are not the same as the real CHOST according to make.conf,
# and --use-portage-chost option was given, so do nothing ...
-if [ "${CHECK_CHOST}" = "yes" -a "${GCC_COMP%-*}" != "${REAL_CHOST}" ]
+if [ "${CHECK_CHOST}" = "yes" -a "${CC_COMP%-*}" != "${REAL_CHOST}" ]
then
exit 0
fi
diff --git a/wrapper.c b/wrapper.c
new file mode 100644
index 0000000..b1cd86c
--- /dev/null
+++ b/wrapper.c
@@ -0,0 +1,125 @@
+/*
+ * Copyright 1999-2003 Gentoo Foundation
+ * Distributed under the terms of the GNU General Public License v2
+ * Author: Martin Schlemmer <azarah@gentoo.org>
+ * $Header: gentoo-x86/sys-devel/gcc-config/files/wrapper.c,v 1.1 2003/01/15 00:25:33 azarah Exp $
+ */
+
+#define _REENTRANT
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <unistd.h>
+#include <wait.h>
+#include <libgen.h>
+#include <string.h>
+
+
+int main(int argc, char **argv) {
+ struct stat sbuf;
+ FILE *inpipe = NULL;
+ char wrapperbin[MAXPATHLEN + 1], wrapfullname[MAXPATHLEN + 1];
+ char *wrappername = NULL;
+ char *buffer = NULL, *token = NULL, *tmpstr = NULL, *state = NULL;
+ int ret = 0;
+
+ wrapperbin[0] = '\0';
+
+ /* What should we find ? */
+ wrappername = strdupa(basename(argv[0]));
+
+ /* cc calls gcc ... */
+ if (0 == strcmp(wrappername, "cc"))
+ sprintf(wrappername, "%s", "gcc");
+
+ /* What is the full name of our wrapper? */
+ snprintf(wrapfullname, strlen("/usr/bin/") + strlen(wrappername) + 1,
+ "%s%s", "/usr/bin/", wrappername);
+
+ buffer = strdup((char *)getenv("PATH"));
+ token = strtok_r(buffer, ":", &state);
+
+ /* Find the first file with suitable name in PATH */
+ while ((NULL != token) && (strlen(token) > 0)) {
+
+ tmpstr = (char *)malloc(strlen(token) + strlen(wrappername) + 2);
+ snprintf(tmpstr, strlen(token) + strlen(wrappername) + 2,
+ "%s/%s", token, wrappername);
+
+ /* Does it exist and is a file? */
+ ret = stat(tmpstr, &sbuf);
+ /* It exists, and are not our wrapper, and its not in /usr/bin ... */
+ if ((0 == ret) && (sbuf.st_mode & S_IFREG) &&
+ (0 != strcmp(tmpstr, wrapfullname)) && (0 == strstr(tmpstr, "/usr/bin"))) {
+
+ strncpy(wrapperbin, tmpstr, MAXPATHLEN);
+
+ if (tmpstr) {
+ free(tmpstr);
+ tmpstr = NULL;
+ }
+
+ break;
+ }
+
+ token = strtok_r(NULL, ":", &state);
+ }
+
+ if (buffer) {
+ free(buffer);
+ buffer = NULL;
+ }
+
+ /* Did we get a valid binary to execute? */
+ if (wrapperbin[0] == '\0') {
+
+ /* It is our wrapper, so get the CC path, and execute the real binary in
+ * there ... */
+ inpipe = popen("/usr/bin/cc-config --get-bin-path", "r");
+ if (NULL == inpipe) {
+
+ fprintf(stderr, "Could not run /usr/bin/cc-config!\n");
+ exit(1);
+ }
+
+ buffer = (char *)malloc(MAXPATHLEN + 1);
+
+ if (fgets(buffer, MAXPATHLEN, inpipe) == 0) {
+
+ fprintf(stderr, "Could not get compiler binary path!\n");
+
+ if (buffer) {
+ free(buffer);
+ buffer = NULL;
+ }
+
+ pclose(inpipe);
+
+ exit(1);
+ }
+
+ sscanf(buffer, "%s", wrapperbin);
+ strncat(wrapperbin, "/", MAXPATHLEN - strlen(wrapperbin));
+ strncat(wrapperbin, wrappername, MAXPATHLEN - strlen(wrapperbin));
+
+ pclose(inpipe);
+
+ if (buffer) {
+ free(buffer);
+ buffer = NULL;
+ }
+ }
+
+ /* Ok, do it ... */
+ if (execv(wrapperbin, argv) < 0) {
+ fprintf(stderr, "Could not run/locate %s!\n", wrappername);
+ exit(1);
+ }
+
+ return 0;
+}
+