@@ -39,6 +39,7 @@ import System.IO.Error (isDoesNotExistError)
3939import System.Process
4040import Text.PrettyPrint.GenericPretty
4141
42+ import Data.List (isInfixOf )
4243import Gibbon.Common
4344import Gibbon.DynFlags
4445import Gibbon.Language
@@ -369,19 +370,26 @@ withPrintInterpProg l0 =
369370 return Nothing
370371
371372compileRTS :: Config -> IO ()
372- compileRTS Config {verbosity,optc,dynflags} = do
373+ compileRTS Config {verbosity,optc,dynflags,cc = ccCmd } = do
373374 gibbon_dir <- getGibbonDir
375+ archiver <- chooseArchiver ccCmd
376+ when (isClangCompiler ccCmd && not (" llvm-ar" `isInfixOf` takeFileName archiver)) $
377+ putStrLn $
378+ " [compiler] clang detected but llvm-ar not found; using '" ++ archiver ++ " ' instead."
374379 let rtsmk = gibbon_dir </> " gibbon-rts/Makefile"
375- let rtsmkcmd = " make -f " ++ rtsmk ++ " "
380+ userCFlags = optc
381+ rtsmkcmd = " make -f " ++ rtsmk ++ " "
376382 ++ (if rts_debug then " MODE=debug " else " MODE=release " )
377383 ++ (if rts_debug && pointer then " -DGC_DEBUG " else " " )
378384 ++ (if not genGC then " GC=nongen " else " GC=gen " )
379385 ++ (if print_gc_stats then " GCSTATS=1 " else " " )
380386 ++ (if pointer then " POINTER=1 " else " " )
381387 ++ (if parallel then " PARALLEL=1 " else " " )
382388 ++ (if bumpAlloc then " BUMPALLOC=1 " else " " )
383- ++ (" USER_CFLAGS=\" " ++ optc ++ " \" " )
389+ ++ (" USER_CFLAGS=\" " ++ userCFlags ++ " \" " )
384390 ++ (" VERBOSITY=" ++ show verbosity)
391+ ++ (" CC=\" " ++ ccCmd ++ " \" " )
392+ ++ (" AR=\" " ++ archiver ++ " \" " )
385393 execCmd
386394 Nothing
387395 rtsmkcmd
@@ -433,7 +441,7 @@ compileAndRunExe cfg@Config{backend,arrayInput,benchInput,mode,cfile,exefile} fp
433441 compileRTS cfg
434442 lib_dir <- getRTSBuildDir
435443 let rts_o_path = lib_dir </> " gibbon_rts.o"
436- let compile_prog_cmd = compilationCmd backend cfg
444+ compile_prog_cmd = compilationCmd backend cfg
437445 ++ " -o " ++ exe
438446 ++ " -I" ++ lib_dir
439447 ++ " -L" ++ lib_dir
@@ -464,6 +472,22 @@ getRTSBuildDir =
464472 unless exists (error " RTS build not found." )
465473 pure build_dir
466474
475+ chooseArchiver :: String -> IO String
476+ chooseArchiver ccCmd = pick candidates
477+ where
478+ candidates
479+ | isClangCompiler ccCmd = [" llvm-ar" , " ar" ]
480+ | otherwise = [" gcc-ar" , " ar" ]
481+ pick [] = pure " ar"
482+ pick (tool: rest) = do
483+ found <- findExecutable tool
484+ case found of
485+ Just path -> pure path
486+ Nothing -> pick rest
487+
488+ isClangCompiler :: String -> Bool
489+ isClangCompiler = (" clang" `isInfixOf` ) . takeFileName
490+
467491
468492execCmd :: Maybe FilePath -> String -> String -> String -> IO ()
469493execCmd dir cmd msg errmsg = do
0 commit comments