scripts/build/libc/eglibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Sep 30 18:19:18 2008 +0000 (2008-09-30)
changeset 892 187d34a9adf4
parent 867 c91b266f4dfa
child 1041 2573519c00d6
permissions -rw-r--r--
Better handle the second pass core gcc build, differentiating between gcc prior to 4.3 with gcc from 4.3.
Simplify detecting wether gcc is 4.3 and later, or older than 4.3 (we already know from .config).

/trunk/scripts/build/cc/gcc.sh | 22 13 9 0 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
     1 # eglibc build functions (initially by Thomas JOURDAN).
     2 
     3 do_print_filename() {
     4     [ "${CT_LIBC}" = "eglibc" ] || return 0
     5     echo "eglibc-${CT_LIBC_VERSION}"
     6     for addon in $(do_libc_add_ons_list " "); do
     7         # NPTL addon is not to be downloaded, in any case
     8         [ "${addon}" = "nptl" ] && continue || true
     9         echo "eglibc-${addon}-${CT_LIBC_VERSION}"
    10     done
    11 }
    12 
    13 # Download eglibc repository
    14 do_eglibc_get() {
    15     CT_HasOrAbort svn
    16 
    17     case "${CT_LIBC_VERSION}" in
    18         trunk)  svn_url="svn://svn.eglibc.org/trunk";;
    19         *)      svn_url="svn://svn.eglibc.org/branches/eglibc-${CT_LIBC_VERSION}";;
    20     esac
    21 
    22     case "${CT_EGLIBC_CHECKOUT}" in
    23         y)  svn_action="checkout";;
    24         *)  svn_action="export --force";;
    25     esac
    26 
    27     CT_DoSetProxy ${CT_PROXY_TYPE}
    28     CT_DoExecLog ALL svn ${svn_action} -r "${CT_EGLIBC_REVISION:-HEAD}" "${svn_url}" . 2>&1
    29 
    30     # Compress eglibc
    31     CT_DoExecLog ALL mv libc "${CT_LIBC_FILE}"
    32     CT_DoExecLog ALL tar cjf "${CT_LIBC_FILE}.tar.bz2" "${CT_LIBC_FILE}"
    33 
    34     # Compress linuxthreads, localedef and ports
    35     # Assign them the name the way ct-ng like it
    36     for addon in linuxthreads localedef ports; do
    37         CT_DoExecLog ALL tar cjf "${CT_LIBC}-${addon}-${CT_LIBC_VERSION}.tar.bz2" "${addon}"
    38     done
    39 }
    40 
    41 # Download glibc
    42 do_libc_get() {
    43     # eglibc is only available through subversion, there are no
    44     # snapshots available. Moreover, addons will be downloaded
    45     # simultaneously.
    46 
    47     # build filename
    48     eglibc="${CT_LIBC_FILE}.tar.bz2"
    49     eglibc_linuxthreads="${CT_LIBC}-linuxthreads-${CT_LIBC_VERSION}.tar.bz2"
    50     eglibc_localedef="${CT_LIBC}-localedef-${CT_LIBC_VERSION}.tar.bz2"
    51     eglibc_ports="${CT_LIBC}-ports-${CT_LIBC_VERSION}.tar.bz2"
    52 
    53     # Check if every tarballs are already present
    54     if [ -a "${CT_TARBALLS_DIR}/${eglibc}" ]              && \
    55        [ -a "${CT_TARBALLS_DIR}/${eglibc_linuxthreads}" ] && \
    56        [ -a "${CT_TARBALLS_DIR}/${eglibc_localedef}" ]    && \
    57        [ -a "${CT_TARBALLS_DIR}/${eglibc_ports}" ]; then
    58         CT_DoLog DEBUG "Already have 'eglibc-${CT_LIBC_VERSION}'"
    59         return 0
    60     fi
    61 
    62     if [ -a "${CT_LOCAL_TARBALLS_DIR}/${eglibc}" ]              && \
    63        [ -a "${CT_LOCAL_TARBALLS_DIR}/${eglibc_linuxthreads}" ] && \
    64        [ -a "${CT_LOCAL_TARBALLS_DIR}/${eglibc_localedef}" ]    && \
    65        [ -a "${CT_LOCAL_TARBALLS_DIR}/${eglibc_ports}" ]        && \
    66        [ "${CT_FORCE_DOWNLOAD}" != "y" ]; 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_ExtractAndPatch "${CT_LIBC_FILE}"
   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_ExtractAndPatch "${CT_LIBC}-${addon}-${CT_LIBC_VERSION}"
   111     done
   112 
   113     # The configure files may be older than the configure.in files
   114     # if using a snapshot (or even some tarballs). Fake them being
   115     # up to date.
   116     find "${CT_SRC_DIR}/${CT_LIBC_FILE}" -type f -name configure -exec touch {} \; 2>&1 |CT_DoLog ALL
   117 
   118     return 0
   119 }
   120 
   121 # There is nothing to do for eglibc check config
   122 do_libc_check_config() {
   123     :
   124 }
   125 
   126 # This function installs the eglibc headers needed to build the core compiler
   127 do_libc_headers() {
   128     # Instead of doing two time the same actions, headers will
   129     # be installed with start files
   130     :
   131 }
   132 
   133 # Build and install start files
   134 do_libc_start_files() {
   135     CT_DoStep INFO "Installing C library headers / start files"
   136 
   137     mkdir -p "${CT_BUILD_DIR}/build-libc-startfiles"
   138     cd "${CT_BUILD_DIR}/build-libc-startfiles"
   139 
   140     CT_DoLog EXTRA "Configuring C library"
   141 
   142     cross_cc=$(CT_Which "${CT_TARGET}-gcc")
   143     cross_cxx=$(CT_Which "${CT_TARGET}-g++")
   144     cross_ar=$(CT_Which "${CT_TARGET}-ar")
   145     cross_ranlib=$(CT_Which "${CT_TARGET}-ranlib")
   146     
   147     CT_DoLog DEBUG "Using gcc for target: '${cross_cc}'"
   148     CT_DoLog DEBUG "Using g++ for target: '${cross_cxx}'"
   149     CT_DoLog DEBUG "Using ar for target: '${cross_ar}'"
   150     CT_DoLog DEBUG "Using ranlib for target: '${cross_ranlib}'"
   151 
   152     BUILD_CC=${CT_CC_NATIVE}                    \
   153     CC=${cross_cc}                              \
   154     CXX=${cross_cxx}                            \
   155     AR=${cross_ar}                              \
   156     RANLIB=${cross_ranlib}                      \
   157     CT_DoExecLog ALL                            \
   158     "${CT_SRC_DIR}/${CT_LIBC_FILE}/configure"   \
   159         --prefix=/usr                           \
   160         --with-headers="${CT_HEADERS_DIR}"      \
   161         --build="${CT_UNIQ_BUILD}"              \
   162         --host="${CT_TARGET}"                   \
   163         --disable-profile                       \
   164         --without-gd                            \
   165         --without-cvs                           \
   166         --enable-add-ons
   167 
   168     CT_DoLog EXTRA "Installing C library headers"
   169 
   170     # use the 'install-headers' makefile target to install the
   171     # headers
   172 
   173     CT_DoExecLog ALL                    \
   174     make install-headers                \
   175          install_root=${CT_SYSROOT_DIR} \
   176          install-bootstrap-headers=yes
   177 
   178     CT_DoLog EXTRA "Installing C library start files"
   179 
   180     # there are a few object files needed to link shared libraries,
   181     # which we build and install by hand
   182 
   183     CT_DoExecLog ALL mkdir -p ${CT_SYSROOT_DIR}/usr/lib
   184     CT_DoExecLog ALL make csu/subdir_lib
   185     CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \
   186         ${CT_SYSROOT_DIR}/usr/lib
   187 
   188     # Finally, 'libgcc_s.so' requires a 'libc.so' to link against.  
   189     # However, since we will never actually execute its code, 
   190     # it doesn't matter what it contains.  So, treating '/dev/null' 
   191     # as a C source file, we produce a dummy 'libc.so' in one step
   192 
   193     CT_DoExecLog ALL ${cross_cc} -nostdlib -nostartfiles -shared -x c /dev/null -o ${CT_SYSROOT_DIR}/usr/lib/libc.so
   194 
   195     CT_EndStep
   196 }
   197 
   198 # This function builds and install the full glibc
   199 do_libc() {
   200     CT_DoStep INFO "Installing C library"
   201 
   202     mkdir -p "${CT_BUILD_DIR}/build-libc"
   203     cd "${CT_BUILD_DIR}/build-libc"
   204 
   205     CT_DoLog EXTRA "Configuring C library"
   206 
   207     # Add some default glibc config options if not given by user.
   208     # We don't need to be conditional on wether the user did set different
   209     # values, as they CT_LIBC_GLIBC_EXTRA_CONFIG is passed after extra_config
   210 
   211     extra_config="--enable-kernel=$(echo ${CT_LIBC_GLIBC_MIN_KERNEL} |sed -r -e 's/^([^.]+\.[^.]+\.[^.]+)(|\.[^.]+)$/\1/;')"
   212 
   213     case "${CT_THREADS}" in
   214         nptl)           extra_config="${extra_config} --with-__thread --with-tls";;
   215         linuxthreads)   extra_config="${extra_config} --with-__thread --without-tls --without-nptl";;
   216         none)           extra_config="${extra_config} --without-__thread --without-nptl"
   217                         case "${CT_LIBC_GLIBC_EXTRA_CONFIG}" in
   218                             *-tls*) ;;
   219                             *) extra_config="${extra_config} --without-tls";;
   220                         esac
   221                         ;;
   222     esac
   223 
   224     case "${CT_SHARED_LIBS}" in
   225         y) extra_config="${extra_config} --enable-shared";;
   226         *) extra_config="${extra_config} --disable-shared";;
   227     esac
   228 
   229     case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
   230         y,) extra_config="${extra_config} --with-fp";;
   231         ,y) extra_config="${extra_config} --without-fp";;
   232     esac
   233 
   234     case "$(do_libc_add_ons_list ,)" in
   235         "") ;;
   236         *)  extra_config="${extra_config} --enable-add-ons=$(do_libc_add_ons_list ,)";;
   237     esac
   238 
   239     extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}"
   240 
   241     cross_cc=$(CT_Which "${CT_TARGET}-gcc")    
   242 
   243     CT_DoLog DEBUG "Using gcc for target:     '${cross_cc}'"
   244     CT_DoLog DEBUG "Configuring with addons : '$(do_libc_add_ons_list ,)'"
   245     CT_DoLog DEBUG "Extra config args passed: '${extra_config}'"
   246     CT_DoLog DEBUG "Extra CC args passed    : '${extra_cc_args}'"
   247 
   248     BUILD_CC=${CT_CC_NATIVE}                                        \
   249     CFLAGS="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} -O"   \
   250     CC="${CT_TARGET}-gcc ${CT_LIBC_EXTRA_CC_ARGS} ${extra_cc_args}" \
   251     AR=${CT_TARGET}-ar                                              \
   252     RANLIB=${CT_TARGET}-ranlib                                      \
   253     CT_DoExecLog ALL                                                \
   254     "${CT_SRC_DIR}/${CT_LIBC_FILE}/configure"                       \
   255         --prefix=/usr                                               \
   256         --with-headers="${CT_HEADERS_DIR}"                          \
   257         --build=${CT_UNIQ_BUILD}                                    \
   258         --host=${CT_TARGET}                                         \
   259         --disable-profile                                           \
   260         --without-gd                                                \
   261         --without-cvs                                               \
   262         ${extra_config}                                             \
   263         ${CT_LIBC_GLIBC_EXTRA_CONFIG}
   264     
   265     CT_DoLog EXTRA "Building C library"
   266 
   267     CT_DoExecLog ALL make
   268 
   269     CT_DoLog EXTRA "Installing C library"
   270 
   271     CT_DoExecLog ALL make install install_root="${CT_SYSROOT_DIR}"
   272 
   273     CT_EndStep
   274 }
   275 
   276 # This function finishes the glibc install
   277 do_libc_finish() {
   278     # Nothing to be done for eglibc
   279     :
   280 }
   281 
   282 # Build up the addons list, separated with $1
   283 do_libc_add_ons_list() {
   284     local sep="$1"
   285     local addons_list=$(echo "${CT_LIBC_ADDONS_LIST//,/${sep}}" |tr -s ,)
   286     case "${CT_THREADS}" in
   287         none)   ;;
   288         *)      addons_list="${addons_list}${sep}${CT_THREADS}";;
   289     esac
   290     [ "${CT_LIBC_GLIBC_USE_PORTS}" = "y" ] && addons_list="${addons_list}${sep}ports"
   291     addons_list="${addons_list%%${sep}}"
   292     echo "${addons_list##${sep}}"
   293 }