Gentoo Archives: gentoo-commits

From: Yuta SATOH <nigoro@×××××××××.jp>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gentoo-bsd:master commit in: eclass/
Date: Wed, 28 Sep 2016 12:25:07
Message-Id: 1475063978.9c7da84db91d7a65a9904fdb251a17ea5d61724a.yuta_satoh@gentoo
1 commit: 9c7da84db91d7a65a9904fdb251a17ea5d61724a
2 Author: Yuta SATOH <nigoro.dev <AT> gmail <DOT> com>
3 AuthorDate: Wed Sep 28 11:59:38 2016 +0000
4 Commit: Yuta SATOH <nigoro <AT> gentoo <DOT> gr <DOT> jp>
5 CommitDate: Wed Sep 28 11:59:38 2016 +0000
6 URL: https://gitweb.gentoo.org/proj/gentoo-bsd.git/commit/?id=9c7da84d
7
8 eclass/freebsd.eclass: import from latest tree
9
10 eclass/freebsd.eclass | 270 ++++++++++++++++++++++++++++++++++++++++++++++++++
11 1 file changed, 270 insertions(+)
12
13 diff --git a/eclass/freebsd.eclass b/eclass/freebsd.eclass
14 new file mode 100644
15 index 0000000..57f9d45
16 --- /dev/null
17 +++ b/eclass/freebsd.eclass
18 @@ -0,0 +1,270 @@
19 +# Copyright 1999-2015 Gentoo Foundation
20 +# Distributed under the terms of the GNU General Public License v2
21 +# $Id$
22 +#
23 +# @MAINTAINER:
24 +# maintainer-needed@g.o
25 +# @AUTHOR:
26 +# Diego Pettenò <flameeyes@g.o>
27 +
28 +inherit versionator eutils flag-o-matic bsdmk
29 +
30 +# Drop patch level from ${PV}
31 +MY_PV=${PV/_p*}
32 +PLEVEL=${PV##*_p}
33 +
34 +LICENSE="BSD"
35 +HOMEPAGE="http://www.freebsd.org/"
36 +
37 +# Define global package names
38 +LIB="freebsd-lib-${PV}"
39 +BIN="freebsd-bin-${PV}"
40 +CONTRIB="freebsd-contrib-${PV}"
41 +SHARE="freebsd-share-${PV}"
42 +UBIN="freebsd-ubin-${PV}"
43 +USBIN="freebsd-usbin-${PV}"
44 +CRYPTO="freebsd-crypto-${PV}"
45 +LIBEXEC="freebsd-libexec-${PV}"
46 +SBIN="freebsd-sbin-${PV}"
47 +GNU="freebsd-gnu-${PV}"
48 +ETC="freebsd-etc-${PV}"
49 +SYS="freebsd-sys-${PV}"
50 +INCLUDE="freebsd-include-${PV}"
51 +RESCUE="freebsd-rescue-${PV}"
52 +CDDL="freebsd-cddl-${PV}"
53 +SECURE="freebsd-secure-${PV}"
54 +
55 +# Release version (5.3, 5.4, 6.0, etc)
56 +RV="$(get_version_component_range 1-2 ${MY_PV})"
57 +
58 +# SVN ebuild support.
59 +# 9.1.0.9999 --> release/9.1.0
60 +# 9.1.9999 --> releng/9.1
61 +# 9.9999 --> stable/9
62 +# 9999 --> head
63 +#
64 +# svn revision can be specified by patch level:
65 +# freebsd-lib-9.9999_p247000 --> set svn -r 247000
66 +
67 +if [[ ${MY_PV} == *9999* ]]; then
68 + inherit subversion
69 +
70 + # Set SVN revision using patch level.
71 + [[ ${PV} == *_p* ]] && ESVN_REVISION="${PLEVEL}"
72 +
73 + case ${MY_PV%.9999} in
74 + *.*.*) BRANCH="release";;
75 + *.*) BRANCH="releng" ;;
76 + 9999) BRANCH="head" ;;
77 + *) BRANCH="stable" ;;
78 + esac
79 +
80 + if [[ ${BRANCH} == head ]] ; then
81 + SVN_SUB_URI="${BRANCH}"
82 + else
83 + SVN_SUB_URI="${BRANCH}/${MY_PV%.9999}"
84 + fi
85 +
86 + ESVN_REPO_URI="svn://svn.freebsd.org/base/${SVN_SUB_URI}"
87 + ESVN_PROJECT="freebsd-${BRANCH}"
88 +fi
89 +
90 +# use the original source code.
91 +if [[ ${MY_PV} != *9999* ]] && version_is_at_least 10.0 ${RV} ; then
92 + DL_PV=${MY_PV/_rc/-RC}
93 + DL_PV=${DL_PV/_beta/-BETA}
94 + DL_PV=${DL_PV/_alpha/-ALPHA}
95 + if [[ ${DL_PV} == ${MY_PV} ]]; then
96 + DL_PV="${DL_PV}-RELEASE"
97 + fi
98 + SRC_URI="mirror://freebsd/releases/i386/${DL_PV}/src.txz -> freebsd-src-${MY_PV}.tar.xz"
99 +fi
100 +
101 +IUSE="profile"
102 +
103 +#unalias -a
104 +alias install-info='/usr/bin/bsdinstall-info'
105 +
106 +EXPORT_FUNCTIONS src_compile src_install src_unpack
107 +
108 +# doperiodic <kind> <file> ...
109 +doperiodic() {
110 + local kind=$1
111 + shift
112 +
113 + ( # dont want to pollute calling env
114 + insinto /etc/periodic/${kind}
115 + insopts -m 0755
116 + doins "$@"
117 + )
118 +}
119 +
120 +freebsd_get_bmake() {
121 + local bmake
122 + bmake=$(get_bmake)
123 + [[ ${CBUILD} == *-freebsd* ]] || bmake="${bmake} -m /usr/share/mk/freebsd"
124 +
125 + echo "${bmake}"
126 +}
127 +
128 +# Generates a patch SRC_URI or DISTDIR of upstream.
129 +freebsd_upstream_patches() {
130 + local opt=$1
131 + [[ ${#UPSTREAM_PATCHES[@]} -eq 0 ]] && return 1
132 + for x in "${UPSTREAM_PATCHES[@]}"
133 + do
134 + local out=${PN}-${x/\//-}
135 + out=${out/:/}
136 + if [[ ${opt} == -s ]] ; then
137 + echo "${DISTDIR}/${out}"
138 + else
139 + echo "https://security.freebsd.org/patches/${x} -> ${out}"
140 + fi
141 + done
142 +}
143 +
144 +freebsd_do_patches() {
145 + if [[ ${#PATCHES[@]} -gt 1 ]] ; then
146 + for x in "${PATCHES[@]}"; do
147 + epatch "${x}"
148 + done
149 + else
150 + for x in ${PATCHES} ; do
151 + epatch "${x}"
152 + done
153 + fi
154 + [[ ${#UPSTREAM_PATCHES[@]} -gt 0 ]] && epatch $(freebsd_upstream_patches -s)
155 + epatch_user
156 +}
157 +
158 +freebsd_rename_libraries() {
159 + ebegin "Renaming libraries"
160 + # We don't use libtermcap, we use libncurses
161 + find "${S}" -name Makefile -print0 | xargs -0 \
162 + sed -i -e 's:-ltermcap:-lncurses:g; s:{LIBTERMCAP}:{LIBNCURSES}:g'
163 + # flex provides libfl, not libl
164 + find "${S}" -name Makefile -print0 | xargs -0 \
165 + sed -i -e 's:-ll$:-lfl:g; s:-ll :-lfl :g; s:{LIBL}:{LIBFL}:g'
166 + # ncurses provides libncursesw not libcursesw
167 + find "${S}" -name Makefile -print0 | xargs -0 \
168 + sed -i -e 's:-lcursesw:-lncursesw:g'
169 + # we use expat instead of bsdxml
170 + find "${S}" -name Makefile -print0 | xargs -0 \
171 + sed -i -e 's:-lbsdxml:-lexpat:g'
172 +
173 + eend $?
174 +}
175 +
176 +freebsd_src_unpack() {
177 + if [[ ${MY_PV} == *9999* ]]; then
178 + S="${WORKDIR}" subversion_src_unpack
179 +
180 + # When share/mk exists in ${WORKDIR}, it is used on FreeBSD 10.0
181 + # Removed "${WORKDIR}"/share/mk/*.mk, use to force /usr/share/mk.
182 + if [[ ${PN} != freebsd-mk-defs ]] ; then
183 + [[ -e "${WORKDIR}"/share/mk ]] && rm -rf "${WORKDIR}"/share/mk/*.mk
184 + fi
185 + else
186 + if version_is_at_least 10.0 ${RV} ; then
187 + local tarball="freebsd-src-${MY_PV}.tar.xz"
188 + local topdir="usr/src/"
189 + local extractlist=()
190 + for i in ${EXTRACTONLY} ; do
191 + extractlist+=( ${topdir}${i} )
192 + done
193 + ebegin "Unpacking parts of ${tarball} to ${WORKDIR}"
194 + cd "${WORKDIR}" || die
195 + tar -xJpf "${DISTDIR}/${tarball}" --strip-components=2 "${extractlist[@]}" 2> /dev/null || die "tar extract command failed"
196 + cd - || die
197 + else
198 + for f in ${A} ; do
199 + [[ ${f} == *.tar.* ]] && unpack ${f}
200 + done
201 + fi
202 + fi
203 + cd "${S}"
204 +
205 + dummy_mk ${REMOVE_SUBDIRS}
206 +
207 + freebsd_do_patches
208 + freebsd_rename_libraries
209 +
210 + # Starting from FreeBSD 9.2, its install command supports the -l option and
211 + # they now use it. Emulate it if we are on a system that does not have it.
212 + if version_is_at_least 9.2 ${RV} && ! has_version '>=sys-freebsd/freebsd-ubin-9.2_beta1' ; then
213 + export INSTALL_LINK="ln -f"
214 + export INSTALL_SYMLINK="ln -fs"
215 + fi
216 +}
217 +
218 +freebsd_src_compile() {
219 + use profile && filter-flags "-fomit-frame-pointer"
220 + use profile || mymakeopts="${mymakeopts} NO_PROFILE= "
221 +
222 + mymakeopts="${mymakeopts} NO_MANCOMPRESS= NO_INFOCOMPRESS= NO_FSCHG="
223 +
224 + # Make sure to use FreeBSD definitions while crosscompiling
225 + [[ -z "${BMAKE}" ]] && BMAKE="$(freebsd_get_bmake)"
226 +
227 + # Create objdir if MAKEOBJDIRPREFIX is defined, so that we can make out of
228 + # tree builds easily.
229 + if [[ -n "${MAKEOBJDIRPREFIX}" ]] ; then
230 + mkmake obj || die
231 + fi
232 +
233 + bsdmk_src_compile "$@"
234 +}
235 +
236 +# Helper function to make a multilib build with FreeBSD Makefiles.
237 +# Usage:
238 +# MULTIBUILD_VARIANTS=( $(get_all_abis) )
239 +# multibuild_foreach_variant freebsd_multilib_multibuild_wrapper my_function
240 +#
241 +# Important note: To use this function you _have_ to:
242 +# - inherit multilib.eclass and multibuild.eclass
243 +# - set MULTIBUILD_VARIANTS
244 +
245 +freebsd_multilib_multibuild_wrapper() {
246 + # Get the ABI from multibuild.eclass
247 + # This assumes MULTIBUILD_VARIANTS contains only valid ABIs.
248 + local ABI=${MULTIBUILD_VARIANT}
249 +
250 + # First, save the variables: CFLAGS, CXXFLAGS, LDFLAGS, LDADD and mymakeopts.
251 + for i in CFLAGS CXXFLAGS LDFLAGS LDADD mymakeopts ; do
252 + export ${i}_SAVE="${!i}"
253 + done
254 +
255 + # Setup the variables specific to this ABI.
256 + multilib_toolchain_setup "${ABI}"
257 +
258 + local target="$(tc-arch-kernel ${CHOST})"
259 + mymakeopts="${mymakeopts} TARGET=${target} MACHINE=${target} MACHINE_ARCH=${target} SHLIBDIR=/usr/$(get_libdir) LIBDIR=/usr/$(get_libdir)"
260 + if [ "${ABI}" != "${DEFAULT_ABI}" ] ; then
261 + mymakeopts="${mymakeopts} COMPAT_32BIT="
262 + fi
263 +
264 + einfo "Building for ABI=${ABI} and TARGET=${target}"
265 +
266 + export MAKEOBJDIRPREFIX="${BUILD_DIR}"
267 + if [ ! -d "${MAKEOBJDIRPREFIX}" ] ; then
268 + mkdir "${MAKEOBJDIRPREFIX}" || die "Could not create ${MAKEOBJDIRPREFIX}."
269 + fi
270 +
271 + CTARGET="${CHOST}" "$@"
272 +
273 + # Restore the variables now.
274 + for i in CFLAGS CXXFLAGS LDFLAGS LDADD mymakeopts ; do
275 + ii="${i}_SAVE"
276 + export ${i}="${!ii}"
277 + done
278 +}
279 +
280 +freebsd_src_install() {
281 + use profile || mymakeopts="${mymakeopts} NO_PROFILE= "
282 +
283 + mymakeopts="${mymakeopts} NO_MANCOMPRESS= NO_INFOCOMPRESS= NO_FSCHG="
284 +
285 + [[ -z "${BMAKE}" ]] && BMAKE="$(freebsd_get_bmake)"
286 +
287 + bsdmk_src_install
288 +}