diff options
author | Steve Bennett <steveb@workware.net.au> | 2011-12-10 08:20:32 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2011-12-12 13:44:43 +1000 |
commit | bdc3729473a79b144cbdf49fddeb288b05ccc8f5 (patch) | |
tree | b219fc22b5ec26688c04281f9fda9d9839a67c2e | |
parent | 9798fcccedb779101becaac5313afb80dbbd283d (diff) | |
download | jimtcl-bdc3729473a79b144cbdf49fddeb288b05ccc8f5.zip jimtcl-bdc3729473a79b144cbdf49fddeb288b05ccc8f5.tar.gz jimtcl-bdc3729473a79b144cbdf49fddeb288b05ccc8f5.tar.bz2 |
Better dynamic extension building
If libjim is built shared, ensure that all symbols are resolved.
This can't be done if libjim is built static.
Also, build-jim-ext now shows stderr from the compiler and linker
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | Makefile.in | 4 | ||||
-rw-r--r-- | autosetup/cc-shared.tcl | 9 | ||||
-rw-r--r-- | build-jim-ext.in | 66 |
3 files changed, 63 insertions, 16 deletions
diff --git a/Makefile.in b/Makefile.in index 8ea97cb..fa70ef3 100644 --- a/Makefile.in +++ b/Makefile.in @@ -10,7 +10,11 @@ STRIP = @STRIP@ SH_CFLAGS ?= @SH_CFLAGS@ SH_LDFLAGS ?= @SH_LDFLAGS@ SHOBJ_CFLAGS ?= @SHOBJ_CFLAGS@ +@if JIM_STATICLIB SHOBJ_LDFLAGS ?= @SHOBJ_LDFLAGS@ +@else +SHOBJ_LDFLAGS ?= @SHOBJ_LDFLAGS_R@ +@endif CFLAGS = @CFLAGS@ CXXFLAGS = @CXXFLAGS@ LDFLAGS = @LDFLAGS@ diff --git a/autosetup/cc-shared.tcl b/autosetup/cc-shared.tcl index 204e06f..1ff9071 100644 --- a/autosetup/cc-shared.tcl +++ b/autosetup/cc-shared.tcl @@ -9,7 +9,8 @@ ## SH_CFLAGS Flags to use compiling sources destined for a shared library ## SH_LDFLAGS Flags to use linking a shared library ## SHOBJ_CFLAGS Flags to use compiling sources destined for a shared object -## SHOBJ_LDFLAGS Flags to use linking a shared object +## SHOBJ_LDFLAGS Flags to use linking a shared object, undefined symbols allowed +## SHOBJ_LDFLAGS_R - as above, but all symbols must be resolved ## SH_LINKFLAGS Flags to use linking an executable which will load shared objects ## LD_LIBRARY_PATH Environment variable which specifies path to shared libraries @@ -27,11 +28,13 @@ switch -glob -- [get-define host] { define SH_LDFLAGS "-dynamiclib" define SHOBJ_CFLAGS "-dynamic -fno-common" define SHOBJ_LDFLAGS "-bundle -undefined dynamic_lookup" + define SHOBJ_LDFLAGS_R "-bundle" define LD_LIBRARY_PATH DYLD_LIBRARY_PATH } *-*-ming* { define SH_LDFLAGS -shared define SHOBJ_LDFLAGS -shared + define SHOBJ_LDFLAGS_R -shared } *-*-cygwin { define SH_LDFLAGS -shared @@ -69,3 +72,7 @@ switch -glob -- [get-define host] { define SHOBJ_LDFLAGS -shared } } + +if {![is-defined SHOBJ_LDFLAGS_R]} { + define SHOBJ_LDFLAGS_R [get-define SHOBJ_LDFLAGS] +} diff --git a/build-jim-ext.in b/build-jim-ext.in index 8eb42fa..9566b83 100644 --- a/build-jim-ext.in +++ b/build-jim-ext.in @@ -12,6 +12,16 @@ proc usage {{msg {}}} { exit 1 } +proc readfile {filename {default_value ""}} { + set result $default_value + catch { + set f [open $filename] + set result [$f read -nonewline] + $f close + } + return $result +} + set linker "@CC@" set testmod 1 set install 0 @@ -101,11 +111,19 @@ lappend includepaths -I@prefix@/include set CPPFLAGS "-D_GNU_SOURCE" -if {"@JIM_STATICLIB@" eq "1" && !$static} { - puts stderr "Warning: libjim is static. Dynamic module may not work on some platforms.\n" - set ljim "" -} else { - set ljim -ljim +set ljim "" +set shobj_cflags "" +set shobj_ldflags "" +if {!$static} { + set shobj_cflags "@SHOBJ_CFLAGS@" + if {"@JIM_STATICLIB@" eq "1"} { + puts stderr "Warning: libjim is static. Dynamic module may not work on some platforms.\n" + set shobj_ldflags "@SHOBJ_LDFLAGS@" + } else { + # If shared, link against the shared libjim to resolve symbols + set ljim -ljim + set shobj_ldflags "@SHOBJ_LDFLAGS_R@" + } } set objs {} @@ -116,25 +134,34 @@ foreach source $sources { } else { set compiler "@CXX@" } - if {$static} { - set shobj_cflags "" - } else { - set shobj_cflags "@SHOBJ_CFLAGS@" - } set compile "$compiler @CFLAGS@ $CPPFLAGS $shobj_cflags $includepaths $opts -c -o $obj $source" puts "Compile: $obj" lappend objs $obj + flush stdout set rc [catch { - exec {*}$compile if {$verbose} { - puts stderr $compile + puts $compile } + exec 2>jimerr.out {*}$compile } msg] + + set errmsg [readfile jimerr.out] + file delete jimerr.out + if {$rc} { - puts stderr $compile + if {!$verbose} { + puts stderr $compile + } puts stderr $msg + if {$errmsg ne ""} { + puts stderr $errmsg + } file delete {*}$objs exit 1 + } else { + if {$errmsg ne ""} { + puts $errmsg + } } } @@ -165,16 +192,19 @@ if {$static} { # Add the standard location after any user lib paths lappend libpaths -L@prefix@/lib - set link "$linker @CFLAGS@ @LDFLAGS@ @SHOBJ_LDFLAGS@ $libpaths $opts -o $target $objs $ljim @LIBS@ $libs" + set link "$linker @CFLAGS@ @LDFLAGS@ $shobj_ldflags $libpaths $opts -o $target $objs $ljim @LIBS@ $libs" puts "Link: $target" set rc [catch { - exec {*}$link if {$verbose} { puts stderr $link } + exec 2>jimerr.out {*}$link } msg] + set errmsg [readfile jimerr.out] + file delete jimerr.out + if {!$keep} { file delete {*}$objs } @@ -183,8 +213,14 @@ if {$static} { file delete $target puts stderr $link puts stderr $msg + if {$errmsg ne ""} { + puts stderr $errmsg + } exit 1 } + if {$errmsg ne ""} { + puts $errmsg + } if {$testmod} { # Now, is testing even possible? |