Fixed LLVMConfig to work with hand-compiled LLVM 3.9.
The shared library naming convention under Linux changed (again, sigh)
"
Copyright (C) 2015-now Jan Vrany
This code is not an open-source (yet). You may use this code
for your own experiments and projects, given that:
* all modification to the code will be sent to the
original author for inclusion in future releases
* this is not used in any commercial software
This license is provisional and may (will) change in
a future.
"
"{ Package: 'jv:llvm_s' }"
"{ NameSpace: Smalltalk }"
Object subclass:#LLVMConfig
instanceVariableNames:''
classVariableNames:'LLVMConfigPath BinDir LibDir LibraryPath'
poolDictionaries:''
category:'LLVM-S-Internal'
!
!LLVMConfig class methodsFor:'documentation'!
copyright
"
Copyright (C) 2015-now Jan Vrany
This code is not an open-source (yet). You may use this code
for your own experiments and projects, given that:
* all modification to the code will be sent to the
original author for inclusion in future releases
* this is not used in any commercial software
This license is provisional and may (will) change in
a future.
"
! !
!LLVMConfig class methodsFor:'initialization'!
initialize
"Invoked at system start or when the class is dynamically loaded."
| path |
LLVMConfigPath := nil.
path := OperatingSystem getEnvironment:'LLVM_CONFIG'.
path notNil ifTrue:[
path asFilename isExecutable ifTrue:[
self llvmConfigPath: path.
^ self
] ifFalse:[
Logger warning:'LLVM_CONFIG environment specified but referred files is not executable. Ignoring'.
].
].
OperatingSystem isUNIXlike ifTrue:[
#('-3.8' '-3.7' '') do:[:ver |
path := OperatingSystem pathOfCommand: 'llvm-config' , ver.
path notNil ifTrue:[
self llvmConfigPath: path.
^ self.
]
].
^ self
].
self error: 'This operating system is not supported'.
"Modified: / 25-09-2015 / 03:54:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
llvmConfigPath: aStringOrFilename
"Set's the path to LLVM config which effectively
defines which version of LLVM to use.
Must be called before using any other LLVM API"
| path |
path := aStringOrFilename asFilename.
path exists ifFalse:[
self error: '`', path pathName ,'` does not exist'.
^ self.
].
path isExecutable ifFalse:[
self error: '`', path pathName ,'` does not executable'.
^ self.
].
LLVMConfigPath := path.
BinDir := LibDir := LibraryPath := nil.
"Created: / 07-08-2015 / 13:31:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!LLVMConfig class methodsFor:'accessing'!
bindir
"Returns result of `llvm-config --bindir` as Filename"
BinDir isNil ifTrue:[
LLVMConfigPath isNil ifTrue:[
self error: 'No path to `llvm-config` set, use #llvmConfigPath:'
].
BinDir := OperatingSystem getCommandOutputFrom: LLVMConfigPath asString, ' --bindir'
].
^ BinDir
"
LLVMConfig bindir
"
"Created: / 07-08-2015 / 13:29:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
libdir
"Returns result of `llvm-config --libdir` as Filename"
LibDir isNil ifTrue:[
LLVMConfigPath isNil ifTrue:[
self error: 'No path to `llvm-config` set, use #llvmConfigPath:'
].
LibDir := OperatingSystem getCommandOutputFrom: LLVMConfigPath asString, ' --libdir'.
LibDir asFilename exists ifFalse:[
Logger warning: 'libdir reported by %1 does not exist (%2)' with: LLVMConfigPath with: LibDir.
OperatingSystem isUNIXlike ifTrue:[
"/ Assume Linux here
ExternalAddress pointerSize == 8 ifTrue:[
"/ Pure guess...
LibDir := '/usr/lib/x86_64-linux-gnu'.
] ifFalse:[
LibDir := '/usr/lib/i386-linux-gnu'.
].
] ifFalse:[
self error: 'Unsupported platform'.
]
].
LibDir asFilename exists ifFalse:[
self error: 'Cannot find LLVM libdir'
].
].
^ LibDir
"
LibDir := nil.
LLVMConfig libdir
"
"Created: / 07-08-2015 / 13:41:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified (comment): / 13-09-2015 / 06:59:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
libraryPath
"Return path to `libLLVM.x.y.z.so` for linking"
LibraryPath isNil ifTrue:[
| vsn libpath |
LLVMConfigPath isNil ifTrue:[
self error: 'No path to `llvm-config` set, use #llvmConfigPath:'
].
vsn := OperatingSystem getCommandOutputFrom: LLVMConfigPath asString, ' --version'.
libpath := self libdir asFilename / ('libLLVM-', vsn , '.so').
libpath exists ifFalse:[
"/ OK, try libLLVM-x.y.so.1
libpath := self libdir asFilename / ('libLLVM-', (vsn copyTo: (vsn lastIndexOf: $.) - 1) , '.so.1').
libpath exists ifFalse:[
"/ OK, try libLLCM-x.ysvn.so - LLVM 3.8 source builds use this
(vsn endsWith: 'svn') ifTrue:[
libpath := self libdir asFilename / ('libLLVM-', (vsn copyTo: (vsn lastIndexOf: $.) - 1) , 'svn.so').
].
libpath exists ifFalse:[
self error: 'Could not find libLLVM.x.y.z.so'
].
].
].
LibraryPath := libpath pathName.
].
^ LibraryPath
"
LibraryPath := nil.
LLVMConfig libraryPath
"
"Created: / 07-08-2015 / 14:04:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 26-01-2016 / 15:50:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!LLVMConfig class methodsFor:'documentation'!
version_HG
^ '$Changeset: <not expanded> $'
! !
LLVMConfig initialize!