uclibc-0.9.33.2-r15.ebuild 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. # Copyright 1999-2016 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. inherit eutils flag-o-matic multilib toolchain-funcs savedconfig
  4. if [[ ${PV} == "9999" ]] ; then
  5. EGIT_REPO_URI="git://git.busybox.net/uClibc"
  6. inherit git-2
  7. fi
  8. export CBUILD=${CBUILD:-${CHOST}}
  9. export CTARGET=${CTARGET:-${CHOST}}
  10. if [[ ${CTARGET} == ${CHOST} ]] ; then
  11. if [[ ${CATEGORY} == cross-* ]] ; then
  12. export CTARGET=${CATEGORY#cross-}
  13. fi
  14. fi
  15. MY_P=uClibc-${PV}
  16. DESCRIPTION="C library for developing embedded Linux systems"
  17. HOMEPAGE="https://www.uclibc.org/"
  18. if [[ ${PV} != "9999" ]] ; then
  19. PATCH_VER="17"
  20. SRC_URI="https://uclibc.org/downloads/${MY_P}.tar.bz2
  21. ${PATCH_VER:+mirror://gentoo/${MY_P}-patches-${PATCH_VER}.tar.bz2}"
  22. KEYWORDS="-* amd64 arm m68k ~mips ppc sh sparc x86"
  23. fi
  24. LICENSE="LGPL-2"
  25. SLOT="0"
  26. IUSE="debug hardened iconv ipv6 nptl rpc ssp uclibc-compat wordexp crosscompile_opts_headers-only"
  27. RESTRICT="strip"
  28. # We cannot migrate between uclibc and uclibc-ng because as soon as portage
  29. # updates the ld.so sym link, the system breaks. Ideally this should be a
  30. # hard blocker, but EAPI=0 doesn't allow hard blockers.
  31. RDEPEND="!sys-libs/uclibc-ng"
  32. S=${WORKDIR}/${MY_P}
  33. is_crosscompile() {
  34. [[ ${CHOST} != ${CTARGET} ]]
  35. }
  36. alt_build_kprefix() {
  37. if [[ ${CBUILD} == ${CHOST} && ${CTARGET} == ${CHOST} ]] ; then
  38. echo /usr/include
  39. else
  40. echo /usr/${CTARGET}/usr/include
  41. fi
  42. }
  43. just_headers() {
  44. use crosscompile_opts_headers-only && is_crosscompile
  45. }
  46. uclibc_endian() {
  47. # XXX: this wont work for a toolchain which is bi-endian, but we
  48. # dont have any such thing at the moment, so not a big deal
  49. touch "${T}"/endian.s
  50. $(tc-getAS ${CTARGET}) "${T}"/endian.s -o "${T}"/endian.o
  51. case $(file "${T}"/endian.o) in
  52. *" MSB "*) echo "BIG";;
  53. *" LSB "*) echo "LITTLE";;
  54. *) echo "NFC";;
  55. esac
  56. rm -f "${T}"/endian.{s,o}
  57. }
  58. pkg_setup() {
  59. if [ ${CTARGET} = ${CHOST} ] ; then
  60. case ${CHOST} in
  61. *-uclinux*|*-uclibc*) ;;
  62. *) die "Use sys-devel/crossdev to build a uclibc toolchain" ;;
  63. esac
  64. fi
  65. }
  66. check_cpu_opts() {
  67. case ${CTARGET} in
  68. # Need to handle $ABI here w/mips.
  69. mips[1234]*) export UCLIBC_CPU="MIPS_ISA_${CTARGET:4:1}";;
  70. sh[2345]*) export UCLIBC_CPU="SH${CTARGET:2:1}";;
  71. i[3456]86*) export UCLIBC_CPU="${CTARGET:1:1}86";;
  72. # XXX: Should figure out how to handle sparc.
  73. esac
  74. if use nptl ; then
  75. case ${CTARGET} in
  76. i386*)
  77. die "Your target has no support for NPTL"
  78. ;;
  79. esac
  80. fi
  81. }
  82. kconfig_q_opt() {
  83. local flag=$1; shift
  84. case ${flag} in
  85. y|n) ;;
  86. *) flag=$(usex ${flag} y n) ;;
  87. esac
  88. local var="defs_${flag}"
  89. eval "${var}+=( $* )"
  90. }
  91. get_opt() {
  92. (
  93. unset ${1}
  94. . ${2:-"${S}"/.config}
  95. echo ${!1}
  96. )
  97. }
  98. src_oldconfig() {
  99. yes "" 2>/dev/null | emake -s oldconfig >/dev/null
  100. }
  101. src_config() {
  102. restore_config .config
  103. if [ -f .config ]; then
  104. src_oldconfig
  105. return 0
  106. else
  107. ewarn "Could not locate user configfile, so we will save a default one"
  108. fi
  109. emake ARCH=${target} defconfig >/dev/null || die
  110. local defs_{y,n} defs
  111. defs=(
  112. DO{DEBUG_PT,ASSERTS}
  113. SUPPORT_LD_DEBUG_EARLY
  114. UCLIBC_HAS_PROFILING
  115. )
  116. kconfig_q_opt n "${defs[@]}"
  117. kconfig_q_opt debug DODEBUG SUPPORT_LD_DEBUG
  118. sed -i -e '/ARCH_.*_ENDIAN/d' .config
  119. kconfig_q_opt y "ARCH_WANTS_$(uclibc_endian)_ENDIAN"
  120. if [[ ${CTARGET} == arm* ]] ; then
  121. kconfig_q_opt n CONFIG_ARM_OABI
  122. kconfig_q_opt y CONFIG_ARM_EABI
  123. fi
  124. defs=(
  125. LDSO_GNU_HASH_SUPPORT
  126. MALLOC_GLIBC_COMPAT
  127. DO_C99_MATH
  128. UCLIBC_HAS_{CTYPE_CHECKED,WCHAR,HEXADECIMAL_FLOATS,GLIBC_CUSTOM_PRINTF,FOPEN_EXCLUSIVE_MODE,GLIBC_CUSTOM_STREAMS,PRINTF_M_SPEC}
  129. UCLIBC_HAS_FENV
  130. UCLIBC_HAS_{N,}FTW
  131. UCLIBC_HAS_GNU_GLOB
  132. UCLIBC_HAS_LIBUTIL
  133. UCLIBC_HAS_PROGRAM_INVOCATION_NAME
  134. UCLIBC_HAS_RESOLVER_SUPPORT
  135. UCLIBC_HAS_SHA256_CRYPT_IMPL
  136. UCLIBC_HAS_SHA512_CRYPT_IMPL
  137. UCLIBC_HAS_TZ_FILE_READ_MANY
  138. UCLIBC_HAS_UTMPX
  139. UCLIBC_SUPPORT_AI_ADDRCONFIG
  140. UCLIBC_SUSV3_LEGACY
  141. UCLIBC_SUSV3_LEGACY_MACROS
  142. UCLIBC_SUSV4_LEGACY
  143. UCLIBC_USE_NETLINK
  144. PTHREADS_DEBUG_SUPPORT
  145. )
  146. kconfig_q_opt y "${defs[@]}"
  147. kconfig_q_opt n UCLIBC_HAS_CTYPE_UNSAFE
  148. kconfig_q_opt n UCLIBC_HAS_LOCALE
  149. kconfig_q_opt n HAS_NO_THREADS
  150. kconfig_q_opt ipv6 UCLIBC_HAS_IPV6
  151. kconfig_q_opt nptl UCLIBC_HAS_THREADS_NATIVE
  152. kconfig_q_opt !nptl LINUXTHREADS_OLD
  153. kconfig_q_opt rpc UCLIBC_HAS_{,{FULL,REENTRANT}_}RPC
  154. kconfig_q_opt wordexp UCLIBC_HAS_WORDEXP
  155. kconfig_q_opt uclibc-compat UCLIBC_HAS_LIB{NSL,RESOLV}_STUB COMPAT_ATEXIT
  156. # we need to do it independently of hardened to get ssp.c built into libc
  157. kconfig_q_opt y UCLIBC_HAS_SSP
  158. kconfig_q_opt n UCLIBC_HAS_SSP_COMPAT
  159. kconfig_q_opt y UCLIBC_HAS_ARC4RANDOM
  160. kconfig_q_opt n PROPOLICE_BLOCK_ABRT
  161. kconfig_q_opt y PROPOLICE_BLOCK_SEGV
  162. # arm/mips do not emit PT_GNU_STACK, but if we enable this here
  163. # it will be emitted as RWE, ppc has to be checked, x86 needs it
  164. # this option should be used independently of hardened
  165. if has $(tc-arch) x86 || has $(tc-arch) ppc ; then
  166. kconfig_q_opt y UCLIBC_BUILD_NOEXECSTACK
  167. else
  168. kconfig_q_opt n UCLIBC_BUILD_NOEXECSTACK
  169. fi
  170. kconfig_q_opt y UCLIBC_BUILD_RELRO
  171. kconfig_q_opt hardened UCLIBC_BUILD_PIE
  172. kconfig_q_opt hardened UCLIBC_BUILD_NOW
  173. kconfig_q_opt !ssp SSP_QUICK_CANARY
  174. kconfig_q_opt ssp UCLIBC_BUILD_SSP
  175. local def
  176. for def in 1 2 ; do
  177. # Run twice as some config opts depend on others being enabled first.
  178. for def in ${defs_y[@]} ; do
  179. sed -i -e "s:.*\<${def}\>.*set:${def}=y:g" .config
  180. done
  181. for def in ${defs_n[@]} ; do
  182. sed -i -e "s:${def}=y:# ${def} is not set:g" .config
  183. done
  184. src_oldconfig
  185. done
  186. einfo "Enabled options:"
  187. for def in ${defs_y[@]} ; do
  188. einfo " " $(grep "^${def}=y" .config || echo "could not find ${def}")
  189. done
  190. einfo "Disabled options:"
  191. for def in ${defs_n[@]} ; do
  192. einfo " " $(grep "^# ${def} is not set" .config || echo "could not find ${def}")
  193. done
  194. # setup build and run paths
  195. sed -i \
  196. -e "/^CROSS_COMPILER_PREFIX/s:=.*:=\"${CTARGET}-\":" \
  197. -e "/^KERNEL_HEADERS/s:=.*:=\"$(alt_build_kprefix)\":" \
  198. -e "/^SHARED_LIB_LOADER_PREFIX/s:=.*:=\"/$(get_libdir)\":" \
  199. -e "/^DEVEL_PREFIX/s:=.*:=\"/usr\":" \
  200. -e "/^RUNTIME_PREFIX/s:=.*:=\"/\":" \
  201. -e "/^UCLIBC_EXTRA_CFLAGS/s:=.*:=\"${UCLIBC_EXTRA_CFLAGS}\":" \
  202. .config || die
  203. src_oldconfig
  204. }
  205. src_unpack() {
  206. if [[ ${PV} == "9999" ]] ; then
  207. git-2_src_unpack
  208. else
  209. unpack ${A}
  210. fi
  211. cd "${S}"
  212. if [[ -n ${PATCH_VER} ]] ; then
  213. EPATCH_SUFFIX="patch" epatch "${WORKDIR}"/patch
  214. fi
  215. epatch_user
  216. check_cpu_opts
  217. echo
  218. einfo "Runtime Prefix: /"
  219. einfo "Devel Prefix: /usr"
  220. einfo "Kernel Prefix: $(alt_build_kprefix)"
  221. einfo "CBUILD: ${CBUILD}"
  222. einfo "CHOST: ${CHOST}"
  223. einfo "CTARGET: ${CTARGET}"
  224. einfo "CPU: ${UCLIBC_CPU:-default}"
  225. einfo "ENDIAN: $(uclibc_endian)"
  226. echo
  227. ########## CPU SELECTION ##########
  228. local target=$(tc-arch) config_target
  229. case ${target} in
  230. amd64) target="x86_64";;
  231. arm) target="arm"; config_target="GENERIC_ARM";;
  232. avr) target="avr32";;
  233. mips) target="mips"; config_target="MIPS_ISA_1";;
  234. ppc) target="powerpc";;
  235. sh) target="sh"; config_target="SH4";;
  236. x86) target="i386"; config_target="486";;
  237. esac
  238. if [[ -n ${config_target} ]] ; then
  239. sed -i -e "s:default CONFIG_${config_target}:default CONFIG_${UCLIBC_CPU:-${config_target}}:" \
  240. extra/Configs/Config.${target} || die
  241. fi
  242. sed -i -e "s:^HOSTCC.*=.*:HOSTCC=$(tc-getBUILD_CC):" Rules.mak
  243. src_config
  244. if use iconv ; then
  245. # Run after make clean, otherwise files removed
  246. find ./extra/locale/charmaps -name "*.pairs" > extra/locale/codesets.txt
  247. if [[ ! -f /etc/locale.gen ]] ; then
  248. # See ./extra/locale/LOCALES for examples
  249. die "Please create an appropriate /etc/locale.gen for locale support"
  250. fi
  251. echo -e "@euro e\n@cyrillic c\n#---\nUTF-8 yes\n8-BIT yes\n#---\n\n" > ./extra/locale/locales.txt
  252. cat /etc/locale.gen >> ./extra/locale/locales.txt
  253. fi
  254. }
  255. src_compile() {
  256. emake headers || die
  257. just_headers && return 0
  258. emake || die
  259. if is_crosscompile ; then
  260. emake -C utils hostutils || die
  261. else
  262. emake utils || die
  263. fi
  264. }
  265. src_test() {
  266. is_crosscompile && return 0
  267. # assert test fails on pax/grsec enabled kernels - normal
  268. # vfork test fails in sandbox (both glibc/uclibc)
  269. emake UCLIBC_ONLY=1 check || die
  270. }
  271. src_install() {
  272. local sysroot=${D}
  273. is_crosscompile && sysroot+="/usr/${CTARGET}"
  274. local target="install"
  275. just_headers && target="install_headers"
  276. emake DESTDIR="${sysroot}" ${target} || die
  277. save_config .config
  278. # remove files coming from kernel-headers
  279. rm -rf "${sysroot}"/usr/include/{linux,asm*}
  280. # Make sure we install the sys-include symlink so that when
  281. # we build a 2nd stage cross-compiler, gcc finds the target
  282. # system headers correctly. See gcc/doc/gccinstall.info
  283. if is_crosscompile ; then
  284. dosym usr/include /usr/${CTARGET}/sys-include
  285. if ! just_headers && [[ -n $(get_opt HAVE_SHARED) ]] ; then
  286. newbin utils/ldconfig.host ${CTARGET}-ldconfig || die
  287. newbin utils/ldd.host ${CTARGET}-ldd || die
  288. fi
  289. return 0
  290. fi
  291. emake DESTDIR="${D}" install_utils || die
  292. dobin extra/scripts/getent
  293. dodoc Changelog* README TODO docs/*.txt DEDICATION.mjn3
  294. }
  295. pkg_postinst() {
  296. is_crosscompile && return 0
  297. if [ ! -e "${ROOT}"/etc/TZ ] ; then
  298. ewarn "Please remember to set your timezone in /etc/TZ"
  299. mkdir -p "${ROOT}"/etc
  300. echo "UTC" > "${ROOT}"/etc/TZ
  301. fi
  302. [ "${ROOT}" != "/" ] && return 0
  303. # update cache before reloading init
  304. ldconfig
  305. # reload init ...
  306. /sbin/telinit U 2>/dev/null
  307. }