uclibc: Get uclibc working in thumb mode.
[vuplus_openembedded] / recipes / uclibc / uclibc.inc
1 DESCRIPTION = "C library for embedded systems"
2 LICENSE = "LGPL"
3 SECTION = "libs"
4 PRIORITY = "required"
5 #
6 # For now, we will skip building of a gcc package if it is a uclibc one
7 # and our build is not a uclibc one, and we skip a glibc one if our build
8 # is a uclibc build.
9 #
10 # See the note in gcc/gcc_3.4.0.oe
11 #
12
13 python __anonymous () {
14     import bb, re
15     uc_os = (re.match('.*uclibc*', bb.data.getVar('TARGET_OS', d, 1)) != None)
16     if not uc_os:
17         raise bb.parse.SkipPackage("incompatible with target %s" %
18                                    bb.data.getVar('TARGET_OS', d, 1))
19 }
20
21 PROVIDES += "virtual/libc virtual/${TARGET_PREFIX}libc-for-gcc"
22 PROVIDES += "${@['virtual/libiconv', ''][bb.data.getVar('USE_NLS', d, 1) != 'yes']}"
23 DEPENDS = "virtual/${TARGET_PREFIX}binutils \
24            virtual/${TARGET_PREFIX}gcc-intermediate linux-libc-headers ncurses-native pax-utils-native"
25 RDEPENDS_${PN}-dev = "linux-libc-headers-dev"
26
27 # Blackfin needs a wrapper around ld
28 #DEPENDS_append_bfin = " elf2flt "
29
30 INHIBIT_DEFAULT_DEPS = "1"
31 PARALLEL_MAKE = ""
32
33 PACKAGES =+ "ldd uclibc-utils-dbg uclibc-utils uclibc-gconv uclibc-thread-db"
34
35 LEAD_SONAME = "libc.so"
36
37 # The last line (gdb and lib1) is for uclinux-uclibc builds 
38 uclibc_baselibs = "/lib/libcrypt*.so* /lib/libdl*.so \
39                    /lib/libintl*.so* /lib/libm*.so \
40                    /lib/libnsl*.so* /lib/libpthread*.so \
41                    /lib/libresolv*.so* /lib/libutil*.so \
42                    /lib/libuClibc*.so* /lib/ld*.so* \
43                    /lib/libc*.so* /lib/libdl*.so* \
44                    /lib/libm*.so* /lib/libutil*.so* \
45                    /lib/libpthread*.so* /lib/librt*.so* \
46                    /usr/lib/libc.gdb /usr/lib/libc /lib/lib1.so \
47                    "
48 FILES_${PN} = "${sysconfdir} ${uclibc_baselibs} /sbin/ldconfig \
49                ${libexecdir} ${datadir}/zoneinfo ${libdir}/locale"
50 FILES_ldd = "${bindir}/ldd"
51 FILES_uclibc-dev += "${libdir}/*.o"
52 FILES_uclibc-utils = "${bindir} ${sbindir}"
53 FILES_uclibc-utils-dbg += "${bindir}/.debug ${sbindir}/.debug"
54 FILES_uclibc-gconv = "${libdir}/gconv"
55 FILES_uclibc-thread-db = "/lib/libthread_db*"
56 RPROVIDES_uclibc-dev += "libc-dev virtual-libc-dev"
57
58 #
59 # This locale file gets copied into uClibc-${PV}/extra/locale/ prior to
60 # build, it does not need to be unpacked, but we can't inhibit the unpacking
61 # in the current build system.
62 #
63 UCLIBC_LOCALE_FILE = "uClibc-locale-030818.tgz"
64 UCLIBC_LOCALE_FILE_arm = "uClibc-locale-030818.arm.tgz"
65 UCLIBC_LOCALE_URI = "http://www.uclibc.org/downloads/${UCLIBC_LOCALE_FILE}"
66 UCLIBC_LOCALE_URI_arm = "http://wiki.openembedded.net/dl/uclibc-locale/${UCLIBC_LOCALE_FILE}"
67
68 SRC_URI = "${@['${UCLIBC_LOCALE_URI}', ''][bb.data.getVar('USE_NLS', d, 1) != 'yes']} \
69            file://uClibc.config"
70
71 UCLIBC_STAGE_PREFIX = "${STAGING_DIR_HOST}${layout_prefix}"
72
73 # do_stage barfs on a CC with whitepspace, therefore put the 'HOST_CC_ARCH' in
74 # the CFLAGS (for when building the utils).
75 OEMAKE_NO_CC = "'STRIPTOOL=true' 'LD=${LD}' \
76                 'LOCALE_DATA_FILENAME=${UCLIBC_LOCALE_FILE}'"
77 EXTRA_OEMAKE = "${OEMAKE_NO_CC} 'CC=${CC}' \
78                 'HOSTCFLAGS=-I${STAGING_INCDIR_NATIVE}'"
79 EXTRA_OEMAKE_task_do_populate_staging = "${OEMAKE_NO_CC}"
80 EXTRA_OEMAKE_task_do_package = "${OEMAKE_NO_CC}"
81
82 KERNEL_SOURCE = "${STAGING_INCDIR}"
83 KERNEL_HEADERS = "${STAGING_INCDIR}"
84
85 # Lets munge this via siteinfo.bbclass as well:
86 # ARCH_BIG_ENDIAN=y
87 # ARCH_WANTS_BIG_ENDIAN=y
88 # ARCH_WANTS_LITTLE_ENDIAN is not set
89
90 configmangle = 's,^KERNEL_SOURCE=.*,KERNEL_SOURCE="${KERNEL_SOURCE}",g; \
91                 s,^KERNEL_HEADERS=.*,KERNEL_HEADERS="${KERNEL_HEADERS}",g; \
92                 s,^RUNTIME_PREFIX=.*,RUNTIME_PREFIX="/",g; \
93                 s,^DEVEL_PREFIX=.*,DEVEL_PREFIX="/${prefix}",g; \
94                 s,^SHARED_LIB_LOADER_PATH=.*,SHARED_LIB_LOADER_PATH="/lib",; \
95                 s,^SHARED_LIB_LOADER_PREFIX=.*,SHARED_LIB_LOADER_PREFIX="/lib",; \
96                 s,.*UCLIBC_HAS_WCHAR.*,UCLIBC_HAS_WCHAR=y,g; \
97                 ${@["","s,.*UCLIBC_HAS_LOCALE.*,UCLIBC_HAS_LOCALE=y,;"][bb.data.getVar("USE_NLS", d, 1) == "yes"]} \
98                 ${@["","s,.*LDSO_GNU_HASH_SUPPORT.*,# LDSO_GNU_HASH_SUPPORT is not set,;"][bb.data.getVar("TARGET_ARCH", d, 1) == "avr32"]} \
99                '
100
101 CFLAGS := "${@oe_filter_out('-I\S+', '${CFLAGS}', d)}"
102
103 python () {
104         if bb.data.getVar('TARGET_FPU', d, 1) in [ 'soft' ]:
105                 bb.data.setVar('configmangle_append', ' s,^HAS_FPU=y,# HAS_FPU is not set,;', d)
106 }
107
108 uclibcbuild_do_patch() {
109         ln -sf ${STAGING_INCDIR}/linux ${S}/include/linux
110         ln -sf ${STAGING_INCDIR}/asm ${S}/include/asm
111         
112         ${@['cp %s/%s extra/locale' % (bb.data.getVar('DL_DIR', d, 1) or '', bb.data.getVar('UCLIBC_LOCALE_FILE', d, 1) or ''), ''][bb.data.getVar('USE_NLS', d, 1) != 'yes']}
113 }
114
115 python do_patch () {
116         bb.build.exec_func('base_do_patch', d)
117         bb.build.exec_func('uclibcbuild_do_patch', d)
118 }
119
120 do_configure() {
121         rm -f ${S}/.config
122
123         # For uClibc 0.9.29, OpenEmbedded splits the uClibc.config in two parts:
124         # uClibc.machine and uClibc.distro. So, if they exist use them, otherwise
125         # use a uClibc.config
126         if [ -f ${WORKDIR}/uClibc.machine -a -f ${WORKDIR}/uClibc.distro ]; then
127                 echo "### uClibc.machine ###" >${S}/merged.config
128                 cat ${WORKDIR}/uClibc.machine >>${S}/merged.config
129                 echo "### uClibc.distro ###" >>${S}/merged.config
130                 cat ${WORKDIR}/uClibc.distro >>${S}/merged.config
131         else
132                 echo "### uClibc.config ###" >${S}/merged.config
133                 cat ${WORKDIR}/uClibc.config >>${S}/merged.config
134         fi
135         cp ${S}/merged.config ${S}/.config      
136
137         # Mangle the resulting .config depending on OE variables
138         perl -i -p -e 's,^CROSS=.*,TARGET_ARCH=${TARGET_ARCH}\nCROSS=${TARGET_PREFIX},g' ${S}/Rules.mak
139         sed -i -e s:'$(CROSS)strip':true: ${S}/Rules.mak        
140         perl -i -p -e '${configmangle}' ${S}/.config
141
142         sed -i -e '/CONFIG_ARM_EABI/d' ${S}/.config
143
144         if [ "${TARGET_OS}" = "linux-gnueabi" -o  "${TARGET_OS}" = "linux-uclibcgnueabi" ]; then
145                 echo "CONFIG_ARM_EABI=y"                >> ${S}/.config
146         else
147                 echo "# CONFIG_ARM_EABI is not set"     >> ${S}/.config
148         fi
149
150         yes '' | oe_runmake oldconfig
151 }
152
153 do_stage() {
154         # This MUST be done first because we
155         # will install crt1.o in the install_dev stage and gcc needs it
156
157         # Install into the staging dir
158         oe_runmake PREFIX= DEVEL_PREFIX=${UCLIBC_STAGE_PREFIX}/ \
159                 RUNTIME_PREFIX=${UCLIBC_STAGE_PREFIX}/ \
160                 install_dev install_runtime
161
162         # We don't really need this
163         rm -f ${UCLIBC_STAGE_PREFIX}/include/.cvsignore
164
165         # Fixup shared lib symlinks
166         ( cd ${UCLIBC_STAGE_PREFIX}/lib
167                 for f in c crypt dl m nsl pthread resolv thread_db util; do
168                         ln -sf lib${f}.so.? lib${f}.so
169                 done
170         )
171
172         # This conflicts with the c++ version of this header
173         rm -f ${UCLIBC_STAGE_PREFIX}/include/bits/atomicity.h
174 }
175
176 do_install() {
177         # Tis MUST be done first because we
178         # will install crt1.o in the install_dev stage and gcc needs it)
179         oe_runmake STRIPTOOL=true PREFIX= DEVEL_PREFIX=${UCLIBC_STAGE_PREFIX}/ \
180                 RUNTIME_PREFIX=${UCLIBC_STAGE_PREFIX}/ \
181                 install_dev install_runtime
182
183         oe_runmake STRIPTOOL=true PREFIX=${D} DEVEL_PREFIX=${prefix}/ RUNTIME_PREFIX=/ \
184                 install_dev install_runtime 
185
186         # We don't really need this in ${includedir}
187         rm -f ${D}${prefix}/include/.cvsignore
188
189         # This conflicts with the c++ version of this header
190         rm -f ${D}${prefix}/include/bits/atomicity.h
191
192         # ugh.. uclibc doesn't like obeying our path variables.
193         if [ "${includedir}" != "${prefix}/include" ]; then
194                 install -d ${D}${includedir}
195                 mv ${D}${prefix}/include/* ${D}${includedir}/
196                 rmdir ${D}${prefix}/include
197         fi
198
199         if [ "${libdir}" != "${prefix}/lib" ]; then
200                 install -d ${D}${libdir}
201                 mv ${D}${prefix}/lib/* ${D}${libdir}/
202                 rmdir ${D}${prefix}/lib
203         fi
204
205         if [ "${bindir}" != "/usr/bin" ]; then
206                 install -d ${D}${bindir}
207                 mv ${D}/usr/bin/* ${D}${bindir}/
208                 rmdir ${D}/usr/bin
209         fi
210
211         oe_runmake utils
212         oe_runmake STRIPTOOL=true PREFIX=${D} DEVEL_PREFIX=${prefix}/ RUNTIME_PREFIX=/ \
213                 install_utils
214         
215         # oe_runstrip needs +x on files 
216         chmod +x ${D}/${base_libdir}/*
217 }
218