scripts/build/libc/uClibc.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Jan 12 19:24:03 2010 +0100 (2010-01-12)
changeset 1761 88020b2c3246
parent 1750 4f07fc2b4491
child 1901 bdb3a98e064b
permissions -rw-r--r--
scripts/functions: change handling of nochdir

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