#
#     Copyright (c) 2017-2018, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#

# Compiler Configurations for C, C++ and Fortran.
#

# YES indicates that we treat chars as unsigned. This can be used to set apropriate
# macros when needed.
variable DEFUNSIGNED is
	help(Default char is unsigned)
	default($DEFDEFUNSIGNED);

variable CPP1ARGS is		# appended by many switches; add --c for C driver
	help(Switches passed to C++ phase 1)
	default();
append CPP1ARGS=$if($FATALERRORS,$FATALERRORS,$MAXERRORS);

variable DIALECTARGS is		# appended by many switches
	help(Switches passed to C++ phase 1)
	default($if($notequal($DRIVER,C++),--c));

variable CPP1ONLY is		# set by -N
	help(C++ phase 1 only)
	default();

variable CPPMCOMP is		# can be changed by targetrc
	hide
	help(Name of the merged C++ compiler phase 1 and 2 module);

variable CPPCOMPDIR is		# set by -Yc
	help(Directory containing the C compiler)
	default($DEFCCOMPDIR);

variable CPPPREINC is		# cleared by --no_preincludes
	help(--preappend switches passed to C++ phase 1);
variable NEWPP1 is default(--preinclude _cplus_preinclude.h --preinclude_macros _cplus_macros.h);
append CPPPREINC=$(NEWPP1);

variable CPP2ARGS is		# appended by many switches
	help(Switches passed to C++ phase 2);

variable CPP1DEFARGS is		# appended by many switches
	help(Switches passed to C++ phase 1)
	default($PREINCLUDE);

variable CPP2DEFARGS is
	help(Switches passed to C++ phase 2)
	default($ZCDEF);

# The include path to pass to the EDG preprocessor.  This is a variable because
# it is used in two places.  Do not change this variable!  If you want to
# change the include path, change one of the many referenced variables.
variable EDG_INCLUDES is default(
	$foreach(i,$USRQUOTEINC,-I$i ) -I-
	$foreach(i,$USRINC,-I$i )
	$foreach(i,$ENVUSRINC,-I$i )
	$foreach(i,$USRSTDINC,--sys_include $i )
	$foreach(i,$ENVSYSINC,--sys_include $i )
    $foreach(i,$replace($USER_INCLUDE_PATH,",", ), -I$i )
	$foreach(i,$SITEINC,--sys_include $i )
	$foreach(i,$ACCPRESTDINC,--sys_include $i )
	$foreach(i,$OMPPRESTDINC,--sys_include $i )
	$foreach(i,$COMPINCDIRFULL,--sys_include $i )
	$foreach(i,$CUDAINC,--sys_include $i )
	$foreach(i,$SYSTEMINC,--sys_include $i )
	$foreach(i,$USRPOSTSTDINC,--sys_include $i )
	$foreach(i,$NVOPTLINCDIR,--sys_include $i ));


variable DEF_PGCG_SOURCE is default();

variable DEFCPPINC is default($OMPPRESTDINC $COMPBASE/$COMPSYS/$COMPVER/$quote($COMPINCPREFIX)include  $if($IS_CPLUS,$GPPDIR) $NVOPTLINCDIR);

variable CCOMPENTRY is default(nvcpfe);

variable CPP2ONLYENTRY is default(nvcpfe);

variable CCOMPCOMMANDS is default($if($PREPROCONLY,$CCOMPENTRY,$ifn($EXTRACTINLINE,$CCOMPENTRY,$CPP2ONLYENTRY)));

variable CPPEXTCOMMANDS is
	help(C++ extract commands)
	default($CCOMPENTRY);

variable OVERRIDESUFFIX is default();  # Set by the -x switch.

# Fully expanded version of COMPINCDIR
variable COMPINCDIRFULL is
	default($foreach(dd,$COMPINCDIR,$COMPBASE/$COMPSYS/$COMPVER/$(COMPINCPREFIX)$dd ));

