Skip to content

Commit

Permalink
build: add so versioning when building shared library
Browse files Browse the repository at this point in the history
Signed-off-by: Zephyr Lykos <[email protected]>
  • Loading branch information
mochaaP committed Jul 17, 2023
1 parent c648e83 commit 3f82834
Showing 1 changed file with 74 additions and 1 deletion.
75 changes: 74 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,24 @@ _get_target_filename() {
_ret="${filename}"
}

# get target soname
_get_target_soname() {
local name="${1}"
_get_target_item "${name}" "filename"; local filename="${_ret}"
if test_z "${filename}"; then
_get_target_basename "${name}"; local basename="${_ret}"
_get_target_extension "${name}"; local extension="${_ret}"
_get_target_prefixname "${name}"; local prefixname="${_ret}"
filename="${prefixname}${basename}${extension}"
fi
_get_target_item "${name}" "soversion"; local soversion="${_ret}"
if test_nz "${soversion}"; then
filename="${filename}.${soversion}"
fi

_ret="${filename}"
}

# get target directory
_get_targetdir() {
local name="${1}"
Expand Down Expand Up @@ -1594,6 +1612,13 @@ _get_target_toolchain_flags_for_gcc() {
flags="${flags} -fPIC"
fi
fi
# add soname, https://github.com/tboox/tbox/issues/214#issuecomment-1608882997
if test_eq "${targetkind}" "shared" && test_eq "${toolkind}" "sh" && is_plat "linux"; then
_get_target_soname "${name}"; local soname="${_ret}"
if test_nz "${soname}"; then
flags="${flags} -Wl,-soname,${soname}"
fi
fi
_ret="${flags}"
}

Expand All @@ -1613,6 +1638,11 @@ _get_target_toolchain_flags_for_clang() {
flags="${flags} -fPIC"
fi
fi
# add soname, https://github.com/tboox/tbox/issues/214#issuecomment-1608882997
if test_eq "${targetkind}" "shared" && test_eq "${toolkind}" "sh" && is_plat "linux"; then
_get_target_soname "${name}"; local soname="${_ret}"
flags="${flags} -Wl,-soname,${soname}"
fi
if is_plat "macosx"; then
_os_iorunv "xcrun" "-sdk" "macosx" "--show-sdk-path"; local sdkdir="${_ret}"
if test_nz "${sdkdir}"; then
Expand Down Expand Up @@ -1946,8 +1976,10 @@ set_version() {
fi
local version="${1}"
local version_build="${2}"
local soversion="${3:-${version%%.*}}"
_set_target_item "${_xmake_sh_target_current}" "version" "${version}"
_set_target_item "${_xmake_sh_target_current}" "version_build" "${version_build}"
_set_target_item "${_xmake_sh_target_current}" "soversion" "${soversion}"
}

# set default in target
Expand Down Expand Up @@ -3964,6 +3996,23 @@ _gmake_add_build_target() {
fi
done

local versioned=false
local filebase=""
local targetbase=""
local targetver=""
local targetsover=""
# add soname, https://github.com/tboox/tbox/issues/214#issuecomment-1608882997
if test_eq "${targetkind}" "shared"; then
_get_target_item "${target}" "version"; targetver="${_ret}"
if test_nz "${targetver}"; then
_get_target_item "${target}" "soversion"; targetsover="${_ret}"
path_filename "${targetfile}"; filebase="${_ret}"
targetbase="${targetfile}"
targetfile="${targetfile}.${targetver}"
versioned=true
fi
fi

# link target
echo "${target}: ${targetfile}" >> "${xmake_sh_makefile}"
echo "${targetfile}: ${depfiles}${objectfiles}" >> "${xmake_sh_makefile}"
Expand All @@ -3979,6 +4028,10 @@ _gmake_add_build_target() {
emar) _gmake_add_build_target_for_ar "${toolkind}" "${targetfile}" "${objectfiles}" "${flagname}";;
*) raise "unknown toolname(${toolname})!" ;;
esac
if ${versioned}; then
print "\t@ln -sf ${filebase}.${targetver} ${targetbase}.${targetsover}" >> "${xmake_sh_makefile}"
print "\t@ln -sf ${filebase}.${targetver} ${targetbase}" >> "${xmake_sh_makefile}"
fi
echo "" >> "${xmake_sh_makefile}"

# build objects
Expand Down Expand Up @@ -4073,8 +4126,23 @@ _gmake_add_install_target() {
installdir="\$(INSTALLDIR)"
fi

# install target file
_get_target_item "${target}" "kind"; local targetkind="${_ret}"

local versioned=false
local filebase=""
local targetsover=""
# add soname, https://github.com/tboox/tbox/issues/214#issuecomment-1608882997
if test_eq "${targetkind}" "shared"; then
_get_target_item "${target}" "version"; local version="${_ret}"
if test_nz "${version}"; then
_get_target_item "${target}" "soversion"; targetsover="${_ret}"
filebase="${filename}"
filename="${filename}.${version}"
versioned=true
fi
fi

# install target file
if test_eq "${targetkind}" "binary"; then
string_replace "${_install_bindir_default}" "\${prefix}" "${installdir}"; _install_bindir_default="${_ret}"
print "\t@echo installing ${targetfile} to ${_install_bindir_default}" >> "${xmake_sh_makefile}"
Expand All @@ -4087,6 +4155,11 @@ _gmake_add_install_target() {
print "\t@cp -p ${targetfile} ${_install_libdir_default}/${filename}" >> "${xmake_sh_makefile}"
fi

if ${versioned}; then
print "\t@ln -sf ${filename} ${_install_libdir_default}/${filebase}.${targetsover}" >> "${xmake_sh_makefile}"
print "\t@ln -sf ${filename} ${_install_libdir_default}/${filebase}" >> "${xmake_sh_makefile}"
fi

# install header files
_get_target_item "${target}" "headerfiles"; local headerfiles="${_ret}"
if test_nz "${headerfiles}"; then
Expand Down

0 comments on commit 3f82834

Please sign in to comment.