build.sh 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. #!/bin/sh
  2. # originally by Iguleder
  3. # hacked to DEATH by 01micko
  4. # see /usr/share/doc/legal NO WARRANTY, NO resposibility accepted
  5. CWD=`pwd`
  6. if [ "$1" = "clean" ];then
  7. echo -en "\033[1;35m""WARNING" #purple?
  8. echo -en "\033[0m" #reset
  9. echo ": This will delete all builds and sources but wont touch configs."
  10. echo "Hit CTRL+C and save your stuff manually if you don't want to clean."
  11. echo "Hit ENTER to clean"
  12. read clean
  13. echo "Please wait..."
  14. rm -rf ./{dist,aufs*,kernel*,build.log*}
  15. echo "Cleaning complete"
  16. exit 0
  17. fi
  18. if [ -d ./dist ];then
  19. echo "This is not a clean kit. Hit ENTER to continue"
  20. echo "or CTRL+C to quit and run './build.sh clean'"
  21. read notcleango
  22. fi
  23. # read config
  24. [ -f ./build.conf ] && . ./build.conf
  25. package_name_suffix=$package_name_suffix
  26. custom_suffix=$custom_suffix
  27. kernel_version=$kernel_version
  28. kernel_mirror=$kernel_mirror
  29. # depcheck
  30. echo "Dependency check..."
  31. if git --version &>/dev/null
  32. then echo -e "\033[1;32m""git is installed" #green
  33. else echo -e "\033[1;31m""git is not installed""\033[0m" && exit #red
  34. fi
  35. if gcc --version &>/dev/null
  36. then echo -e "\033[1;32m""gcc is installed"
  37. else
  38. echo -e "\033[1;31m""gcc is not installed""\033[0m" && exit
  39. fi
  40. MKSQ="$(which mksquashfs)"
  41. if [ "$MKSQ" ]
  42. then
  43. echo -e "\033[1;32m""mksquashfs is installed"
  44. else #yellow
  45. echo -e "\033[1;30m""mksquashfs is not installed but you can continue"
  46. fi
  47. echo -e "\033[0m" #reset to original
  48. # .configs
  49. [ -f /tmp/kernel_configs ] && rm -f /tmp/kernel_configs
  50. CONFIGS=$(ls ./configs_extra)
  51. # list
  52. echo "Choose a number of the config you want to try"
  53. NUM=1
  54. for C in $CONFIGS
  55. do echo "${NUM}. $C" >> /tmp/kernel_configs
  56. NUM=$(($NUM + 1))
  57. done
  58. echo "z. Custom DOTconfig" >> /tmp/kernel_configs
  59. echo "d. Default DOTconfig" >> /tmp/kernel_configs
  60. cat /tmp/kernel_configs
  61. echo -n "Enter choice: "
  62. read Chosen
  63. if [ ! $Chosen ];then
  64. echo -e "\033[1;31m""ERROR: you didn't choose, start again!""\033[0m" \
  65. && exit
  66. else
  67. Choice=$(grep ^$Chosen /tmp/kernel_configs|cut -d ' ' -f2)
  68. [ ! $Choice ] && \
  69. echo -e "\033[1;31m""ERROR: your choice is not sane ..quiting""\033[0m" \
  70. && exit
  71. echo -e "You chose $Choice. If this is ok hit ENTER, \
  72. \nif not hit CTRL|C to quit"
  73. read oknow
  74. if [[ "$Choice" = "Default" || "$Choice" = "Custom" ]];then
  75. echo $Choice
  76. else
  77. cp -af configs_extra/$Choice DOTconfig
  78. fi
  79. fi
  80. [ ! -f DOTconfig ] && echo -e \
  81. "\033[1;31m""ERROR: No DOTconfig found ..quiting""\033[0m" \
  82. && exit
  83. # the aufs major version
  84. #aufs_version=${kernel_version%.*.*} #
  85. aufs_version=${kernel_version%%.*}
  86. # fail-safe switch in case someone clicks the script in ROX (real story! not
  87. # fun at all!!!!) :p
  88. read -p "Press ENTER to begin" dummy
  89. # get the major version (2.6.32 in the case of 2.6.32.40)
  90. kernel_major_version=$kernel_version #blah, hack for 3.x
  91. # get the kernel branch (32 in the case of 2.6.32.40; needed to download Aufs)
  92. kernel_branch=`echo $kernel_major_version | cut -f 2 -d .` #3.x kernels
  93. # get the minor version (40 in the case of 2.6.32.40)
  94. #case $kernel_version in
  95. #*.*.*.*) kernel_minor_version=`echo $kernel_version | cut -f 4 -d .` ;;
  96. #esac
  97. # old 2 series info
  98. # the package name suffix (-40 in the case of 2.6.32.40); Woof assumes the
  99. # package version is identical to the kernel version and uses paths that
  100. # contain the package version, so use $kernel_major version as the version and
  101. # "-$kernel_minor_version" as the suffix
  102. #case "$kernel_minor_version" in
  103. #*) package_name_suffix="-$kernel_minor_version";;
  104. #esac
  105. # create directories for the results
  106. [ ! -d dist/sources/vanilla ] && mkdir -p dist/sources/{patches,vanilla}
  107. # get today's date
  108. today=`date +%d%m%y`
  109. # delete the previous log
  110. [ -f build.log ] && rm -f build.log
  111. [ -f build.log.tar.bz2 ] && mv -f build.log.${today}.tar.bz2
  112. # download the kernel
  113. echo ${kernel_version##*-}|grep -q "rc"
  114. [ "$?" -eq 0 ] && testing=testing||testing=
  115. if [ ! -f dist/sources/vanilla/linux-$kernel_version.tar.* ]; then
  116. echo "Downloading the kernel sources"
  117. wget -P dist/sources/vanilla $kernel_mirror/$testing/linux-$kernel_version.tar.xz --no-check-certificate > build.log 2>&1
  118. if [ $? -ne 0 ]; then
  119. echo "Error: failed to download the kernel sources."
  120. exit 1
  121. fi
  122. fi
  123. # download Aufs
  124. if [ ! -f dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2 ]; then
  125. echo "Downloading the Aufs sources"
  126. #git clone http://git.c3sl.ufpr.br/pub/scm/aufs/aufs2-standalone.git aufs$aufs_version-$kernel_branch-git$today >> build.log 2>&1
  127. #git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs3-standalone.git aufs$aufs_version-$kernel_branch-git$today >> build.log 2>&1
  128. #git clone git://github.com/sfjro/aufs3-linux.git aufs$aufs_version-$kernel_branch-git$today >> build.log 2>&1
  129. git clone $aufs_git aufs$aufs_version-$kernel_branch-git$today >> build.log 2>&1
  130. if [ $? -ne 0 ]; then
  131. echo "Error: failed to download the Aufs sources."
  132. exit 1
  133. fi
  134. cd aufs$aufs_version-$kernel_branch-git$today
  135. if [ "$aufsv" ];then #new far for new kernels
  136. git checkout origin/aufs$aufsv >> ../build.log 2>&1
  137. else
  138. git checkout origin/aufs$aufs_version.$kernel_branch >> ../build.log 2>&1
  139. fi
  140. if [ $? -ne 0 ]; then
  141. echo "Error: failed to download the Aufs sources."
  142. exit 1
  143. fi
  144. rm -rf .git
  145. cd ..
  146. echo "Creating the Aufs sources tarball"
  147. tar -c aufs$aufs_version-$kernel_branch-git$today | bzip2 -9 > dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2
  148. else
  149. echo "Extracting the Aufs sources"
  150. tar xf dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2 >> build.log 2>&1
  151. if [ $? -ne 0 ]; then
  152. echo "Error: failed to extract the Aufs sources."
  153. exit 1
  154. fi
  155. fi
  156. # patch Aufs
  157. if [ -f aufs-allow-sfs.patch ];then #removed for K3.9 experiment
  158. echo "Patching the Aufs sources"
  159. patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-allow-sfs.patch >> build.log 2>&1
  160. if [ $? -ne 0 ]; then
  161. echo "Error: failed to patch the Aufs sources."
  162. exit 1
  163. fi
  164. cp aufs-allow-sfs.patch dist/sources/patches
  165. fi
  166. if [ -f aufs-kconfig.patch ];then #special for K3.9
  167. echo "Patching the Aufs sources"
  168. patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-kconfig.patch >> build.log 2>&1
  169. if [ $? -ne 0 ]; then
  170. echo "Error: failed to patch the Aufs sources for kconfig."
  171. exit 1
  172. fi
  173. cp aufs-kconfig.patch dist/sources/patches
  174. fi
  175. # extract the kernel
  176. echo "Extracting the kernel sources"
  177. tar xf dist/sources/vanilla/linux-$kernel_version.tar.* >> build.log 2>&1
  178. if [ $? -ne 0 ]; then
  179. echo "Error: failed to extract the kernel sources."
  180. exit 1
  181. fi
  182. cd linux-$kernel_version
  183. echo "Adding Aufs to the kernel sources"
  184. for i in kbuild base standalone mmap; do
  185. patch -N -p1 < ../aufs$aufs_version-$kernel_branch-git$today/aufs$aufs_version-$i.patch >> ../build.log 2>&1
  186. if [ $? -ne 0 ]; then
  187. #echo "Error: failed to add Aufs to the kernel sources."
  188. #exit 1
  189. echo "WARNING: failed to add some Aufs patches to the kernel sources."
  190. echo "Check it manually and either CRTL+C to bail or hit enter to go on"
  191. read goon
  192. fi
  193. done
  194. cp -r ../aufs$aufs_version-$kernel_branch-git$today/{fs,Documentation} .
  195. cp ../aufs$aufs_version-$kernel_branch-git$today/include/linux/aufs_type.h include/linux 2>/dev/null
  196. cp ../aufs$aufs_version-$kernel_branch-git$today/include/uapi/linux/aufs_type.h include/linux 2>/dev/null
  197. [ -d ../aufs$aufs_version-$kernel_branch-git$today/include/uapi ] && \
  198. cp -r ../aufs$aufs_version-$kernel_branch-git$today/include/uapi/linux/aufs_type.h include/uapi/linux
  199. #cat ../aufs$aufs_version-1-git$today/include/linux/Kbuild >> include/Kbuild
  200. ################################################################################
  201. echo "Resetting the minor version number"
  202. cp Makefile Makefile-orig
  203. sed -i "s/^EXTRAVERSION =/EXTRAVERSION = $custom_suffix/" Makefile
  204. diff -up Makefile-orig Makefile > ../dist/sources/patches/extra-version.patch
  205. rm Makefile-orig
  206. echo "Reducing the number of consoles"
  207. if [ "$kernel_branch" -ge 12 ];then
  208. cp kernel/printk/printk.c kernel/printk/printk.c-orig
  209. sed -i s/'#define MAX_CMDLINECONSOLES 8'/'#define MAX_CMDLINECONSOLES 5'/ kernel/printk/printk.c
  210. diff -up kernel/printk/printk.c-orig kernel/printk/printk.c > ../dist/sources/patches/less-consoles.patch
  211. echo "Reducing the verbosity level"
  212. cp -f kernel/printk/printk.c kernel/printk/printk.c-orig
  213. sed -i s/'#define DEFAULT_CONSOLE_LOGLEVEL 7 \/\* anything MORE serious than KERN_DEBUG \*\/'/'#define DEFAULT_CONSOLE_LOGLEVEL 3 \/\* anything MORE serious than KERN_ERR \*\/'/ kernel/printk/printk.c
  214. diff -up kernel/printk/printk.c-orig kernel/printk/printk.c > ../dist/sources/patches/lower-verbosity.patch
  215. else
  216. cp kernel/printk.c kernel/printk.c-orig
  217. sed -i s/'#define MAX_CMDLINECONSOLES 8'/'#define MAX_CMDLINECONSOLES 5'/ kernel/printk.c
  218. diff -up kernel/printk.c-orig kernel/printk.c > ../dist/sources/patches/less-consoles.patch
  219. echo "Reducing the verbosity level"
  220. cp -f kernel/printk.c kernel/printk.c-orig
  221. sed -i s/'#define DEFAULT_CONSOLE_LOGLEVEL 7 \/\* anything MORE serious than KERN_DEBUG \*\/'/'#define DEFAULT_CONSOLE_LOGLEVEL 3 \/\* anything MORE serious than KERN_ERR \*\/'/ kernel/printk.c
  222. diff -up kernel/printk.c-orig kernel/printk.c > ../dist/sources/patches/lower-verbosity.patch
  223. fi
  224. for patch in ../patches/*; do
  225. echo "Applying $patch"
  226. patch -p1 < $patch >> ../build.log 2>&1
  227. if [ $? -ne 0 ]; then
  228. echo "Error: failed to apply $patch on the kernel sources."
  229. exit 1
  230. fi
  231. cp $patch ../dist/sources/patches
  232. done
  233. echo "Cleaning the kernel sources"
  234. make clean
  235. make mrproper
  236. find . -name '*.orig' -delete
  237. find . -name '*.rej' -delete
  238. find . -name '*~' -delete
  239. cp ../DOTconfig .config
  240. #echo "exiting for config" #uncomment this to change .config #nah, pause routine
  241. #exit #uncomment this to change .config
  242. #pause to configure
  243. echo -en "You now should configure your kernel. The supplied .config\nis \
  244. already configured but you may want to make changes, plus the date \
  245. \nshould be updated. You can choose to run \"make menuconfig\" for \
  246. \nan ncurses based gui (recommended if you don't change stuff or\
  247. \nfor advanced users) or run \"make gconfig\" for a gtk based gui \
  248. \nor if you have qt installed \"make xconfig\" is nice.\
  249. \nHit a number or s to skip\
  250. \n1. make menuconfig\
  251. \n2. make gconfig\
  252. \n3. make xconfig \n"
  253. echo
  254. read kernelconfig
  255. case $kernelconfig in
  256. 1)make menuconfig ;;
  257. 2)make gconfig ;;
  258. 3)make xconfig
  259. [ "$?" -ne "0" ] && echo "woops.. no qt? exiting" && exit ;;
  260. s)echo "skipping" ;;
  261. esac
  262. echo
  263. echo "Ok, kernel is configured. hit ENTER to continue, CTRL+C to quit"
  264. read goon
  265. [ ! -d ../dist/packages ] && mkdir ../dist/packages
  266. echo "Creating the kernel headers package"
  267. make headers_check >> ../build.log 2>&1
  268. make INSTALL_HDR_PATH=kernel_headers-$kernel_major_version-$package_name_suffix/usr headers_install >> ../build.log 2>&1
  269. find kernel_headers-$kernel_major_version-$package_name_suffix/usr/include \( -name .install -o -name ..install.cmd \) -delete
  270. mv kernel_headers-$kernel_major_version-$package_name_suffix ../dist/packages
  271. echo "Compiling the kernel"
  272. make ${JOBS} bzImage modules >> ../build.log 2>&1
  273. if [[ ! -f arch/x86/boot/bzImage || ! -f System.map ]]; then
  274. echo "Error: failed to compile the kernel sources."
  275. exit 1
  276. fi
  277. cp .config ../dist/sources/DOTconfig-$kernel_version-$today
  278. echo "Creating the kernel package"
  279. make INSTALL_MOD_PATH=linux_kernel-$kernel_major_version-$package_name_suffix modules_install >> ../build.log 2>&1
  280. rm -f linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{build,source}
  281. #(cd linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/; ln -s ${kernel_major_version}$custom_suffix $kernel_major_version)
  282. mkdir linux_kernel-$kernel_major_version-$package_name_suffix/boot
  283. mkdir -p linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules
  284. cp .config linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/DOTconfig-$kernel_version-$today
  285. cp arch/x86/boot/bzImage linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz
  286. BZIMAGE=`find . -type f -name bzImage`
  287. cp System.map linux_kernel-$kernel_major_version-$package_name_suffix/boot
  288. cp $BZIMAGE linux_kernel-$kernel_major_version-$package_name_suffix/boot
  289. cp linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{modules.builtin,modules.order} \
  290. linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/
  291. [ "$FD" = "1" ] || \
  292. rm linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/modules*
  293. mv linux_kernel-$kernel_major_version-$package_name_suffix ../dist/packages
  294. if [ "$FD" = "1" ];then #make fatdog kernel module package
  295. mv ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz ../dist/packages/vmlinuz-$kernel_major_version-$package_name_suffix
  296. #gzip -9 ../dist/packages/vmlinuz-$kernel_major_version-$package_name_suffix
  297. [ -f ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/bzImage ] &&
  298. rm -f ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/bzImage
  299. echo "FatDog compatible kernel is ready in dist"
  300. fi
  301. echo "Cleaning the kernel sources"
  302. make clean >> ../build.log 2>&1
  303. make prepare >> ../build.log 2>&1
  304. cd ..
  305. echo "Creating a kernel sources SFS"
  306. mkdir -p kernel_sources-$kernel_major_version-$package_name_suffix/usr/src
  307. mv linux-$kernel_version kernel_sources-$kernel_major_version-$package_name_suffix/usr/src/linux
  308. mkdir -p kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix
  309. ln -s /usr/src/linux kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/build
  310. [ ! -f kernel_sources-${kernel_major_version}-$package_name_suffix/usr/src/linux/include/linux/version.h ] && \
  311. ln -s /usr/src/linux/include/generated/uapi/linux/version.h kernel_sources-${kernel_major_version}-$package_name_suffix/usr/src/linux/include/linux/version.h
  312. ln -s /usr/src/linux kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/source
  313. mksquashfs kernel_sources-$kernel_major_version-$package_name_suffix dist/sources/kernel_sources-$kernel_major_version-$package_name_suffix.sfs $COMP
  314. # build aufs-utils userspace modules
  315. echo "Now to build the aufs-utils for userspace"
  316. if [ ! -f dist/sources/vanilla/aufs-util${today}.tar.bz2 ];then
  317. #git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs-util.git aufs-util >> build.log 2>&1
  318. git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util
  319. [ $? -ne 0 ] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
  320. cd aufs-util
  321. git branch -a | grep 'aufs3' |grep -v 'rcN' | cut -d '.' -f2 > /tmp/aufs-util-version #we go for stable only
  322. while read line
  323. do
  324. if [ "$kernel_branch" = "$line" ];then branch=$line
  325. else
  326. while [ "$kernel_branch" -gt "$line" ]
  327. do branch=$line
  328. echo $branch && break
  329. done
  330. fi
  331. done < /tmp/aufs-util-version
  332. git checkout origin/aufs3.${branch} >> ../build.log 2>&1
  333. [ $? -ne 0 ] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
  334. # patch Makefile for static build
  335. echo "Patching aufs-util sources"
  336. cp Makefile Makefile.orig
  337. sed -i 's/-static //' Makefile
  338. diff -ru Makefile.orig Makefile > ../dist/sources/patches/aufs-util-dynamic.patch
  339. rm *.orig
  340. else
  341. echo "Extracting the Aufs-util sources"
  342. tar xf dist/sources/vanilla/aufs-util$today.tar.bz2 >> ../build.log 2>&1
  343. if [ $? -ne 0 ]; then
  344. echo "Error: failed to extract the aufs-util sources."
  345. exit 1
  346. fi
  347. cd aufs-util
  348. patch -p1 < ../dist/sources/patches/aufs-util-dynamic.patch >> ../build.log 2>&1
  349. [ "$?" -ne 0 ] && echo "Failed to patch the aufs-util sources, do it manually. Kernel is compiled ok" && exit
  350. fi
  351. arch=`uname -m`
  352. LinuxSrc=../dist/packages/kernel_headers*
  353. export CPPFLAGS="-I $LinuxSrc/usr/include"
  354. make >> ../build.log 2>&1
  355. [ $? -ne 0 ] && echo "Failed to compile aufs-util, do it manually. Kernel is compiled OK :)" && exit
  356. make DESTDIR=$CWD/dist/packages/aufs-util-$kernel_version-$arch install >> ../build.log 2>&1 #maybe needs absolute path
  357. make clean >> ../build.log 2>&1
  358. if [ "$arch" = "x86_64" ];then
  359. mv $CWD/dist/packages/aufs-util-$kernel_version-$arch/usr/lib \
  360. $CWD/dist/packages/aufs-util-$kernel_version-$arch/usr/lib64
  361. fi
  362. echo "aufs-util-$kernel_version is in dist"
  363. cd ..
  364. if [ "$FD" = "1" ];then #shift aufs-utils to kernel-modules.sfs
  365. echo "Installing aufs-utils into kernel package"
  366. cp -a --remove-destination dist/packages/aufs-util-$kernel_version-$arch/* dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix
  367. echo "Pausing here, pending a better method, to add extra firmware"
  368. echo "once you have manually added firmware to "
  369. echo "dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/lib/firmware"
  370. echo "hit ENTER to continue"
  371. read firm
  372. mksquashfs dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix dist/packages/kernel-modules.sfs-$kernel_major_version-$package_name_suffix $COMP
  373. [ "$?" = 0 ] && echo "FatDog compatible kernel packages are ready in dist/" || exit 1
  374. fi
  375. tar -c aufs-util | bzip2 -9 > dist/sources/vanilla/aufs-util$today-$arch.tar.bz2
  376. echo "Compressing the log"
  377. bzip2 -9 build.log
  378. cp build.log.bz2 dist/sources
  379. echo "Done!"
  380. aplay /usr/share/sounds/2barks.au