mirror of
https://github.com/edwinb/Idris2-boot.git
synced 2025-01-04 19:05:25 +03:00
load library using OS-dependent names
This commit is contained in:
parent
75459e7fca
commit
9e7d79cb65
@ -40,6 +40,28 @@ findLibs = mapMaybe (isLib . trim)
|
||||
then Just (trim (substr 3 (length d) d))
|
||||
else Nothing
|
||||
|
||||
||| Generate the correct dynamic library loading code depending on the target machine
|
||||
loadSharedLibs : List String -> String
|
||||
loadSharedLibs [] = ""
|
||||
loadSharedLibs libs =
|
||||
"(case (machine-type)\n" ++
|
||||
" [(i3le ti3le a6le ta6le) " ++ load asLinux ++ "]\n" ++
|
||||
" [(i3osx ti3osx a6osx ta6osx) " ++ load asMac ++ "]\n" ++
|
||||
" [(i3nt ti3nt a6nt ta6nt) " ++ load asWin ++ "]\n" ++
|
||||
" [else " ++ load asLinux ++ "])"
|
||||
where
|
||||
load : (String -> String) -> String
|
||||
load fmt = "(begin\n" ++ showSep "\n" (map (\ s => "(load-shared-object \"" ++ fmt s ++ "\")") libs) ++ ")\n"
|
||||
|
||||
asLinux : String -> String
|
||||
asLinux s = "lib" ++ s ++ ".so"
|
||||
|
||||
asMac : String -> String
|
||||
asMac s = "lib" ++ s ++ ".dylib"
|
||||
|
||||
asWin : String -> String
|
||||
asWin s = s ++ ".dll"
|
||||
|
||||
escapeQuotes : String -> String
|
||||
escapeQuotes s = pack $ foldr escape [] $ unpack s
|
||||
where
|
||||
@ -56,7 +78,7 @@ schHeader chez libs
|
||||
" [(i3osx ti3osx a6osx ta6osx) (load-shared-object \"libc.dylib\")]\n" ++
|
||||
" [(i3nt ti3nt a6nt ta6nt) (load-shared-object \"msvcrt.dll\")]\n" ++
|
||||
" [else (load-shared-object \"libc.so\")])\n\n" ++
|
||||
showSep "\n" (map (\x => "(load-shared-object \"" ++ escapeQuotes x ++ "\")") libs) ++ "\n\n" ++
|
||||
loadSharedLibs libs ++ "\n\n" ++
|
||||
"(let ()\n"
|
||||
|
||||
schFooter : String
|
||||
@ -159,4 +181,3 @@ executeExpr c tm
|
||||
export
|
||||
codegenChez : Codegen
|
||||
codegenChez = MkCG compileExpr executeExpr
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user