scripts/build/libc/uClibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Jul 03 00:17:54 2010 +0200 (2010-07-03)
branch1.7
changeset 2010 12853e4d2c52
parent 1910 207ad430c254
permissions -rw-r--r--
libc/uClibc: fix snapshots

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