Fossil SCM

Add rpath when required (eg for NetBSD) so libs in less-common directories are found at runtime

danshearer 2026-08-18 11:47 UTC autodef-build-fixes
Commit d45b557c00f6c5a774a3a4aca4f4ea231459d94ee40a16ff272b35e0e359e5e2
1 file changed +26 -1
+26 -1
--- auto.def
+++ auto.def
@@ -377,11 +377,34 @@
377377
} else {
378378
msg-result "no"
379379
return 0
380380
}
381381
}
382
-
382
+#
383
+# Give a runtime search path to every -L directory we added ourselves.
384
+#
385
+# The probes below look outside the compiler's default paths for various OSs.
386
+# A -L will link at build time but the runtime linker needs to find the libs too.
387
+# The pkgsrc convention is to add the matching rpath so rtld works.
388
+#
389
+proc fossil-rpath-ldflags {ldflags} {
390
+ set rv {}
391
+ foreach flag $ldflags {
392
+ if {![string match -L* $flag]} continue
393
+ set dir [string range $flag 2 end]
394
+ if {$dir eq "" || ![file isdirectory $dir]} continue
395
+ set rp "-Wl,-rpath,$dir"
396
+ if {$rp in $rv} continue
397
+ if {[cctest -link 1 -cflags $rp]} {
398
+ lappend rv $rp
399
+ }
400
+ }
401
+ if {[llength $rv]} {
402
+ define-append EXTRA_LDFLAGS {*}$rv
403
+ msg-result "Runtime search path: $rv"
404
+ }
405
+}
383406
#
384407
# Check for zlib, using the given location if specified
385408
#
386409
proc handle-zlib {} {
387410
set ::zlibpath [opt-val with-zlib]; # used by downstream tcl tests
@@ -429,10 +452,11 @@
429452
if {$lcheck eq ""} {
430453
msg-result "Linked to zlib via default library path"
431454
} else {
432455
define-append EXTRA_LDFLAGS "$lcheck"
433456
msg-result "Linked to zlib via $lcheck"
457
+ fossil-rpath-ldflags $lcheck
434458
}
435459
# Keep the flags that worked for every later probe too, in the
436460
# persistent form of cc-with, as the --with-zlib=tree branch above
437461
# already does. check-for-openssl appends $::zlib_lib to its own link
438462
# test, and without these it links a bare -lz against a path autosetup
@@ -530,10 +554,11 @@
530554
}
531555
if {$found} {
532556
define FOSSIL_ENABLE_SSL
533557
define-append EXTRA_CFLAGS $cflags
534558
define-append EXTRA_LDFLAGS $ldflags
559
+ fossil-rpath-ldflags $ldflags
535560
if {[info exists ssllibs]} {
536561
define-append LIBS $ssllibs
537562
} else {
538563
define-append LIBS -lssl -lcrypto
539564
}
540565
--- auto.def
+++ auto.def
@@ -377,11 +377,34 @@
377 } else {
378 msg-result "no"
379 return 0
380 }
381 }
382
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
383 #
384 # Check for zlib, using the given location if specified
385 #
386 proc handle-zlib {} {
387 set ::zlibpath [opt-val with-zlib]; # used by downstream tcl tests
@@ -429,10 +452,11 @@
429 if {$lcheck eq ""} {
430 msg-result "Linked to zlib via default library path"
431 } else {
432 define-append EXTRA_LDFLAGS "$lcheck"
433 msg-result "Linked to zlib via $lcheck"
 
434 }
435 # Keep the flags that worked for every later probe too, in the
436 # persistent form of cc-with, as the --with-zlib=tree branch above
437 # already does. check-for-openssl appends $::zlib_lib to its own link
438 # test, and without these it links a bare -lz against a path autosetup
@@ -530,10 +554,11 @@
530 }
531 if {$found} {
532 define FOSSIL_ENABLE_SSL
533 define-append EXTRA_CFLAGS $cflags
534 define-append EXTRA_LDFLAGS $ldflags
 
535 if {[info exists ssllibs]} {
536 define-append LIBS $ssllibs
537 } else {
538 define-append LIBS -lssl -lcrypto
539 }
540
--- auto.def
+++ auto.def
@@ -377,11 +377,34 @@
377 } else {
378 msg-result "no"
379 return 0
380 }
381 }
382 #
383 # Give a runtime search path to every -L directory we added ourselves.
384 #
385 # The probes below look outside the compiler's default paths for various OSs.
386 # A -L will link at build time but the runtime linker needs to find the libs too.
387 # The pkgsrc convention is to add the matching rpath so rtld works.
388 #
389 proc fossil-rpath-ldflags {ldflags} {
390 set rv {}
391 foreach flag $ldflags {
392 if {![string match -L* $flag]} continue
393 set dir [string range $flag 2 end]
394 if {$dir eq "" || ![file isdirectory $dir]} continue
395 set rp "-Wl,-rpath,$dir"
396 if {$rp in $rv} continue
397 if {[cctest -link 1 -cflags $rp]} {
398 lappend rv $rp
399 }
400 }
401 if {[llength $rv]} {
402 define-append EXTRA_LDFLAGS {*}$rv
403 msg-result "Runtime search path: $rv"
404 }
405 }
406 #
407 # Check for zlib, using the given location if specified
408 #
409 proc handle-zlib {} {
410 set ::zlibpath [opt-val with-zlib]; # used by downstream tcl tests
@@ -429,10 +452,11 @@
452 if {$lcheck eq ""} {
453 msg-result "Linked to zlib via default library path"
454 } else {
455 define-append EXTRA_LDFLAGS "$lcheck"
456 msg-result "Linked to zlib via $lcheck"
457 fossil-rpath-ldflags $lcheck
458 }
459 # Keep the flags that worked for every later probe too, in the
460 # persistent form of cc-with, as the --with-zlib=tree branch above
461 # already does. check-for-openssl appends $::zlib_lib to its own link
462 # test, and without these it links a bare -lz against a path autosetup
@@ -530,10 +554,11 @@
554 }
555 if {$found} {
556 define FOSSIL_ENABLE_SSL
557 define-append EXTRA_CFLAGS $cflags
558 define-append EXTRA_LDFLAGS $ldflags
559 fossil-rpath-ldflags $ldflags
560 if {[info exists ssllibs]} {
561 define-append LIBS $ssllibs
562 } else {
563 define-append LIBS -lssl -lcrypto
564 }
565

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button