# System include files.  Either GPPDIR for C++, or GCCINC for C and Fortran.
# GPPDIR already includes everything from GCCINC, so it is one or the other,
# never both.
variable SYSTEMINC is
	default($if($IS_CPLUS,$GPPDIR,$GCCINC)
          $replace($WININCLUDE,";", ));

variable CPATH_ENV is environment(CPATH);
variable ENVUSRINC is default($replace($CPATH_ENV,":", ));

variable C_INCLUDE_PATH_ENV is environment(C_INCLUDE_PATH);
variable CPLUS_INCLUDE_PATH_ENV is environment(CPLUS_INCLUDE_PATH);
variable ENVSYSINC is
	default($replace($if($IS_CPLUS,$CPLUS_INCLUDE_PATH_ENV,$C_INCLUDE_PATH_ENV),":", ));

# Chose highest compute capability, except "next"
variable MOSTCAPABLECOMPILEDCC is default($if($equal($first($COMPUTECAPS),next),$first($rest($COMPUTECAPS))0,$first($COMPUTECAPS)0));

tool nvcpfe is hide help(C++ phases 1 and 2 merged)
	program($CPPMCOMP) directory($CPPCOMPDIR);

switch -alias is
	help(Select optimizations based on type-based pointer alias rules (deprecated, use -f[no-]strict-aliasing instead))
	helpgroup(opt)
	keyword(
	    ansi(help(Enable optimizations using ANSI C/C++ type-based pointer disambiguation)
		set(ALIASMODE=))
	    traditional(help(Disable C/C++ optimizations based on type-based pointer disambiguation)
		set(ALIASMODE=-x 2 0x400 -x 209 0x10))
	)
	onekeyword
  append(RW=$warning( The -alias switch is deprecated, please use -f[no-]strict-aliasing instead));

switch -B is
	help(Allow C++ comments in C source)
	helpgroup(language)
	set(BMODE=-x 123 4);

switch --wrap_diagnostics is
    help(Enable diagnostic wrapping)
    helpgroup(language)
    helpname(--[no_]wrap_diagnostics)
    append(CPP1ARGS=--wrap_diagnostics);
replace switch --no_wrap_diagnostics is
    help(Disable diagnostic wrapping) hide
    helpgroup(language)
    append(CPP1ARGS=--no_wrap_diagnostics);

switch -c23 is
	help(C23 language dialect)
	helpgroup(languag)
	set(IS_CPLUS=0)
	set(DIALECT_FLAG=-c23)
	set(GNU_EXTENSIONS=0)
	append(DIALECTARGS= --c23)
	append(CARGS=-x 122 0x400000 -y 125 0x100000)
	set(EXCEPTIONS_ENABLED=0)
	set(DEFC99=1);

switch -c17 is
	help(C17 language dialect)
	helpgroup(language)
	set(IS_CPLUS=0)
	set(DIALECT_FLAG=-c17)
	set(GNU_EXTENSIONS=0)
	append(DIALECTARGS= --c17)
	append(CARGS=-x 122 0x400000 -y 125 0x100000)
	set(EXCEPTIONS_ENABLED=0)
	set(DEFC99=1);

switch -c18 is helpgroup(language) shorthand(-c17);

switch -c11 is
	help(C11 language dialect)
	helpgroup(language)
	set(IS_CPLUS=0)
	set(DIALECT_FLAG=-c11)
	set(GNU_EXTENSIONS=0)
	append(DIALECTARGS= --c11)
	append(CARGS=-x 122 0x400000 -y 125 0x100000)
	set(EXCEPTIONS_ENABLED=0)
	set(DEFC99=1);

switch -c1x is hide shorthand(-c11);

switch -c99 is
	help(C99 language dialect)
	helpgroup(language)
	set(IS_CPLUS=0)
	set(DIALECT_FLAG=-c99)
	set(GNU_EXTENSIONS=0)
	set(EXCEPTIONS_ENABLED=0)
	append(CARGS= -y 125 0x100000)
	append(DIALECTARGS= --c99)
	set(DEFC99=1);

