Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Try to fix linux libraries not found on /lib /usr/lib + now ncurses o…
Browse files Browse the repository at this point in the history
…r tinfo are not needed & openal & glut do not require dev versions, only runtime ones (#519)
  • Loading branch information
soywiz authored Mar 21, 2022
1 parent 6ee5d31 commit 55b99f1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -1028,9 +1028,9 @@ afterEvaluate {

if (isLinux) {
project.logger.info("LD folders: ${LDLibraries.ldFolders}")
for (lib in listOf("libncurses.so.5", "libtinfo.so.5", "libglut.so.3", "libopenal.so.1")) {
for (lib in listOf("libglut.so.3", "libopenal.so.1")) {
if (!LDLibraries.hasLibrary(lib)) {
System.err.println("Can't find $lib. Please: sudo apt-get -y install freeglut3-dev libopenal-dev libncurses5 libtinfo5")
System.err.println("Can't find $lib. Please: sudo apt-get -y install freeglut3 libopenal1")
}
}
}
30 changes: 24 additions & 6 deletions buildSrc/src/main/kotlin/com/soywiz/korlibs/util/LDLibraries.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,32 @@ import java.nio.file.Files
object LDLibraries {
private val libFolders = LinkedHashSet<File>()
private val loadConfFiles = LinkedHashSet<File>()

val ldFolders: List<File> get() = libFolders.toList()

// /etc/ld.so.conf
// include /etc/ld.so.conf.d/*.conf

fun addPath(path: String) {
val file = File(path)
if (file.isDirectory) {
libFolders.add(file)
}
}

init {
try {
// Fixed paths as described https://renenyffenegger.ch/notes/Linux/fhs/etc/ld_so_conf
addPath("/lib")
addPath("/usr/lib")
// Load config file
loadConfFile(File("/etc/ld.so.conf"))
} catch (e: Throwable) {
e.printStackTrace()
}
}

val ldFolders = libFolders.toList()

fun hasLibrary(name: String) = ldFolders.any { File(it, name).exists() }
fun hasLibrary(name: String) = libFolders.any { File(it, name).exists() }

private fun loadConfFile(file: File) {
if (file in loadConfFiles) return
Expand All @@ -29,11 +41,17 @@ object LDLibraries {

if (tline.startsWith("include ")) {
val glob = tline.removePrefix("include ")
for (folder in Files.newDirectoryStream(File(glob).parentFile.toPath(), File(glob).name).toList().map { it.toFile() }) {
loadConfFile(folder)
val globFolder = File(glob).parentFile
val globPattern = File(glob).name
if (globFolder.isDirectory) {
for (folder in
Files.newDirectoryStream(globFolder.toPath(), globPattern).toList().map { it.toFile() }
) {
loadConfFile(folder)
}
}
} else {
libFolders += File(tline)
addPath(tline)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class KorgeGradleApply(val project: Project) {

if (isLinux) {
project.logger.info("LD folders: ${LDLibraries.ldFolders}")
for (lib in listOf("libncurses.so.5", "libtinfo.so.5", "libglut.so.3", "libopenal.so.1")) {
for (lib in listOf("libglut.so.3", "libopenal.so.1")) {
if (!LDLibraries.hasLibrary(lib)) {
System.err.println("Can't find $lib. Please: sudo apt-get -y install freeglut3-dev libopenal-dev libncurses5 libtinfo5")
System.err.println("Can't find $lib. Please: sudo apt-get -y install freeglut3 libopenal1")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,32 @@ import java.nio.file.Files
object LDLibraries {
private val libFolders = LinkedHashSet<File>()
private val loadConfFiles = LinkedHashSet<File>()

val ldFolders: List<File> get() = libFolders.toList()

// /etc/ld.so.conf
// include /etc/ld.so.conf.d/*.conf

fun addPath(path: String) {
val file = File(path)
if (file.isDirectory) {
libFolders.add(file)
}
}

init {
try {
// Fixed paths as described https://renenyffenegger.ch/notes/Linux/fhs/etc/ld_so_conf
addPath("/lib")
addPath("/usr/lib")
// Load config file
loadConfFile(File("/etc/ld.so.conf"))
} catch (e: Throwable) {
e.printStackTrace()
}
}

val ldFolders = libFolders.toList()

fun hasLibrary(name: String) = ldFolders.any { File(it, name).exists() }
fun hasLibrary(name: String) = libFolders.any { File(it, name).exists() }

private fun loadConfFile(file: File) {
if (file in loadConfFiles) return
Expand All @@ -33,13 +45,13 @@ object LDLibraries {
val globPattern = File(glob).name
if (globFolder.isDirectory) {
for (folder in
Files.newDirectoryStream(globFolder.toPath(), globPattern).toList().map { it.toFile() }
Files.newDirectoryStream(globFolder.toPath(), globPattern).toList().map { it.toFile() }
) {
loadConfFile(folder)
}
}
} else {
libFolders += File(tline)
addPath(tline)
}
}
}
Expand Down

0 comments on commit 55b99f1

Please sign in to comment.