Skip to content

Commit a37a8fc

Browse files
committed
Add ability to switch between gcc and clang
Enable -Werror since we've fixed the errors in prev commits Also explicitly bundle uthash
1 parent 1132b07 commit a37a8fc

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

gibbon-compiler/src/Gibbon/Compiler.hs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import System.IO.Error (isDoesNotExistError)
3939
import System.Process
4040
import Text.PrettyPrint.GenericPretty
4141

42+
import Data.List (isInfixOf)
4243
import Gibbon.Common
4344
import Gibbon.DynFlags
4445
import Gibbon.Language
@@ -369,19 +370,26 @@ withPrintInterpProg l0 =
369370
return Nothing
370371

371372
compileRTS :: 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

468492
execCmd :: Maybe FilePath -> String -> String -> String -> IO ()
469493
execCmd dir cmd msg errmsg = do

gibbon-rts/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
CC := gcc
3030
AR := gcc-ar
31-
CFLAGS := -Wall -Wextra -Wpedantic -Wshadow -std=gnu11 -flto
31+
CFLAGS := -Wall -Wextra -Wpedantic -Wshadow -Werror -std=gnu11 -flto
3232
RSC := cargo
3333
RSFLAGS := -v
3434
VERBOSITY := 1
@@ -107,6 +107,11 @@ RUST_RTS_SO := libgibbon_rts_ng.so
107107
RUST_RTS_PATH := $(RUST_RTS_DIR)/target/$(MODE)/$(RUST_RTS_SO)
108108
RUST_SOURCES := $(shell find $(RUST_RTS_DIR) -type f -name *.rs)
109109

110+
UTHASH_INCLUDE ?= $(GIBBONDIR)/deps/uthash
111+
ifneq ($(strip $(UTHASH_INCLUDE)),)
112+
CFLAGS += -I$(UTHASH_INCLUDE)
113+
endif
114+
110115

111116
all: rts
112117

0 commit comments

Comments
 (0)