uclibc-0.9.33.9999.ebuild 9.2 KB

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