switch -c9x is hide shorthand(-c99);

switch -c90 is helpgroup(language) shorthand(-c89);

switch -c8x is hide shorthand(-c89);

switch -c89 is
	help(C89/C90 language dialect)
	helpgroup(language)
	set(IS_CPLUS=0)
	set(DIALECT_FLAG=-c89)
	set(GNU_EXTENSIONS=0)
	set(EXCEPTIONS_ENABLED=0)
	append(DIALECTARGS= --c89)
	append(CARGS=-x 125 0x100000)
	set(DEFC99=0);

switch --c23 is hide shorthand(-c23);
switch --c18 is hide shorthand(-c17);
switch --c17 is hide shorthand(-c17);
switch --c11 is hide shorthand(-c11);
switch --c1x is hide shorthand(-c11);
switch --c99 is hide shorthand(-c99);
switch --c9x is hide shorthand(-c99);
switch --c90 is hide shorthand(-c89);
switch --c89 is hide shorthand(-c89);

switch -Mvariadic_macros is
	help(Allow variadic macros)
	helpname(-M[no]variadic_macros)
	helpgroup(language)
	append(CARGS=-y 125 0x100000);

switch -Mnovariadic_macros is hide
	help(Disallow variadic macros)
	helpgroup(language)
	append(CARGS=-x 125 0x100000);

variable ASMKEY is default(1);

switch -Masmkeyword is
	help(Allow asm keyword in C source)
	helpgroup(language)
	helpname(-M[no]asmkeyword)
	append(CARGS=-x 127 $ASMKEY);

switch -Mnoasmkeyword is hide
	help(Disallow asm keyword in source)
	helpgroup(language)
	append(CARGS=-y 127 $ASMKEY);

switch -MT mttarget is
	help(Print makefile dependencies with a custom target)
	helpgroup(prepro)
	append(CPP1ARGS=--dependencies_target_to_stdout $mttarget);

# TODO: -MQ should be "Same as -MT, but it quotes any characters which are
#       special to Make" to match gcc's behavior.
switch -MQ=mttarget is shorthand(-MT=mttarget);

switch -MM is
	help(Print dependencies with quoted include files only)
	helpgroup(prepro)
	append(CPP1ARGS=$ifn($OVERRIDECPPDEPENDFILE,--dependencies_to_stdout_quoted_only))
	set(CPPDEPEND=$if($OVERRIDECPPDEPENDFILE,--dependencies_to_file_quoted_only))
	set(NOASM=YES)
	set(CPP1ONLY=YES)
	set(COMPILEONLY=YES)
	stopafter(Compile);

switch -MMD$ is
	help(Print dependencies to file with quoted include files only)
	helpgroup(prepro)
	optional(dfile)
	set(CPPDEPENDFILE=$dfile)
	set(CPPDEPEND=--dependencies_to_file_quoted_only);

switch -M is
	help(Print dependencies to stdout in C++)
	helpgroup(prepro)
	append(CPP1ARGS=$ifn($OVERRIDECPPDEPENDFILE,--dependencies_to_stdout))
	set(CPPDEPEND=$if($OVERRIDECPPDEPENDFILE,--dependencies_to_file))
	append(NOASM=YES)
	append(CPP1ONLY=YES)
	append(COMPILEONLY=YES)
	stopafter(Compile);


switch -MD$ is
	help(Print dependencies to file)
	helpgroup(prepro)
	optional(dfile)
	set(CPPDEPENDFILE=$dfile)
	set(CPPDEPEND=--dependencies_to_file);

switch -MF arg is
  help(When used with -M, -MM, -MD or -MMD, specify output file)
  helpgroup(prepro)
  set(OVERRIDECPPDEPENDFILE=$arg);

switch -MP is hide
  help(Ignored, for compatibility only);

switch -Mgen-c is
	hide
	help(Generate lowered C-code)
	set(KEEPIL=YES)
	append(CPP1ARGS=--call_back_end);

