scripts/build/libc/eglibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Jan 17 23:04:37 2011 +0100 (2011-01-17)
changeset 2270 287e1e00dea4
parent 2229 6884dcb80121
child 2278 e86826b8621a
permissions -rw-r--r--
libc/eglibc: move generic code to a common file

The build procedure for eglibc is generic enough to
be shared between glibc and eglibc. This includes:
- headers install (empty!)
- start files build
- complete libc build
- libc finish (empty!)
- add-ons list

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