linux-mod.eclass 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. # Copyright 1999-2016 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: linux-mod.eclass
  4. # @MAINTAINER:
  5. # kernel@gentoo.org
  6. # @AUTHOR:
  7. # John Mylchreest <johnm@gentoo.org>,
  8. # Stefan Schweizer <genstef@gentoo.org>
  9. # @BLURB: It provides the functionality required to install external modules against a kernel source tree.
  10. # @DESCRIPTION:
  11. # This eclass is used to interface with linux-info.eclass in such a way
  12. # to provide the functionality and initial functions
  13. # required to install external modules against a kernel source
  14. # tree.
  15. # A Couple of env vars are available to effect usage of this eclass
  16. # These are as follows:
  17. # @ECLASS-VARIABLE: MODULES_OPTIONAL_USE
  18. # @DESCRIPTION:
  19. # A string containing the USE flag to use for making this eclass optional
  20. # The recommended non-empty value is 'modules'
  21. # @ECLASS-VARIABLE: KERNEL_DIR
  22. # @DESCRIPTION:
  23. # A string containing the directory of the target kernel sources. The default value is
  24. # "/usr/src/linux"
  25. # @ECLASS-VARIABLE: ECONF_PARAMS
  26. # @DESCRIPTION:
  27. # It's a string containing the parameters to pass to econf.
  28. # If this is not set, then econf isn't run.
  29. # @ECLASS-VARIABLE: BUILD_PARAMS
  30. # @DESCRIPTION:
  31. # It's a string with the parameters to pass to emake.
  32. # @ECLASS-VARIABLE: BUILD_TARGETS
  33. # @DESCRIPTION:
  34. # It's a string with the build targets to pass to make. The default value is "clean module"
  35. # @ECLASS-VARIABLE: MODULE_NAMES
  36. # @DESCRIPTION:
  37. # It's a string containing the modules to be built automatically using the default
  38. # src_compile/src_install. It will only make ${BUILD_TARGETS} once in any directory.
  39. #
  40. # The structure of each MODULE_NAMES entry is as follows:
  41. #
  42. # modulename(libdir:srcdir:objdir)
  43. #
  44. # where:
  45. #
  46. # modulename = name of the module file excluding the .ko
  47. # libdir = place in system modules directory where module is installed (by default it's misc)
  48. # srcdir = place for ebuild to cd to before running make (by default it's ${S})
  49. # objdir = place the .ko and objects are located after make runs (by default it's set to srcdir)
  50. #
  51. # To get an idea of how these variables are used, here's a few lines
  52. # of code from around line 540 in this eclass:
  53. #
  54. # einfo "Installing ${modulename} module"
  55. # cd ${objdir} || die "${objdir} does not exist"
  56. # insinto /lib/modules/${KV_FULL}/${libdir}
  57. # doins ${modulename}.${KV_OBJ} || die "doins ${modulename}.${KV_OBJ} failed"
  58. #
  59. # For example:
  60. # MODULE_NAMES="module_pci(pci:${S}/pci:${S}) module_usb(usb:${S}/usb:${S})"
  61. #
  62. # what this would do is
  63. #
  64. # cd "${S}"/pci
  65. # make ${BUILD_PARAMS} ${BUILD_TARGETS}
  66. # cd "${S}"
  67. # insinto /lib/modules/${KV_FULL}/pci
  68. # doins module_pci.${KV_OBJ}
  69. #
  70. # cd "${S}"/usb
  71. # make ${BUILD_PARAMS} ${BUILD_TARGETS}
  72. # cd "${S}"
  73. # insinto /lib/modules/${KV_FULL}/usb
  74. # doins module_usb.${KV_OBJ}
  75. # There is also support for automated modprobe.d file generation.
  76. # This can be explicitly enabled by setting any of the following variables.
  77. # @ECLASS-VARIABLE: MODULESD_<modulename>_ENABLED
  78. # @DESCRIPTION:
  79. # This is used to disable the modprobe.d file generation otherwise the file will be
  80. # always generated (unless no MODULESD_<modulename>_* variable is provided). Set to "no" to disable
  81. # the generation of the file and the installation of the documentation.
  82. # @ECLASS-VARIABLE: MODULESD_<modulename>_EXAMPLES
  83. # @DESCRIPTION:
  84. # This is a bash array containing a list of examples which should
  85. # be used. If you want us to try and take a guess set this to "guess".
  86. #
  87. # For each array_component it's added an options line in the modprobe.d file
  88. #
  89. # options array_component
  90. #
  91. # where array_component is "<modulename> options" (see modprobe.conf(5))
  92. # @ECLASS-VARIABLE: MODULESD_<modulename>_ALIASES
  93. # @DESCRIPTION:
  94. # This is a bash array containing a list of associated aliases.
  95. #
  96. # For each array_component it's added an alias line in the modprobe.d file
  97. #
  98. # alias array_component
  99. #
  100. # where array_component is "wildcard <modulename>" (see modprobe.conf(5))
  101. # @ECLASS-VARIABLE: MODULESD_<modulename>_ADDITIONS
  102. # @DESCRIPTION:
  103. # This is a bash array containing a list of additional things to
  104. # add to the bottom of the file. This can be absolutely anything.
  105. # Each entry is a new line.
  106. # @ECLASS-VARIABLE: MODULESD_<modulename>_DOCS
  107. # @DESCRIPTION:
  108. # This is a string list which contains the full path to any associated
  109. # documents for <modulename>. These files are installed in the live tree.
  110. # @ECLASS-VARIABLE: KV_OBJ
  111. # @DESCRIPTION:
  112. # It's a read-only variable. It contains the extension of the kernel modules.
  113. inherit eutils linux-info multilib
  114. EXPORT_FUNCTIONS pkg_setup pkg_preinst pkg_postinst src_install src_compile pkg_postrm
  115. IUSE="kernel_linux ${MODULES_OPTIONAL_USE}"
  116. SLOT="0"
  117. RDEPEND="${MODULES_OPTIONAL_USE}${MODULES_OPTIONAL_USE:+? (} kernel_linux? ( virtual/modutils ) ${MODULES_OPTIONAL_USE:+)}"
  118. DEPEND="${RDEPEND}
  119. ${MODULES_OPTIONAL_USE}${MODULES_OPTIONAL_USE:+? (}
  120. sys-apps/sed
  121. kernel_linux? ( virtual/linux-sources )
  122. ${MODULES_OPTIONAL_USE:+)}"
  123. # eclass utilities
  124. # ----------------------------------
  125. check_vermagic() {
  126. debug-print-function ${FUNCNAME} $*
  127. local curr_gcc_ver=$(gcc -dumpversion)
  128. local tmpfile old_chost old_gcc_ver result=0
  129. [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
  130. tmpfile=`find "${KV_DIR}/" -iname "*.o.cmd" -exec grep usr/lib/gcc {} \; -quit`
  131. tmpfile=${tmpfile//*usr/lib}
  132. tmpfile=${tmpfile//\/include*}
  133. old_chost=${tmpfile//*gcc\/}
  134. old_chost=${old_chost//\/*}
  135. old_gcc_ver=${tmpfile//*\/}
  136. if [[ -z ${old_gcc_ver} || -z ${old_chost} ]]; then
  137. ewarn ""
  138. ewarn "Unable to detect what version of GCC was used to compile"
  139. ewarn "the kernel. Build will continue, but you may experience problems."
  140. elif [[ ${curr_gcc_ver} != ${old_gcc_ver} ]]; then
  141. ewarn ""
  142. ewarn "The version of GCC you are using (${curr_gcc_ver}) does"
  143. ewarn "not match the version of GCC used to compile the"
  144. ewarn "kernel (${old_gcc_ver})."
  145. result=1
  146. elif [[ ${CHOST} != ${old_chost} ]]; then
  147. ewarn ""
  148. ewarn "The current CHOST (${CHOST}) does not match the chost"
  149. ewarn "used when compiling the kernel (${old_chost})."
  150. result=1
  151. fi
  152. if [[ ${result} -gt 0 ]]; then
  153. ewarn ""
  154. ewarn "Build will not continue, because you will experience problems."
  155. ewarn "To fix this either change the version of GCC you wish to use"
  156. ewarn "to match the kernel, or recompile the kernel first."
  157. die "GCC Version Mismatch."
  158. fi
  159. }
  160. # @FUNCTION: use_m
  161. # @RETURN: true or false
  162. # @DESCRIPTION:
  163. # It checks if the kernel version is greater than 2.6.5.
  164. use_m() {
  165. debug-print-function ${FUNCNAME} $*
  166. # if we haven't determined the version yet, we need too.
  167. get_version;
  168. # if the kernel version is greater than 2.6.6 then we should use
  169. # M= instead of SUBDIRS=
  170. [ ${KV_MAJOR} -eq 3 ] && return 0
  171. [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -gt 5 -a ${KV_PATCH} -gt 5 ] && \
  172. return 0 || return 1
  173. }
  174. # @FUNCTION: convert_to_m
  175. # @USAGE: /path/to/the/file
  176. # @DESCRIPTION:
  177. # It converts a file (e.g. a makefile) to use M= instead of SUBDIRS=
  178. convert_to_m() {
  179. debug-print-function ${FUNCNAME} $*
  180. if use_m
  181. then
  182. [ ! -f "${1}" ] && \
  183. die "convert_to_m() requires a filename as an argument"
  184. ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIRS="
  185. sed -i 's:SUBDIRS=:M=:g' "${1}"
  186. eend $?
  187. fi
  188. }
  189. # internal function
  190. #
  191. # FUNCTION: update_depmod
  192. # DESCRIPTION:
  193. # It updates the modules.dep file for the current kernel.
  194. update_depmod() {
  195. debug-print-function ${FUNCNAME} $*
  196. # if we haven't determined the version yet, we need too.
  197. get_version;
  198. ebegin "Updating module dependencies for ${KV_FULL}"
  199. if [ -r "${KV_OUT_DIR}"/System.map ]
  200. then
  201. depmod -ae -F "${KV_OUT_DIR}"/System.map -b "${ROOT}" ${KV_FULL}
  202. eend $?
  203. else
  204. ewarn
  205. ewarn "${KV_OUT_DIR}/System.map not found."
  206. ewarn "You must manually update the kernel module dependencies using depmod."
  207. eend 1
  208. ewarn
  209. fi
  210. }
  211. # internal function
  212. #
  213. # FUNCTION: move_old_moduledb
  214. # DESCRIPTION:
  215. # It updates the location of the database used by the module-rebuild utility.
  216. move_old_moduledb() {
  217. debug-print-function ${FUNCNAME} $*
  218. local OLDDIR="${ROOT}"/usr/share/module-rebuild/
  219. local NEWDIR="${ROOT}"/var/lib/module-rebuild/
  220. if [[ -f "${OLDDIR}"/moduledb ]]; then
  221. [[ ! -d "${NEWDIR}" ]] && mkdir -p "${NEWDIR}"
  222. [[ ! -f "${NEWDIR}"/moduledb ]] && \
  223. mv "${OLDDIR}"/moduledb "${NEWDIR}"/moduledb
  224. rm -f "${OLDDIR}"/*
  225. rmdir "${OLDDIR}"
  226. fi
  227. }
  228. # internal function
  229. #
  230. # FUNCTION: update_moduledb
  231. # DESCRIPTION:
  232. # It adds the package to the /var/lib/module-rebuild/moduledb database used by the module-rebuild utility.
  233. update_moduledb() {
  234. debug-print-function ${FUNCNAME} $*
  235. local MODULEDB_DIR="${ROOT}"/var/lib/module-rebuild/
  236. move_old_moduledb
  237. if [[ ! -f "${MODULEDB_DIR}"/moduledb ]]; then
  238. [[ ! -d "${MODULEDB_DIR}" ]] && mkdir -p "${MODULEDB_DIR}"
  239. touch "${MODULEDB_DIR}"/moduledb
  240. fi
  241. if ! grep -qs ${CATEGORY}/${PN}-${PVR} "${MODULEDB_DIR}"/moduledb ; then
  242. einfo "Adding module to moduledb."
  243. echo "a:1:${CATEGORY}/${PN}-${PVR}" >> "${MODULEDB_DIR}"/moduledb
  244. fi
  245. }
  246. # internal function
  247. #
  248. # FUNCTION: remove_moduledb
  249. # DESCRIPTION:
  250. # It removes the package from the /var/lib/module-rebuild/moduledb database used by
  251. # the module-rebuild utility.
  252. remove_moduledb() {
  253. debug-print-function ${FUNCNAME} $*
  254. local MODULEDB_DIR="${ROOT}"/var/lib/module-rebuild/
  255. move_old_moduledb
  256. if grep -qs ${CATEGORY}/${PN}-${PVR} "${MODULEDB_DIR}"/moduledb ; then
  257. einfo "Removing ${CATEGORY}/${PN}-${PVR} from moduledb."
  258. sed -i -e "/.*${CATEGORY}\/${PN}-${PVR}.*/d" "${MODULEDB_DIR}"/moduledb
  259. fi
  260. }
  261. # @FUNCTION: set_kvobj
  262. # @DESCRIPTION:
  263. # It sets the KV_OBJ variable.
  264. set_kvobj() {
  265. debug-print-function ${FUNCNAME} $*
  266. if kernel_is ge 2 6
  267. then
  268. KV_OBJ="ko"
  269. else
  270. KV_OBJ="o"
  271. fi
  272. # Do we really need to know this?
  273. # Lets silence it.
  274. # einfo "Using KV_OBJ=${KV_OBJ}"
  275. }
  276. get-KERNEL_CC() {
  277. debug-print-function ${FUNCNAME} $*
  278. if [[ -n ${KERNEL_CC} ]] ; then
  279. echo "${KERNEL_CC}"
  280. return
  281. fi
  282. local kernel_cc
  283. if [ -n "${KERNEL_ABI}" ]; then
  284. # In future, an arch might want to define CC_$ABI
  285. #kernel_cc="$(get_abi_CC)"
  286. #[ -z "${kernel_cc}" ] &&
  287. kernel_cc="$(tc-getCC $(ABI=${KERNEL_ABI} get_abi_CHOST))"
  288. else
  289. kernel_cc=$(tc-getCC)
  290. fi
  291. echo "${kernel_cc}"
  292. }
  293. # internal function
  294. #
  295. # FUNCTION:
  296. # USAGE: /path/to/the/modulename_without_extension
  297. # RETURN: A file in /etc/modprobe.d
  298. # DESCRIPTION:
  299. # This function will generate and install the neccessary modprobe.d file from the
  300. # information contained in the modules exported parms.
  301. # (see the variables MODULESD_<modulename>_ENABLED, MODULESD_<modulename>_EXAMPLES,
  302. # MODULESD_<modulename>_ALIASES, MODULESD_<modulename>_ADDITION and MODULESD_<modulename>_DOCS).
  303. #
  304. # At the end the documentation specified with MODULESD_<modulename>_DOCS is installed.
  305. generate_modulesd() {
  306. debug-print-function ${FUNCNAME} $*
  307. [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
  308. local currm_path currm currm_t t myIFS myVAR
  309. local module_docs module_enabled module_aliases \
  310. module_additions module_examples module_modinfo module_opts
  311. for currm_path in ${@}
  312. do
  313. currm=${currm_path//*\/}
  314. currm=$(echo ${currm} | tr '[:lower:]' '[:upper:]')
  315. currm_t=${currm}
  316. while [[ -z ${currm_t//*-*} ]]; do
  317. currm_t=${currm_t/-/_}
  318. done
  319. module_docs="$(eval echo \${MODULESD_${currm_t}_DOCS})"
  320. module_enabled="$(eval echo \${MODULESD_${currm_t}_ENABLED})"
  321. module_aliases="$(eval echo \${#MODULESD_${currm_t}_ALIASES[*]})"
  322. module_additions="$(eval echo \${#MODULESD_${currm_t}_ADDITIONS[*]})"
  323. module_examples="$(eval echo \${#MODULESD_${currm_t}_EXAMPLES[*]})"
  324. [[ ${module_aliases} -eq 0 ]] && unset module_aliases
  325. [[ ${module_additions} -eq 0 ]] && unset module_additions
  326. [[ ${module_examples} -eq 0 ]] && unset module_examples
  327. # If we specify we dont want it, then lets exit, otherwise we assume
  328. # that if its set, we do want it.
  329. [[ ${module_enabled} == no ]] && return 0
  330. # unset any unwanted variables.
  331. for t in ${!module_*}
  332. do
  333. [[ -z ${!t} ]] && unset ${t}
  334. done
  335. [[ -z ${!module_*} ]] && return 0
  336. # OK so now if we have got this far, then we know we want to continue
  337. # and generate the modprobe.d file.
  338. module_modinfo="$(modinfo -p ${currm_path}.${KV_OBJ})"
  339. module_config="${T}/modulesd-${currm}"
  340. ebegin "Preparing file for modprobe.d"
  341. #-----------------------------------------------------------------------
  342. echo "# modprobe.d configuration file for ${currm}" >> "${module_config}"
  343. #-----------------------------------------------------------------------
  344. [[ -n ${module_docs} ]] && \
  345. echo "# For more information please read:" >> "${module_config}"
  346. for t in ${module_docs}
  347. do
  348. echo "# ${t//*\/}" >> "${module_config}"
  349. done
  350. echo >> "${module_config}"
  351. #-----------------------------------------------------------------------
  352. if [[ ${module_aliases} -gt 0 ]]
  353. then
  354. echo "# Internal Aliases - Do not edit" >> "${module_config}"
  355. echo "# ------------------------------" >> "${module_config}"
  356. for((t=0; t<${module_aliases}; t++))
  357. do
  358. echo "alias $(eval echo \${MODULESD_${currm}_ALIASES[$t]})" \
  359. >> "${module_config}"
  360. done
  361. echo '' >> "${module_config}"
  362. fi
  363. #-----------------------------------------------------------------------
  364. if [[ -n ${module_modinfo} ]]
  365. then
  366. echo >> "${module_config}"
  367. echo "# Configurable module parameters" >> "${module_config}"
  368. echo "# ------------------------------" >> "${module_config}"
  369. myIFS="${IFS}"
  370. IFS="$(echo -en "\n\b")"
  371. for t in ${module_modinfo}
  372. do
  373. myVAR="$(echo ${t#*:} | grep -o "[^ ]*[0-9][ =][^ ]*" | tail -1 | grep -o "[0-9]")"
  374. if [[ -n ${myVAR} ]]
  375. then
  376. module_opts="${module_opts} ${t%%:*}:${myVAR}"
  377. fi
  378. echo -e "# ${t%%:*}:\t${t#*:}" >> "${module_config}"
  379. done
  380. IFS="${myIFS}"
  381. echo '' >> "${module_config}"
  382. fi
  383. #-----------------------------------------------------------------------
  384. if [[ $(eval echo \${MODULESD_${currm}_ALIASES[0]}) == guess ]]
  385. then
  386. # So lets do some guesswork eh?
  387. if [[ -n ${module_opts} ]]
  388. then
  389. echo "# For Example..." >> "${module_config}"
  390. echo "# --------------" >> "${module_config}"
  391. for t in ${module_opts}
  392. do
  393. echo "# options ${currm} ${t//:*}=${t//*:}" >> "${module_config}"
  394. done
  395. echo '' >> "${module_config}"
  396. fi
  397. elif [[ ${module_examples} -gt 0 ]]
  398. then
  399. echo "# For Example..." >> "${module_config}"
  400. echo "# --------------" >> "${module_config}"
  401. for((t=0; t<${module_examples}; t++))
  402. do
  403. echo "options $(eval echo \${MODULESD_${currm}_EXAMPLES[$t]})" \
  404. >> "${module_config}"
  405. done
  406. echo '' >> "${module_config}"
  407. fi
  408. #-----------------------------------------------------------------------
  409. if [[ ${module_additions} -gt 0 ]]
  410. then
  411. for((t=0; t<${module_additions}; t++))
  412. do
  413. echo "$(eval echo \${MODULESD_${currm}_ADDITIONS[$t]})" \
  414. >> "${module_config}"
  415. done
  416. echo '' >> "${module_config}"
  417. fi
  418. #-----------------------------------------------------------------------
  419. # then we install it
  420. insinto /etc/modprobe.d
  421. newins "${module_config}" "${currm_path//*\/}.conf"
  422. # and install any documentation we might have.
  423. [[ -n ${module_docs} ]] && dodoc ${module_docs}
  424. done
  425. eend 0
  426. return 0
  427. }
  428. # internal function
  429. #
  430. # FUNCTION: find_module_params
  431. # USAGE: A string "NAME(LIBDIR:SRCDIR:OBJDIR)"
  432. # RETURN: The string "modulename:NAME libdir:LIBDIR srcdir:SRCDIR objdir:OBJDIR"
  433. # DESCRIPTION:
  434. # Analyze the specification NAME(LIBDIR:SRCDIR:OBJDIR) of one module as described in MODULE_NAMES.
  435. find_module_params() {
  436. debug-print-function ${FUNCNAME} $*
  437. local matched_offset=0 matched_opts=0 test="${@}" temp_var result
  438. local i=0 y=0 z=0
  439. for((i=0; i<=${#test}; i++))
  440. do
  441. case ${test:${i}:1} in
  442. \() matched_offset[0]=${i};;
  443. \:) matched_opts=$((${matched_opts} + 1));
  444. matched_offset[${matched_opts}]="${i}";;
  445. \)) matched_opts=$((${matched_opts} + 1));
  446. matched_offset[${matched_opts}]="${i}";;
  447. esac
  448. done
  449. for((i=0; i<=${matched_opts}; i++))
  450. do
  451. # i = offset were working on
  452. # y = last offset
  453. # z = current offset - last offset
  454. # temp_var = temporary name
  455. case ${i} in
  456. 0) tempvar=${test:0:${matched_offset[0]}};;
  457. *) y=$((${matched_offset[$((${i} - 1))]} + 1))
  458. z=$((${matched_offset[${i}]} - ${matched_offset[$((${i} - 1))]}));
  459. z=$((${z} - 1))
  460. tempvar=${test:${y}:${z}};;
  461. esac
  462. case ${i} in
  463. 0) result="${result} modulename:${tempvar}";;
  464. 1) result="${result} libdir:${tempvar}";;
  465. 2) result="${result} srcdir:${tempvar}";;
  466. 3) result="${result} objdir:${tempvar}";;
  467. esac
  468. done
  469. echo ${result}
  470. }
  471. # default ebuild functions
  472. # --------------------------------
  473. # @FUNCTION: linux-mod_pkg_setup
  474. # @DESCRIPTION:
  475. # It checks the CONFIG_CHECK options (see linux-info.eclass(5)), verifies that the kernel is
  476. # configured, verifies that the sources are prepared, verifies that the modules support is builtin
  477. # in the kernel and sets the object extension KV_OBJ.
  478. linux-mod_pkg_setup() {
  479. debug-print-function ${FUNCNAME} $*
  480. [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
  481. local is_bin="${MERGE_TYPE}"
  482. # If we are installing a binpkg, take a different path.
  483. # use MERGE_TYPE if available (eapi>=4); else use non-PMS EMERGE_FROM (eapi<4)
  484. if has ${EAPI} 0 1 2 3; then
  485. is_bin=${EMERGE_FROM}
  486. fi
  487. if [[ ${is_bin} == binary ]]; then
  488. linux-mod_pkg_setup_binary
  489. return
  490. fi
  491. # External modules use kernel symbols (bug #591832)
  492. CONFIG_CHECK+=" !TRIM_UNUSED_KSYMS"
  493. linux-info_pkg_setup;
  494. require_configured_kernel
  495. check_kernel_built;
  496. strip_modulenames;
  497. [[ -n ${MODULE_NAMES} ]] && check_modules_supported
  498. set_kvobj;
  499. # Commented out with permission from johnm until a fixed version for arches
  500. # who intentionally use different kernel and userland compilers can be
  501. # introduced - Jason Wever <weeve@gentoo.org>, 23 Oct 2005
  502. #check_vermagic;
  503. }
  504. # @FUNCTION: linux-mod_pkg_setup_binary
  505. # @DESCRIPTION:
  506. # Perform all kernel option checks non-fatally, as the .config and
  507. # /proc/config.gz might not be present. Do not do anything that requires kernel
  508. # sources.
  509. linux-mod_pkg_setup_binary() {
  510. debug-print-function ${FUNCNAME} $*
  511. local new_CONFIG_CHECK
  512. # ~ needs always to be quoted, else bash expands it.
  513. for config in $CONFIG_CHECK ; do
  514. optional='~'
  515. [[ ${config:0:1} == "~" ]] && optional=''
  516. new_CONFIG_CHECK="${new_CONFIG_CHECK} ${optional}${config}"
  517. done
  518. CONFIG_CHECK="${new_CONFIG_CHECK}"
  519. linux-info_pkg_setup;
  520. }
  521. strip_modulenames() {
  522. debug-print-function ${FUNCNAME} $*
  523. local i
  524. for i in ${MODULE_IGNORE}; do
  525. MODULE_NAMES=${MODULE_NAMES//${i}(*}
  526. done
  527. }
  528. # @FUNCTION: linux-mod_src_compile
  529. # @DESCRIPTION:
  530. # It compiles all the modules specified in MODULE_NAMES. For each module the econf command is
  531. # executed only if ECONF_PARAMS is defined, the name of the target is specified by BUILD_TARGETS
  532. # while the options are in BUILD_PARAMS (all the modules share these variables). The compilation
  533. # happens inside ${srcdir}.
  534. #
  535. # Look at the description of these variables for more details.
  536. linux-mod_src_compile() {
  537. debug-print-function ${FUNCNAME} $*
  538. [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
  539. local modulename libdir srcdir objdir i n myABI="${ABI}"
  540. set_arch_to_kernel
  541. ABI="${KERNEL_ABI}"
  542. BUILD_TARGETS=${BUILD_TARGETS:-clean module}
  543. strip_modulenames;
  544. cd "${S}"
  545. touch Module.symvers
  546. for i in ${MODULE_NAMES}
  547. do
  548. unset libdir srcdir objdir
  549. for n in $(find_module_params ${i})
  550. do
  551. eval ${n/:*}=${n/*:/}
  552. done
  553. libdir=${libdir:-misc}
  554. srcdir=${srcdir:-${S}}
  555. objdir=${objdir:-${srcdir}}
  556. if [ ! -f "${srcdir}/.built" ];
  557. then
  558. cd "${srcdir}"
  559. ln -s "${S}"/Module.symvers Module.symvers
  560. einfo "Preparing ${modulename} module"
  561. if [[ -n ${ECONF_PARAMS} ]]
  562. then
  563. econf ${ECONF_PARAMS} || \
  564. die "Unable to run econf ${ECONF_PARAMS}"
  565. fi
  566. # This looks messy, but it is needed to handle multiple variables
  567. # being passed in the BUILD_* stuff where the variables also have
  568. # spaces that must be preserved. If don't do this, then the stuff
  569. # inside the variables gets used as targets for Make, which then
  570. # fails.
  571. eval "emake HOSTCC=\"$(tc-getBUILD_CC)\" \
  572. CROSS_COMPILE=${CHOST}- \
  573. LDFLAGS=\"$(get_abi_LDFLAGS)\" \
  574. ${BUILD_FIXES} \
  575. ${BUILD_PARAMS} \
  576. ${BUILD_TARGETS} " \
  577. || die "Unable to emake HOSTCC="$(tc-getBUILD_CC)" CROSS_COMPILE=${CHOST}- LDFLAGS="$(get_abi_LDFLAGS)" ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS}"
  578. cd "${OLDPWD}"
  579. touch "${srcdir}"/.built
  580. fi
  581. done
  582. set_arch_to_portage
  583. ABI="${myABI}"
  584. }
  585. # @FUNCTION: linux-mod_src_install
  586. # @DESCRIPTION:
  587. # It install the modules specified in MODULES_NAME. The modules should be inside the ${objdir}
  588. # directory and they are installed inside /lib/modules/${KV_FULL}/${libdir}.
  589. #
  590. # The modprobe.d configuration file is automatically generated if the
  591. # MODULESD_<modulename>_* variables are defined. The only way to stop this process is by
  592. # setting MODULESD_<modulename>_ENABLED=no. At the end the documentation specified via
  593. # MODULESD_<modulename>_DOCS is also installed.
  594. #
  595. # Look at the description of these variables for more details.
  596. linux-mod_src_install() {
  597. debug-print-function ${FUNCNAME} $*
  598. [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
  599. local modulename libdir srcdir objdir i n
  600. strip_modulenames;
  601. for i in ${MODULE_NAMES}
  602. do
  603. unset libdir srcdir objdir
  604. for n in $(find_module_params ${i})
  605. do
  606. eval ${n/:*}=${n/*:/}
  607. done
  608. libdir=${libdir:-misc}
  609. srcdir=${srcdir:-${S}}
  610. objdir=${objdir:-${srcdir}}
  611. einfo "Installing ${modulename} module"
  612. cd "${objdir}" || die "${objdir} does not exist"
  613. insinto /lib/modules/${KV_FULL}/${libdir}
  614. doins ${modulename}.${KV_OBJ} || die "doins ${modulename}.${KV_OBJ} failed"
  615. cd "${OLDPWD}"
  616. generate_modulesd "${objdir}/${modulename}"
  617. done
  618. }
  619. # @FUNCTION: linux-mod_pkg_preinst
  620. # @DESCRIPTION:
  621. # It checks what to do after having merged the package.
  622. linux-mod_pkg_preinst() {
  623. debug-print-function ${FUNCNAME} $*
  624. [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
  625. [ -d "${D}lib/modules" ] && UPDATE_DEPMOD=true || UPDATE_DEPMOD=false
  626. [ -d "${D}lib/modules" ] && UPDATE_MODULEDB=true || UPDATE_MODULEDB=false
  627. }
  628. # @FUNCTION: linux-mod_pkg_postinst
  629. # @DESCRIPTION:
  630. # It executes /sbin/depmod and adds the package to the /var/lib/module-rebuild/moduledb
  631. # database (if ${D}/lib/modules is created)"
  632. linux-mod_pkg_postinst() {
  633. debug-print-function ${FUNCNAME} $*
  634. [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
  635. ${UPDATE_DEPMOD} && update_depmod;
  636. ${UPDATE_MODULEDB} && update_moduledb;
  637. }
  638. # @FUNCTION: linux-mod_pkg_postrm
  639. # @DESCRIPTION:
  640. # It removes the package from the /var/lib/module-rebuild/moduledb database but it doens't
  641. # call /sbin/depmod because the modules are still installed.
  642. linux-mod_pkg_postrm() {
  643. debug-print-function ${FUNCNAME} $*
  644. [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
  645. remove_moduledb;
  646. }