def add_common_nvcc_variables(env):
    """
    Add underlying common "NVIDIA CUDA compiler" variables that
    are used by multiple builders.
    """
    
    # nvcc needs '-I' prepended before each include path, regardless of platform
    env['_NVCC_CPPPATH'] = '${_concat("-I ", CPPPATH, "", __env__)}'
    
    # prepend -Xcompiler before each flag which needs it; some do not
    disallowed_flags = ['-std=c++03']
    
    # these flags don't need the -Xcompiler prefix because nvcc understands them
    # XXX might want to make these regular expressions instead of repeating similar flags
    need_no_prefix = ['-std=c++03', '-std=c++11', '-O0', '-O1', '-O2', '-O3']
    def flags_which_need_no_prefix(flags):
        # first filter out flags which nvcc doesn't allow
        flags = [flag for flag in flags if flag not in disallowed_flags]
        result = [flag for flag in flags if flag in need_no_prefix]
        return result
    
    def flags_which_need_prefix(flags):
        # first filter out flags which nvcc doesn't allow
        flags = [flag for flag in flags if flag not in disallowed_flags]
        result = [flag for flag in flags if flag not in need_no_prefix]
        return result
    
    env['_NVCC_BARE_FLAG_FILTER'] = flags_which_need_no_prefix
    env['_NVCC_PREFIXED_FLAG_FILTER'] = flags_which_need_prefix
    
    # CCFLAGS: options passed to C and C++ compilers
    env['_NVCC_BARE_CCFLAGS']      = '${_concat("",            CCFLAGS, "", __env__, _NVCC_BARE_FLAG_FILTER)}'
    env['_NVCC_PREFIXED_CCFLAGS']  = '${_concat("-Xcompiler ", CCFLAGS, "", __env__, _NVCC_PREFIXED_FLAG_FILTER)}'
    env['_NVCC_CCFLAGS']           = '$_NVCC_BARE_CCFLAGS $_NVCC_PREFIXED_CCFLAGS'

    # CXXFLAGS: options passed to C++ compilers
    env['_NVCC_BARE_CXXFLAGS']     = '${_concat("",            CXXFLAGS, "", __env__, _NVCC_BARE_FLAG_FILTER)}'
    env['_NVCC_PREFIXED_CXXFLAGS'] = '${_concat("-Xcompiler ", CXXFLAGS, "", __env__, _NVCC_PREFIXED_FLAG_FILTER)}'
    env['_NVCC_CXXFLAGS']          = '$_NVCC_BARE_CXXFLAGS $_NVCC_PREFIXED_CXXFLAGS'
    
    # CPPFLAGS: C preprocessor flags
    env['_NVCC_BARE_CPPFLAGS']      = '${_concat("",            CPPFLAGS, "", __env__, _NVCC_BARE_FLAG_FILTER)}'
    env['_NVCC_PREFIXED_CPPFLAGS']  = '${_concat("-Xcompiler ", CPPFLAGS, "", __env__, _NVCC_PREFIXED_FLAG_FILTER)}'
    env['_NVCC_CPPFLAGS']           = '$_NVCC_BARE_CPPFLAGS $_NVCC_PREFIXED_CPPFLAGS'

    # this function takes a list of compilers, and it returns the list with the name of nvcc's default host compiler removed
    # this is used in the _concat() call below to use the -ccbin switch with nvcc only if env['CXX'] specifies a host compiler
    # different than its default
    def filter_default_host_compiler(words):
        if 'gcc' in words:
            return []
        elif 'g++' in words:
            return []
        return words

    env['_NVCC_DEFAULT_HOST_COMPILER_FILTER'] = filter_default_host_compiler

    # CCBIN: the name of the c++ compiler to use for host code
    env['_NVCC_CCBIN'] = '${_concat("-ccbin=", CXX, "", __env__, _NVCC_DEFAULT_HOST_COMPILER_FILTER)}'
    
    # assemble portion of the command line common to all nvcc commands
    env['_NVCC_COMMON_CMD'] = '$_NVCC_CCBIN $_NVCC_CPPFLAGS $_CPPDEFFLAGS $_NVCC_CPPPATH'