Skip to content

Commit

Permalink
Make companion libs static.
Browse files Browse the repository at this point in the history
This follows the trend set by 1*.sh scripts that configure ISL, GMP,
MPFR, CLooG, etc. Building with shared libraries presents all kinds
of problems:
- The shared libraries need to be installed into ${CT_PREFIX_DIR}.
- The binaries linked against companion libs need to have proper
RPATH, or they're looking for shared libs in
.build/${CT_PREFIX}/buildtools/lib.
- All libraries must agree as to whether they're built shared,
static, or both. Otherwise, gettext tries to link in static libncurses.a
into a shared library and fails (since libncurses was compiled without
the -fPIC switch and hence contains relocations that cannot be handled
in a shared library).

So this fixes the current mess. If we decide to re-enable building
the companion libs shared, we should probably make this dependent on
a separate suboption of CT_STATIC_TOOLCHAIN.

Add a config loosely based on one reported in the issue 274.

Signed-off-by: Alexey Neyman <stilor@att.net>
  • Loading branch information
stilor committed Dec 11, 2016
1 parent da3f8c4 commit 3dbb576
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 35 deletions.
@@ -0,0 +1,26 @@
CT_EXPERIMENTAL=y
CT_LOCAL_TARBALLS_DIR="${HOME}/src"
CT_SAVE_TARBALLS=y
CT_LOG_EXTRA=y
CT_ARCH_CPU="cortex-a9"
CT_ARCH_FPU="neon"
CT_ARCH_FLOAT_HW=y
CT_ARCH_arm=y
CT_TARGET_VENDOR="cortexa9_neon"
CT_CANADIAN=y
CT_HOST="x86_64-w64-mingw32"
CT_TOOLCHAIN_ENABLE_NLS=y
CT_KERNEL_linux=y
CT_BINUTILS_LINKER_LD_GOLD=y
CT_BINUTILS_GOLD_THREADS=y
CT_BINUTILS_LD_WRAPPER=y
CT_LIBC_ADDONS_LIST="libidn"
CT_LIBC_LOCALES=y
CT_LIBC_GLIBC_KERNEL_VERSION_NONE=y
CT_CC_GCC_SHOW_LINARO=y
# CT_CC_GCC_ENABLE_TARGET_OPTSPACE is not set
CT_CC_LANG_CXX=y
CT_DEBUG_gdb=y
# CT_GDB_CROSS_PYTHON is not set
CT_GDB_NATIVE=y
CT_GDB_NATIVE_STATIC=y
@@ -0,0 +1,3 @@
reporter_name="modbw"
reporter_url=""
reporter_comment="Loosely based on config submitted in issue 274"
2 changes: 1 addition & 1 deletion scripts/build/companion_libs/200-libelf.sh
Expand Up @@ -87,7 +87,7 @@ do_libelf_for_target() {
libelf_opts+=( "host=${CT_TARGET}" )

libelf_opts+=( "prefix=${prefix}" )
libelf_opts+=( "shared=y" )
libelf_opts+=( "shared=${CT_SHARED_LIBS}" )
do_libelf_backend "${libelf_opts[@]}"

CT_Popd
Expand Down
8 changes: 4 additions & 4 deletions scripts/build/companion_libs/210-expat.sh
Expand Up @@ -31,7 +31,6 @@ do_expat_for_host() {
expat_opts+=( "prefix=${CT_HOST_COMPLIBS_DIR}" )
expat_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
expat_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
expat_opts+=( "static_build=${CT_STATIC_TOOLCHAIN}" )

do_expat_backend "${expat_opts[@]}"

Expand Down Expand Up @@ -59,7 +58,7 @@ do_expat_for_target() {
esac
expat_opts+=( "prefix=${prefix}" )
expat_opts+=( "destdir=${CT_SYSROOT_DIR}" )
expat_opts+=( "static_build=y" )
expat_opts+=( "shared=${CT_SHARED_LIBS}" )

do_expat_backend "${expat_opts[@]}"

Expand All @@ -78,16 +77,16 @@ do_expat_backend() {
local prefix
local cflags
local ldflags
local shared
local arg
local -a extra_config

for arg in "$@"; do
eval "${arg// /\\ }"
done

if [ "${static_build}" = "y" ]; then
if [ "${shared}" != "y" ]; then
extra_config+=("--disable-shared")
extra_config+=("--enable-static")
fi

CT_DoLog EXTRA "Configuring expat"
Expand All @@ -99,6 +98,7 @@ do_expat_backend() {
--build=${CT_BUILD} \
--host=${host} \
--prefix="${prefix}" \
--enable-static \
"${extra_config[@]}"

CT_DoLog EXTRA "Building expat"
Expand Down
10 changes: 9 additions & 1 deletion scripts/build/companion_libs/220-ncurses.sh
Expand Up @@ -90,6 +90,7 @@ do_ncurses_for_target() {
do_ncurses_backend host="${CT_TARGET}" \
prefix="${prefix}" \
destdir="${CT_SYSROOT_DIR}" \
shared="${CT_SHARED_LIBS}" \
"${opts[@]}"
CT_Popd
CT_EndStep
Expand All @@ -102,13 +103,15 @@ fi
# prefix : prefix to install into : dir : (none)
# cflags : cflags to use : string : (empty)
# ldflags : ldflags to use : string : (empty)
# shared : build shared lib : bool : n
# --* : passed to configure : n/a : n/a
do_ncurses_backend() {
local -a ncurses_opts
local host
local prefix
local cflags
local ldflags
local shared
local arg
local for_target

Expand All @@ -127,7 +130,7 @@ do_ncurses_backend() {
ncurses_opts+=("--with-abi-version=5")
fi

case "$host" in
case "${host}" in
*-*-mingw*)
# Needed to build for mingw, see
# http://lists.gnu.org/archive/html/info-gnu/2011-02/msg00020.html
Expand All @@ -136,6 +139,10 @@ do_ncurses_backend() {
;;
esac

if [ "${shared}" = "y" ]; then
ncurses_opts+=("--with-shared")
fi

CT_DoLog EXTRA "Configuring ncurses"
CT_DoExecLog CFG \
CFLAGS="${cflags}" \
Expand All @@ -145,6 +152,7 @@ do_ncurses_backend() {
--host=${host} \
--prefix="${prefix}" \
--with-install-prefix="${destdir}" \
--without-debug \
--enable-termcap \
"${ncurses_opts[@]}"

Expand Down
18 changes: 4 additions & 14 deletions scripts/build/companion_libs/320-libiconv.sh
Expand Up @@ -35,7 +35,6 @@ do_libiconv_for_build() {
libiconv_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
libiconv_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
libiconv_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
libiconv_opts+=( "static_build=y" )
do_libiconv_backend "${libiconv_opts[@]}"

CT_Popd
Expand All @@ -46,20 +45,13 @@ do_libiconv_for_build() {
do_libiconv_for_host() {
local -a libiconv_opts

case "$CT_HOST" in
*darwin*|*linux*)
return 0
;;
esac

CT_DoStep INFO "Installing libiconv for host"
CT_mkdir_pushd "${CT_BUILD_DIR}/build-libiconv-host-${CT_HOST}"

libiconv_opts+=( "host=${CT_HOST}" )
libiconv_opts+=( "prefix=${CT_HOST_COMPLIBS_DIR}" )
libiconv_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
libiconv_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
libiconv_opts+=( "static_build=${CT_STATIC_TOOLCHAIN}" )
do_libiconv_backend "${libiconv_opts[@]}"

CT_Popd
Expand All @@ -70,13 +62,13 @@ do_libiconv_for_host() {
# Parameter : description : type : default
# host : machine to run on : tuple : (none)
# prefix : prefix to install into : dir : (none)
# static_build : build statically : bool : no
# shared : build shared lib : bool : no
# cflags : host cflags to use : string : (empty)
# ldflags : host ldflags to use : string : (empty)
do_libiconv_backend() {
local host
local prefix
local static_build
local shared
local cflags
local ldflags
local arg
Expand All @@ -88,11 +80,8 @@ do_libiconv_backend() {

CT_DoLog EXTRA "Configuring libiconv"

CT_DoExecLog ALL cp -aT "${CT_SRC_DIR}/libiconv-${CT_LIBICONV_VERSION}/." "."

if [ "${static_build}" = "y" ]; then
if [ "${shared}" != "y" ]; then
extra_config+=("--disable-shared")
extra_config+=("--enable-static")
fi

CT_DoExecLog CFG \
Expand All @@ -102,6 +91,7 @@ do_libiconv_backend() {
--build=${CT_BUILD} \
--host="${host}" \
--prefix="${prefix}" \
--enable-static \
--disable-nls \
"${extra_config[@]}" \

Expand Down
23 changes: 8 additions & 15 deletions scripts/build/companion_libs/330-gettext.sh
Expand Up @@ -35,7 +35,6 @@ do_gettext_for_build() {
gettext_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
gettext_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
gettext_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
gettext_opts+=( "static_build=y" )
do_gettext_backend "${gettext_opts[@]}"

CT_Popd
Expand All @@ -46,20 +45,13 @@ do_gettext_for_build() {
do_gettext_for_host() {
local -a gettext_opts

case "$CT_HOST" in
*linux*)
return 0
;;
esac

CT_DoStep INFO "Installing gettext for host"
CT_mkdir_pushd "${CT_BUILD_DIR}/build-gettext-host-${CT_HOST}"

gettext_opts+=( "host=${CT_HOST}" )
gettext_opts+=( "prefix=${CT_HOST_COMPLIBS_DIR}" )
gettext_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
gettext_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
gettext_opts+=( "static_build=${CT_STATIC_TOOLCHAIN}" )
do_gettext_backend "${gettext_opts[@]}"

CT_Popd
Expand All @@ -70,13 +62,13 @@ do_gettext_for_host() {
# Parameter : description : type : default
# host : machine to run on : tuple : (none)
# prefix : prefix to install into : dir : (none)
# static_build : build statically : bool : no
# shared : build shared lib : bool : no
# cflags : host cflags to use : string : (empty)
# ldflags : host ldflags to use : string : (empty)
do_gettext_backend() {
local host
local prefix
local static_build
local shared
local cflags
local ldflags
local arg
Expand All @@ -88,14 +80,15 @@ do_gettext_backend() {

CT_DoLog EXTRA "Configuring gettext"

CT_DoExecLog ALL cp -av "${CT_SRC_DIR}/gettext-${CT_GETTEXT_VERSION}/." .

# A bit ugly. D__USE_MINGW_ANSI_STDIO=1 has its own {v}asprintf functions
# but gettext configure doesn't see this flag when it checks for that. An
# alternative may be to use CC="${host}-gcc ${cflags}" but that didn't
# work.
# -O2 works around bug at http://savannah.gnu.org/bugs/?36443
# gettext needs some fixing for MinGW-w64 it would seem.
# -DLIBXML_STATIC needed to link with libxml (provided by gnulib) under
# MinGW: without this flag, xmlFree is defined as `dllimport` by libxml
# headers and hence fails to link.
case "${host}" in
*mingw*)
case "${cflags}" in
Expand All @@ -104,13 +97,12 @@ do_gettext_backend() {
;;
esac
extra_config+=( --enable-threads=win32 )
cflags=$cflags" -O2"
cflags=$cflags" -O2 -DLIBXML_STATIC"
;;
esac

if [ "${static_build}" = "y" ]; then
if [ "${shared}" != "y" ]; then
extra_config+=("--disable-shared")
extra_config+=("--enable-static")
fi

CT_DoExecLog CFG \
Expand All @@ -120,6 +112,7 @@ do_gettext_backend() {
--build=${CT_BUILD} \
--host="${host}" \
--prefix="${prefix}" \
--enable-static \
--disable-java \
--disable-native-java \
--disable-csharp \
Expand Down

0 comments on commit 3dbb576

Please sign in to comment.