switch -Mdollar=char is
	help(Map dollar sign in identifiers to this character)
	helpgroup(language)
	append(CARGS=-dollar $char);

switch -Mfcon is
	help(Compile floating point constants as single precision)
	helpgroup(language)
	append(CPP1ARGS=--float_constants)
	append(CARGS=-fcon);

switch -Mllalign is
	help(Require 8 byte alignment for long long)
	helpname(-M[no]llalign)
	helpgroup(language)
	append(CGARGS=-y 119 0x100000)
	append(F901ARGS=-y 119 0x100000)
	append(CPP1ARGS=--llalign);

switch -Mnollalign is hide
	help(Don't require 8 byte alignment for long long)
	helpgroup(language)
	append(CGARGS=-x 119 0x100000)
	append(F901ARGS=-x 119 0x100000)
	append(CPP1ARGS=--nollalign);

switch -Mschar is hide
	help(Plain char is a signed type (default on x86))
	helpgroup(language)
	append(CPP1ARGS=--signed_chars)
	set(DEFUNSIGNED=);

switch -Msingle is
	help(Don't convert float arguments to double without prototypes)
	helpgroup(language)
	helpname(-M[no]single)
	append(CARGS=-single);

switch -Mnosingle is hide
	help(Convert float arguments to double without prototypes)
	helpgroup(language)
	append(CARGS=-nosingle);

switch -Muchar is hide
	help(Plain char is an unsigned type (default on Arm and Power))
	helpgroup(language)
	append(CPP1ARGS=--unsigned_chars)
	set(DEFUNSIGNED=YES);

switch -E is early
    help(Preprocess only with "#line" directives, output to standard output)
    helpgroup(prepro)
    append(CPP1ARGS=--preprocess -D__PREPROCESS_ONLY__)
    set(DEFKEEPPREPRO=)
    set(PREPROCONLY=YES)
    set(DEFOUTFILE=) #DEFOUTFILE= for llvm
    set(HANDLEOTHER=$OTHERPREPROCESS)
    set(CPP1ONLY=YES)
    set(NOASM=YES)
    set(NOILM=YES)
    set(F90X=$F90E)
    set(CUFX=)
    stopafter(Compile)
    set(COMPILEONLY=YES);

switch -P is early
	help(Stop after preprocessing)
	helpgroup(prepro)
	append(CPP1ARGS=--no_line_commands -D__PREPROCESS_ONLY__)
	set(KEEPPREPRO=YES)
	set(PREPROCONLY=YES)
	set(DEFOUTFILE=)
	set(HANDLEOTHER=$OTHERPREPROCESS)
	set(CPP1ONLY=YES)
	set(KEEPIL=YES)
	set(NOASM=YES)
	set(NOILM=YES)
	set(F90X=$F90E)
	set(CUFX=)
	stopafter(Compile)
	set(COMPILEONLY=YES);

switch -Wc,arg is
	help(Pass argument to C++ compiler)
	helpgroup(language)
	append(CPP1ARGS=$replace($arg,",", ));

# -Werror turns all warnings to errors, but -Werror=X is noop'd for now
# until better warnings implementation.
variable FLANG_WERROR is default(-Werror);
variable F901_WERROR is default(-x 0 0x100);
variable CPP_WERROR is default(--diag_all_error);
switch -Werror= is optional(arg)
	help(Turn all warnings into errors; optional arg is ignored)
	helpgroup(language)
	set(ISWERROR=1)
	# re-set the flags here to ensure that mixing the order of -Werror and
	# -Wno-error always results in the last specified flag giving the
	# desired behavior.
	set(FLANG_WERROR=$ifn($arg,-Werror))
	set(CPP_WERROR=$ifn($arg,--diag_all_error))
	set(F901_WERROR=$ifn($arg,-x 0 0x100))
	append(FLANG1ARGS=$FLANG_WERROR)
	append(F901ARGS=$F901_WERROR)
	append(CPP1ARGS=$CPP_WERROR);

switch -Wno-error is hide
	help(Disable turning all warning messages into errors)
	helpgroup(language)
	set(ISWERROR=0)
	set(FLANG_WERROR=)
	set(F901_WERROR=)
	set(CPP_WERROR=);

switch -Wfatal-errors is
  early  # early because DRIVERERRORLIMIT needs to be set before everything.
  help(Stop compilation on the first error)
  helpgroup(overall)
  set(DRIVERERRORLIMIT=1)
  set(FATALERRORS=--error_limit 1)  # For cpp1
  append(CPP2ARGS=-errlimit 1)
  append(F901ARGS=-errlimit 1)
  append(F902ARGS=-errlimit 1);

switch -fstrict-aliasing is
	help(Enable optimizations based on a strict interpretation of the aliasing rules that apply to the language being compiled, such as type-based alias analysis.)
  set(ALIASMODE=)
  helpname(-f[no-]strict-aliasing)
	helpgroup(overall);

switch -fno-strict-aliasing is hide
	set(ALIASMODE=-x 2 0x400 -x 209 0x10)
	helpgroup(overall);

# no-op for now
switch -Wall is hide
	help(Ignored, for compatibility only)
	helpgroup(overall);

# no-op for now
switch -Wextra is hide
	help(Ignored, for compatibility only)
	helpgroup(overall);

switch -W is shorthand(-Wextra) hide;

switch -Xa is
	help(Use ANSI mode (deprecated))
	helpgroup(language)
	set(DEFBMODE=$STRICTBMODE)
  append(RW=$warning( The -Xa switch is deprecated))
	append(CARGS=-x 123 256 -x 123 16);

switch -Xc is
	help(Use ANSI conformance mode; generate warnings for some extensions (deprecated))
	helpgroup(language)
  append(RW=$warning( The -Xc switch is deprecated))
	append(CARGS=-x 123 256 -y 123 16);

switch -Xs is
	help(Use legacy standard mode";" implies -fno-strict-aliasing (deprecated))
	helpgroup(language)
	set(DEFBMODE=$STRICTBMODE)
	set(ALIASMODE=-x 2 0x400)
  append(RW=$warning( The -Xs switch is deprecated))
	append(CARGS=-x 122 2 -x 123 96);

switch -Xt is
	help(Use legacy transitional mode; generate warnings for conflicts with ANSI semantics";" implies -fno-strict-aliasing (deprecated))
	helpgroup(language)
	set(ALIASMODE=-x 2 0x400)
	append(CARGS=-x 123 128 -x 123 64)
  append(RW=$warning( The -Xt switch is deprecated));

# For general purpose preprocessing, use the C/C++ preprocessor if the user
# invoked the C or C++ compiler, and use the general purpose preprocessor if
# the user invoked the Fortran compiler.
set OTHERPREPROCESS=$if($equal($DRIVER,Fortran),otherpreprocess,cpreprocess);
set GENPREPROCESS=$if($equal($DRIVER,Fortran),genpreprocess,cpreprocess);

command cpreprocess is
	help(Preprocess any file)
	suffix(other a o asm)
	tool(nvcpfe)
	set(CPP1ONLY=YES)
	set(ppfile=$if($PREPROCONLY,$if($OUTFILE$KEEPPREPRO,$if($OUTFILE,$OUTFILE,$basename($input).$PREPROSUFFIX))))
	arguments(--
		$DEFCPP1ARGS $HOSTCPP1ARGS
		$if($VERSION,-v)
		$foreach(d,$STDDEF,-D$d )
		$foreach(d,$LOCALDEFS,-D$d )
		$foreach(d,$DEFCPPDEFS,-D$d )
		$foreach(d,$SITEDEFS,-D$d )
		$DIALECTARGS
		$EDG_INCLUDES
		$USRDDEF
		$STDPARDEFS
		$ifn($currentsuffix(i,cup),$CPPPREINC)
		$CPP1DEFARGS $CPP1ARGS $PEDANTIC
		$if($notequal($CPPDEPEND,),$CPPDEPEND $if($OVERRIDECPPDEPENDFILE,$mknewfile($path($OVERRIDECPPDEPENDFILE)),$mknewfile($if($OUTFILE, $dirname($OUTFILE)/$basename($OUTFILE).d, $basename($input).d))))
		$ifn($KEEPIL,-q)
		$if($ppfile,-o $ppfile)
		$input
		--);

# front end flag to use for printing dependences to a file
variable CPPDEPEND is default();
# the file to which to print dependences, if named
variable CPPDEPENDFILE is default();
variable OVERRIDECPPDEPENDFILE is default($CPPDEPENDFILE);

# Include `include-stdpar` path when `.cu`, `-x cu`, or `-cuda` is used
# Always include `include-stdexec`
append COMPINCDIR=$if($land($not($NVCCHOST),$or($ANYCU,$TGTCUDA)),include-stdpar) include-stdexec;

command nvcpfe is
	hide
	help(C++ Phases 1 and 2, merged)
	tool(nvcpfe)
	suffix($CSUFFIX $CPPSUFFIX $if($notequal($SYSACCELS,),$CUSUFFIX $CUPSUFFIX))

	# cpp1 settings
	echo($if($and($ECHONAME,$expr($count($realfiles)>1)),$input:))
	set(tidir=$dirname($OUTFILE))
	set(ofile=$basename($OUTFILE))
	set(tifile=$tidir/$ofile.ti)
	set(iifile=$tidir/$ofile.ii)
	set(ilfile=$ifn($PREPROCONLY,$if($or($KEEPTEMP,$KEEPIL,$ILDIR),$if($ILDIR,$ILDIR/)$basename($input).il,$tempfile(il))))
	set(dbgfile=$dirname($ilfile)/$basename($ilfile).dbg)
	tempfile($dbgfile)
	set(ppfile=$if($PREPROCONLY,$if($OUTFILE$KEEPPREPRO,$if($OUTFILE,$OUTFILE,$basename($input).$PREPROSUFFIX))))

	# cpp2 settings
	set(asmfile=$ifn($or($NOASM,$PREASM),$if($and($COMPILEONLY,$notequal($OUTFILE,)),$OUTFILE,$ifn($KEEPASM$KEEPTEMP,$tempfile($ASMSUFFIX),$if($and($ASMONLY,$notequal($OUTFILE,)),$dirname($OUTFILE)/$basename($OUTFILE).s,$basename($file).$ASMSUFFIX)))))
	set(llfile=$ifn($NOASM,$if($and($COMPILEONLY,$notequal($OUTFILE,)),$OUTFILE,$ifn($KEEPTEMP$KEEPLL$KEEPASM,$tempfile(ll),$if($and($LLONLY$ASMONLY,$notequal($OUTFILE,)),$dirname($OUTFILE)/$basename($OUTFILE).ll,$basename($file).ll)))))
	set(thisoutfile=$if($and($or($COMPILEONLY,$ASMONLY),$OUTFILE),$OUTFILE))
	set(doappend=$if($IPALINK,YES))
	set(ipofile=$if($IPALINK,$if($IPOFILE$KEEPTEMP,$if($thisoutfile,$dirname($thisoutfile)/$basename($thisoutfile).ipo,$basename($file).ipo),$tempfile(ipo))))
	set(ipxfile=$if($IPALINK,$if($KEEPTEMP,$basename($input).ipx,$tempfile(ipx))))
	# .ipn file holds -Mipa=inline information
	set(ipnfile=$if($IPAINLINE,$if($KEEPTEMP,$basename($input).ipn,$tempfile(ipn))))
	# .ipm file holds -Mipa=inline index information
	set(ipmfile=$if($IPAINLINE,$if($KEEPTEMP,$basename($input).ipm,$tempfile(ipm))))
	append(CARGS=$if($PGLLVMTARGET, $PGLLVMVFP $LLVMVERFLAGS))
	set(DONTINSTRFILE=$if($foreach(d,$NOINSTRFILELIST,$if($contains($file, $d),1)),-y 129 0x800))	

	# CUDA .cu definitions
	# From cpp1
	set(ENABLECUDA1=)
	error($if($land($not($NVCCHOST),$currentsuffix(cu,cup),$equal($USECUDAROOT,)),CUDA version $CUDAXDY is not available in this installation.))
	append(ENABLECUDA1=$if($land($not($NVCCHOST),$currentsuffix(cu,cup)),$foreach(f,$ACCDEFINES, -D$f)))
	append(ENABLECUDA1=$if($land($not($NVCCHOST),$currentsuffix(cu,cup)),-DPGI_TESLA_TARGET))
	# Needs to be removed when the compiler supports multiple capabilities
	append(ENABLECUDA1=$if($land($not($NVCCHOST),$currentsuffix(cu,cup)),-D__PGI_CUDA_ARCH__=$MOSTCAPABLECOMPILEDCC -D__NVCOMPILER_CUDA_ARCH__=$MOSTCAPABLECOMPILEDCC))
	#
	append(ENABLECUDA1=$if($land($not($NVCCHOST),$currentsuffix(cu,cup)),-D_CUDA))
	set(CUARGS=$if($land($not($NVCCHOST),$currentsuffix(cu,cup)),--cuda -D__CUDACC__ -D__NV_NO_HOST_COMPILER_CHECK $ifn($currentsuffix(cup),--preinclude _cuda_preinclude.h) $foreach(c,$COMPUTECAPS,--cudacap=$c )) $if($land($not($NVCCHOST),$ACCRELOC),-D_NVHPC_RDC))

	# From cpp2
	set(ENABLECUDA2=)
	append(ENABLECUDA2=$if($land($not($NVCCHOST),$currentsuffix(cu,cup)),$DEFAULTCAPFLAG))
	append(ENABLECUDA2=$if($land($not($NVCCHOST),$currentsuffix(cu,cup)),$TOOLKITFLAG))
	append(ENABLECUDA2=$if($land($not($NVCCHOST),$currentsuffix(cu,cup)),-accel tesla))
	append(ENABLECUDA2=$if($land($not($NVCCHOST),$currentsuffix(cu,cup)),-x 121 0xc00))
	append(ENABLECUDA2=$if($land($not($NVCCHOST),$currentsuffix(cu,cup)),$if($ACCRELOC,-x 189 0x8000)))
	append(ENABLECUDA2=$if($land($not($NVCCHOST),$currentsuffix(cu,cup)),-x 137 1))
	append(ENABLECUDA2=$if($land($not($NVCCHOST),$currentsuffix(cu,cup)),-x 137 0x200000))
	# End CUDA .cu definitions

	arguments(
		# Mode selection arguments
		$if($Extract,-extract)
		--
		# cpp1 arguments
		$DEFCPP1ARGS $HOSTCPP1ARGS
		$if($VERSION,-v)
		$if($NOWARN,--no_warnings)
		#$if($OPTLEVEL,-D__OPTIMIZE__) # FIXME: FS#30559
		#$ifn($or($INLINE,$AUTOINLINE),-D__NO_INLINE__) # FIXME: FS#30559
		$foreach(d,$STDDEF,-D$d ) 
		$foreach(d,$LOCALDEFS,-D$d ) 
		$foreach(d,$DEFCPPDEFS,-D$d ) 
		$foreach(d,$SITEDEF,-D$d ) 
		$DIALECTARGS
		$EDG_INCLUDES
		$USRDDEF
		$STDPARDEFS
		$ENABLECUDA1
		$ifn($currentsuffix(i,cup),$CPPPREINC)
		$CPP1DEFARGS $CPP1ARGS $PEDANTIC $CUARGS
		$if($notequal($CPPDEPEND,),$CPPDEPEND $if($OVERRIDECPPDEPENDFILE,$mknewfile($path($OVERRIDECPPDEPENDFILE)),$mknewfile($if($OUTFILE, $dirname($OUTFILE)/$basename($OUTFILE).d, $basename($input).d))))
		$ifn($KEEPIL,-q)
		$ifn($PREPROCONLY,-o $ilfile)
		$if($ppfile,-o $ppfile)
		$input
		--
		# cpp2/cpp2ex arguments
		$if($equal($PREPROCONLY$CPP1ONLY,),
		  # Common to both cpp2 and cpp2ex
		  $file $COMMONARGS $DEFCPPARGS $EXTRACGARGS $COMMONCGARGS
		  -fn $file -il $ilfile
		  $CPP2DEFARGS $CARGS $CGARGS $CPP2ARGS
		  $ifn($Extract,
			# cpp2 args
			$INLINEARGS $INLINECARGS $NOINSTRFUNCS
			$ENABLECUDA2 $DONTINSTRFILE
			$ifn($DRYRUN,-cmdline $quote(+$DRIVERCOMMAND $input $switches))
			$if($and($IPALINK,$IPAEXPORT),
			-ipacomp $quote($DRIVERNAME)
			-ipacompsw $quote(+"$"n $escape($switches) -c --ZIPAimport "$"f "$"b "$"a -o "$"o)
			-ipaexport $ipxfile
			)
			$if($ipnfile,-exfile $ipnfile -exifile $ipmfile)
			$if($IPALINK,-ipofile $ipofile)
			$if($NOASM,-noasm,-asm $if($PGLLVMTARGET, $llfile, $asmfile))
		  ,
			# cpp2ex args
			$CEXTARGS -exlib $EXTRACTLIB
		  )
		)
	)
	execute(
        condition($equal($Extract,))
        condition($not($or($equal($TARGET,win64),$equal($TARGET,win64-llvm))))
        condition($USEBITCODERT)
        condition($equal($PGLLVMTARGET,yes))
        input($llfile)
        command($LLVMAS)
	)
	execute(
		condition($equal($Extract,))
		condition($not($USEBITCODERT))
		condition($equal($PGLLVMTARGET,yes))
		condition($equal($NOASM,))
		condition($equal($LLONLY,))
		input($llfile)
		command($if($USENVBE,$NVBE,$if($USECLANG,$CLANGCMD,$LLCCMD)))
	)
	execute(
		condition($equal($Extract,))
		condition($equal($NOASM$COMPILEONLY,))
		condition($equal($PGLLVMTARGET,))
		input($asmfile)
		command(Nasm)
	);

# temp directory to hold .il files between extract/compile phases
# with -Minline and no lib:
variable ILDIR is
    default($if($EXTRACTINLINE,$if($KEEPIL,.,$tempdir(il))));

switch -dD is
	help(Print macros and values)
	helpgroup(prepro)
	append(CPP1ARGS=--list_macros)
	append(F901ARGS=-x 122 0x50000)
	set(CPP1ONLY=1);

switch -dM is shorthand(-dD);

switch -dN is shorthand(-dD);

switch -dI is
	help(Print include file names)
	helpgroup(prepro)
	append(CPP1ARGS=--trace_includes);

switch -Munsigned-ldst is hide
	help(Load and store carries unsigned msize information)
  append(CPP2ARGS=-y 22 0xf)
  append(F902ARGS=-y 22 0xf);
  
switch -Mno-unsigned-ldst is hide
	help(Load and store does not carry unsigned msize information)
  append(CPP2ARGS=-x 22 0xf)
  append(F902ARGS=-x 22 0xf);


# Variables associated with -fmax-errors=, --ferror-limit=, and --error_limit=
variable MAXERRORS is default();
variable FATALERRORS is default();  # Overrides MAXERROR

switch -fmax-errors=n is
    help(Set error limit to <n>)
    helpgroup(language)
    set(MAXERRORS=$if($isnum($n),--error_limit $n,$error(Illegal option to -fmax-errors - option must be numeric)))
    append(F901ARGS=$if($isnum($n),-errlimit $n))
    ;
