Skip to content

Commit

Permalink
Building and installation of shared libraries: fixes for portability
Browse files Browse the repository at this point in the history
* Don't assume we are on Linux.
* Let SCons create the symlinks: it knows how to do that.
  • Loading branch information
Olga-Yakovleva committed Sep 9, 2018
1 parent 355dc39 commit 8b8f126
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
2 changes: 0 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ def clone_base_env(base_env,user_vars,arch=None):
env.MergeFlags("-pthread")
env.AppendUnique(CXXFLAGS=["-std=c++03"])
env.AppendUnique(CFLAGS=["-std=c99"])
if sys.platform.startswith("linux"):
env.Append(SHLINKFLAGS="-Wl,-soname,${TARGET.file}.${libversion.split('.')[0]}")
if sys.platform=="win32":
bits="64" if arch.endswith("64") else "32"
env["BUILDDIR"]=os.path.join(BUILDDIR,arch)
Expand Down
19 changes: 6 additions & 13 deletions site_scons/site_tools/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ def exists(env):
else:
return True

def Install(env,src,instpath,instname=None,sysdir=True,mode=0o644):
def Install(env,src,instpath,instname=None,sysdir=True,mode=0o644,shlib=False):
destpath=env.subst("$DESTDIR"+instpath)
env.Alias("install",destpath)
if instname:
inst=env.InstallAs(os.path.join(destpath,instname),src)
else:
inst=env.Install(destpath,src)
if shlib:
inst=env.InstallVersionedLib(destpath,src)
else:
inst=env.Install(destpath,src)
env.AddPostAction(inst,Chmod("$TARGET",mode))
return inst

Expand All @@ -57,17 +60,7 @@ def InstallStaticLibrary(env,src):
return Install(env,src,"$libdir")

def InstallSharedLibrary(env,src):
if sys.platform.startswith("linux"):
name=os.path.split(str(src[0]))[1]
version=env["libversion"]
inst=Install(env,src,"$libdir",instname=name+"."+version,mode=0o755)
libpath=os.path.split(inst[0].path)[0]
for s in [name+"."+version.split(".")[0],name]:
inst+=env.Command(os.path.join(libpath,s),inst[0],"ln -s ${SOURCE.file} ${TARGET.file}",chdir=1)
env.AddPostAction(inst[-1],Chmod("$TARGET",0o755))
else:
inst=Install(env,src,"$libdir",mode=0o755)
return inst
return Install(env,src,"$libdir",shlib=True,mode=0o755)

def InstallLibrary(env,src):
if env.IsLibraryShared():
Expand Down
2 changes: 1 addition & 1 deletion site_scons/site_tools/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def BuildLibrary(env,target,sources):
if sys.platform=="win32":
return env.SharedLibrary(target,sources,MS_LINKER_SUBSYSTEM="WINDOWS")
else:
return env.SharedLibrary(target,sources)
return env.SharedLibrary(target,sources,SHLIBVERSION=env["libversion"])
elif env["liblevel"]==0:
if env.get("enable_shared",False):
return env.SharedObject(sources)
Expand Down

0 comments on commit 8b8f126

Please sign in to comment.