summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2024-03-19 19:22:28 +0000
committerOmar Rizwan <omar@omar.website>2024-03-19 19:22:28 +0000
commit3fc8f85c828d9dde9db826fdef8db0744ae674a3 (patch)
tree20aa77d569a5c5b57d43d0916ce45368c6ec699c
parentfolk0: Stick with 720p for now (diff)
downloadfolk-3fc8f85c828d9dde9db826fdef8db0744ae674a3.tar.gz
folk-3fc8f85c828d9dde9db826fdef8db0744ae674a3.zip
Make loadlibLd, filter by architecture if multiple candidates
Fixes https://discord.com/channels/956758212152025098/956758650700046366/1202431317971570728
-rw-r--r--lib/c.tcl12
-rw-r--r--lib/terminal.tcl2
-rw-r--r--main.tcl2
-rw-r--r--pi/Camera.tcl8
-rw-r--r--pi/Gpu.tcl2
-rw-r--r--virtual-programs/images.folk7
6 files changed, 24 insertions, 9 deletions
diff --git a/lib/c.tcl b/lib/c.tcl
index 5d995fd5..abc696b9 100644
--- a/lib/c.tcl
+++ b/lib/c.tcl
@@ -524,9 +524,19 @@ namespace eval c {
$loader compile
proc loadlib {filename} {
if {[loadlibImpl $filename] == "(void*) 0x0"} {
- error "Failed to dlopen $filename: [loadlibError]"
+ error "c loadlib: Failed to dlopen $filename: [loadlibError]"
}
}
+ proc loadlibLd {libname} {
+ set candidates [split [exec /usr/sbin/ldconfig -p | grep $libname] "\n"]
+ if {[llength $candidates] == 0} {
+ error "c loadlibLd: Could not find library $libname"
+ } elseif {[llength $candidates] > 1} {
+ # Is it greater than 1? if so, filter by arch
+ set candidates [lsearch -all -inline $candidates *$::tcl_platform(machine)*]
+ }
+ loadlib [lindex $candidates 0 end]
+ }
namespace export *
namespace ensemble create
diff --git a/lib/terminal.tcl b/lib/terminal.tcl
index f81847e6..2ab8dd2d 100644
--- a/lib/terminal.tcl
+++ b/lib/terminal.tcl
@@ -63,7 +63,7 @@ set cc [c create]
$cc cflags -I./vendor/libtmt ./vendor/libtmt/tmt.c
if {$::tcl_platform(os) ne "Darwin"} {
- c loadlib [lindex [exec /usr/sbin/ldconfig -p | grep libutil.so | head -1] end]
+ c loadlibLd libutil
}
$cc cflags -lutil
diff --git a/main.tcl b/main.tcl
index cdc15393..fa82a336 100644
--- a/main.tcl
+++ b/main.tcl
@@ -468,7 +468,7 @@ namespace eval ::Heap {
}
if {$::tcl_platform(os) eq "Linux"} {
$cc cflags -lrt
- c loadlib [lindex [exec /usr/sbin/ldconfig -p | grep librt.so | head -1] end]
+ c loadlibLd librt.so
}
$cc compile
folkHeapMount
diff --git a/pi/Camera.tcl b/pi/Camera.tcl
index 10c2812b..3532805c 100644
--- a/pi/Camera.tcl
+++ b/pi/Camera.tcl
@@ -272,9 +272,11 @@ namespace eval Camera {
folkHeapFree(image.data);
}
- c loadlib [expr {$tcl_platform(os) eq "Darwin" ?
- "/opt/homebrew/lib/libjpeg.dylib" :
- [lindex [exec /usr/sbin/ldconfig -p | grep libjpeg] end]}]
+ if {$tcl_platform(os) eq "Darwin"} {
+ c loadlib "/opt/homebrew/lib/libjpeg.dylib"
+ } else {
+ c loadlibLd libjpeg.so
+ }
camc compile
variable camera
diff --git a/pi/Gpu.tcl b/pi/Gpu.tcl
index cfeecba8..c6bdfa75 100644
--- a/pi/Gpu.tcl
+++ b/pi/Gpu.tcl
@@ -1514,7 +1514,7 @@ Try doing `sudo chmod 666 $renderFile`."
if {!$macos} {
# Needed on Raspberry Pi 4:
- c loadlib [lindex [exec /usr/sbin/ldconfig -p | grep libatomic.so | head -1] end]
+ c loadlibLd libatomic.so
}
dc compile
diff --git a/virtual-programs/images.folk b/virtual-programs/images.folk
index 1be51424..002760c0 100644
--- a/virtual-programs/images.folk
+++ b/virtual-programs/images.folk
@@ -23,10 +23,13 @@ namespace eval ::image {
}
set cc [c create]
- c loadlib [expr {$tcl_platform(os) eq "Darwin" ? "/opt/homebrew/lib/libjpeg.dylib" : [lindex [exec /usr/sbin/ldconfig -p | grep libjpeg] end]}]
- c loadlib [expr {$tcl_platform(os) eq "Darwin" ? "/opt/homebrew/lib/libpng.dylib" : [lindex [exec /usr/sbin/ldconfig -p | grep libpng] end]}]
if {$tcl_platform(os) eq "Darwin"} {
+ c loadlib "/opt/homebrew/lib/libjpeg.dylib"
+ c loadlib "/opt/homebrew/lib/libpng.dylib"
$cc cflags -I/opt/homebrew/include -L/opt/homebrew/lib
+ } else {
+ c loadlibLd libjpeg.so
+ c loadlibLd libpng
}
$cc cflags -ljpeg -lpng