
-- | Compiler configuration for the cygwin-x86 target
--	Everything specific to this target should be in this file.
--
module Config.Config where
import DDC.Main.Arg


-- | Pointer size in bits and bytes.
pointerBytes, pointerBits :: Int
pointerBytes = 4
pointerBits = pointerBytes * 8


-- | The extension to use for a shared object
extSharedObject
	= "dll"


-- | The system command to compile a Sea source file.
makeSeaCompileCmd
	:: [Arg]		-- ^ ddc command line args
	-> FilePath		-- ^ path of source c file
	-> FilePath             -- ^ path of output o file
	-> FilePath		-- ^ path to runtime system
	-> FilePath		-- ^ path to base libraries
	-> [FilePath]		-- ^ extra include dirs
	-> [String]		-- ^ extra flags to compile with, from .build file
	-> String		-- ^ the compile command

makeSeaCompileCmd
	args pathC pathO pathRuntime pathLibrary
	extraIncludeDirs extraCompileFlags

	=  "gcc-3"		-- Must use 'gcc-3' on Cygwin because plain 'gcc' is a symlink
				-- and Windows cmd doesn't support them. If you use plain 'gcc'
				-- you will get "Access is Denied" errors.

	++ " -Werror"
	++ " -std=c99"
	++ " -D BITS=" ++ show pointerBits

	++ " -c " ++ pathC
	++ " -o " ++ pathO

	++ (if elem Debug args   then " -g"  else "")
	++ (if elem OptAll args  then " -O3" else "")
	++ (if elem Profile args then " -pg" else "")

	++ " -I."
	++ " -I"  ++ (take (length pathRuntime - length "/runtime") pathRuntime)
	++ " -I"  ++ pathLibrary

	++ concat [ " -I" ++ p | p <- extraIncludeDirs ]
	++ concat [ " "   ++ f | f <- extraCompileFlags ]


-- | The system command to link objects into an executable.
makeLinkCmd
	:: [Arg]		-- ^ ddc command line args
	-> [FilePath]		-- ^ objects to link
	-> FilePath		-- ^ path of output binary
	-> FilePath		-- ^ path to the runtime system
	-> [FilePath]		-- ^ extra libs to link with
	-> [FilePath]		-- ^ extra lib dirs to search
	-> String

makeLinkCmd
	args objects outFile pathRuntime extraLibs extraLibDirs

	-- Must use gcc-3 on Cygwin because plain 'gcc' is a symlink
	-- and Windows cmd doesn't support them. If you use plain 'gcc'
	-- you will get "Access is Deined" errors.
	= "gcc-3"

	++ " -std=c99"

	++ " -o " ++ outFile

	++ (if elem Profile args
		then " -pg"
		else "")

	++ " " ++ concat [" " ++ obj | obj <- objects]

	-- Shared libraries/DLLS don't work on Windows/Cygwin
	-- so we always link against the static runtime.
	++ " " ++ pathRuntime ++ "/libddc-runtime.a"

	++ " -lm"

	++ " " ++ concat [" -L" ++ dir | dir <- extraLibDirs]
	++ " " ++ concat [" -l" ++ lib | lib <- extraLibs]


-- | Command to run the LLVM compiler
llcCommand :: String
llcCommand = "llc -march=x86"


-- | Command to assemble a file.
asCommand :: String
asCommand  = "as "
