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.

504 lines
15 KiB

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