uclibc-ng-1.0.20.ebuild 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI="6"
  4. inherit flag-o-matic multilib savedconfig toolchain-funcs versionator
  5. if [[ ${PV} == "9999" ]] ; then
  6. EGIT_REPO_URI="git://uclibc-ng.org/git/uclibc-ng"
  7. inherit git-r3
  8. MY_P=uclibc-ng-${PV}
  9. else
  10. MY_P=uClibc-ng-${PV}
  11. fi
  12. DESCRIPTION="C library for developing embedded Linux systems"
  13. HOMEPAGE="http://www.uclibc-ng.org/"
  14. if [[ ${PV} != "9999" ]] ; then
  15. PATCH_VER=""
  16. SRC_URI="http://downloads.uclibc-ng.org/releases/${PV}/${MY_P}.tar.bz2"
  17. KEYWORDS="-* amd64 arm ~mips ppc x86"
  18. fi
  19. LICENSE="LGPL-2"
  20. SLOT="0"
  21. IUSE="debug hardened iconv ipv6 rpc symlink-compat crosscompile_opts_headers-only"
  22. RESTRICT="strip"
  23. # 1) We can't upgrade from uclibc to uclibc-ng via a soft blocker since portage
  24. # will delete the ld.so sym link prematurely and break the system. So we
  25. # will hard block and give manual migration instructions.
  26. # 2) Currently uclibc and uclibc-ng's iconv are in bad shape. We've been using
  27. # the breakout library. The disadvantage here is that we have to sprinkle
  28. # LDFAGS=-liconv on build systems that need to link against libiconv.
  29. RDEPEND="
  30. !!sys-libs/uclibc
  31. iconv? ( dev-libs/libiconv )"
  32. S=${WORKDIR}/${MY_P}
  33. export CBUILD=${CBUILD:-${CHOST}}
  34. export CTARGET=${CTARGET:-${CHOST}}
  35. if [[ ${CHOST} == ${CTARGET} ]] ; then
  36. if [[ ${CATEGORY} == cross-* ]] ; then
  37. export CTARGET=${CATEGORY#cross-}
  38. fi
  39. fi
  40. is_crosscompile() {
  41. [[ ${CHOST} != ${CTARGET} ]]
  42. }
  43. alt_build_kprefix() {
  44. if [[ ${CBUILD} == ${CHOST} && ${CHOST} == ${CTARGET} ]] ; then
  45. echo /usr/include
  46. else
  47. echo /usr/${CTARGET}/usr/include
  48. fi
  49. }
  50. just_headers() {
  51. use crosscompile_opts_headers-only && is_crosscompile
  52. }
  53. uclibc_endian() {
  54. # XXX: this wont work for a toolchain which is bi-endian, but we
  55. # dont have any such thing at the moment, so not a big deal
  56. touch "${T}"/endian.s
  57. $(tc-getAS ${CTARGET}) "${T}"/endian.s -o "${T}"/endian.o
  58. case $(file "${T}"/endian.o) in
  59. *" MSB "*) echo "BIG";;
  60. *" LSB "*) echo "LITTLE";;
  61. *) echo "NFC";;
  62. esac
  63. rm -f "${T}"/endian.{s,o}
  64. }
  65. kconfig_q_opt() {
  66. local flag=$1; shift
  67. case ${flag} in
  68. y|n) ;;
  69. *) flag=$(usex ${flag} y n) ;;
  70. esac
  71. local var="defs_${flag}"
  72. eval "${var}+=( $* )"
  73. }
  74. get_opt() {
  75. (
  76. unset ${1}
  77. . ${2:-"${S}"/.config}
  78. echo ${!1}
  79. )
  80. }
  81. make_oldconfig() {
  82. yes "" 2>/dev/null | emake -s oldconfig >/dev/null
  83. }
  84. make_config() {
  85. restore_config .config
  86. if [ -f .config ]; then
  87. make_oldconfig
  88. return 0
  89. else
  90. ewarn "Could not locate user configfile, so we will save a default one"
  91. fi
  92. emake ARCH=$1 defconfig >/dev/null
  93. local defs_{y,n}
  94. # These are forced off
  95. defs_n=(
  96. DOASSERTS
  97. DODEBUG_PT
  98. HAS_NO_THREADS
  99. PROPOLICE_BLOCK_ABRT
  100. SSP_QUICK_CANARY
  101. SUPPORT_LD_DEBUG_EARLY
  102. UCLIBC_HAS_CTYPE_UNSAFE
  103. UCLIBC_HAS_LOCALE
  104. UCLIBC_HAS_SSP_COMPAT
  105. )
  106. # These are forced on
  107. defs_y=(
  108. COMPAT_ATEXIT
  109. DO_C99_MATH
  110. DO_XSI_MATH
  111. FORCE_SHAREABLE_TEXT_SEGMENTS
  112. LDSO_GNU_HASH_SUPPORT
  113. LDSO_PRELINK_SUPPORT
  114. LDSO_PRELOAD_FILE_SUPPORT
  115. LDSO_RUNPATH_OF_EXECUTABLE
  116. LDSO_STANDALONE_SUPPORT
  117. MALLOC_GLIBC_COMPAT
  118. PROPOLICE_BLOCK_SEGV
  119. PTHREADS_DEBUG_SUPPORT
  120. UCLIBC_HAS_ARC4RANDOM
  121. UCLIBC_HAS_BACKTRACE
  122. UCLIBC_HAS_BSD_RES_CLOSE
  123. UCLIBC_HAS_CONTEXT_FUNCS
  124. UCLIBC_HAS_CTYPE_CHECKED
  125. UCLIBC_HAS_EXTRA_COMPAT_RES_STATE
  126. UCLIBC_HAS_FENV
  127. UCLIBC_HAS_FOPEN_CLOSEEXEC_MODE
  128. UCLIBC_HAS_FOPEN_EXCLUSIVE_MODE
  129. UCLIBC_HAS_FOPEN_LARGEFILE_MODE
  130. UCLIBC_HAS_FTS
  131. UCLIBC_HAS_FTW
  132. UCLIBC_HAS_GETPT
  133. UCLIBC_HAS_GLIBC_CUSTOM_PRINTF
  134. UCLIBC_HAS_GLIBC_CUSTOM_STREAMS
  135. UCLIBC_HAS_GNU_GLOB
  136. UCLIBC_HAS_HEXADECIMAL_FLOATS
  137. UCLIBC_HAS_LIBNSL_STUB
  138. UCLIBC_HAS_LIBRESOLV_STUB
  139. UCLIBC_HAS_LIBUTIL
  140. UCLIBC_HAS_NFTW
  141. UCLIBC_HAS_OBSOLETE_BSD_SIGNAL
  142. UCLIBC_HAS_OBSTACK
  143. UCLIBC_HAS_PRINTF_M_SPEC
  144. UCLIBC_HAS_PROGRAM_INVOCATION_NAME
  145. UCLIBC_HAS_RESOLVER_SUPPORT
  146. UCLIBC_HAS_SHA256_CRYPT_IMPL
  147. UCLIBC_HAS_SHA512_CRYPT_IMPL
  148. UCLIBC_HAS_SSP
  149. UCLIBC_HAS_STUBS
  150. UCLIBC_HAS_SYS_ERRLIST
  151. UCLIBC_HAS_SYS_SIGLIST
  152. UCLIBC_HAS_THREADS_NATIVE
  153. UCLIBC_HAS_TZ_FILE_READ_MANY
  154. UCLIBC_HAS_UTMP
  155. UCLIBC_HAS_UTMPX
  156. UCLIBC_HAS_WCHAR
  157. UCLIBC_HAS_WORDEXP
  158. UCLIBC_NTP_LEGACY
  159. UCLIBC_SUPPORT_AI_ADDRCONFIG
  160. UCLIBC_SUSV2_LEGACY
  161. UCLIBC_SUSV3_LEGACY
  162. UCLIBC_SUSV3_LEGACY_MACROS
  163. UCLIBC_SUSV4_LEGACY
  164. UCLIBC_USE_NETLINK
  165. )
  166. sed -i -e '/ARCH_.*_ENDIAN/d' .config
  167. kconfig_q_opt y "ARCH_WANTS_$(uclibc_endian)_ENDIAN"
  168. kconfig_q_opt debug DODEBUG
  169. kconfig_q_opt debug SUPPORT_LD_DEBUG
  170. kconfig_q_opt debug UCLIBC_HAS_PROFILING
  171. kconfig_q_opt ipv6 UCLIBC_HAS_IPV6
  172. kconfig_q_opt rpc UCLIBC_HAS_RPC
  173. kconfig_q_opt rpc UCLIBC_HAS_FULL_RPC
  174. kconfig_q_opt rpc UCLIBC_HAS_REENTRANT_RPC
  175. kconfig_q_opt hardened UCLIBC_BUILD_NOEXECSTACK
  176. kconfig_q_opt hardened UCLIBC_BUILD_NOW
  177. kconfig_q_opt hardened UCLIBC_BUILD_PIE
  178. kconfig_q_opt hardened UCLIBC_BUILD_RELRO
  179. kconfig_q_opt hardened UCLIBC_BUILD_SSP
  180. local count def
  181. for count in 1 2 ; do
  182. # Run twice as some config opts depend on others being enabled first.
  183. for def in ${defs_y[@]} ; do
  184. sed -i -e "s|.*\<${def}\>.*set|${def}=y|g" .config
  185. done
  186. for def in ${defs_n[@]} ; do
  187. sed -i -e "s|${def}=y|# ${def} is not set|g" .config
  188. done
  189. make_oldconfig
  190. done
  191. einfo "Enabled options:"
  192. for def in ${defs_y[@]} ; do
  193. einfo " " $(grep "^${def}=y" .config || echo "could not find ${def}")
  194. done
  195. einfo "Disabled options:"
  196. for def in ${defs_n[@]} ; do
  197. einfo " " $(grep "^# ${def} is not set" .config || echo "could not find ${def}")
  198. done
  199. # setup build and run paths
  200. sed -i \
  201. -e "/^CROSS_COMPILER_PREFIX/s|=.*|=\"${CTARGET}-\"|" \
  202. -e "/^KERNEL_HEADERS/s|=.*|=\"$(alt_build_kprefix)\"|" \
  203. -e "/^SHARED_LIB_LOADER_PREFIX/s|=.*|=\"/$(get_libdir)\"|" \
  204. -e "/^DEVEL_PREFIX/s|=.*|=\"/usr\"|" \
  205. -e "/^RUNTIME_PREFIX/s|=.*|=\"/\"|" \
  206. -e "/^UCLIBC_EXTRA_CFLAGS/s|=.*|=\"${UCLIBC_EXTRA_CFLAGS}\"|" \
  207. .config || die
  208. make_oldconfig
  209. }
  210. pkg_setup() {
  211. # Make sure our CHOST is a uclibc toolchain for native compiling
  212. if [[ ${CHOST} == ${CTARGET} ]]; then
  213. case ${CHOST} in
  214. *-uclinux*|*-uclibc*) ;;
  215. *) die "Use sys-devel/crossdev to build a uclibc toolchain" ;;
  216. esac
  217. fi
  218. # uClibc-ng doesn't carry old Linux threads, and since we force
  219. # threading our only choice is NPTL which requires i486 and later.
  220. [[ ${CTARGET} == i386* ]] && die "i386 can't support Native Posix Threads (NPTL)."
  221. }
  222. src_prepare() {
  223. local version subversion extraversion
  224. # uclibc-ng tries to create a two sym link with ld.so,
  225. # ld-uClibc.so.{0,MAJOR_VERSION} -> ld-uClibc-<version>.so
  226. # where MAJOR_VERSION != 0 indicates the ABI verison.
  227. # We want to get rid of this and just have ABI = 0.
  228. eapply "${FILESDIR}"/uclibc-compat-r1.patch
  229. # We need to change the major.minor.sublevel of uclibc-ng.
  230. # Upstream sets MAJOR_VERSION = 1 which breaks runtime linking.
  231. # If we really want the ABI bump, we'll have to hack the gcc
  232. # spec file and change the '*link:' rule.
  233. version=( $(get_version_components) )
  234. if [[ -z ${version[1]} ]]; then
  235. subversion=0
  236. extraversion=0
  237. else
  238. subversion=${version[1]}
  239. if [[ -z ${version[2]} ]]; then
  240. extraversion=0
  241. else
  242. extraversion=.${version[2]}
  243. fi
  244. fi
  245. sed -i \
  246. -e "/^MAJOR_VERSION/s|:=.*|:= 0|" \
  247. -e "/^MINOR_VERSION/s|:=.*|:= ${version[0]}|" \
  248. -e "/^SUBLEVEL/s|:=.*|:= ${subversion}|" \
  249. -e "/^EXTRAVERSION/s|:=.*|:= ${extraversion}|" \
  250. Rules.mak || die
  251. eapply_user
  252. }
  253. src_configure() {
  254. # Map our toolchain arch name to the name expected by uClibc-ng.
  255. local target=$(tc-arch)
  256. case ${target} in
  257. amd64) target="x86_64";;
  258. arm) target="arm";;
  259. mips) target="mips";;
  260. ppc) target="powerpc";;
  261. x86) target="i386";;
  262. esac
  263. # Do arch specific configuration by changing the defaults in
  264. # extra/Configs/Config.<arch>. If these are not overridden
  265. # by an save .config, they will be selected by default.
  266. # For i386, i486, i586 and i686
  267. local cpu
  268. if [[ ${target} == "i386" ]]; then
  269. [[ ${CTARGET} == i[456]86* ]] && cpu="${CTARGET:1:1}86"
  270. sed -i -e "s|default CONFIG_686|default CONFIG_${cpu:-486}|" \
  271. extra/Configs/Config.i386 || die
  272. fi
  273. # For arm
  274. if [[ ${target} == "arm" ]]; then
  275. sed -i -e '/Build for EABI/a \\tdefault y' extra/Configs/Config.arm
  276. fi
  277. # We set HOSTCC to the proper tuple rather than just 'gcc'
  278. sed -i -e "s|^HOSTCC.*=.*|HOSTCC=$(tc-getBUILD_CC)|" Rules.mak
  279. make_config ${target}
  280. einfo
  281. einfo "Runtime Prefix: /"
  282. einfo "Devel Prefix: /usr"
  283. einfo "Kernel Prefix: $(alt_build_kprefix)"
  284. einfo "CBUILD: ${CBUILD}"
  285. einfo "CHOST: ${CHOST}"
  286. einfo "CTARGET: ${CTARGET}"
  287. einfo "ABI: ${ABI}"
  288. einfo "ENDIAN: $(uclibc_endian)"
  289. einfo
  290. }
  291. src_compile() {
  292. emake headers
  293. just_headers && return 0
  294. emake
  295. if is_crosscompile ; then
  296. emake -C utils hostutils
  297. else
  298. emake utils
  299. fi
  300. }
  301. src_test() {
  302. is_crosscompile && return 0
  303. # assert test fails on pax/grsec enabled kernels
  304. # normal vfork test fails in sandbox (both glibc/uclibc)
  305. emake UCLIBC_ONLY=1 check
  306. }
  307. src_install() {
  308. local sysroot=${D}
  309. is_crosscompile && sysroot+="/usr/${CTARGET}"
  310. local target="install"
  311. just_headers && target="install_headers"
  312. emake DESTDIR="${sysroot}" ${target}
  313. save_config .config
  314. # remove files coming from kernel-headers
  315. rm -rf "${sysroot}"/usr/include/{linux,asm*}
  316. # Make sure we install the sys-include symlink so that when
  317. # we build a 2nd stage cross-compiler, gcc finds the target
  318. # system headers correctly. See gcc/doc/gccinstall.info
  319. if is_crosscompile ; then
  320. dosym usr/include /usr/${CTARGET}/sys-include
  321. if ! just_headers && [[ -n $(get_opt HAVE_SHARED) ]] ; then
  322. newbin utils/ldconfig.host ${CTARGET}-ldconfig
  323. newbin utils/ldd.host ${CTARGET}-ldd
  324. fi
  325. return 0
  326. fi
  327. if use symlink-compat; then
  328. dosym libc.so.0 "${DESTDIR}"/lib/libcrypt.so.0
  329. dosym libc.so.0 "${DESTDIR}"/lib/libdl.so.0
  330. dosym libc.so.0 "${DESTDIR}"/lib/libm.so.0
  331. dosym libc.so.0 "${DESTDIR}"/lib/libpthread.so.0
  332. dosym libc.so.0 "${DESTDIR}"/lib/librt.so.0
  333. dosym libc.so.0 "${DESTDIR}"/lib/libresolv.so.0
  334. dosym libc.so.0 "${DESTDIR}"/lib/libubacktrace.so.0
  335. dosym libc.so.0 "${DESTDIR}"/lib/libutil.so.0
  336. fi
  337. emake DESTDIR="${D}" install_utils
  338. dobin extra/scripts/getent
  339. dodoc README docs/*.txt
  340. }
  341. pkg_postinst() {
  342. is_crosscompile && return 0
  343. if [ ! -e "${ROOT}"/etc/TZ ] ; then
  344. ewarn "Please remember to set your timezone in /etc/TZ"
  345. mkdir -p "${ROOT}"/etc
  346. echo "UTC" > "${ROOT}"/etc/TZ
  347. fi
  348. [ "${ROOT}" != "/" ] && return 0
  349. # update cache before reloading init
  350. ldconfig
  351. # reload init ...
  352. /sbin/telinit U 2>/dev/null
  353. }