scripts/build/libc/uClibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Jan 31 17:38:26 2009 +0000 (2009-01-31)
changeset 1180 734db80cc9b9
parent 1123 8c5881324a79
child 1206 3f1078387d8b
permissions -rw-r--r--
Further handle the lib64 -> lib symlinks.
It at least helps powerpc64 to build, and should innocuous to other archs.

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