mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-12-25 12:42:02 +03:00
Add support for standard C env vars
Also, organize the env var listing a bit more.
This commit is contained in:
parent
1020437aad
commit
c5c842726a
@ -17,6 +17,36 @@ findCC
|
||||
| Just cc => pure cc
|
||||
pure "cc"
|
||||
|
||||
findCFLAGS : IO String
|
||||
findCFLAGS
|
||||
= do Nothing <- getEnv "IDRIS2_CFLAGS"
|
||||
| Just cflags => pure cflags
|
||||
Nothing <- getEnv "CFLAGS"
|
||||
| Just cflags => pure cflags
|
||||
pure ""
|
||||
|
||||
findCPPFLAGS : IO String
|
||||
findCPPFLAGS
|
||||
= do Nothing <- getEnv "IDRIS2_CPPFLAGS"
|
||||
| Just cppflags => pure cppflags
|
||||
Nothing <- getEnv "CPPFLAGS"
|
||||
| Just cppflags => pure cppflags
|
||||
pure ""
|
||||
|
||||
findLDFLAGS : IO String
|
||||
findLDFLAGS
|
||||
= do Nothing <- getEnv "IDRIS2_LDFLAGS"
|
||||
| Just ldflags => pure ldflags
|
||||
Nothing <- getEnv "LDFLAGS"
|
||||
| Just ldflags => pure ldflags
|
||||
pure ""
|
||||
|
||||
clibdirs : List String -> String
|
||||
clibdirs ds = concat (map (\d => "-L" ++ d ++ " ") ds)
|
||||
|
||||
-- cincdirs : List String -> String
|
||||
-- cincdirs ds = concat (map (\d => "-I" ++ d ++ " ") ds)
|
||||
|
||||
export
|
||||
compileCObjectFile : {auto c : Ref Ctxt Defs}
|
||||
-> {default False asLibrary : Bool}
|
||||
@ -25,15 +55,20 @@ compileCObjectFile : {auto c : Ref Ctxt Defs}
|
||||
-> Core (Maybe String)
|
||||
compileCObjectFile {asLibrary} sourceFile objectFile =
|
||||
do cc <- coreLift findCC
|
||||
cFlags <- coreLift findCFLAGS
|
||||
cppFlags <- coreLift findCPPFLAGS
|
||||
|
||||
refcDir <- findDataFile "refc"
|
||||
cDir <- findDataFile "c"
|
||||
|
||||
let libraryFlag = if asLibrary then "-fpic " else ""
|
||||
let libraryFlag = if asLibrary then "-fpic" else ""
|
||||
|
||||
let runccobj = cc ++ " -Werror -c " ++ libraryFlag ++ sourceFile ++
|
||||
let runccobj = cc ++ " " ++ cFlags ++ " -Werror -c " ++ libraryFlag ++
|
||||
" " ++ sourceFile ++
|
||||
" -o " ++ objectFile ++
|
||||
" -I" ++ refcDir ++
|
||||
" -I" ++ cDir
|
||||
" -I" ++ cDir ++
|
||||
" " ++ cppFlags
|
||||
|
||||
log "compiler.refc.cc" 10 runccobj
|
||||
0 <- coreLift $ system runccobj
|
||||
@ -49,26 +84,27 @@ compileCFile : {auto c : Ref Ctxt Defs}
|
||||
-> Core (Maybe String)
|
||||
compileCFile {asShared} objectFile outFile =
|
||||
do cc <- coreLift findCC
|
||||
cFlags <- coreLift findCFLAGS
|
||||
ldFlags <- coreLift findLDFLAGS
|
||||
|
||||
dirs <- getDirs
|
||||
refcDir <- findDataFile "refc"
|
||||
supportFile <- findLibraryFile "libidris2_support.a"
|
||||
|
||||
let sharedFlag = if asShared then "-shared " else ""
|
||||
let sharedFlag = if asShared then "-shared" else ""
|
||||
|
||||
let runcc = cc ++ " -Werror " ++ sharedFlag ++ objectFile ++
|
||||
" -o " ++ outFile ++ " " ++
|
||||
supportFile ++ " " ++
|
||||
"-lidris2_refc " ++
|
||||
"-L" ++ refcDir ++ " " ++
|
||||
clibdirs (lib_dirs dirs) ++
|
||||
"-lgmp -lm"
|
||||
let runcc = cc ++ " " ++ cFlags ++ " -Werror " ++ sharedFlag ++
|
||||
" " ++ objectFile ++
|
||||
" -o " ++ outFile ++
|
||||
" " ++ supportFile ++
|
||||
" -lidris2_refc " ++
|
||||
" -L" ++ refcDir ++
|
||||
" " ++ clibdirs (lib_dirs dirs) ++
|
||||
" " ++ ldFlags ++
|
||||
" -lgmp -lm"
|
||||
|
||||
log "compiler.refc.cc" 10 runcc
|
||||
0 <- coreLift $ system runcc
|
||||
| _ => pure Nothing
|
||||
|
||||
pure (Just outFile)
|
||||
|
||||
where
|
||||
clibdirs : List String -> String
|
||||
clibdirs ds = concat (map (\d => "-L" ++ d ++ " ") ds)
|
||||
|
@ -20,24 +20,30 @@ record EnvDesc where
|
||||
public export
|
||||
envs : List EnvDesc
|
||||
envs = [
|
||||
MkEnvDesc "EDITOR" "Editor used in REPL :e command",
|
||||
MkEnvDesc "IDRIS2_PREFIX" "Idris2 installation prefix",
|
||||
MkEnvDesc "IDRIS2_PATH" "Places Idris2 looks for import files",
|
||||
MkEnvDesc "IDRIS2_PACKAGE_PATH" "Places Idris2 looks for packages",
|
||||
MkEnvDesc "IDRIS2_DATA" "Places Idris2 looks for data files",
|
||||
MkEnvDesc "IDRIS2_LIBS" "Places Idris2 looks for libraries (for code generation)",
|
||||
MkEnvDesc "IDRIS2_CG" "Codegen backend",
|
||||
MkEnvDesc "IDRIS2_INC_CGS" "Code generators to use (comma separated) when compiling modules incrementally",
|
||||
MkEnvDesc "CHEZ" "chez executable used in Chez codegen",
|
||||
MkEnvDesc "RACKET" "racket executable used in Racket codegen",
|
||||
MkEnvDesc "RACKET_RACO" "raco executable used in Racket codegen",
|
||||
MkEnvDesc "GAMBIT_GSI" "gsi executable used in Gambit codegen",
|
||||
MkEnvDesc "GAMBIT_GSC" "gsc executable used in Gambit codegen",
|
||||
MkEnvDesc "GAMBIT_GSC_BACKEND" "gsc executable backend argument",
|
||||
MkEnvDesc "IDRIS2_CC" "C compiler executable used in RefC codegen",
|
||||
MkEnvDesc "CC" "C compiler executable used in RefC codegen",
|
||||
MkEnvDesc "NODE" "node executable used in Node codegen",
|
||||
MkEnvDesc "PATH" "PATH variable is used to search for executables in certain codegens"
|
||||
MkEnvDesc "EDITOR" "Editor used in REPL :e command",
|
||||
MkEnvDesc "IDRIS2_PREFIX" "Idris2 installation prefix.",
|
||||
MkEnvDesc "IDRIS2_PATH" "Directories where Idris2 looks for import files.",
|
||||
MkEnvDesc "IDRIS2_PACKAGE_PATH" "Directories where Idris2 looks for Idris 2 packages.",
|
||||
MkEnvDesc "IDRIS2_DATA" "Directories where Idris2 looks for data files.",
|
||||
MkEnvDesc "IDRIS2_LIBS" "Directories where Idris2 looks for libraries (for code generation).",
|
||||
MkEnvDesc "IDRIS2_CG" "Codegen backend",
|
||||
MkEnvDesc "IDRIS2_INC_CGS" "Code generators to use (comma separated) when compiling modules incrementally",
|
||||
MkEnvDesc "CHEZ" "Chez backend: chez executable.",
|
||||
MkEnvDesc "RACKET" "Racket backend: racket executable.",
|
||||
MkEnvDesc "RACKET_RACO" "Racket backend: raco executable.",
|
||||
MkEnvDesc "GAMBIT_GSI" "Gambit backend: gsi executable.",
|
||||
MkEnvDesc "GAMBIT_GSC" "Gambit backend: gsc executable.",
|
||||
MkEnvDesc "GAMBIT_GSC_BACKEND" "Gambit backend: arguments passed to gsc.",
|
||||
MkEnvDesc "IDRIS2_CC" "RefC backend: C compiler executable.",
|
||||
MkEnvDesc "IDRIS2_CFLAGS" "RefC backend: C compiler flags.",
|
||||
MkEnvDesc "IDRIS2_CPPFLAGS" "RefC backend: C preprocessor flags.",
|
||||
MkEnvDesc "IDRIS2_LDFLAGS" "RefC backend: C linker flags.",
|
||||
MkEnvDesc "CC" "RefC backend: C compiler executable (IDRIS2_CC takes precedence).",
|
||||
MkEnvDesc "CFLAGS" "RefC backend: C compiler flags (IDRIS2_CFLAGS takes precedence).",
|
||||
MkEnvDesc "CPPFLAGS" "RefC backend: C preprocessor flags (IDRIS2_CPPFLAGS takes precedence).",
|
||||
MkEnvDesc "LDFLAGS" "RefC backend: C linker flags (IDRIS2_LDFLAGS takes precedence).",
|
||||
MkEnvDesc "NODE" "NodeJS backend: NodeJS executable.",
|
||||
MkEnvDesc "PATH" "PATH variable is used to search for executables in certain codegens."
|
||||
]
|
||||
|
||||
--- `public export` only for `auto` to work in `idrisGetEnv`
|
||||
|
Loading…
Reference in New Issue
Block a user