mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

543 lines
15 KiB

  1. #!/bin/bash
  2. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  3. #
  4. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  5. # Please add additional copyright information _after_ the line containing
  6. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  7. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  8. #
  9. # ROCK Linux: rock-src/package/base/linux/linux.conf
  10. # ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; either version 2 of the License, or
  15. # (at your option) any later version. A copy of the GNU General Public
  16. # License can be found at Documentation/COPYING.
  17. #
  18. # Many people helped and are helping developing ROCK Linux. Please
  19. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  20. # file for details.
  21. #
  22. # --- ROCK-COPYRIGHT-NOTE-END ---
  23. pkg_linux_mode=image
  24. pkg_linux_cross=""
  25. # do not replicate docs
  26. createdocs=0
  27. forcefpic=0
  28. prefix=usr
  29. set_confopt
  30. case "$xpkg-" in
  31. *-source-*)
  32. unset splitdesc_dev
  33. pkg_linux_mode=source ;;
  34. *-src-*)
  35. abort "If you want to build a source package, use '${xpkg//src/source}'.";;
  36. *-headers-cross-*)
  37. pkg_linux_mode=headers
  38. pkg_linux_cross="${xpkg#*-cross-}"
  39. echo_status "Preparing to build a cross-binutils package for $pkg_binutils_cross."
  40. prefix="$prefix/${pkg_linux_cross}-unknown-linux-gnu"
  41. set_confopt
  42. ;;
  43. *-headers-*)
  44. pkg_linux_mode=headers ;;
  45. esac
  46. echo_status "Preparing to build a linux kernel $pkg_linux_mode package."
  47. treever=${xpkg/linux/}
  48. treever=${treever/-*/}
  49. vanilla_ver="$ver"
  50. # vanilla_ver=$( echo ${vanilla_ver} | cut -d. -f-3 )
  51. srctar="linux-${vanilla_ver}.tar.bz2"
  52. lx_extraversion=""
  53. lx_kernelrelease=""
  54. if [ -z "$pkg_linux_cross" ]
  55. then
  56. lx_cpu=$( echo "$arch_machine" | \
  57. sed -e s/x86$/i386/ \
  58. -e s/hppa/parisc/ -e s/i.86/i386/ \
  59. -e s/sun4u/sparc64/ -e s/arm.*/arm/ \
  60. -e s/sa110/arm/ -e s/s390x/s390/ \
  61. -e s/parisc64/parisc/ )
  62. if [ $arch = sparc -a "$ROCKCFG_SPARC_64BIT_KERNEL" = 1 ] ; then
  63. lx_cpu=sparc64 ;
  64. KCC=sparc64-unknown-linux-gnu-gcc
  65. archprefix=sparc64-unknown-linux-gnu-
  66. fi
  67. else
  68. lx_cpu=$( echo "$pkg_linux_cross" | \
  69. sed -e s/x86$/i386/ \
  70. -e s/hppa/parisc/ -e s/i.86/i386/ \
  71. -e s/sun4u/sparc64/ -e s/arm.*/arm/ \
  72. -e s/sa110/arm/ -e s/s390x/s390/ \
  73. -e s/mips.*/mips/ -e s/parisc64/parisc/ )
  74. fi
  75. MAKE="$MAKE ARCH=$lx_cpu CROSS_COMPILE=$archprefix KCC=$KCC"
  76. # correct the abolute path for patchfiles supplied in the .desc file
  77. for x in $patchfiles ; do
  78. if [ ! -e "$x" -a -n "${x##*/*}" ] ; then
  79. var_remove patchfiles " " "$x"
  80. var_append patchfiles " " "$archdir/$x"
  81. fi
  82. done
  83. # add kernel specific patchfiles
  84. for x in $confdir/linux$treever/*.patch; do
  85. var_append patchfiles " " "$x"
  86. done
  87. # add hppa patch if needed
  88. #if [[ "$arch" == hppa && "$vanillaver" == 2.6.* ]]; then
  89. # var_insert patchfiles " " "$archdir/patch-2.6.*-pa*.bz2"
  90. #fi
  91. auto_config ()
  92. {
  93. case "$arch" in
  94. powerpc)
  95. defconfig="configs/common_defconfig"
  96. ;;
  97. *)
  98. defconfig="defconfig"
  99. ;;
  100. esac
  101. for x in $base/architecture/$arch/kernel{$treever,}.conf{.sh,.m4,} \
  102. arch/$lx_cpu/$defconfig
  103. do
  104. if [ -f $x ] ; then
  105. echo " using: $x"
  106. case "${x##*.}" in
  107. m4) m4 -I $base/architecture/$arch \
  108. -I $base/architecture/share \
  109. $x > .config ;;
  110. sh) . $x > .config ;;
  111. *) cp $x .config ;;
  112. esac
  113. break
  114. fi
  115. done
  116. echo " merging (system default): 'arch/$lx_cpu/$defconfig'"
  117. grep '^CONF.*=y' arch/$lx_cpu/$defconfig | cut -f1 -d= | \
  118. while read tag ; do egrep -q "(^| )$tag[= ]" .config || echo "$tag=y"
  119. done >> .config ; cp .config .config.1
  120. # all modules needs to be first so modules can be disabled by i.e.
  121. # the targets later
  122. echo "Enabling all modules ..."
  123. yes '' | eval $MAKE no2modconfig > /dev/null ; cp .config .config.2
  124. for x in $base/target/$target/kernel{$treever,}.conf.sh ; do
  125. if [ -f $x ] ; then
  126. confscripts="$x $confscripts"
  127. break
  128. fi
  129. done
  130. for x in $confscripts ; do
  131. echo " running: $x"
  132. . $x .config
  133. done
  134. cp .config .config.3
  135. # merge various text/plain config files
  136. for x in $base/config/$config/linux.cfg \
  137. $base/target/$target/kernel{,$treever}.conf ; do
  138. if [ -f $x ] ; then
  139. echo " merging: '$x'"
  140. tag="$(sed '/CONFIG_/ ! d; s,.*CONFIG_\([^ =]*\).*,\1,' \
  141. $x | tr '\n' '|')"
  142. egrep -v "\bCONFIG_($tag)\b" < .config > .config.4
  143. sed 's,\(CONFIG_.*\)=n,# \1 is not set,' \
  144. $x >> .config.4
  145. cp .config.4 .config
  146. fi
  147. done
  148. # create a valid .config
  149. yes '' | eval $MAKE oldconfig > /dev/null ; cp .config .config.5
  150. # last disable broken stuff
  151. rm -f /tmp/$$.sed
  152. list="CONFIG_THIS_DOES_NOT_EXIST"
  153. for x in $pkg_linux_brokenfiles ; do
  154. if [ -f "$x" ] ; then
  155. echo "Disable broken file: $x"
  156. list="$list `tr ' ' '\t' < $x | cut -f1 | grep '^CONFIG_'`"
  157. fi
  158. done
  159. for x in $list ; do
  160. echo "s,^$x=.\$,# $x is not set,;" >> /tmp/$$.sed
  161. done
  162. sed -f /tmp/$$.sed < .config > .config.6
  163. cp .config.6 .config ; rm -f /tmp/$$.sed
  164. # create a valid .config (dependencies might need to be disabled)
  165. yes '' | eval $MAKE oldconfig > /dev/null
  166. # save final config
  167. cp .config .config_modules
  168. echo "Creating config without modules ...."
  169. sed "s,\(CONFIG_.*\)=m,# \1 is not set," .config > .config_new
  170. mv .config_new .config
  171. # create a valid .config (dependencies might need to be disabled)
  172. yes '' | eval $MAKE oldconfig > /dev/null
  173. mv .config .config_nomods
  174. # which .config to use?
  175. if [ "$ROCKCFG_PKG_LINUX_CONFIG_STYLE" = "modules" ] ; then
  176. cp .config_modules .config
  177. else
  178. cp .config_nomods .config
  179. fi
  180. }
  181. lx_grabextraversion () {
  182. local ev
  183. ev=$( sed -n -e 's,^[ \t]*EXTRAVERSION[ \t]*=[ \t]*\([^ \t]*\),\1,p' Makefile | tail -n 1 )
  184. if [ "$ev" ]; then
  185. lx_extraversion="${lx_extraversion}$ev"
  186. # keep intact but commented since the second EXTRAVERSION
  187. # definition, and clean the first.
  188. sed -e 's,^\([ \t]*EXTRAVERSION[ \t]*=.*\),#\1,g' \
  189. -e 's,^#\(EXTRAVERSION =\).*,\1,' \
  190. Makefile > Makefile.new
  191. mv Makefile.new Makefile
  192. fi
  193. }
  194. lx_injectextraversion () {
  195. lx_extraversion="${lx_extraversion}-rock"
  196. # inject final EXTRAVERSION into Makefile
  197. sed -i -e "s,^\([ \t]*EXTRAVERSION[ \t]*\)=.*,\1= ${lx_extraversion},g" Makefile
  198. # update version.h - we only do this, because some other freaky
  199. # projects like rsbac change EXTRAVERSION in other Makefiles ...
  200. rerun=""; eval $MAKE include/linux/version.h | grep -q "is up to date" && rerun=1
  201. if [ "$rerun" ] ; then
  202. echo "WARNING: Your system's timer resolution is too low ..."
  203. sleep 1 ; touch Makefile
  204. eval $MAKE include/linux/version.h
  205. fi
  206. }
  207. lx_config ()
  208. {
  209. echo "Generic linux source patching and configuration ..."
  210. # grab extraversion from vanilla
  211. lx_grabextraversion
  212. hook_eval prepatch
  213. apply_patchfiles "lx_grabextraversion"
  214. hook_eval postpatch
  215. echo "Redefining some VERSION flags ..."
  216. lx_injectextraversion
  217. if [[ $treever = 24* ]] ; then
  218. echo "Create symlinks and a few headers for <$lx_cpu> ... "
  219. eval $MAKE symlinks
  220. cp $confdir/autoconf.h include/linux/
  221. touch include/linux/modversions.h
  222. fi
  223. if [ "$ROCKCFG_PKG_LINUX_CONFIG_STYLE" = none ] ; then
  224. echo "Using \$base/config/\$config/linux.cfg."
  225. echo "Since automatic generation is disabled ..."
  226. cp -v $base/config/$config/linux.cfg .config
  227. else
  228. echo "Automatically creating default configuration ...."
  229. auto_config
  230. fi
  231. echo "... configuration finished!"
  232. if [[ $treever != 24* ]] ; then
  233. echo "Create symlinks and a few headers for <$lx_cpu> ... "
  234. eval $MAKE include/asm
  235. yes '' | eval $MAKE oldconfig > /dev/null
  236. fi
  237. # get kernel_release
  238. if [ $treever == 24 ] ; then
  239. lx_kernelrelease="$( echo -e "#include <linux/version.h>\nUTS_RELEASE" \
  240. > conftest.c && \
  241. gcc -E -I./include conftest.c | tail -n 1 \
  242. | cut -d '"' -f 2 && rm -f conftest.c )"
  243. else
  244. make include/config/kernel.release
  245. lx_kernelrelease="$( < include/config/kernel.release )"
  246. fi
  247. lx_cleanup
  248. echo "Generic linux source configuration finished."
  249. }
  250. pkg_linux_brokenfiles="$base/architecture/$arch/kernel-disable.lst \
  251. $base/architecture/$arch/kernel$treever-disable.lst \
  252. $confdir/linux$treever/disable-broken.lst $pkg_linux_brokenfiles"
  253. lx_source() {
  254. echo "Extracting the Linux Kernel Sources [$vanilla_ver] ... "
  255. tar $taropt $archdir/$srctar
  256. cd linux-$vanilla_ver
  257. # if [ -e $archdir/patch-${ver}.bz2 ] ; then
  258. # echo "Patching up to $ver ..."
  259. # bzcat $archdir/patch-${ver}.bz2 | patch $patchopt
  260. # fi
  261. echo "Correcting ownership and permissions ..."
  262. chown -R 0:0 . ; chmod -R u=rwX,go=rX .
  263. }
  264. lx_cleanup() {
  265. echo "Clean up the *.orig and *~ files ... "
  266. find -name '*.orig' -o -name '*~' | xargs rm -f
  267. rm -f .config.old .config.[1-9]
  268. }
  269. main_lx_src() {
  270. lx_source
  271. lx_config
  272. echo "Copying to $root/usr/src/linux-${lx_kernelrelease} ..."
  273. cd $root/usr/src
  274. rm -rf linux-${lx_kernelrelease}
  275. cp -r $builddir/linux-$vanilla_ver linux-${lx_kernelrelease}
  276. if [ "${xpkg%-source}" = "$ROCKCFG_PKG_LINUX_DEFAULT" ] ; then
  277. rm -f linux
  278. ln -svf linux-${lx_kernelrelease} $root/usr/src/linux
  279. fi
  280. echo "Copying kernel patches ... "
  281. rm -rf linux$treever-patches ; mkdir -p linux$treever-patches
  282. { echo "This directory contains all the stuff used by ROCK Linux to"
  283. echo "build the Kernel (in addition to the official Kernel Sources)."
  284. } > linux$treever-patches/README
  285. cp -v $patchfiles linux$treever-patches/
  286. cd linux-${lx_kernelrelease}
  287. if [ "$ROCKCFG_PKG_LINUX_CONFIG_STYLE" = none ] ; then
  288. # create a valid .config (new settings may be available etc.)
  289. yes '' | eval $MAKE oldconfig > /dev/null
  290. else
  291. cp -v .config_nomods ../linux$treever-patches/config_nomods.txt
  292. cp -v .config_modules ../linux$treever-patches/config_modules.txt
  293. fi
  294. # can fail in stage 0-2 ...
  295. if [ $stagelevel -ge 3 ] && [[ $treever = 24* ]] ; then
  296. echo "Creating dependencies (e.g. for versioned symbols) ..."
  297. eval $MAKE dep-files
  298. fi
  299. if [ $stagelevel -ge 3 ] && [[ $treever = 26* ]] ; then
  300. echo "Creating scripts/* because external modules need it ..."
  301. eval $MAKE scripts/
  302. fi
  303. lx_cleanup
  304. }
  305. main_lx() {
  306. lx_source
  307. lx_config
  308. # we need to rerun the oldconfig since the used .config
  309. # might not match the one used in the last oldconfig run
  310. # (e.g. the nomods is run last - and normally the module
  311. # one is used)
  312. yes '' | eval $MAKE oldconfig > /dev/null
  313. if [[ $treever = 24* ]] ; then
  314. echo "Creating dependencies ..."
  315. eval $MAKE -j 1 dep
  316. fi
  317. echo "Cleanup kernel ..."
  318. eval $MAKE -j 1 clean > /dev/null
  319. echo "Building the kernel ..."
  320. case "$lx_cpu" in
  321. i386|x86_64)
  322. eval $MAKE bzImage
  323. cp -vf arch/$lx_cpu/boot/bzImage $root/boot/vmlinuz_${lx_kernelrelease}
  324. if [ "$xpkg" = "$ROCKCFG_PKG_LINUX_DEFAULT" ]; then
  325. ln -svf vmlinuz_${lx_kernelrelease} $root/boot/vmlinuz
  326. fi
  327. ;;
  328. alpha)
  329. eval $MAKE vmlinux
  330. gzip < vmlinux > $root/boot/vmlinux_${lx_kernelrelease}.gz
  331. if [ "$xpkg" = "$ROCKCFG_PKG_LINUX_DEFAULT" ]; then
  332. ln -svf vmlinuz_${lx_kernelrelease}.gz $root/boot/vmlinuz.gz
  333. fi
  334. ;;
  335. arm)
  336. eval $MAKE zImage
  337. cp -vf arch/arm/boot/zImage $root/boot/zImage_${lx_kernelrelease}
  338. if [ "$xpkg" = "$ROCKCFG_PKG_LINUX_DEFAULT" ]; then
  339. ln -svf zImage_${lx_kernelrelease} $root/boot/zImage
  340. fi
  341. ;;
  342. mips)
  343. eval $MAKE vmlinux
  344. $BUILDCC arch/mips/boot/elf2ecoff.c -o elf2ecoff
  345. ./elf2ecoff vmlinux vmlinux.ecoff
  346. cp -vf vmlinux.ecoff $root/boot/vmlinux_${lx_kernelrelease}.ecoff
  347. if [ "$xpkg" = "$ROCKCFG_PKG_LINUX_DEFAULT" ]; then
  348. ln -svf vmlinux_${lx_kernelrelease}.ecoff $root/boot/vmlinux.ecoff
  349. fi
  350. ;;
  351. ppc)
  352. eval $MAKE vmlinux
  353. cp -vf vmlinux $root/boot/vmlinux_${lx_kernelrelease}
  354. if [ "$xpkg" = "$ROCKCFG_PKG_LINUX_DEFAULT" ]; then
  355. ln -svf vmlinux_${lx_kernelrelease} $root/boot/vmlinux
  356. fi
  357. eval $MAKE zImage
  358. for x in arch/ppc/boot/images/zImage.* ; do
  359. y=$( echo $x | sed 's,.*/zImage\.,,'; )
  360. cp -v $x $root/boot/zImage_${lx_kernelrelease}.$y
  361. if [ "$xpkg" = "$ROCKCFG_PKG_LINUX_DEFAULT" ]; then
  362. ln -svf zImage_${lx_kernelrelease}.$y $root/boot/zImage.$y
  363. fi
  364. done
  365. ;;
  366. sparc)
  367. # sparc doesn't seem to support gzipped kernel images
  368. if [ "$treever" = 24 ] ; then
  369. eval $MAKE vmlinux
  370. cp -a vmlinux $root/boot/vmlinux32_${lx_kernelrelease}
  371. if [ "$xpkg" = "$ROCKCFG_PKG_LINUX_DEFAULT" ]; then
  372. ln -svf vmlinux32_${lx_kernelrelease} $root/boot/vmlinux32
  373. fi
  374. else
  375. eval $MAKE image
  376. cp -a arch/sparc/boot/image $root/boot/image_${lx_kernelrelease}
  377. if [ "$xpkg" = "$ROCKCFG_PKG_LINUX_DEFAULT" ]; then
  378. ln -svf image_${lx_kernelrelease} $root/boot/image
  379. fi
  380. fi
  381. ;;
  382. sparc64)
  383. eval $MAKE vmlinux
  384. gzip -9 < vmlinux > $root/boot/vmlinux64_${lx_kernelrelease}.gz
  385. if [ "$xpkg" = "$ROCKCFG_PKG_LINUX_DEFAULT" ]; then
  386. ln -svf vmlinux64_${lx_kernelrelease}.gz $root/boot/vmlinux64.gz
  387. fi
  388. ;;
  389. um)
  390. eval $MAKE linux
  391. cp -vf linux $root/boot/linux_${lx_kernelrelease}
  392. if [ "$xpkg" = "$ROCKCFG_PKG_LINUX_DEFAULT" ]; then
  393. ln -svf linux_${lx_kernelrelease} $root/boot/linux
  394. fi
  395. ;;
  396. *)
  397. eval $MAKE vmlinux
  398. cp -vf vmlinux $root/boot/vmlinux_${lx_kernelrelease}
  399. if [ "$xpkg" = "$ROCKCFG_PKG_LINUX_DEFAULT" ]; then
  400. ln -svf vmlinux_${lx_kernelrelease} $root/boot/vmlinux
  401. fi
  402. ;;
  403. esac
  404. cp -vf .config $root/boot/kconfig_${lx_kernelrelease}
  405. cp -vf System.map $root/boot/System.map-${lx_kernelrelease}
  406. if [ "$xpkg" = "$ROCKCFG_PKG_LINUX_DEFAULT" ]; then
  407. ln -svf System.map-${lx_kernelrelease} $root/boot/System.map
  408. fi
  409. # only build modules if enabled in the kernel config,
  410. # otherwise a build error will occur
  411. if [ "`egrep "^CONFIG_MODULES=[ym]" .config`" ] ; then
  412. echo "Building the modules ..."
  413. eval $MAKE modules
  414. echo "Installing the modules ..."
  415. if [ $stagelevel -le 2 ] ; then
  416. eval $MAKE modules_install \
  417. INSTALL_MOD_PATH=$root DEPMOD=/bin/true
  418. else
  419. eval $MAKE modules_install DEPMOD=/bin/true
  420. fi
  421. echo "Running 'depmod -a -F ${root}/boot/System.map -b ${root:-/} ${lx_kernelrelease}' .."
  422. depmod -a -F ${root}/boot/System.map-${lx_kernelrelease} \
  423. -b ${root:-/} ${lx_kernelrelease}
  424. for x in ${root}/lib/modules/${lx_kernelrelease}/modules.*
  425. do [ -f $x ] && add_flist $x; done
  426. else
  427. echo "No module support configured for this kernel ..."
  428. mkdir -p $root/lib/modules/${lx_kernelrelease}
  429. fi
  430. # fix /lib/modules/${ver}/{build,source} symlinks
  431. rm -f $root/lib/modules/${lx_kernelrelease}/build
  432. rm -f $root/lib/modules/${lx_kernelrelease}/source
  433. ln -sf ../../../usr/src/linux-${lx_kernelrelease} \
  434. $root/lib/modules/${lx_kernelrelease}/build
  435. ln -sf ../../../usr/src/linux-${lx_kernelrelease} \
  436. $root/lib/modules/${lx_kernelrelease}/source
  437. # just create a symlink to the default initrd image here; the file
  438. # pointed to will be created by the rockinitrd postinstall script
  439. if [ "$xpkg" = "$ROCKCFG_PKG_LINUX_DEFAULT" ]; then
  440. ln -svf initrd-${lx_kernelrelease}.img $root/boot/initrd.img
  441. fi
  442. }
  443. main_lx_headers() {
  444. lx_source
  445. $MAKE mrproper
  446. $MAKE headers_check
  447. $MAKE INSTALL_HDR_PATH=dest headers_install
  448. for x in $confdir/linux26-hdrs/*.patch; do
  449. [ -f $x ] || continue
  450. echo "Applying linux userspace headers patch $x.."
  451. ( cd dest/include && patch -p1 --no-backup-if-mismatch < $x; )
  452. done
  453. mkdir -p $CLFS/$prefix/include
  454. rm -rf dest/include/scsi
  455. cp -rv dest/include/* $CLFS/$prefix/include
  456. }
  457. autoextract=0
  458. case "$pkg_linux_mode" in
  459. source)
  460. createdocs=0
  461. custmain="main_lx_src"
  462. ;;
  463. image)
  464. custmain="main_lx"
  465. ;;
  466. headers)
  467. custmain="main_lx_headers"
  468. ;;
  469. esac
  470. # ignore pseudo-deps to other modules
  471. var_append flistrfilter "|" ".*lib/modules/.*/.*"