Index: head/Mk/Scripts/functions.sh =================================================================== --- head/Mk/Scripts/functions.sh (revision 463258) +++ head/Mk/Scripts/functions.sh (revision 463259) @@ -1,263 +1,263 @@ #!/bin/sh # $FreeBSD$ # This file for common functions used for port scripts. # # MAINTAINER: portmgr@FreeBSD.org # Expand TMPPLIST to absolute paths, splitting files and dirs into separate # descriptors. # Input: # fd:0 - plist to parse # Required params: # PREFIX # parse_comments: Whether to parse and include commented files. # Output: # fd:1 - list of files # fd:2 - stderr # fd:3 - list of directories parse_plist() { local cwd cwd_save commented_cwd comment line newcwd parse_comments \ PREFIX PREFIX="${1}" parse_comments="${2:-1}" cwd=${PREFIX} cwd_save= commented_cwd= while read -r line; do # Handle deactivated OPTIONS. Treat "@comment file" as being in # the plist so it does not show up as an orphan. PLIST_SUB uses # a @comment to deactive files. XXX: It would be better to # make all ports use @ignore instead of @comment. if [ ${parse_comments} -eq 1 -a -z "${line%%@comment *}" ]; then line="${line##*@comment }" # Remove @comment so it can be parsed as a file, # but later prepend it again to create a list of # all files commented and uncommented. comment="@comment " # Only consider comment @cwd for commented lines if [ -n "${commented_cwd}" ]; then [ -z "${cwd_save}" ] && cwd_save=${cwd} cwd=${commented_cwd} fi else comment= # On first uncommented line, forget about commented # @cwd if [ -n "${cwd_save}" ]; then cwd=${cwd_save} cwd_save= commented_cwd= fi fi # Strip (owner,group,perm) from keywords line="$(printf %s "$line" \ | sed -Ee 's/^@\([^)]*\)[[:space:]]+//' \ -e 's/^(@[[:alpha:]]+)\([^)]*\)[[:space:]]+/\1 /')" case $line in @dir*|'@unexec rmdir'*|'@unexec /bin/rmdir'*) line="$(printf %s "$line" \ | sed -Ee 's/\|\|.*//;s|[[:space:]]+[0-9]*[[:space:]]*>[&]?[[:space:]]*[^[:space:]]+||g' \ -e "/^@unexec[[:space:]]+(\/bin\/)?rmdir( -p)?/s|([^%])%D([^%])|\1${cwd}\2|g" \ -e '/^@unexec[[:space:]]+(\/bin\/)?rmdir( -p)?/s|"(.*)"[[:space:]]*|\1|g' \ -e 's/@unexec[[:space:]]+(\/bin\/)?rmdir( -p)?[[:space:]]+//' \ -e 's/@dir(rm|rmtry)?[[:space:]]+//' \ -e 's/[[:space:]]+$//')" case "$line" in /*) echo >&3 "${comment}${line%/}" ;; *) echo >&3 "${comment}${cwd}/${line%/}" ;; esac ;; # Handle [file] Keywords @info\ *|@shell\ *|@xmlcatmgr\ *) set -- $line shift case "$@" in /*) echo "${comment}$@" ;; *) echo "${comment}${cwd}/$@" ;; esac ;; @sample\ *) set -- $line shift sample_file=$1 target_file=${1%.sample} if [ $# -eq 2 ]; then target_file=$2 fi case "${sample_file}" in /*) ;; *) sample_file=${cwd}/${sample_file} ;; esac case "${target_file}" in /*) ;; *) target_file=${cwd}/${target_file} ;; esac # Ignore the actual file if it is in stagedir echo "@comment ${target_file}" echo "${comment}${sample_file}" ;; # Handle [dir] Keywords @fc\ *|@fcfontsdir\ *|@fontsdir\ *) set -- $line shift case "$@" in /*) echo >&3 "${comment}$@" ;; *) echo >&3 "${comment}${cwd}/$@" ;; esac ;; # order matters here - we must check @cwd first because # otherwise the @cwd* would also match it first, shadowing the # @cwd) line. @cwd|@cd) # Don't actually reset cwd for commented @cwd if [ -n "${comment}" ]; then commented_cwd=${PREFIX} else cwd=${PREFIX} fi ;; @cwd*|@cd*) set -- $line newcwd=$2 # Don't set cwd=/ as it causes // in plist and # won't match later. [ "${newcwd}" = "/" ] && newcwd= # Don't actually reset cwd for commented @cwd if [ -n "${comment}" ]; then commented_cwd=${newcwd} else cwd=${newcwd} fi unset newcwd ;; @*) ;; /*) echo "${comment}${line}" ;; *) echo "${comment}${cwd}/${line}" ;; esac done } validate_env() { local envfault for i ; do if ! (eval ": \${${i}?}" ) >/dev/null; then envfault="${envfault}${envfault:+" "}${i}" fi done if [ -n "${envfault}" ]; then echo "Environment variable ${envfault} undefined. Aborting." \ | fmt >&2 exit 1 fi } export_ports_env() { local export_vars make_cmd make_env var results value uses validate_env MAKE PORTSDIR - uses="python" + uses="python compiler:features" make_env="\ _PORTS_ENV_CHECK=1 \ PACKAGE_BUILDING=1 \ GNU_CONFIGURE=1 \ USE_JAVA=1 \ USE_LINUX=1 \ " make_cmd="${make_env}" export_vars="$(${MAKE} -f ${PORTSDIR}/Mk/bsd.port.mk \ -V PORTS_ENV_VARS ${make_env} USES="${uses}")" for var in ${export_vars}; do make_cmd="${make_cmd}${make_cmd:+ }-V ${var}=\${${var}:Q}" done # Bring in all the vars, but not empty ones. eval $(${MAKE} -f ${PORTSDIR}/Mk/bsd.port.mk ${make_cmd} \ USES="${uses}" | grep -v '=$' | sed -e 's,\\ $,,') for var in ${export_vars}; do # Export and display non-empty ones. This is not redundant # with above since we're looping on all vars here; do not # export a var we didn't eval in. value="$(eval echo \$${var})" if [ -n "${value}" ]; then export ${var} echo "export ${var}=\"${value}\"" fi done } distinfo_data() { local alg file alg=$1 file=$2 if [ \( -n "${dp_DISABLE_SIZE}" -a -n "${dp_NO_CHECKSUM}" \) -o ! -f "${dp_DISTINFO_FILE}" ]; then exit fi awk -v alg="$alg" -v file="${file}" \ '$1 == alg && $2 == "(" file ")" {print $4}' "${dp_DISTINFO_FILE}" } check_checksum_algorithms() { for alg in ${dp_CHECKSUM_ALGORITHMS}; do eval "alg_executable=\$dp_$alg" if [ -z "$alg_executable" ]; then ${dp_ECHO_MSG} "Checksum algorithm $alg: Couldn't find the executable." ${dp_ECHO_MSG} "Set $alg=/path/to/$alg in /etc/make.conf and try again." exit 1 elif [ ! -x "$alg_executable" ]; then ${dp_ECHO_MSG} "Checksum algorithm $alg: $alg_executable is not executable." ${dp_ECHO_MSG} "Fix modes, or change $alg=$alg_executable in /etc/make.conf and try again." exit 1 fi done } escape() { echo "$1" | sed -e 's/[&;()!#]/\\&/g' } unescape() { echo "$1" | sed -e 's/\\//g' } # Fetch vars from the Makefile and set them locally. # port_var_fetch ports-mgmt/pkg "" PKGNAME pkgname PKGBASE pkgbase ... # the 2nd variable is for passing any wanted make arguments, such as # DEPENDS_ARGS. port_var_fetch() { local origin="$1" local make_args="$2" local _makeflags _vars local _portvar _var _line _makeflags= _vars= shift 2 while [ $# -ge 2 ]; do _portvar="$1" _var="$2" _makeflags="${_makeflags}${_makeflags:+ }-V${_portvar}" _vars="${_vars}${_vars:+ }${_var}" shift 2 done set -- ${_vars} while read -r _line; do setvar "$1" "${_line}" shift done <<-EOF $(${dp_MAKE} -C "${origin}" ${make_args} ${_makeflags} || echo) EOF } Index: head/Mk/Uses/compiler.mk =================================================================== --- head/Mk/Uses/compiler.mk (revision 463258) +++ head/Mk/Uses/compiler.mk (revision 463259) @@ -1,245 +1,272 @@ # $FreeBSD$ # # Allows to determine the compiler being used # # Feature: compiler # Usage: USES=compiler or USES=compiler:ARGS # Valid ARGS: env (default, implicit) c++0x c++11-lib c++11-lang c11 openmp nestedfct features # # c++0x: The port needs a compiler understanding C++0X # c++11-lang: The port needs a compiler understanding C++11 # c++14-lang: The port needs a compiler understanding C++14 # gcc-c++11-lib:The port needs g++ compiler with a C++11 library # c++11-lib: The port needs a compiler understanding C++11 and with a C++11 ready standard library # c11: The port needs a compiler understanding C11 # openmp: The port needs a compiler understanding openmp # nestedfct: The port needs a compiler understanding nested functions # features: The port will determine the features supported by the default compiler # # Variable to test after # # COMPILER_TYPE: can be gcc or clang # ALT_COMPILER_TYPE: can be gcc or clang depending on COMPILER_TYPE, only set if the base system has 2 compilers # COMPILER_VERSION: first 2 digits of the version: 33 for clang 3.3.*, 47 for gcc 4.7.* # ALT_COMPILER_VERSION: first 2 digits of the version: 33 for clang 3.3.*, 47 for gcc 4.7.* of the ALT_COMPILER_TYPE # # COMPILER_FEATURES: the list of features supported by the compiler includes the standard C++ library. # CHOSEN_COMPILER_TYPE: can be gcc or clang (type of compiler chosen by the framework) # # MAINTAINER: portmgr@FreeBSD.org .if !defined(_INCLUDE_USES_COMPILER_MK) _INCLUDE_USES_COMPILER_MK= yes .if empty(compiler_ARGS) compiler_ARGS= env .endif VALID_ARGS= c++11-lib c++11-lang c++14-lang c11 features openmp env nestedfct c++0x gcc-c++11-lib +_CC_hash:= ${CC:hash} +_CXX_hash:= ${CXX:hash} + .if ${compiler_ARGS} == gcc-c++11-lib _COMPILER_ARGS+= features gcc-c++11-lib .elif ${compiler_ARGS} == c++11-lib _COMPILER_ARGS+= features c++11-lib .elif ${compiler_ARGS} == c++0x _COMPILER_ARGS+= features c++0x .elif ${compiler_ARGS} == c++11-lang _COMPILER_ARGS+= features c++11-lang .elif ${compiler_ARGS} == c++14-lang _COMPILER_ARGS+= features c++14-lang .elif ${compiler_ARGS} == c11 _COMPILER_ARGS+= features c11 .elif ${compiler_ARGS} == features _COMPILER_ARGS+= features .elif ${compiler_ARGS} == env _COMPILER_ARGS+= env .elif ${compiler_ARGS} == openmp _COMPILER_ARGS+= env openmp .elif ${compiler_ARGS} == nestedfct _COMPILER_ARGS+= env nestedfct .else IGNORE= Invalid argument "${compiler_ARGS}", valid arguments are: ${VALID_ARGS} _COMPILER_ARGS= # .endif .if ${_COMPILER_ARGS:Mc++*} || ${_COMPILER_ARGS:Mc11} _COMPILER_ARGS+= features .endif +.if defined(_CCVERSION_${_CC_hash}) +_CCVERSION= ${_CCVERSION_${_CC_hash}} +.else _CCVERSION!= ${CC} --version +_CCVERSION_${_CC_hash}= ${_CCVERSION} +PORTS_ENV_VARS+= _CCVERSION_${_CC_hash} +.endif COMPILER_VERSION= ${_CCVERSION:M[0-9].[0-9]*:tW:C/([0-9]).([0-9]).*/\1\2/g} .if ${_CCVERSION:Mclang} COMPILER_TYPE= clang .else COMPILER_TYPE= gcc .endif ALT_COMPILER_VERSION= 0 ALT_COMPILER_TYPE= none -_ALTCCVERSION= +_ALTCCVERSION= none +.if defined(_ALTCCVERSION_${_CC_hash}) +_ALTCCVERSION= ${_ALTCCVERSION_${_CC_hash}} +.else .if ${COMPILER_TYPE} == gcc && exists(/usr/bin/clang) .if ${ARCH} == amd64 || ${ARCH} == i386 # clang often non-default for a reason _ALTCCVERSION!= /usr/bin/clang --version .endif .elif ${COMPILER_TYPE} == clang && exists(/usr/bin/gcc) _ALTCCVERSION!= /usr/bin/gcc --version .endif +_ALTCCVERSION_${_CC_hash}= ${_ALTCCVERSION} +PORTS_ENV_VARS+= _ALTCCVERSION_${_CC_hash} +.endif ALT_COMPILER_VERSION= ${_ALTCCVERSION:M[0-9].[0-9]*:tW:C/([0-9]).([0-9]).*/\1\2/g} .if ${_ALTCCVERSION:Mclang} ALT_COMPILER_TYPE= clang -.elif !empty(_ALTCCVERSION) +.elif ${_ALTCCVERSION} != none ALT_COMPILER_TYPE= gcc .endif CHOSEN_COMPILER_TYPE= ${COMPILER_TYPE} .if ${_COMPILER_ARGS:Mopenmp} .if ${COMPILER_TYPE} == clang USE_GCC= yes CHOSEN_COMPILER_TYPE= gcc .endif .endif .if ${_COMPILER_ARGS:Mnestedfct} .if ${COMPILER_TYPE} == clang USE_GCC= any CHOSEN_COMPILER_TYPE= gcc .endif .endif .if ${_COMPILER_ARGS:Mfeatures} +.if defined(_CXXINTERNAL_${_CXX_hash}) +_CXXINTERNAL= ${_CXXINTERNAL_${_CXX_hash}} +.else _CXXINTERNAL!= ${CXX} -\#\#\# /dev/null 2>&1 +_CXXINTERNAL_${_CXX_hash}= ${_CXXINTERNAL} +PORTS_ENV_VARS+= _CXXINTERNAL_${_CXX_hash} +.endif .if ${_CXXINTERNAL:M\"-lc++\"} COMPILER_FEATURES= libc++ .else COMPILER_FEATURES= libstdc++ .endif CSTD= c89 c99 c11 gnu89 gnu99 gnu11 CXXSTD= c++98 c++0x c++11 c++14 gnu++98 gnu++11 .for std in ${CSTD} ${CXXSTD} _LANG=c .if ${CXXSTD:M${std}} _LANG=c++ .endif -OUTPUT_${std}!= echo | ${CC} -std=${std} -c -x ${_LANG} /dev/null -o /dev/null 2>&1; echo +.if defined(OUTPUT_${std:hash}_${_CC_hash}) +OUTPUT_${std}= ${OUTPUT_${std:hash}_${_CC_hash}} +.else +OUTPUT_${std}!= ${CC} -std=${std} -c -x ${_LANG} /dev/null -o /dev/null 2>&1; echo yes +OUTPUT_${std:hash}_${_CC_hash}= ${OUTPUT_${std}} +PORTS_ENV_VARS+= OUTPUT_${std:hash}_${_CC_hash} +.endif .if !${OUTPUT_${std}:M*error*} COMPILER_FEATURES+= ${std} .endif .endfor .endif .if ${_COMPILER_ARGS:Mc++11-lib} .if !${COMPILER_FEATURES:Mc++11} USE_GCC= yes CHOSEN_COMPILER_TYPE= gcc .elif ${COMPILER_TYPE} == clang && ${COMPILER_FEATURES:Mlibstdc++} USE_GCC= yes CHOSEN_COMPILER_TYPE= gcc .endif .endif .if ${_COMPILER_ARGS:Mc++14-lang} .if !${COMPILER_FEATURES:Mc++14} .if (defined(FAVORITE_COMPILER) && ${FAVORITE_COMPILER} == gcc) || (${ARCH} != amd64 && ${ARCH} != i386) # clang not always supported on Tier-2 USE_GCC= yes CHOSEN_COMPILER_TYPE= gcc .elif (${COMPILER_TYPE} == clang && ${COMPILER_VERSION} < 35) || ${COMPILER_TYPE} == gcc .if ${ALT_COMPILER_TYPE} == clang && ${ALT_COMPILER_VERSION} >= 35 CPP= clang-cpp CC= clang CXX= clang++ CHOSEN_COMPILER_TYPE= clang .else BUILD_DEPENDS+= ${LOCALBASE}/bin/clang50:devel/llvm50 CPP= ${LOCALBASE}/bin/clang-cpp50 CC= ${LOCALBASE}/bin/clang50 CXX= ${LOCALBASE}/bin/clang++50 CHOSEN_COMPILER_TYPE= clang .endif .endif .endif .endif .if ${_COMPILER_ARGS:Mc++11-lang} .if !${COMPILER_FEATURES:Mc++11} .if (defined(FAVORITE_COMPILER) && ${FAVORITE_COMPILER} == gcc) || (${ARCH} != amd64 && ${ARCH} != i386) # clang not always supported on Tier-2 USE_GCC= yes CHOSEN_COMPILER_TYPE= gcc .elif ${COMPILER_TYPE} == gcc .if ${ALT_COMPILER_TYPE} == clang CPP= clang-cpp CC= clang CXX= clang++ CHOSEN_COMPILER_TYPE= clang .else BUILD_DEPENDS+= ${LOCALBASE}/bin/clang50:devel/llvm50 CPP= ${LOCALBASE}/bin/clang-cpp50 CC= ${LOCALBASE}/bin/clang50 CXX= ${LOCALBASE}/bin/clang++50 CHOSEN_COMPILER_TYPE= clang .endif .endif .endif .endif .if ${_COMPILER_ARGS:Mc++0x} .if !${COMPILER_FEATURES:Mc++0x} .if (defined(FAVORITE_COMPILER) && ${FAVORITE_COMPILER} == gcc) || (${ARCH} != amd64 && ${ARCH} != i386) # clang not always supported on Tier-2 USE_GCC= yes CHOSEN_COMPILER_TYPE= gcc .elif ${COMPILER_TYPE} == gcc .if ${ALT_COMPILER_TYPE} == clang CPP= clang-cpp CC= clang CXX= clang++ CHOSEN_COMPILER_TYPE= clang .else BUILD_DEPENDS+= ${LOCALBASE}/bin/clang50:devel/llvm50 CHOSEN_COMPILER_TYPE= clang CPP= ${LOCALBASE}/bin/clang-cpp50 CC= ${LOCALBASE}/bin/clang50 CXX= ${LOCALBASE}/bin/clang++50 .endif .endif .endif .endif .if ${_COMPILER_ARGS:Mc11} .if !${COMPILER_FEATURES:Mc11} .if (defined(FAVORITE_COMPILER) && ${FAVORITE_COMPILER} == gcc) || (${ARCH} != amd64 && ${ARCH} != i386) # clang not always supported on Tier-2 USE_GCC= yes CHOSEN_COMPILER_TYPE= gcc .elif ${COMPILER_TYPE} == gcc .if ${ALT_COMPILER_TYPE} == clang CPP= clang-cpp CC= clang CXX= clang++ CHOSEN_COMPILER_TYPE= clang .else BUILD_DEPENDS+= ${LOCALBASE}/bin/clang50:devel/llvm50 CHOSEN_COMPILER_TYPE= clang CPP= ${LOCALBASE}/bin/clang-cpp50 CC= ${LOCALBASE}/bin/clang50 CXX= ${LOCALBASE}/bin/clang++50 .endif .endif .endif .endif .if ${_COMPILER_ARGS:Mgcc-c++11-lib} USE_GCC= yes CHOSEN_COMPILER_TYPE= gcc .if ${COMPILER_FEATURES:Mlibc++} CXXFLAGS+= -nostdinc++ -isystem /usr/include/c++/v1 LDFLAGS+= -L${WRKDIR} _USES_configure+= 200:gcc-libc++-configure gcc-libc++-configure: @${LN} -fs /usr/lib/libc++.so ${WRKDIR}/libstdc++.so .endif .endif .endif