scripts/build/libc_glibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon May 07 09:04:02 2007 +0000 (2007-05-07)
changeset 63 89b41dbffe8d
parent 1 eeea35fbf182
child 64 7dab8d1a2426
permissions -rw-r--r--
Merge the save-sample branch to trunk:
- reorder most of the environment setup,
- geting, extracting and patching are now components' sub-actions,
- save the current config as a sample to be used as a pre-configured target.
     1 # This file adds functions to build glibc
     2 # Copyright 2007 Yann E. MORIN
     3 # Licensed under the GPL v2. See COPYING in the root of this package
     4 
     5 # Download glibc
     6 do_libc_download() {
     7     # Ah! Not all GNU folks seem stupid. All glibc releases are in the same
     8     # directory. Good. Alas, there is no snapshot there. I'll deal with them
     9     # later on... :-/
    10     CT_GetFile "${CT_LIBC_FILE}" ftp://ftp.gnu.org/gnu/glibc
    11 
    12     # C library addons
    13     addons_list=`echo "${CT_LIBC_ADDONS}" |sed -r -e 's/,/ /g; s/ $//g;'`
    14     for addon in ${addons_list}; do
    15         CT_GetFile "${CT_LIBC}-${addon}-${CT_LIBC_VERSION}" ftp://ftp.gnu.org/gnu/glibc
    16     done
    17     [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && CT_GetFile "${CT_LIBC}-ports-${CT_LIBC_VERSION}" ftp://ftp.gnu.org/gnu/glibc
    18 }
    19 
    20 # Extract glibc
    21 do_libc_extract() {
    22     CT_ExtractAndPatch "${CT_LIBC_FILE}"
    23 
    24     # C library addons
    25     addons_list=`echo "${CT_LIBC_ADDONS}" |sed -r -e 's/,/ /g; s/ $//g;'`
    26     for addon in ${addons_list}; do
    27         CT_ExtractAndPatch "${CT_LIBC}-${addon}-${CT_LIBC_VERSION}"
    28     done
    29     [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && CT_ExtractAndPatch "${CT_LIBC}-ports-${CT_LIBC_VERSION}"
    30 }
    31 
    32 # There is nothing to do for glibc check config
    33 do_libc_check_config() {
    34     CT_DoStep INFO "Checking C library configuration"
    35     CT_DoLog EXTRA "glibc has nothing to check"
    36     CT_EndStep
    37 }
    38 
    39 # This function installs the glibc headers needed to build the core compiler
    40 do_libc_headers() {
    41     # Only need to install bootstrap glibc headers for gcc-3.0 and above?  Or maybe just gcc-3.3 and above?
    42     # See also http://gcc.gnu.org/PR8180, which complains about the need for this step.
    43     grep -q 'gcc-[34]' "${CT_SRC_DIR}/${CT_CC_CORE_FILE}/ChangeLog" || return 0
    44 
    45     CT_DoStep INFO "Installing C library headers"
    46 
    47     mkdir -p "${CT_BUILD_DIR}/build-libc-headers"
    48     cd "${CT_BUILD_DIR}/build-libc-headers"
    49 
    50     CT_DoLog EXTRA "Configuring C library headers"
    51 
    52     # The following three things have to be done to build glibc-2.3.x, but they don't hurt older versions.
    53     # 1. override CC to keep glibc's configure from using $TARGET-gcc. 
    54     # 2. disable linuxthreads, which needs a real cross-compiler to generate tcb-offsets.h properly
    55     # 3. build with gcc 3.2 or later
    56     # Compare these options with the ones used when building glibc for real below - they're different.
    57     # As of glibc-2.3.2, to get this step to work for hppa-linux, you need --enable-hacker-mode
    58     # so when configure checks to make sure gcc has access to the assembler you just built...
    59     # Alternately, we could put ${PREFIX}/${TARGET}/bin on the path.
    60     # Set --build so maybe we don't have to specify "cross-compiling=yes" below (haven't tried yet)
    61     # Note: the warning
    62     # "*** WARNING: Are you sure you do not want to use the `linuxthreads'"
    63     # *** add-on?"
    64     # is ok here, since all we want are the basic headers at this point.
    65     # Override libc_cv_ppc_machine so glibc-cvs doesn't complain
    66     # 'a version of binutils that supports .machine "altivec" is needed'.
    67     libc_cv_ppc_machine=yes                     \
    68     CC=${CT_CC_NATIVE}                          \
    69     "${CT_SRC_DIR}/${CT_LIBC_FILE}/configure"   \
    70         --build="${CT_BUILD}"                   \
    71         --host="${CT_TARGET}"                   \
    72         --prefix=/usr                           \
    73         --with-headers="${CT_HEADERS_DIR}"      \
    74         --without-cvs                           \
    75         --disable-sanity-checks                 \
    76         --enable-hacker-mode                    \
    77         --enable-add-ons=""                     \
    78         --without-nptl                          2>&1 |CT_DoLog DEBUG
    79 
    80     CT_DoLog EXTRA "Installing C library headers"
    81 
    82     if grep -q GLIBC_2.3 "${CT_SRC_DIR}/${CT_LIBC_FILE}/ChangeLog"; then
    83         # glibc-2.3.x passes cross options to $(CC) when generating errlist-compat.c,
    84         # which fails without a real cross-compiler.
    85         # Fortunately, we don't need errlist-compat.c, since we just need .h
    86         # files, so work around this by creating a fake errlist-compat.c and
    87         # satisfying its dependencies.
    88         # Another workaround might be to tell configure to not use any cross
    89         # options to $(CC).
    90         # The real fix would be to get install-headers to not generate
    91         # errlist-compat.c.
    92         # Note: BOOTSTRAP_GCC is used by:
    93         # patches/glibc-2.3.5/glibc-mips-bootstrap-gcc-header-install.patch
    94         libc_cv_ppc_machine=yes                             \
    95         make CFLAGS=-DBOOTSTRAP_GCC sysdeps/gnu/errlist.c   2>&1 |CT_DoLog DEBUG
    96         mkdir -p stdio-common
    97         # sleep for 2 seconds for benefit of filesystems with lousy time
    98         # resolution, like FAT, so make knows for sure errlist-compat.c doesn't
    99         # need generating
   100         sleep 2
   101         touch stdio-common/errlist-compat.c
   102     fi
   103     # Note: BOOTSTRAP_GCC (see above)
   104     libc_cv_ppc_machine=yes                                 \
   105     make cross-compiling=yes install_root=${CT_SYSROOT_DIR} \
   106         CFLAGS=-DBOOTSTRAP_GCC ${LIBC_SYSROOT_ARG}          \
   107         install-headers                                     2>&1 |CT_DoLog DEBUG
   108 
   109     # Two headers -- stubs.h and features.h -- aren't installed by install-headers,
   110     # so do them by hand.  We can tolerate an empty stubs.h for the moment.
   111     # See e.g. http://gcc.gnu.org/ml/gcc/2002-01/msg00900.html
   112     mkdir -p "${CT_HEADERS_DIR}/gnu"
   113     touch "${CT_HEADERS_DIR}/gnu/stubs.h"
   114     cp "${CT_SRC_DIR}/${CT_LIBC_FILE}/include/features.h" "${CT_HEADERS_DIR}/features.h"
   115 
   116     # Building the bootstrap gcc requires either setting inhibit_libc, or
   117     # having a copy of stdio_lim.h... see
   118     # http://sources.redhat.com/ml/libc-alpha/2003-11/msg00045.html
   119     cp bits/stdio_lim.h "${CT_HEADERS_DIR}/bits/stdio_lim.h"
   120 
   121     # Following error building gcc-4.0.0's gcj:
   122     #  error: bits/syscall.h: No such file or directory
   123     # solved by following copy; see http://sourceware.org/ml/crossgcc/2005-05/msg00168.html
   124     # but it breaks arm, see http://sourceware.org/ml/crossgcc/2006-01/msg00091.html
   125     [ "${CT_ARCH}" != "arm" ] && cp misc/syscall-list.h "${CT_HEADERS_DIR}/bits/syscall.h" || true
   126 
   127     CT_EndStep
   128 }
   129 
   130 # This function builds and install the full glibc
   131 do_libc() {
   132     CT_DoStep INFO "Installing C library"
   133 
   134     mkdir -p "${CT_BUILD_DIR}/build-libc"
   135     cd "${CT_BUILD_DIR}/build-libc"
   136 
   137     CT_DoLog EXTRA "Configuring C library"
   138 
   139     # Add some default glibc config options if not given by user.
   140     extra_config=""
   141     case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
   142         *enable-kernel*) ;;
   143         *) extra_config="${extra_config} --enable-kernel=${CT_KERNEL_VERSION}"
   144     esac
   145     case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
   146         *-tls*) ;;
   147         *) extra_config="${extra_config} --without-tls"
   148     esac
   149     case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
   150         *-__thread*) ;;
   151         *) extra_config="${extra_config} --without-__thread"
   152     esac
   153     case "${CT_SHARED_LIBS}" in
   154         y) extra_config="${extra_config} --enable-shared";;
   155         *) extra_config="${extra_config} --disable-shared";;
   156     esac
   157     case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
   158     	*--with-fp*) ;;
   159     	*--without-fp*) ;;
   160     	*)  case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
   161                 y,) extra_config="${extra_config} --with-fp";;
   162                 ,y) extra_config="${extra_config} --without-fp";;
   163             esac;;
   164     esac
   165     case "${CT_LIBC_ADDONS},${CT_LIBC_ADDONS_LIST}" in
   166         y,) extra_config="${extra_config} --enable-add-ons";;
   167         y,*) extra_config="${extra_config} --enable-add-ons=${CT_LIBC_ADDONS_LIST}";;
   168     esac
   169 
   170     CT_DoLog DEBUG "Extra config args passed: \"${extra_config}\""
   171 
   172     # Add some default CC args
   173     extra_cc_args="${CT_CFLAGS_FOR_HOST}"
   174     case "${CT_LIBC_EXTRA_CC_ARGS}" in
   175         *-mbig-endian*) ;;
   176         *-mlittle-endian*) ;;
   177         *)  case "${CT_ARCH_BE},${CT_ARCH_LE}" in
   178                 y,) extra_cc_args="${extra_cc_args} -mbig-endian";;
   179                 ,y) extra_cc_args="${extra_cc_args} -mlittle-endian";;
   180             esac;;
   181     esac
   182 
   183     CT_DoLog DEBUG "Extra CC args passed: \"${extra_cc_args}\""
   184 
   185     # sh3 and sh4 really need to set configparms as of gcc-3.4/glibc-2.3.2
   186     # note: this is awkward, doesn't work well if you need more than one line in configparms
   187     echo ${CT_LIBC_GLIBC_CONFIGPARMS} > configparms
   188 
   189     # For glibc 2.3.4 and later we need to set some autoconf cache
   190     # variables, because nptl/sysdeps/pthread/configure.in does not
   191     # work when cross-compiling.
   192     if test -d ${GLIBC_DIR}/nptl; then
   193         libc_cv_forced_unwind=yes
   194         libc_cv_c_cleanup=yes
   195         export libc_cv_forced_unwind libc_cv_c_cleanup
   196     fi
   197 
   198     # Configure with --prefix the way we want it on the target...
   199     # There are a whole lot of settings here.  You'll probably want
   200     # to read up on what they all mean, and customize a bit, possibly by setting GLIBC_EXTRA_CONFIG
   201     # Compare these options with the ones used when installing the glibc headers above - they're different.
   202     # Adding "--without-gd" option to avoid error "memusagestat.c:36:16: gd.h: No such file or directory" 
   203     # See also http://sources.redhat.com/ml/libc-alpha/2000-07/msg00024.html. 
   204     # Set BUILD_CC, or you won't be able to build datafiles
   205     # Set --build, else glibc-2.3.2 will think you're not cross-compiling, and try to run the test programs
   206 
   207     BUILD_CC=${CT_CC_NATIVE}                                        \
   208     CFLAGS="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} -O"   \
   209     CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \
   210     AR=${CT_TARGET}-ar                                              \
   211     RANLIB=${CT_TARGET}-ranlib                                      \
   212     "${CT_SRC_DIR}/${CT_LIBC_FILE}/configure"                       \
   213         --prefix=/usr                                               \
   214         --build=${CT_BUILD} --host=${CT_TARGET}                     \
   215         ${CT_LIBC_GLIBC_EXTRA_CONFIG}                               \
   216         ${extra_config}                                             \
   217         --without-cvs                                               \
   218         --disable-profile                                           \
   219         --disable-debug                                             \
   220         --without-gd                                                \
   221         --with-headers="${CT_HEADERS_DIR}"                          2>&1 |CT_DoLog DEBUG
   222 
   223     if grep -l '^install-lib-all:' "${CT_SRC_DIR}/${CT_LIBC_FILE}/Makerules" > /dev/null; then
   224         # nptl-era glibc.
   225         # If the install-lib-all target (which is added by our make-install-lib-all.patch)
   226         # is present, it means we're building glibc-2.3.3 or later, and we can't
   227         # build programs yet, as they require libeh, which won't be installed
   228         # until full build of gcc
   229         GLIBC_INITIAL_BUILD_RULE=lib
   230         GLIBC_INITIAL_INSTALL_RULE="install-lib-all install-headers"
   231         GLIBC_INSTALL_APPS_LATER=yes
   232     else
   233         # classic glibc.  
   234         # We can build and install everything with the bootstrap compiler.
   235         GLIBC_INITIAL_BUILD_RULE=all
   236         GLIBC_INITIAL_INSTALL_RULE=install
   237         GLIBC_INSTALL_APPS_LATER=no
   238     fi
   239 
   240     # If this fails with an error like this:
   241     # ...  linux/autoconf.h: No such file or directory 
   242     # then you need to set the KERNELCONFIG variable to point to a .config file for this arch.
   243     # The following architectures are known to need kernel .config: alpha, arm, ia64, s390, sh, sparc
   244     # Note: LD and RANLIB needed by glibc-2.1.3's c_stub directory, at least on macosx
   245     # No need for PARALLELMFLAGS here, Makefile already reads this environment variable
   246     CT_DoLog EXTRA "Building C library"
   247     make LD=${CT_TARGET}-ld             \
   248          RANLIB=${CT_TARGET}-ranlib     \
   249          ${GLIBC_INITIAL_BUILD_RULE}    2>&1 |CT_DoLog DEBUG
   250 
   251     CT_DoLog EXTRA "Installing C library"
   252     make install_root="${CT_SYSROOT_DIR}"   \
   253          ${LIBC_SYSROOT_ARG}                \
   254          ${GLIBC_INITIAL_INSTALL_RULE}      2>&1 |CT_DoLog DEBUG
   255 
   256     # This doesn't seem to work when building a crosscompiler,
   257     # as it tries to execute localedef using the just-built ld.so!?
   258     #CT_DoLog EXTRA "Installing locales"
   259     #make localedata/install-locales install_root=${SYSROOT} 2>&1 |CT_DoLog DEBUG
   260 
   261     # Fix problems in linker scripts.
   262     #
   263     # 1. Remove absolute paths
   264     # Any file in a list of known suspects that isn't a symlink is assumed to be a linker script.
   265     # FIXME: test -h is not portable
   266     # FIXME: probably need to check more files than just these three...
   267     # Need to use sed instead of just assuming we know what's in libc.so because otherwise alpha breaks
   268     #
   269     # 2. Remove lines containing BUG per http://sources.redhat.com/ml/bug-glibc/2003-05/msg00055.html,
   270     # needed to fix gcc-3.2.3/glibc-2.3.2 targeting arm
   271     #
   272     # To make "strip *.so.*" not fail (ptxdist does this), rename to .so_orig rather than .so.orig
   273     CT_DoLog EXTRA "Fixing C library linker scripts"
   274     for file in libc.so libpthread.so libgcc_s.so; do
   275         for dir in lib lib64 usr/lib usr/lib64; do
   276             if [ -f "${CT_SYSROOT_DIR}/${dir}/${file}" -a ! -L ${CT_SYSROOT_DIR}/$lib/$file ]; then
   277                 mv "${CT_SYSROOT_DIR}/${dir}/${file}" "${CT_SYSROOT_DIR}/${dir}/${file}_orig"
   278                 CT_DoLog DEBUG "Fixing \"${CT_SYS_ROOT_DIR}/${dir}/${file}\""
   279                 sed -i -r -e 's,/usr/lib/,,g;
   280                               s,/usr/lib64/,,g;
   281                               s,/lib/,,g;
   282                               s,/lib64/,,g;
   283                               /BUG in libc.scripts.output-format.sed/d' "${CT_SYSROOT_DIR}/${dir}/${file}_orig"
   284             fi
   285         done
   286     done
   287 
   288     CT_EndStep
   289 }
   290 
   291 # This function finishes the glibc install
   292 do_libc_finish() {
   293     # Finally, build and install glibc programs, now that libeh (if any) is installed
   294     # Don't do this unless needed, 'cause it causes glibc-2.{1.3,2.2} to fail here with
   295     # .../gcc-3.4.1-glibc-2.1.3/build-glibc/libc.so.6: undefined reference to `__deregister_frame_info'
   296     # .../gcc-3.4.1-glibc-2.1.3/build-glibc/libc.so.6: undefined reference to `__register_frame_info'
   297     [ "${GLIBC_INSTALL_APPS_LATER}" = "yes" ] || return 0
   298 
   299     CT_DoStep INFO "Finishing C library"
   300 
   301     cd "${CT_BUILD_DIR}/build-libc"
   302 
   303     CT_DoLog EXTRA "Re-building C library"
   304     make LD=${CT_TARGET}-ld RANLIB=${CT_TARGET}-ranlib 2>&1 |CT_DoLog DEBUG
   305 
   306     CT_DoLog EXTRA "Installing missing C library components"
   307     # note: should do full install and then fix linker scripts, but this is faster
   308     for t in bin rootsbin sbin data others; do
   309         make install_root="${CT_SYSROOT_DIR}"   \
   310              ${LIBC_SYSROOT_ARG}                \
   311              install-${t}                       2>&1 |CT_DoLog DEBUG
   312     done
   313 }