From 571f588a5c6622ead0ed757b2884a76bb45bdb56 Mon Sep 17 00:00:00 2001 From: John Marino Date: Tue, 21 Oct 2014 15:11:34 +0200 Subject: [PATCH] customcc: Improve wrapper script efficiency and capabilities The wrapper script had some deficies, such as: * awk called every invocation * cc and gcc treated the same * c++ and g++ treated the same * evals for variables not used * every invocation of c++ or g++ called cc -dumpmachine * g++ hardcoded to dports include scheme * no support for "CC" or "gcov" (both defined by base compilers) The update addresses these by: * awk eliminated by pushing INCOPT definition to defaults/compilers.conf * cc -dumpmachine eliminated during creation of defaults/compilers.conf It was only used for dports gcc, so with the assumption that the dports compiler matches the uname information (a decent assumption), this was predefined, yet overridable by /etc/compilers.conf * cc is treated separately from gcc * CC and c++ are treated the same but separately from g++ * by wrapper default, gcc and g++ refer to base gcc4.7, but the default compilers.conf sets them to the same as the specified dports gcc * Support for clang, clang++, clang-cpp, CC, and gcov was added * Support for base clang, clang++, and clang-cpp was added in anticipation of bringing clang into base. * variables are only evaluated if used. * supports the ability to have gcc, g++, clang, clang++ point to base compilers while cc, c++, CC point to custom compiler. However, the custom compiler can also point to any combination of cc, gcc, c++, and g++ and that's controllable by compilers.conf. The /etc/defaults/compilers.conf file was augmented and support for clang35 from dports added. man 5 compilers.conf was edited accordingly with placeholders for _CLANG, _CLANGCXX and _CLANGCPP which aren't applicable until clang comes into base. --- etc/defaults/compilers.conf | 73 +++++++++++++++ libexec/customcc/Makefile | 15 +++- libexec/customcc/cc.sh | 152 ++++++++++++++++++++++++-------- share/man/man5/compilers.conf.5 | 88 ++++++++++++------ 4 files changed, 265 insertions(+), 63 deletions(-) diff --git a/etc/defaults/compilers.conf b/etc/defaults/compilers.conf index 5cc88e3662..a885c4ebd5 100644 --- a/etc/defaults/compilers.conf +++ b/etc/defaults/compilers.conf @@ -29,20 +29,93 @@ # SUCH DAMAGE. # + +STD_INCOPT="-nostdinc -iprefix ${INCPREFIX} -iwithprefixbefore /usr/include" +DPORT_GCC_STD_INCOPTXX="-isystem /usr/local/lib/${CCVER}/include/c++ \ + -isystem /usr/local/lib/${CCVER}/include/c++/${MACHARCH}-portbld-${MACHREL}" +DPORT_CLANG_STD_INCOPTXX="-isystem /usr/include/c++/4.7" + + +# For each custom compiler definition, it is mandatory to define the +# following variables: +# _CC (path to C compiler) +# _CXX (path to C++ compiler) +# _CPP (path to pre-processor) +# _INCOPT (include options for cc, c++ and cpp) +# _INCOPTCXX (extra include options for c++) +# +# The following variables are optional: +# _CFLAGS (extra CFLAGS) +# _CXXFLAGS (extra CXXFLAGS) +# _CPPFLAGS (extra CPPFLAGS) +# _GCOV (path to gcov, /usr/libexec/gcc47/gcov is default) +# +# The following commands call the base compilers by default: +# gcc, g++, clang, clang++, clang-cpp +# +# However, these can be individually overridden: +# _GCC (path executed when /usr/bin/gcc called) +# _GXX (path executed when /usr/bin/g++ called) +# _CLANG (path executed when /usr/bin/clang called) +# _CLANGCXX (path executed when /usr/bin/clang++ called) +# _CLANGCPP (path executed when /usr/bin/clang-cpp called) +# + + # lang/gcc5 (dports) # gcc5_CC=/usr/local/bin/gcc5 gcc5_CXX=/usr/local/bin/g++5 gcc5_CPP=/usr/local/bin/cpp5 +gcc5_GCOV=/usr/local/bin/gcov5 +gcc5_INCOPT=${STD_INCOPT} +gcc5_INCOPTCXX=${DPORT_GCC_STD_INCOPTXX} +gcc5_GCC=${gcc5_CC} +gcc5_GXX=${gcc5_CXX} +# +# Put the 3 following lines uncommented in /etc/compilers.conf to force +# /usr/bin/clang* to execute the custom gcc5 compiler instead of base clang +# gcc5_CLANG=${gcc5_CC} +# gcc5_CLANGCXX=${gcc5_CXX} +# gcc5_CLANGCPP=${gcc5_CPP} + # lang/gcc49 (dports) # gcc49_CC=/usr/local/bin/gcc49 gcc49_CXX=/usr/local/bin/g++49 gcc49_CPP=/usr/local/bin/cpp49 +gcc49_GCOV=/usr/local/bin/gcov49 +gcc49_INCOPT=${STD_INCOPT} +gcc49_INCOPTCXX=${DPORT_GCC_STD_INCOPTXX} +gcc49_GCC=${gcc49_CC} +gcc49_GXX=${gcc49_CXX} + # lang/gcc48 (dports) # gcc48_CC=/usr/local/bin/gcc48 gcc48_CXX=/usr/local/bin/g++48 gcc48_CPP=/usr/local/bin/cpp48 +gcc48_GCOV=/usr/local/bin/gcov48 +gcc48_INCOPT=${STD_INCOPT} +gcc48_INCOPTCXX=${DPORT_GCC_STD_INCOPTXX} +gcc48_GCC=${gcc48_CC} +gcc48_GXX=${gcc48_CXX} + + +# lang/clang35 (dports) +# +clang35_CC=/usr/local/bin/clang35 +clang35_CXX=/usr/local/bin/clang++35 +clang35_CPP=/usr/local/bin/clang-cpp35 +clang35_INCOPT=${STD_INCOPT} +clang35_INCOPTCXX=${DPORT_CLANG_STD_INCOPTXX} +clang35_CLANG=${clang35_CC} +clang35_CLANGCXX=${clang35_CXX} +clang35_CLANGCPP=${clang35_CPP} +# +# Put the 2 following lines uncommented in /etc/compilers.conf to force +# /usr/bin/gcc* to execute the custom clang35 compiler instead of base gcc +# clang35_GCC=${clang35_CC} +# clang35_GXX=${clang35_CXX} diff --git a/libexec/customcc/Makefile b/libexec/customcc/Makefile index 3eff760a46..f4abcbc6b2 100644 --- a/libexec/customcc/Makefile +++ b/libexec/customcc/Makefile @@ -3,11 +3,22 @@ SCRIPTSDIR= /usr/libexec/custom SYMLINKS= cc ${SCRIPTSDIR}/cpp \ cc ${SCRIPTSDIR}/c++ \ cc ${SCRIPTSDIR}/gcc \ - cc ${SCRIPTSDIR}/g++ + cc ${SCRIPTSDIR}/g++ \ + cc ${SCRIPTSDIR}/clang-cpp \ + cc ${SCRIPTSDIR}/clang++ \ + cc ${SCRIPTSDIR}/clang \ + cc ${SCRIPTSDIR}/gcov \ + cc ${SCRIPTSDIR}/CC CLEANFILES= cc NOMAN= +DFLYVERSION!= awk '/^\#define[[:blank:]]__DragonFly_version/ {print $$3}' < ${.CURDIR}/../../sys/sys/param.h +MACHREL!= echo ${DFLYVERSION} | awk '{a=int($$1/100000); b=int(($$1-(a*100000))/100); print a "." b}' + ${.OBJDIR}/cc: cc.sh - sed "s#@@INCPREFIX@@#${USRDATA_PREFIX:S;^$;/;}#g" $> > $@ + sed -e "s#@@INCPREFIX@@#${USRDATA_PREFIX:S;^$;/;}#g" \ + -e "s|@@MACHARCH@@|${MACHINE_ARCH}|g" \ + -e "s|@@MACHREL@@|${MACHREL}|g" \ + $> > $@ .include diff --git a/libexec/customcc/cc.sh b/libexec/customcc/cc.sh index 4f7a3ba628..ceaada8cc5 100644 --- a/libexec/customcc/cc.sh +++ b/libexec/customcc/cc.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (c) 2009-2012 +# Copyright (c) 2009-2014 # The DragonFly Project. All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -32,44 +32,126 @@ # CNAME=$(basename $0) -CCVER3=`echo ${CCVER} | awk '{print substr($0, 1, 3);}'` -if [ "${CCVER3}" = "gcc" ]; then - INCOPT="-nostdinc \ - -iprefix @@INCPREFIX@@ \ - -iwithprefixbefore /usr/include" -fi +INCPREFIX=@@INCPREFIX@@ +MACHARCH=@@MACHARCH@@ +MACHREL=@@MACHREL@@ . /etc/defaults/compilers.conf [ -f /etc/compilers.conf ] && . /etc/compilers.conf -CUSTOM_CC=`eval echo \$\{${CCVER}_CC\}` -CUSTOM_CFLAGS=`eval echo \$\{${CCVER}_CFLAGS\}` -CUSTOM_CXX=`eval echo \$\{${CCVER}_CXX\}` -CUSTOM_CXXFLAGS=`eval echo \$\{${CCVER}_CXXFLAGS\}` -CUSTOM_CPP=`eval echo \$\{${CCVER}_CPP\}` -CUSTOM_CPPFLAGS=`eval echo \$\{${CCVER}_CPPFLAGS\}` -if [ "${CNAME}" = "cc" -o "${CNAME}" = "gcc" ]; then - if [ -z ${CUSTOM_CC} ]; then - echo "${CCVER}_CC undefined, see compilers.conf(5)" +case ${CNAME} in + gcc) + CUSTOM_GCC=`eval echo \$\{${CCVER}_GCC\}` + if [ -n "${CUSTOM_GCC}" ]; then + COMPILER=${CUSTOM_GCC} + INCOPT=`eval echo \$\{${CCVER}_INCOPT\}` + else + COMPILER=/usr/libexec/gcc47/gcc + INCOPT=${STD_INCOPT} + fi + ;; + g++) + CUSTOM_GXX=`eval echo \$\{${CCVER}_GXX\}` + if [ -n "${CUSTOM_GXX}" ]; then + COMPILER=${CUSTOM_GXX} + INCOPT=`eval echo \$\{${CCVER}_INCOPT\}` + INCOPTCXX=`eval echo \$\{${CCVER}_INCOPTCXX\}` + else + COMPILER=/usr/libexec/gcc47/g++ + INCOPT=${GCC_INCOPT} + INCOPTCXX="-isystem /usr/include/c++/4.7" + fi + ;; + clang) + CUSTOM_CLANG=`eval echo \$\{${CCVER}_CLANG\}` + if [ -n "${CUSTOM_CLANG}" ]; then + COMPILER=${CUSTOM_CLANG} + INCOPT=`eval echo \$\{${CCVER}_INCOPT\}` + else + COMPILER=/usr/libexec/clangbase/clang + INCOPT=${STD_INCOPT} + fi + ;; + clang++) + CUSTOM_CLANGCXX=`eval echo \$\{${CCVER}_CLANGCXX\}` + if [ -n "${CUSTOM_CLANGCXX}" ]; then + COMPILER=${CUSTOM_CLANGCXX} + INCOPT=`eval echo \$\{${CCVER}_INCOPT\}` + INCOPTCXX=`eval echo \$\{${CCVER}_INCOPTCXX\}` + else + COMPILER=/usr/libexec/clangbase/clang++ + INCOPT=${CLANG_INCOPT} + INCOPTCXX="-isystem /usr/include/c++/4.7" + fi + ;; + cc) + CUSTOM_CC=`eval echo \$\{${CCVER}_CC\}` + if [ -n ${CUSTOM_CC} ]; then + COMPILER=${CUSTOM_CC} + INCOPT=`eval echo \$\{${CCVER}_INCOPT\}` + else + echo "${CCVER}_CC undefined, see compilers.conf(5)" + exit 1 + fi + ;; + c++|CC) + CUSTOM_CXX=`eval echo \$\{${CCVER}_CXX\}` + if [ -n ${CUSTOM_CXX} ]; then + COMPILER=${CUSTOM_CXX} + INCOPT=`eval echo \$\{${CCVER}_INCOPT\}` + INCOPTCXX=`eval echo \$\{${CCVER}_INCOPTCXX\}` + else + echo "${CCVER}_CXX undefined, see compilers.conf(5)" + exit 1 + fi + ;; + cpp) + CUSTOM_CPP=`eval echo \$\{${CCVER}_CPP\}` + if [ -n ${CUSTOM_CPP} ]; then + COMPILER=${CUSTOM_CPP} + INCOPT=`eval echo \$\{${CCVER}_INCOPT\}` + else + echo "${CCVER}_CPP undefined, see compilers.conf(5)" + exit 1 + fi + ;; + clang-cpp) + CUSTOM_CLANGCPP=`eval echo \$\{${CCVER}_CLANGCPP\}` + if [ -n "${CUSTOM_CLANGCPP}" ]; then + COMPILER=${CUSTOM_CLANGCPP} + INCOPT=`eval echo \$\{${CCVER}_INCOPT\}` + else + COMPILER=/usr/libexec/clangbase/clang-cpp + INCOPT=${CLANG_INCOPT} + fi + ;; + gcov) + CUSTOM_GCOV=`eval echo \$\{${CCVER}_GCOV\}` + if [ -n "${CUSTOM_GCOV}" ]; then + exec ${CUSTOM_GCOV} "$@" + else + exec /usr/libexec/gcc47/gcov "$@" + fi + ;; + *) + echo "customcc: unrecognized command '${CNAME}'" exit 1 - fi - exec ${CUSTOM_CC} ${INCOPT} ${CUSTOM_CFLAGS} "$@" -elif [ "${CNAME}" = "c++" -o "${CNAME}" = "g++" ]; then - if [ -z ${CUSTOM_CXX} ]; then - echo "${CCVER}_CXX undefined, see compilers.conf(5)" - exit 1 - fi - INCOPT="${INCOPT} -isystem /usr/local/lib/${CCVER}/include/c++" - CXXMACHINE=`${CUSTOM_CXX} -dumpmachine` - MDINCOPT="-isystem \ - /usr/local/lib/${CCVER}/include/c++/${CXXMACHINE}" - exec ${CUSTOM_CXX} ${INCOPT} ${MDINCOPT} ${CUSTOM_CXXFLAGS} "$@" -elif [ "${CNAME}" = "cpp" ]; then - if [ -z ${CUSTOM_CPP} ]; then - echo "${CCVER}_CPP undefined, see compilers.conf(5)" - exit 1 - fi - exec ${CUSTOM_CPP} ${INCOPT} ${CUSTOM_CPPFLAGS} "$@" -fi + ;; +esac + +case ${CNAME} in + gcc|clang|cc) + CUSTOM_CFLAGS=`eval echo \$\{${CCVER}_CFLAGS\}` + exec ${COMPILER} ${INCOPT} ${CUSTOM_CFLAGS} "$@" + ;; + g++|clang++|c++|CC) + CUSTOM_CXXFLAGS=`eval echo \$\{${CCVER}_CXXFLAGS\}` + exec ${COMPILER} ${INCOPT} ${INCOPTCXX} ${CUSTOM_CFLAGS} "$@" + ;; + cpp|clang-cpp) + CUSTOM_CPPFLAGS=`eval echo \$\{${CCVER}_CPPFLAGS\}` + exec ${COMPILER} ${INCOPT} ${CUSTOM_CPPFLAGS} "$@" + ;; +esac diff --git a/share/man/man5/compilers.conf.5 b/share/man/man5/compilers.conf.5 index 2ddf388704..6cbe521fc0 100644 --- a/share/man/man5/compilers.conf.5 +++ b/share/man/man5/compilers.conf.5 @@ -29,7 +29,7 @@ .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd October 14, 2014 +.Dd October 21, 2014 .Dt COMPILERS.CONF 5 .Os .Sh NAME @@ -53,45 +53,81 @@ file specifies the default settings for all variables, the .Pa /etc/compilers.conf file specifies override settings. .Pp -The following variables are available: -.Bl -tag -width ".Va _CPPFLAGS" +The following variable definitions are mandatory: +.Bl -tag -width ".Va _INCOPTCXX" .It Va _CC The pathname of the .Nm cc -program of the compiler. -.It Va _CFLAGS -Any additional flags to pass to -.Va _CC . +compiler. +.It Va _CXX +The pathname of the +.Nm c++ +and +.Nm CC +compilers. .It Va _CPP The pathname of the .Nm cpp -program of the compiler. -.It Va _CPPFLAGS -Any additional flags to pass to -.Va _CPP . -.It Va _CXX +pre-processor. +.It Va _INCOPT +The include flags passed to the invocation of every version of c compiler, +c++ compiler, and pre-processor program. This is normally set to the +predefined STD_INCOPT variable. +.It Va _INCOPTCXX +The include flags passed to the invocation of every version of c++ +compiler. This is normally set to either the DPORT_GCC_STD_INCOPTXX or +DPORT_CLANG_STD_INCOPTXX predefined variables. +.El +.Pp +These variables are optionally available: +.Bl -tag -width ".Va _INCOPTCXX" +.It Va _GCC The pathname of the -.Nm c++ -program of the compiler. +.Nm gcc +compiler. +.It Va _GXX +The pathname of the +.Nm g++ +compiler. +.It Va _GCOV +The pathname of the +.Nm gcov +coverage testing tool. +.\" +.\" Uncomment the following after clang is brought into base +.\".It Va _CLANG +.\"The pathname of the +.\".Nm clang +.\"compiler. +.\".It Va _CLANGCXX +.\"The pathname of the +.\".Nm clang++ +.\"compiler. +.\".It Va _CLANGCPP +.\"The pathname of the +.\".Nm clang-cpp +.\"pre-processor. +.\" +.It Va _CFLAGS +Additional flags to pass to the c compilers. .It Va _CXXFLAGS -Any additional flags to pass to -.Va _CXX . +Additional flags to pass to the c++ compilers. +.It Va _CPPFLAGS +Additional flags to pass to the pre-processors. .El .Pp -Currently, defaults are provided for +Currently, defaults are provided for the +.Xr dports 7 +compilers of +.Nm clang35 +.Pa ( lang/clang35 ) , .Nm gcc48 -(installed from -.Xr dports 7 Ap s -.Pa lang/gcc48 ) , +.Pa ( lang/gcc48 ) , .Nm gcc49 -(installed from -.Xr dports 7 Ap s -.Pa lang/gcc49 ) , +.Pa ( lang/gcc49 ) , and .Nm gcc5 -(installed from -.Xr dports 7 Ap s -.Pa lang/gcc5 ) . +.Pa ( lang/gcc5 ) . .Sh IMPLEMENTATION NOTES In .Dx , -- 2.41.0