LLVMConfig.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 07 Aug 2015 14:10:48 +0100
changeset 21 64c5f01be2b3
child 36 51ac97a0e87d
permissions -rw-r--r--
Introduced class LLVMConfig to abstract a particular LLVM version

"
    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."

    LLVMConfigPath := nil.
    OperatingSystem isUNIXlike ifTrue:[ 
        #('-3.8' '-3.7' '') do:[:ver |
            | path |
            path := OperatingSystem pathOfCommand: 'llvm-config' , ver.
            path notNil ifTrue:[
                self llvmConfigPath: path.
                ^ self.
            ]
        ].
        ^ self
    ].
    self error: 'This iperating system is not supported'.

    "Modified: / 07-08-2015 / 14:06:24 / 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

    "
    LLVMConfig libdir
    "

    "Created: / 07-08-2015 / 13:41:30 / 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:[ 
            self error: 'Could not find libLLVM.x.y.z.so'
        ].
        LibraryPath := libpath pathName.                                                        

    ].
    ^ LibraryPath 

    "
    LLVMConfig libraryPath
    "

    "Created: / 07-08-2015 / 14:04:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LLVMConfig class methodsFor:'documentation'!

version
    ^ 'Path: jv/llvm_s/LLVMConfig.st, Version: 1.0, User: jv, Time: 2015-08-07T14:09:57.868+01'
!

version_HG
    ^ 'Path: jv/llvm_s/LLVMConfig.st, Version: 1.0, User: jv, Time: 2015-08-07T14:09:57.868+01'
! !


LLVMConfig initialize!