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