scripts/build/libc/eglibc.sh
author "Nicolás Reynolds" <fauno@kiwwwi.com.ar>
Fri May 27 22:02:30 2011 -0300 (2011-05-27)
branch1.11
changeset 2553 fe2c448bf3b7
parent 2278 e86826b8621a
child 2483 fa3a18f9abcf
permissions -rw-r--r--
libc/glibc: fix {e,}glibc add-ons with short or long names

Fixes the issue with {e,}glibc addons having short and long names (such as
eglibc-ports-2_13 and ports), which caused configure scripts to run
through them twice and thus configuring incorrectly.

For instance, the mips64el-n32-linux-gnu toolchain would be recognized
correctly first, but then the second pass would change it to mips32,
building a mixed MIPS-III N32 and MIPS-I libc.

Signed-off-by: Nicolás Reynolds <fauno@kiwwwi.com.ar>
[yann.morin.1992@anciens.enib.fr: remove spurious trailing spaces]
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
(transplanted from af25723a794f2017f45c300369a6d36849e22236)
     1 # eglibc build functions (initially by Thomas JOURDAN).
     2 
     3 # Add the definitions common to glibc and eglibc
     4 #   do_libc_start_files
     5 #   do_libc
     6 #   do_libc_finish
     7 #   do_libc_add_ons_list
     8 . "${CT_LIB_DIR}/scripts/build/libc/glibc-eglibc.sh-common"
     9 
    10 # Download eglibc repository
    11 do_eglibc_get() {
    12     CT_HasOrAbort svn
    13 
    14     case "${CT_LIBC_VERSION}" in
    15         trunk)  svn_url="svn://svn.eglibc.org/trunk";;
    16         *)      svn_url="svn://svn.eglibc.org/branches/eglibc-${CT_LIBC_VERSION}";;
    17     esac
    18 
    19     case "${CT_EGLIBC_CHECKOUT}" in
    20         y)  svn_action="checkout";;
    21         *)  svn_action="export --force";;
    22     esac
    23 
    24     CT_DoExecLog ALL svn ${svn_action} -r "${CT_EGLIBC_REVISION:-HEAD}" "${svn_url}" "$(pwd)"
    25 
    26     # Compress eglibc
    27     CT_DoExecLog ALL mv libc "eglibc-${CT_LIBC_VERSION}"
    28     CT_DoExecLog ALL tar cjf "eglibc-${CT_LIBC_VERSION}.tar.bz2" "eglibc-${CT_LIBC_VERSION}"
    29 
    30     # Compress linuxthreads, localedef and ports
    31     # Assign them the name the way ct-ng like it
    32     for addon in linuxthreads localedef ports; do
    33         CT_DoExecLog ALL mv "${addon}" "eglibc-${addon}-${CT_LIBC_VERSION}"
    34         CT_DoExecLog ALL tar cjf "eglibc-${addon}-${CT_LIBC_VERSION}.tar.bz2" "eglibc-${addon}-${CT_LIBC_VERSION}"
    35     done
    36 }
    37 
    38 # Download glibc
    39 do_libc_get() {
    40     # eglibc is only available through subversion, there are no
    41     # snapshots available. Moreover, addons will be downloaded
    42     # simultaneously.
    43 
    44     # build filename
    45     eglibc="eglibc-${CT_LIBC_VERSION}.tar.bz2"
    46     eglibc_linuxthreads="${CT_LIBC}-linuxthreads-${CT_LIBC_VERSION}.tar.bz2"
    47     eglibc_localedef="${CT_LIBC}-localedef-${CT_LIBC_VERSION}.tar.bz2"
    48     eglibc_ports="${CT_LIBC}-ports-${CT_LIBC_VERSION}.tar.bz2"
    49 
    50     # Check if every tarballs are already present
    51     if [    -f "${CT_TARBALLS_DIR}/${eglibc}"                   \
    52          -a -f "${CT_TARBALLS_DIR}/${eglibc_linuxthreads}"      \
    53          -a -f "${CT_TARBALLS_DIR}/${eglibc_localedef}"         \
    54          -a -f "${CT_TARBALLS_DIR}/${eglibc_ports}"             \
    55        ]; then
    56         CT_DoLog DEBUG "Already have 'eglibc-${CT_LIBC_VERSION}'"
    57         return 0
    58     fi
    59 
    60     if [    -f "${CT_LOCAL_TARBALLS_DIR}/${eglibc}"                 \
    61          -a -f "${CT_LOCAL_TARBALLS_DIR}/${eglibc_linuxthreads}"    \
    62          -a -f "${CT_LOCAL_TARBALLS_DIR}/${eglibc_localedef}"       \
    63          -a -f "${CT_LOCAL_TARBALLS_DIR}/${eglibc_ports}"           \
    64          -a "${CT_FORCE_DOWNLOAD}" != "y"                           \
    65        ]; then
    66         CT_DoLog DEBUG "Got 'eglibc-${CT_LIBC_VERSION}' from local storage"
    67         for file in ${eglibc} ${eglibc_linuxthreads} ${eglibc_localedef} ${eglibc_ports}; do
    68             CT_DoExecLog ALL ln -s "${CT_LOCAL_TARBALLS_DIR}/${file}" "${CT_TARBALLS_DIR}/${file}"
    69         done
    70         return 0
    71     fi
    72 
    73     # Not found locally, try from the network
    74     CT_DoLog EXTRA "Retrieving 'eglibc-${CT_LIBC_VERSION}'"
    75 
    76     CT_MktempDir tmp_dir
    77     CT_Pushd "${tmp_dir}"
    78 
    79     do_eglibc_get
    80     CT_DoLog DEBUG "Moving 'eglibc-${CT_LIBC_VERSION}' to tarball directory"
    81     for file in ${eglibc} ${eglibc_linuxthreads} ${eglibc_localedef} ${eglibc_ports}; do
    82         CT_DoExecLog ALL mv -f "${file}" "${CT_TARBALLS_DIR}"
    83     done
    84 
    85     CT_Popd
    86 
    87     # Remove source files
    88     CT_DoExecLog ALL rm -rf "${tmp_dir}"
    89 
    90     if [ "${CT_SAVE_TARBALLS}" = "y" ]; then
    91         CT_DoLog EXTRA "Saving 'eglibc-${CT_LIBC_VERSION}' to local storage"
    92         for file in ${eglibc} ${eglibc_linuxthreads} ${eglibc_localedef} ${eglibc_ports}; do
    93             CT_DoExecLog ALL mv -f "${CT_TARBALLS_DIR}/${file}" "${CT_LOCAL_TARBALLS_DIR}"
    94             CT_DoExecLog ALL ln -s "${CT_LOCAL_TARBALLS_DIR}/${file}" "${CT_TARBALLS_DIR}/${file}"
    95         done
    96     fi
    97 
    98     return 0
    99 }
   100 
   101 # Extract eglibc
   102 do_libc_extract() {
   103     CT_Extract "eglibc-${CT_LIBC_VERSION}"
   104     CT_Patch "eglibc" "${CT_LIBC_VERSION}"
   105 
   106     # C library addons
   107     for addon in $(do_libc_add_ons_list " "); do
   108         # NPTL addon is not to be extracted, in any case
   109         [ "${addon}" = "nptl" ] && continue || true
   110         CT_Pushd "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}"
   111         CT_Extract nochdir "eglibc-${addon}-${CT_LIBC_VERSION}"
   112 
   113         CT_TestAndAbort "Error in add-on '${addon}': both short and long names in tarball" \
   114             -d "${addon}" -a -d "eglibc-${addon}-${CT_LIBC_VERSION}"
   115 
   116         # Some addons have the 'long' name, while others have the
   117         # 'short' name, but patches are non-uniformly built with
   118         # either the 'long' or 'short' name, whatever the addons name
   119         # but we prefer the 'short' name and avoid duplicates.
   120         if [ -d "eglibc-${addon}-${CT_LIBC_VERSION}" ]; then
   121             mv "eglibc-${addon}-${CT_LIBC_VERSION}" "${addon}"
   122         fi
   123 
   124         ln -s "${addon}" "eglibc-${addon}-${CT_LIBC_VERSION}"
   125 
   126         CT_Patch nochdir "eglibc" "${addon}-${CT_LIBC_VERSION}"
   127 
   128         # Remove the long name since it can confuse configure scripts to run
   129         # the same source twice.
   130         rm "eglibc-${addon}-${CT_LIBC_VERSION}"
   131 
   132         CT_Popd
   133     done
   134 
   135     # The configure files may be older than the configure.in files
   136     # if using a snapshot (or even some tarballs). Fake them being
   137     # up to date.
   138     find "${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}" -type f -name configure -exec touch {} \; 2>&1 |CT_DoLog ALL
   139 
   140     return 0
   141 }
   142 
   143 # Copy user provided eglibc configuration file if provided
   144 do_libc_check_config() {
   145     if [ "${CT_EGLIBC_CUSTOM_CONFIG}" != "y" ]; then
   146         return 0
   147     fi
   148 
   149     CT_DoStep INFO "Checking C library configuration"
   150 
   151     CT_TestOrAbort "You did not provide an eglibc config file!" \
   152         -n "${CT_EGLIBC_OPTION_GROUPS_FILE}" -a \
   153         -f "${CT_EGLIBC_OPTION_GROUPS_FILE}"
   154 
   155     CT_DoExecLog ALL cp "${CT_EGLIBC_OPTION_GROUPS_FILE}" "${CT_CONFIG_DIR}/eglibc.config"
   156 
   157     # NSS configuration
   158     if grep -E '^OPTION_EGLIBC_NSSWITCH[[:space:]]*=[[:space:]]*n' "${CT_EGLIBC_OPTION_GROUPS_FILE}" >/dev/null 2>&1; then
   159         CT_DoLog DEBUG "Using fixed-configuration nsswitch facility"
   160 
   161         if [ "${CT_EGLIBC_BUNDLED_NSS_CONFIG}" = "y" ]; then
   162             nss_config="${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/nss/fixed-nsswitch.conf"
   163         else
   164             nss_config="${CT_EGLIBC_NSS_CONFIG_FILE}"
   165         fi
   166         CT_TestOrAbort "NSS config file not found!" -n "${nss_config}" -a -f "${nss_config}"
   167 
   168         CT_DoExecLog ALL cp "${nss_config}" "${CT_CONFIG_DIR}/nsswitch.config"
   169         echo "OPTION_EGLIBC_NSSWITCH_FIXED_CONFIG = ${CT_CONFIG_DIR}/nsswitch.config" \
   170             >> "${CT_CONFIG_DIR}/eglibc.config"
   171 
   172         if [ "${CT_EGLIBC_BUNDLED_NSS_FUNCTIONS}" = "y" ]; then
   173             nss_functions="${CT_SRC_DIR}/eglibc-${CT_LIBC_VERSION}/nss/fixed-nsswitch.functions"
   174         else
   175             nss_functions="${CT_EGLIBC_NSS_FUNCTIONS_FILE}"
   176         fi
   177         CT_TestOrAbort "NSS functions file not found!" -n "${nss_functions}" -a -f "${nss_functions}"
   178 
   179         CT_DoExecLog ALL cp "${nss_functions}" "${CT_CONFIG_DIR}/nsswitch.functions"
   180         echo "OPTION_EGLIBC_NSSWITCH_FIXED_FUNCTIONS = ${CT_CONFIG_DIR}/nsswitch.functions" \
   181             >> "${CT_CONFIG_DIR}/eglibc.config"
   182     else
   183         CT_DoLog DEBUG "Using full-blown nsswitch facility"
   184     fi
   185 
   186     CT_EndStep
   187 }