scripts/build/libc/uClibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Jan 03 21:11:41 2009 +0000 (2009-01-03)
changeset 1112 c72aecd1a9ef
parent 1052 5581761d6e97
child 1121 4b7ed9da5a21
permissions -rw-r--r--
Get rid of all stuff related to building a /delivery' traball:
- building a delivery tarball has long been broken (since crostool-Ng is installable)
- get rid of implied do_print_filename, that can be mis-leading now tarballs can not be built

/trunk/scripts/build/kernel/bare-metal.sh | 4 0 4 0 ----
/trunk/scripts/build/kernel/linux.sh | 4 0 4 0 ----
/trunk/scripts/build/tools/000-template.sh | 11 0 11 0 -----------
/trunk/scripts/build/tools/100-libelf.sh | 4 0 4 0 ----
/trunk/scripts/build/tools/200-sstrip.sh | 11 1 10 0 +----------
/trunk/scripts/build/binutils.sh | 4 0 4 0 ----
/trunk/scripts/build/cc/gcc.sh | 5 0 5 0 -----
/trunk/scripts/build/debug/000-template.sh | 11 0 11 0 -----------
/trunk/scripts/build/debug/100-dmalloc.sh | 4 0 4 0 ----
/trunk/scripts/build/debug/400-ltrace.sh | 4 0 4 0 ----
/trunk/scripts/build/debug/300-gdb.sh | 7 0 7 0 -------
/trunk/scripts/build/debug/500-strace.sh | 4 0 4 0 ----
/trunk/scripts/build/debug/200-duma.sh | 4 0 4 0 ----
/trunk/scripts/build/libc/none.sh | 5 0 5 0 -----
/trunk/scripts/build/libc/glibc.sh | 10 0 10 0 ----------
/trunk/scripts/build/libc/uClibc.sh | 6 0 6 0 ------
/trunk/scripts/build/libc/eglibc.sh | 10 0 10 0 ----------
/trunk/scripts/build/gmp.sh | 6 0 6 0 ------
/trunk/scripts/build/mpfr.sh | 6 0 6 0 ------
/trunk/docs/overview.txt | 9 0 9 0 ---------
20 files changed, 1 insertion(+), 128 deletions(-)
     1 # This file declares functions to install the uClibc C library
     2 # Copyright 2007 Yann E. MORIN
     3 # Licensed under the GPL v2. See COPYING in the root of this package
     4 
     5 # Download uClibc
     6 do_libc_get() {
     7     libc_src="http://www.uclibc.org/downloads
     8               http://www.uclibc.org/downloads/snapshots
     9               http://www.uclibc.org/downloads/old-releases"
    10     # For uClibc, we have almost every thing: releases, and snapshots
    11     # for the last month or so. We'll have to deal with svn revisions
    12     # later...
    13     CT_GetFile "${CT_LIBC_FILE}" ${libc_src}
    14     # uClibc locales
    15     [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] && CT_GetFile "uClibc-locale-030818" ${libc_src} || true
    16 
    17     return 0
    18 }
    19 
    20 # Extract uClibc
    21 do_libc_extract() {
    22     CT_ExtractAndPatch "${CT_LIBC_FILE}"
    23     # uClibc locales
    24     [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] && CT_ExtractAndPatch "uClibc-locale-030818" || true
    25 
    26     return 0
    27 }
    28 
    29 # Check that uClibc has been previously configured
    30 do_libc_check_config() {
    31     CT_DoStep INFO "Checking C library configuration"
    32 
    33     CT_TestOrAbort "You did not provide a uClibc config file!" -n "${CT_LIBC_UCLIBC_CONFIG_FILE}" -a -f "${CT_LIBC_UCLIBC_CONFIG_FILE}"
    34 
    35     if egrep '^KERNEL_SOURCE=' "${CT_LIBC_UCLIBC_CONFIG_FILE}" >/dev/null 2>&1; then
    36         CT_DoLog WARN "Your uClibc version refers to the kernel _sources_, which is bad."
    37         CT_DoLog WARN "I can't guarantee that our little hack will work. Please try to upgrade."
    38     fi
    39 
    40     CT_DoLog EXTRA "Munging uClibc configuration"
    41     mungeuClibcConfig "${CT_LIBC_UCLIBC_CONFIG_FILE}" "${CT_BUILD_DIR}/uClibc.config"
    42 
    43     CT_EndStep
    44 }
    45 
    46 # This functions installs uClibc's headers
    47 do_libc_headers() {
    48     # Only need to install bootstrap uClibc headers for gcc-3.0 and above?  Or maybe just gcc-3.3 and above?
    49     # See also http://gcc.gnu.org/PR8180, which complains about the need for this step.
    50     grep -q 'gcc-[34]' "${CT_SRC_DIR}/${CT_CC_FILE}/ChangeLog" 2>/dev/null || return 0
    51 
    52     CT_DoStep INFO "Installing C library headers"
    53 
    54     mkdir -p "${CT_BUILD_DIR}/build-libc-headers"
    55     cd "${CT_BUILD_DIR}/build-libc-headers"
    56 
    57     # Simply copy files until uClibc has the ablity to build out-of-tree
    58     CT_DoLog EXTRA "Copying sources to build dir"
    59     { cd "${CT_SRC_DIR}/${CT_LIBC_FILE}"; tar cf - .; } |tar xf -
    60 
    61     # Retrieve the config file
    62     cp "${CT_BUILD_DIR}/uClibc.config" .config
    63 
    64     # uClibc uses the CROSS environment variable as a prefix to the
    65     # compiler tools to use.  Setting it to the empty string forces
    66     # use of the native build host tools, which we need at this
    67     # stage, as we don't have target tools yet.
    68     CT_DoLog EXTRA "Applying configuration"
    69     CT_DoYes "" |CT_DoExecLog ALL make CROSS= PREFIX="${CT_SYSROOT_DIR}/" oldconfig
    70 
    71     CT_DoLog EXTRA "Building headers"
    72     CT_DoExecLog ALL make ${CT_LIBC_UCLIBC_VERBOSITY} CROSS= PREFIX="${CT_SYSROOT_DIR}/" headers
    73 
    74     CT_DoLog EXTRA "Installing headers"
    75     CT_DoExecLog ALL make ${CT_LIBC_UCLIBC_VERBOSITY} CROSS= PREFIX="${CT_SYSROOT_DIR}/" install_headers
    76 
    77     CT_EndStep
    78 }
    79 
    80 # Build and install start files
    81 do_libc_start_files() {
    82     :
    83 }
    84 
    85 # This function build and install the full uClibc
    86 do_libc() {
    87     CT_DoStep INFO "Installing C library"
    88 
    89     mkdir -p "${CT_BUILD_DIR}/build-libc"
    90     cd "${CT_BUILD_DIR}/build-libc"
    91 
    92     # Simply copy files until uClibc has the ablity to build out-of-tree
    93     CT_DoLog EXTRA "Copying sources to build dir"
    94     { cd "${CT_SRC_DIR}/${CT_LIBC_FILE}"; tar cf - .; } |tar xf -
    95 
    96     # Retrieve the config file
    97     cp "${CT_BUILD_DIR}/uClibc.config" .config
    98 
    99     # uClibc uses the CROSS environment variable as a prefix to the compiler
   100     # tools to use.  The newly built tools should be in our path, so we need
   101     # only give the correct name for them.
   102     # Note about CFLAGS: In uClibc, CFLAGS are generated by Rules.mak,
   103     # depending  on the configuration of the library. That is, they are tailored
   104     # to best fit the target. So it is useless and seems to be a bad thing to
   105     # use LIBC_EXTRA_CFLAGS here.
   106     CT_DoLog EXTRA "Applying configuration"
   107     CT_DoYes "" |CT_DoExecLog ALL               \
   108                  make CROSS=${CT_TARGET}-       \
   109                  PREFIX="${CT_SYSROOT_DIR}/"    \
   110                  oldconfig
   111 
   112     # We do _not_ want to strip anything for now, in case we specifically
   113     # asked for a debug toolchain, thus the STRIPTOOL= assignment
   114     # /Old/ versions can not build in //
   115     CT_DoLog EXTRA "Building C library"
   116     CT_DoExecLog ALL                                    \
   117     make ${CT_LIBC_UCLIBC_PARALLEL:+${PARALLELMFLAGS}}  \
   118          CROSS=${CT_TARGET}-                            \
   119          PREFIX="${CT_SYSROOT_DIR}/"                    \
   120          STRIPTOOL=true                                 \
   121          ${CT_LIBC_UCLIBC_VERBOSITY}                    \
   122          all
   123 
   124     # YEM-FIXME: we want to install libraries in $SYSROOT/lib, but we don't want
   125     # to install headers in $SYSROOT/include, thus making only install_runtime.
   126     # Plus, the headers were previously installed earlier with install_headers,
   127     # so all should be well. Unfortunately, the install_headers target does not
   128     # install crti.o and consorts... :-( So reverting to target 'install'.
   129     # Note: PARALLELMFLAGS is not usefull for installation.
   130     # We do _not_ want to strip anything for now, in case we specifically
   131     # asked for a debug toolchain, hence the STRIPTOOL= assignment
   132     CT_DoLog EXTRA "Installing C library"
   133     CT_DoExecLog ALL                    \
   134     make CROSS=${CT_TARGET}-            \
   135          PREFIX="${CT_SYSROOT_DIR}/"    \
   136          STRIPTOOL=true                 \
   137          ${CT_LIBC_UCLIBC_VERBOSITY}    \
   138          install
   139 
   140     CT_EndStep
   141 }
   142 
   143 # This function is used to install those components needing the final C compiler
   144 do_libc_finish() {
   145     # Build and install host-side ldd
   146     CT_DoStep INFO "Finishing C library"
   147 
   148     mkdir -p "${CT_BUILD_DIR}/build-libc-finish"
   149     cd "${CT_BUILD_DIR}/build-libc-finish"
   150 
   151     # Simply copy files until uClibc has the ablity to build out-of-tree
   152     CT_DoLog EXTRA "Copying sources to build dir"
   153     { cd "${CT_SRC_DIR}/${CT_LIBC_FILE}"; tar cf - .; } |tar xf -
   154 
   155     # Retrieve the config file
   156     cp "${CT_BUILD_DIR}/uClibc.config" .config
   157 
   158     CT_DoLog EXTRA "Applying configuration"
   159     CT_DoYes "" |CT_DoExecLog ALL               \
   160                  make CROSS=${CT_TARGET}-       \
   161                  PREFIX="${CT_SYSROOT_DIR}/"    \
   162                  oldconfig
   163 
   164     CT_DoLog EXTRA "Installing C library host utils"
   165     CT_DoExecLog ALL                    \
   166     make PREFIX="${CT_SYSROOT_DIR}/"    \
   167          ${CT_LIBC_UCLIBC_VERBOSITY}    \
   168          -C utils hostutils
   169     CT_DoExecLog ALL install -m 0755 utils/ldd.host "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ldd"
   170 
   171     CT_EndStep
   172 }
   173 
   174 # Initialises the .config file to sensible values
   175 # $1: original file
   176 # $2: munged file
   177 mungeuClibcConfig() {
   178     src_config_file="$1"
   179     dst_config_file="$2"
   180     munge_file="${CT_BUILD_DIR}/munge-uClibc-config.sed"
   181 
   182     # Start with a fresh file
   183     rm -f "${munge_file}"
   184     touch "${munge_file}"
   185 
   186     # Hack our target in the config file.
   187     # Also remove stripping: its the responsibility of the
   188     # firmware builder to strip or not.
   189     cat >>"${munge_file}" <<-ENDSED
   190 s/^(TARGET_.*)=y$/# \\1 is not set/
   191 s/^# TARGET_${CT_KERNEL_ARCH} is not set/TARGET_${CT_KERNEL_ARCH}=y/
   192 s/^TARGET_ARCH=".*"/TARGET_ARCH="${CT_KERNEL_ARCH}"/
   193 s/.*(DOSTRIP).*/# \\1 is not set/
   194 ENDSED
   195 
   196     # Ah. We may one day need architecture-specific handler here...
   197     # Hack the ARM {E,O}ABI into the config file
   198     if [ "${CT_ARCH_ARM_EABI}" = "y" ]; then
   199         cat >>"${munge_file}" <<-ENDSED
   200 s/.*(CONFIG_ARM_OABI).*/# \\1 is not set/
   201 s/.*(CONFIG_ARM_EABI).*/\\1=y/
   202 ENDSED
   203     else
   204         cat >>"${munge_file}" <<-ENDSED
   205 s/.*(CONFIG_ARM_OABI).*/\\1=y/
   206 s/.*(CONFIG_ARM_EABI).*/# \\1 is not set/
   207 ENDSED
   208     fi
   209 
   210     # Accomodate for old and new uClibc versions, where the
   211     # way to select between big/little endian has changed
   212     case "${CT_ARCH_BE},${CT_ARCH_LE}" in
   213         y,) cat >>"${munge_file}" <<-ENDSED
   214 s/.*(ARCH_LITTLE_ENDIAN).*/# \\1 is not set/
   215 s/.*(ARCH_BIG_ENDIAN).*/\\1=y/
   216 s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/# \\1 is not set/
   217 s/.*(ARCH_WANTS_BIG_ENDIAN).*/\\1=y/
   218 ENDSED
   219         ;;
   220         ,y) cat >>"${munge_file}" <<-ENDSED
   221 s/.*(ARCH_LITTLE_ENDIAN).*/\\1=y/
   222 s/.*(ARCH_BIG_ENDIAN).*/# \\1 is not set/
   223 s/.*(ARCH_WANTS_LITTLE_ENDIAN).*/\\1=y/
   224 s/.*(ARCH_WANTS_BIG_ENDIAN).*/# \\1 is not set/
   225 ENDSED
   226         ;;
   227     esac
   228 
   229     # Accomodate for old and new uClibc version, where the
   230     # way to select between hard/soft float has changed
   231     case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
   232         y,) cat >>"${munge_file}" <<-ENDSED
   233 s/^[^_]*(HAS_FPU).*/\\1=y/
   234 s/.*(UCLIBC_HAS_FPU).*/\\1=y/
   235 ENDSED
   236             ;;
   237         ,y) cat >>"${munge_file}" <<-ENDSED
   238 s/^[^_]*(HAS_FPU).*/\\# \\1 is not set/
   239 s/.*(UCLIBC_HAS_FPU).*/# \\1 is not set/
   240 ENDSED
   241             ;;
   242     esac
   243 
   244     # Change paths to work with crosstool-NG
   245     # From http://www.uclibc.org/cgi-bin/viewcvs.cgi?rev=16846&view=rev
   246     #  " we just want the kernel headers, not the whole kernel source ...
   247     #  " so people may need to update their paths slightly
   248     quoted_kernel_source=$(echo "${CT_HEADERS_DIR}" | sed -r -e 's,/include/?$,,; s,/,\\/,g;')
   249     quoted_headers_dir=$(echo "${CT_HEADERS_DIR}" | sed -r -e 's,/,\\/,g;')
   250     # CROSS_COMPILER_PREFIX is left as is, as the CROSS parameter is forced on the command line
   251     # DEVEL_PREFIX is left as '/usr/' because it is post-pended to $PREFIX, wich is the correct value of ${PREFIX}/${TARGET}
   252     # Some (old) versions of uClibc use KERNEL_SOURCE (which is _wrong_), and
   253     # newer versions use KERNEL_HEADERS (which is right). See:
   254     cat >>"${munge_file}" <<-ENDSED
   255 s/^DEVEL_PREFIX=".*"/DEVEL_PREFIX="\\/usr\\/"/
   256 s/^RUNTIME_PREFIX=".*"/RUNTIME_PREFIX="\\/"/
   257 s/^SHARED_LIB_LOADER_PREFIX=.*/SHARED_LIB_LOADER_PREFIX="\\/lib\\/"/
   258 s/^KERNEL_SOURCE=".*"/KERNEL_SOURCE="${quoted_kernel_source}"/
   259 s/^KERNEL_HEADERS=".*"/KERNEL_HEADERS="${quoted_headers_dir}"/
   260 s/^UCLIBC_DOWNLOAD_PREGENERATED_LOCALE=y/\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE is not set/
   261 ENDSED
   262 
   263     if [ "${CT_USE_PIPES}" = "y" ]; then
   264         if grep UCLIBC_EXTRA_CFLAGS extra/Configs/Config.in >/dev/null 2>&1; then
   265             # Good, there is special provision for such things as -pipe!
   266             cat >>"${munge_file}" <<-ENDSED
   267 s/^(UCLIBC_EXTRA_CFLAGS=".*)"$/\\1 -pipe"/
   268 ENDSED
   269         else
   270             # Hack our -pipe into WARNINGS, which will be internally incorporated to
   271             # CFLAGS. This a dirty hack, but yet needed
   272             cat >> "${munge_file}" <<-ENDSED
   273 s/^(WARNINGS=".*)"$/\\1 -pipe"/
   274 ENDSED
   275         fi
   276     fi
   277 
   278     # Locales support
   279     # Note that the two PREGEN_LOCALE and the XLOCALE lines may be missing
   280     # entirely if LOCALE is not set.  If LOCALE was already set, we'll
   281     # assume the user has already made all the appropriate generation
   282     # arrangements.  Note that having the uClibc Makefile download the
   283     # pregenerated locales is not compatible with crosstool; besides,
   284     # crosstool downloads them as part of getandpatch.sh.
   285     if [ "${CT_LIBC_UCLIBC_LOCALES}" = "y" ] ; then
   286        cat >>"${munge_file}" <<-ENDSED
   287 s/^# UCLIBC_HAS_LOCALE is not set/UCLIBC_HAS_LOCALE=y\\nUCLIBC_PREGENERATED_LOCALE_DATA=y\\n\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE_DATA is not set\\n\\# UCLIBC_HAS_XLOCALE is not
   288 ENDSED
   289     fi
   290 
   291     # Force on options needed for C++ if we'll be making a C++ compiler.
   292     # I'm not sure locales are a requirement for doing C++... Are they?
   293     if [ "${CT_CC_LANG_CXX}" = "y" ]; then
   294         cat >>"${munge_file}" <<-ENDSED
   295 s/^# DO_C99_MATH is not set/DO_C99_MATH=y/
   296 s/^# UCLIBC_CTOR_DTOR is not set/UCLIBC_CTOR_DTOR=y/
   297 # Add these three lines when doing C++?
   298 s/^# UCLIBC_HAS_WCHAR is not set/UCLIBC_HAS_WCHAR=y/
   299 #s/^# UCLIBC_HAS_LOCALE is not set/UCLIBC_HAS_LOCALE=y\\nUCLIBC_PREGENERATED_LOCALE_DATA=y\\n\\# UCLIBC_DOWNLOAD_PREGENERATED_LOCALE_DATA is not set\\n\\# UCLIBC_HAS_XLOCALE is not set/
   300 s/^# UCLIBC_HAS_GNU_GETOPT is not set/UCLIBC_HAS_GNU_GETOPT=y/
   301 ENDSED
   302     fi
   303 
   304     # Always build the libpthread_db
   305     cat >>"${munge_file}" <<-ENDSED
   306 s/^# PTHREADS_DEBUG_SUPPORT is not set.*/PTHREADS_DEBUG_SUPPORT=y/
   307 ENDSED
   308 
   309     # Force on debug options if asked for
   310     case "${CT_LIBC_UCLIBC_DEBUG_LEVEL}" in
   311       0)
   312         cat >>"${munge_file}" <<-ENDSED
   313 s/^DODEBUG=y/# DODEBUG is not set/
   314 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
   315 s/^DOASSERTS=y/# DOASSERTS is not set/
   316 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
   317 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
   318 s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
   319 ENDSED
   320         ;;
   321       1)
   322         cat >>"${munge_file}" <<-ENDSED
   323 s/^# DODEBUG is not set.*/DODEBUG=y/
   324 s/^DODEBUG_PT=y/# DODEBUG_PT is not set/
   325 s/^DOASSERTS=y/# DOASSERTS is not set/
   326 s/^SUPPORT_LD_DEBUG=y/# SUPPORT_LD_DEBUG is not set/
   327 s/^SUPPORT_LD_DEBUG_EARLY=y/# SUPPORT_LD_DEBUG_EARLY is not set/
   328 s/^UCLIBC_MALLOC_DEBUGGING=y/# UCLIBC_MALLOC_DEBUGGING is not set/
   329 ENDSED
   330         ;;
   331       2)
   332         cat >>"${munge_file}" <<-ENDSED
   333 s/^# DODEBUG is not set.*/DODEBUG=y/
   334 s/^# DODEBUG_PT is not set.*/DODEBUG_PT=y/
   335 s/^# DOASSERTS is not set.*/DOASSERTS=y/
   336 s/^# SUPPORT_LD_DEBUG is not set.*/SUPPORT_LD_DEBUG=y/
   337 s/^# SUPPORT_LD_DEBUG_EARLY is not set.*/SUPPORT_LD_DEBUG_EARLY=y/
   338 s/^# UCLIBC_MALLOC_DEBUGGING is not set/UCLIBC_MALLOC_DEBUGGING=y/
   339 ENDSED
   340         ;;
   341     esac
   342     sed -r -f "${munge_file}" "${src_config_file}" >"${dst_config_file}"
   343 }