scripts/build/libc/eglibc.sh
author Bob Dunlop <bob.dunlop@xyzzy.org.uk>
Tue Nov 09 10:44:29 2010 +0100 (2010-11-09)
changeset 2178 42cc9bd0db7e
parent 2154 250cdcc86441
child 2180 d3af3efce68c
child 2232 f0318bba39bc
permissions -rw-r--r--
libc/eglibc: fix downloading

Since Subversion 1.6.13 was released, it is no longer possible
to checkout/export to the current working directory using '.'
(eg. "svn co bla://blabla/foo/bar ." no longer extracts the content
of bar into ./ but into ./bar).

Fix this by luring Subversion to extract into "$(pwd)", which has
the advantage of working both with all known versions so far.

At the same time, remove the useless redirection.
     1 # eglibc build functions (initially by Thomas JOURDAN).
     2 
     3 # Download eglibc repository
     4 do_eglibc_get() {
     5     CT_HasOrAbort svn
     6 
     7     case "${CT_LIBC_VERSION}" in
     8         trunk)  svn_url="svn://svn.eglibc.org/trunk";;
     9         *)      svn_url="svn://svn.eglibc.org/branches/eglibc-${CT_LIBC_VERSION}";;
    10     esac
    11 
    12     case "${CT_EGLIBC_CHECKOUT}" in
    13         y)  svn_action="checkout";;
    14         *)  svn_action="export --force";;
    15     esac
    16 
    17     CT_DoExecLog ALL svn ${svn_action} -r "${CT_EGLIBC_REVISION:-HEAD}" "${svn_url}" "$(pwd)"
    18 
    19     # Compress eglibc
    20     CT_DoExecLog ALL mv libc "eglibc-${CT_LIBC_VERSION}"
    21     CT_DoExecLog ALL tar cjf "eglibc-${CT_LIBC_VERSION}.tar.bz2" "eglibc-${CT_LIBC_VERSION}"
    22 
    23     # Compress linuxthreads, localedef and ports
    24     # Assign them the name the way ct-ng like it
    25     for addon in linuxthreads localedef ports; do
    26         CT_DoExecLog ALL mv "${addon}" "eglibc-${addon}-${CT_LIBC_VERSION}"
    27         CT_DoExecLog ALL tar cjf "eglibc-${addon}-${CT_LIBC_VERSION}.tar.bz2" "eglibc-${addon}-${CT_LIBC_VERSION}"
    28     done
    29 }
    30 
    31 # Download glibc
    32 do_libc_get() {
    33     # eglibc is only available through subversion, there are no
    34     # snapshots available. Moreover, addons will be downloaded
    35     # simultaneously.
    36 
    37     # build filename
    38     eglibc="eglibc-${CT_LIBC_VERSION}.tar.bz2"
    39     eglibc_linuxthreads="${CT_LIBC}-linuxthreads-${CT_LIBC_VERSION}.tar.bz2"
    40     eglibc_localedef="${CT_LIBC}-localedef-${CT_LIBC_VERSION}.tar.bz2"
    41     eglibc_ports="${CT_LIBC}-ports-${CT_LIBC_VERSION}.tar.bz2"
    42 
    43     # Check if every tarballs are already present
    44     if [    -f "${CT_TARBALLS_DIR}/${eglibc}"                   \
    45          -a -f "${CT_TARBALLS_DIR}/${eglibc_linuxthreads}"      \
    46          -a -f "${CT_TARBALLS_DIR}/${eglibc_localedef}"         \
    47          -a -f "${CT_TARBALLS_DIR}/${eglibc_ports}"             \
    48        ]; then
    49         CT_DoLog DEBUG "Already have 'eglibc-${CT_LIBC_VERSION}'"
    50         return 0
    51     fi
    52 
    53     if [    -f "${CT_LOCAL_TARBALLS_DIR}/${eglibc}"                 \
    54          -a -f "${CT_LOCAL_TARBALLS_DIR}/${eglibc_linuxthreads}"    \
    55          -a -f "${CT_LOCAL_TARBALLS_DIR}/${eglibc_localedef}"       \
    56          -a -f "${CT_LOCAL_TARBALLS_DIR}/${eglibc_ports}"           \
    57          -a "${CT_FORCE_DOWNLOAD}" != "y"                           \
    58        ]; then
    59         CT_DoLog DEBUG "Got 'eglibc-${CT_LIBC_VERSION}' from local storage"
    60         for file in ${eglibc} ${eglibc_linuxthreads} ${eglibc_localedef} ${eglibc_ports}; do
    61             CT_DoExecLog ALL ln -s "${CT_LOCAL_TARBALLS_DIR}/${file}" "${CT_TARBALLS_DIR}/${file}"
    62         done
    63         return 0
    64     fi
    65 
    66     # Not found locally, try from the network
    67     CT_DoLog EXTRA "Retrieving 'eglibc-${CT_LIBC_VERSION}'"
    68 
    69     CT_MktempDir tmp_dir
    70     CT_Pushd "${tmp_dir}"
    71 
    72     do_eglibc_get
    73     CT_DoLog DEBUG "Moving 'eglibc-${CT_LIBC_VERSION}' to tarball directory"
    74     for file in ${eglibc} ${eglibc_linuxthreads} ${eglibc_localedef} ${eglibc_ports}; do
    75         CT_DoExecLog ALL mv -f "${file}" "${CT_TARBALLS_DIR}"
    76     done
    77 
    78     CT_Popd
    79 
    80     # Remove source files
    81     CT_DoExecLog ALL rm -rf "${tmp_dir}"
    82 
    83     if [ "${CT_SAVE_TARBALLS}" = "y" ]; then
    84         CT_DoLog EXTRA "Saving 'eglibc-${CT_LIBC_VERSION}' to local storage"
    85         for file in ${eglibc} ${eglibc_linuxthreads} ${eglibc_localedef} ${eglibc_ports}; do
    86             CT_DoExecLog ALL mv -f "${CT_TARBALLS_DIR}/${file}" "${CT_LOCAL_TARBALLS_DIR}"
    87             CT_DoExecLog ALL ln -s "${CT_LOCAL_TARBALLS_DIR}/${file}" "${CT_TARBALLS_DIR}/${file}"
    88         done
    89     fi
    90 
    91     return 0
    92 }
    93 
    94 # Extract eglibc
    95 do_libc_extract() {
    96     CT_Extract "eglibc-${CT_LIBC_VERSION}"
    97     CT_Patch "eglibc" "${CT_LIBC_VERSION}"
    98 
    99     # C library addons
   100     for addon in $(do_libc_add_ons_list " "); do
   101         # NPTL addon is not to be extracted, in any case
   102         [ "${addon}" = "nptl" ] && continue || true
   103         CT_Pushd "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}"
   104         CT_Extract nochdir "eglibc-${addon}-${CT_LIBC_VERSION}"
   105         # Some addons have the 'long' name, while others have the
   106         # 'short' name, but patches are non-uniformly built with
   107         # either the 'long' or 'short' name, whatever the addons name
   108         # so we have to make symlinks from the existing to the missing
   109         # Fortunately for us, [ -d foo ], when foo is a symlink to a
   110         # directory, returns true!
   111         [ -d "${addon}" ] || ln -s "eglibc-${addon}-${CT_LIBC_VERSION}" "${addon}"
   112         [ -d "eglibc-${addon}-${CT_LIBC_VERSION}" ] || ln -s "${addon}" "eglibc-${addon}-${CT_LIBC_VERSION}"
   113         CT_Patch nochdir "eglibc" "${addon}-${CT_LIBC_VERSION}"
   114         CT_Popd
   115     done
   116 
   117     # The configure files may be older than the configure.in files
   118     # if using a snapshot (or even some tarballs). Fake them being
   119     # up to date.
   120     find "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}" -type f -name configure -exec touch {} \; 2>&1 |CT_DoLog ALL
   121 
   122     return 0
   123 }
   124 
   125 # Copy user provided eglibc configuration file if provided
   126 do_libc_check_config() {
   127     if [ "${CT_EGLIBC_CUSTOM_CONFIG}" != "y" ]; then
   128         return 0
   129     fi
   130 
   131     CT_DoStep INFO "Checking C library configuration"
   132 
   133     CT_TestOrAbort "You did not provide an eglibc config file!" \
   134         -n "${CT_EGLIBC_OPTION_GROUPS_FILE}" -a \
   135         -f "${CT_EGLIBC_OPTION_GROUPS_FILE}"
   136 
   137     CT_DoExecLog ALL cp "${CT_EGLIBC_OPTION_GROUPS_FILE}" "${CT_CONFIG_DIR}/eglibc.config"
   138 
   139     # NSS configuration
   140     if grep -E '^OPTION_EGLIBC_NSSWITCH[[:space:]]*=[[:space:]]*n' "${CT_EGLIBC_OPTION_GROUPS_FILE}" >/dev/null 2>&1; then
   141         CT_DoLog DEBUG "Using fixed-configuration nsswitch facility"
   142 
   143         if [ "${CT_EGLIBC_BUNDLED_NSS_CONFIG}" = "y" ]; then
   144             nss_config="${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/nss/fixed-nsswitch.conf"
   145         else
   146             nss_config="${CT_EGLIBC_NSS_CONFIG_FILE}"
   147         fi
   148         CT_TestOrAbort "NSS config file not found!" -n "${nss_config}" -a -f "${nss_config}"
   149 
   150         CT_DoExecLog ALL cp "${nss_config}" "${CT_CONFIG_DIR}/nsswitch.config"
   151         echo "OPTION_EGLIBC_NSSWITCH_FIXED_CONFIG = ${CT_CONFIG_DIR}/nsswitch.config" \
   152             >> "${CT_CONFIG_DIR}/eglibc.config"
   153 
   154         if [ "${CT_EGLIBC_BUNDLED_NSS_FUNCTIONS}" = "y" ]; then
   155             nss_functions="${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/nss/fixed-nsswitch.functions"
   156         else
   157             nss_functions="${CT_EGLIBC_NSS_FUNCTIONS_FILE}"
   158         fi
   159         CT_TestOrAbort "NSS functions file not found!" -n "${nss_functions}" -a -f "${nss_functions}"
   160 
   161         CT_DoExecLog ALL cp "${nss_functions}" "${CT_CONFIG_DIR}/nsswitch.functions"
   162         echo "OPTION_EGLIBC_NSSWITCH_FIXED_FUNCTIONS = ${CT_CONFIG_DIR}/nsswitch.functions" \
   163             >> "${CT_CONFIG_DIR}/eglibc.config"
   164     else
   165         CT_DoLog DEBUG "Using full-blown nsswitch facility"
   166     fi
   167 
   168     CT_EndStep
   169 }
   170 
   171 # This function installs the eglibc headers needed to build the core compiler
   172 do_libc_headers() {
   173     # Instead of doing two time the same actions, headers will
   174     # be installed with start files
   175     :
   176 }
   177 
   178 # Build and install start files
   179 do_libc_start_files() {
   180     CT_DoStep INFO "Installing C library headers / start files"
   181 
   182     mkdir -p "${CT_BUILD_DIR}/build-libc-startfiles"
   183     cd "${CT_BUILD_DIR}/build-libc-startfiles"
   184 
   185     CT_DoLog EXTRA "Configuring C library"
   186 
   187     if [ "${CT_EGLIBC_CUSTOM_CONFIG}" = "y" ]; then
   188         CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/eglibc.config" option-groups.config
   189     fi
   190 
   191     cross_cc=$(CT_Which "${CT_TARGET}-gcc")
   192     cross_cxx=$(CT_Which "${CT_TARGET}-g++")
   193     cross_ar=$(CT_Which "${CT_TARGET}-ar")
   194     cross_ranlib=$(CT_Which "${CT_TARGET}-ranlib")
   195     
   196     CT_DoLog DEBUG "Using gcc for target: '${cross_cc}'"
   197     CT_DoLog DEBUG "Using g++ for target: '${cross_cxx}'"
   198     CT_DoLog DEBUG "Using ar for target: '${cross_ar}'"
   199     CT_DoLog DEBUG "Using ranlib for target: '${cross_ranlib}'"
   200 
   201     BUILD_CC="${CT_BUILD}-gcc"                          \
   202     CC=${cross_cc}                                      \
   203     CXX=${cross_cxx}                                    \
   204     AR=${cross_ar}                                      \
   205     RANLIB=${cross_ranlib}                              \
   206     CT_DoExecLog CFG                                    \
   207     "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/configure" \
   208         --prefix=/usr                                   \
   209         --with-headers="${CT_HEADERS_DIR}"              \
   210         --build="${CT_BUILD}"                           \
   211         --host="${CT_TARGET}"                           \
   212         --disable-profile                               \
   213         --without-gd                                    \
   214         --without-cvs                                   \
   215         --enable-add-ons
   216 
   217     CT_DoLog EXTRA "Installing C library headers"
   218 
   219     # use the 'install-headers' makefile target to install the
   220     # headers
   221 
   222     CT_DoExecLog ALL                    \
   223     make install-headers                \
   224          install_root=${CT_SYSROOT_DIR} \
   225          install-bootstrap-headers=yes
   226 
   227     CT_DoLog EXTRA "Installing C library start files"
   228 
   229     # there are a few object files needed to link shared libraries,
   230     # which we build and install by hand
   231 
   232     CT_DoExecLog ALL mkdir -p ${CT_SYSROOT_DIR}/usr/lib
   233     CT_DoExecLog ALL make csu/subdir_lib
   234     CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \
   235         ${CT_SYSROOT_DIR}/usr/lib
   236 
   237     # Finally, 'libgcc_s.so' requires a 'libc.so' to link against.  
   238     # However, since we will never actually execute its code, 
   239     # it doesn't matter what it contains.  So, treating '/dev/null' 
   240     # as a C source file, we produce a dummy 'libc.so' in one step
   241 
   242     CT_DoExecLog ALL ${cross_cc} -nostdlib -nostartfiles -shared -x c /dev/null -o ${CT_SYSROOT_DIR}/usr/lib/libc.so
   243 
   244     CT_EndStep
   245 }
   246 
   247 # This function builds and install the full glibc
   248 do_libc() {
   249     local -a extra_config
   250 
   251     CT_DoStep INFO "Installing C library"
   252 
   253     mkdir -p "${CT_BUILD_DIR}/build-libc"
   254     cd "${CT_BUILD_DIR}/build-libc"
   255 
   256     CT_DoLog EXTRA "Configuring C library"
   257 
   258     if [ "${CT_EGLIBC_CUSTOM_CONFIG}" = "y" ]; then
   259         CT_DoExecLog ALL cp "${CT_CONFIG_DIR}/eglibc.config" option-groups.config
   260     fi
   261 
   262     if [ "${CT_EGLIBC_OPT_SIZE}" = "y" ]; then
   263         OPTIMIZE=-Os
   264     else
   265         OPTIMIZE=-O2
   266     fi
   267 
   268     # Add some default glibc config options if not given by user.
   269     # We don't need to be conditional on wether the user did set different
   270     # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG is passed after extra_config
   271 
   272     extra_config+=("--enable-kernel=$(echo ${CT_LIBC_GLIBC_MIN_KERNEL} |sed -r -e 's/^([^.]+\.[^.]+\.[^.]+)(|\.[^.]+)$/\1/;')")
   273 
   274     case "${CT_THREADS}" in
   275         nptl)           extra_config+=("--with-__thread" "--with-tls");;
   276         linuxthreads)   extra_config+=("--with-__thread" "--without-tls" "--without-nptl");;
   277         none)           extra_config+=("--without-__thread" "--without-nptl")
   278                         case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
   279                             *-tls*) ;;
   280                             *) extra_config+=("--without-tls");;
   281                         esac
   282                         ;;
   283     esac
   284 
   285     case "${CT_SHARED_LIBS}" in
   286         y) extra_config+=("--enable-shared");;
   287         *) extra_config+=("--disable-shared");;
   288     esac
   289 
   290     case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
   291         y,) extra_config+=("--with-fp");;
   292         ,y) extra_config+=("--without-fp");;
   293     esac
   294 
   295     case "$(do_libc_add_ons_list ,)" in
   296         "") ;;
   297         *)  extra_config+=("--enable-add-ons=$(do_libc_add_ons_list ,)");;
   298     esac
   299 
   300     extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}"
   301 
   302     cross_cc=$(CT_Which "${CT_TARGET}-gcc")    
   303 
   304     CT_DoLog DEBUG "Using gcc for target:     '${cross_cc}'"
   305     CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'"
   306     CT_DoLog DEBUG "Extra config args passed: '${extra_config[*]}'"
   307     CT_DoLog DEBUG "Extra CC args passed    : '${extra_cc_args}'"
   308 
   309     BUILD_CC="${CT_BUILD}-gcc"                                      \
   310     CFLAGS="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} ${OPTIMIZE}"  \
   311     CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \
   312     AR=${CT_TARGET}-ar                                              \
   313     RANLIB=${CT_TARGET}-ranlib                                      \
   314     CT_DoExecLog CFG                                                \
   315     "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/configure"             \
   316         --prefix=/usr                                               \
   317         --with-headers="${CT_HEADERS_DIR}"                          \
   318         --build=${CT_BUILD}                                         \
   319         --host=${CT_TARGET}                                         \
   320         --disable-profile                                           \
   321         --without-gd                                                \
   322         --without-cvs                                               \
   323         "${extra_config[@]}"                                        \
   324         ${CT_LIBC_GLIBC_EXTRA_CONFIG}
   325     
   326     CT_DoLog EXTRA "Building C library"
   327 
   328     # eglibc build hacks
   329     # http://sourceware.org/ml/crossgcc/2008-10/msg00068.html
   330     case "${CT_ARCH},${CT_ARCH_CPU}" in
   331         powerpc,8??)
   332             CT_DoLog DEBUG "Activating support for memset on broken ppc-8xx (CPU15 erratum)"
   333             EGLIBC_BUILD_ASFLAGS="-DBROKEN_PPC_8xx_CPU15";;
   334     esac
   335 
   336     CT_DoExecLog ALL make ASFLAGS="${EGLIBC_BUILD_ASFLAGS}"
   337 
   338     CT_DoLog EXTRA "Installing C library"
   339 
   340     CT_DoExecLog ALL make install install_root="${CT_SYSROOT_DIR}"
   341 
   342     CT_EndStep
   343 }
   344 
   345 # This function finishes the glibc install
   346 do_libc_finish() {
   347     # Nothing to be done for eglibc
   348     :
   349 }
   350 
   351 # Build up the addons list, separated with $1
   352 do_libc_add_ons_list() {
   353     local sep="$1"
   354     local addons_list=$(echo "${CT_LIBC_ADDONS_LIST//,/${sep}}" |tr -s ,)
   355     case "${CT_THREADS}" in
   356         none)   ;;
   357         *)      addons_list="${addons_list}${sep}${CT_THREADS}";;
   358     esac
   359     [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && addons_list="${addons_list}${sep}ports"
   360     addons_list="${addons_list%%${sep}}"
   361     echo "${addons_list##${sep}}"
   362 }