toEnv :: ToolChain -> Action [(String,String)]
toEnv tc = do
  flags <- (\f -> f mempty) <$> get defaultBuildFlags tc
  let cflags =  concatMapFlag "-I" (map escapeSpaces (get systemIncludes flags))
             ++ concatMapFlag "-I" (map escapeSpaces (get userIncludes flags))
             ++ defineFlags flags
             ++ get preprocessorFlags flags
             ++ compilerFlagsFor (Just C) flags
      cxxflags = cflags ++ compilerFlagsFor (Just Cpp) flags
      ldflags =  get linkerFlags flags
              ++ concatMapFlag "-L" (get libraryPath flags)
              ++ concatMapFlag "-l" (get libraries flags)
      c2cxx path = let x = takeFileName path
                   in if "gcc" `isSuffixOf` x
                      then (++"g++") . reverse . drop 3 . reverse $ path
                      else if "clang" `isSuffixOf` x
                           then path ++ "++"
                           else path
  let cc = tool tc compilerCommand
      cpp = toolFromString tc "cpp"
  cppExists <- doesFileExist cpp
  let cpp' = if cppExists then cpp else cc ++ " -E"
  return $ [
      ("CPP", cpp')
    , ("AR", tool tc archiverCommand)
    , ("NM", toolFromString tc "nm")
    , ("CC", tool tc compilerCommand)
    -- FIXME: Configure toolchain with compiler command per language?
    , ("CXX", c2cxx $ tool tc compilerCommand)
    , ("LD", toolFromString tc "ld")
    , ("RANLIB", toolFromString tc "ranlib")
    , ("CFLAGS", unwords cflags)
    , ("CPPFLAGS", unwords cflags)
    , ("CXXFLAGS", unwords cxxflags)
    , ("LDFLAGS", unwords ldflags)
    ]
toEnv :: ToolChain -> Action [(String,String)]
toEnv tc = do
  flags <- (\f -> f mempty) <$> get defaultBuildFlags tc
  let cflags =  concatMapFlag "-I" (map escapeSpaces (get systemIncludes flags))
             ++ concatMapFlag "-I" (map escapeSpaces (get userIncludes flags))
             ++ defineFlags flags
             ++ get preprocessorFlags flags
             ++ compilerFlagsFor (Just C) flags
      cxxflags = cflags ++ compilerFlagsFor (Just Cpp) flags
      ldflags =  get linkerFlags flags
              ++ concatMapFlag "-L" (get libraryPath flags)
              ++ concatMapFlag "-l" (get libraries flags)
      c2cxx path = let x = takeFileName path
                   in if "gcc" `isSuffixOf` x
                      then (++"g++") . reverse . drop 3 . reverse $ path
                      else if "clang" `isSuffixOf` x
                           then path ++ "++"
                           else path
  let cc = tool tc compilerCommand
      cpp = toolFromString tc "cpp"
  cppExists <- doesFileExist cpp
  let cpp' = if cppExists then cpp else cc ++ " -E"
  return $ [
      ("CPP", cpp')
    , ("AR", tool tc archiverCommand)
    , ("NM", toolFromString tc "nm")
    , ("CC", tool tc compilerCommand)
    -- FIXME: Configure toolchain with compiler command per language?
    , ("CXX", c2cxx $ tool tc compilerCommand)
    , ("LD", toolFromString tc "ld")
    , ("RANLIB", toolFromString tc "ranlib")
    , ("CFLAGS", unwords cflags)
    , ("CPPFLAGS", unwords cflags)
    , ("CXXFLAGS", unwords cxxflags)
    , ("LDFLAGS", unwords ldflags)
    ]
toEnv tc = do
  flags <- (\f -> f mempty) <$> get defaultBuildFlags tc
  let cflags =  concatMapFlag "-I" (map escapeSpaces (get systemIncludes flags))
             ++ concatMapFlag "-I" (map escapeSpaces (get userIncludes flags))
             ++ defineFlags flags
             ++ get preprocessorFlags flags
             ++ compilerFlagsFor (Just C) flags
      cxxflags = cflags ++ compilerFlagsFor (Just Cpp) flags
      ldflags =  get linkerFlags flags
              ++ concatMapFlag "-L" (get libraryPath flags)
              ++ concatMapFlag "-l" (get libraries flags)
      c2cxx path = let x = takeFileName path
                   in if "gcc" `isSuffixOf` x
                      then (++"g++") . reverse . drop 3 . reverse $ path
                      else if "clang" `isSuffixOf` x
                           then path ++ "++"
                           else path
  let cc = tool tc compilerCommand
      cpp = toolFromString tc "cpp"
  cppExists <- doesFileExist cpp
  let cpp' = if cppExists then cpp else cc ++ " -E"
  return $ [
      ("CPP", cpp')
    , ("AR", tool tc archiverCommand)
    , ("NM", toolFromString tc "nm")
    , ("CC", tool tc compilerCommand)
    -- FIXME: Configure toolchain with compiler command per language?
    , ("CXX", c2cxx $ tool tc compilerCommand)
    , ("LD", toolFromString tc "ld")
    , ("RANLIB", toolFromString tc "ranlib")
    , ("CFLAGS", unwords cflags)
    , ("CPPFLAGS", unwords cflags)
    , ("CXXFLAGS", unwords cxxflags)
    , ("LDFLAGS", unwords ldflags)
    ]