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.

339 lines
9.6 KiB

  1. #!/bin/bash
  2. #
  3. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. #
  5. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. # Please add additional copyright information _after_ the line containing
  7. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. #
  10. # ROCK Linux: rock-src/scripts/Config
  11. # ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version. A copy of the GNU General Public
  17. # License can be found at Documentation/COPYING.
  18. #
  19. # Many people helped and are helping developing ROCK Linux. Please
  20. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. # file for details.
  22. #
  23. # --- ROCK-COPYRIGHT-NOTE-END ---
  24. if [ -z "${lines:=$LINES}" -o -z "${columns:=$COLUMNS}" ] ; then
  25. if [ "$( type -p stty )" ] ; then
  26. lines="$( stty size 2> /dev/null | cut -d' ' -f1 )"
  27. columns="$( stty size 2> /dev/null | cut -d' ' -f2 )"
  28. fi
  29. [ -z "$lines" -o "$lines" -le 0 ] 2> /dev/null && lines=24
  30. [ -z "$columns" -o "$columns" -le 0 ] 2> /dev/null && columns=80
  31. fi
  32. eval "$(egrep '^rockver=' scripts/parse-config)"
  33. config=default
  34. do_config_cycle=0
  35. delete_mode=0
  36. oldconfig=''
  37. nobashmod=''
  38. profile=''
  39. while [ "$1" ] ; do
  40. case "$1" in
  41. # -cycle) do_config_cycle=1 ; shift ;;
  42. -delete) delete_mode=1 ; shift ;;
  43. -profile) profile='-profile' ; shift ;;
  44. -oldconfig) oldconfig='-oldconfig' ; shift ;;
  45. -nobashmod) nobashmod='-nobashmod' ; shift ;;
  46. -cfg) config="$2" ; shift ; shift ;;
  47. *)
  48. echo
  49. echo "Usage: $0 [ -delete | -oldconfig ] [ -cfg <config> ]"
  50. echo " Create and modify build configurations for the other"
  51. echo " scripts, e.g. Download, Build-Target, and Emerge-Pkg."
  52. echo
  53. echo " -cfg <config> use <config> as the configuration name. If this option"
  54. echo " is not set the name 'default' is used. If no"
  55. echo " configuration by this name exists, one with default"
  56. echo " settings is created."
  57. echo " -delete delete the specified configuration"
  58. echo " -oldconfig run without a menu-based interface; changes to settings"
  59. echo " in configuration files have to be made manually before"
  60. echo " ./scripts/Config recreates the whole configuration"
  61. echo
  62. echo "Other options:"
  63. echo " -profile create a config.profile with profiling data"
  64. echo " -nobashmod don't use the bash config helper plugin"
  65. echo
  66. exit 1 ;;
  67. esac
  68. done
  69. ./scripts/Check-System || exit 1
  70. if [ $delete_mode = 1 ] ; then
  71. rm -rv config/$config
  72. exit $?
  73. fi
  74. # hook for third-party targets that need to insert additional packages before config runs, for example.
  75. # for precnf in target/*/preconfig.sh ; do
  76. # [ -f $precnf ] && . $precnf
  77. # done
  78. swpid=swp$$
  79. swpdir="config/$config.$swpid"
  80. rm -f rockdialog.scrltmp # src/rockdialog.bin
  81. mkdir -p src
  82. if [ -z "$oldconfig" -a ! -f src/rockdialog.bin ] ; then
  83. echo "Creating rockdialog tool."
  84. command="gcc misc/rockdialog/*.c `
  85. `-Imisc/rockdialog -lncurses -o src/rockdialog.bin"
  86. eval "$command.$swpid"
  87. mv src/rockdialog.bin{.$swpid,}
  88. fi
  89. if [ -z "$nobashmod" ]; then
  90. if [ ! -f src/config_helper.so -o misc/tools-source/config_helper.c -nt src/config_helper.so ]; then
  91. echo "Building src/config_helper.so."
  92. gcc -shared -fPIC -Wall -o src/config_helper.so misc/tools-source/config_helper.c || exit 1
  93. fi
  94. enable -f src/config_helper.so cfghlp || exit 1
  95. fi
  96. if [ -z "$profile" ]; then
  97. bprof() { :; }
  98. bprof_print() { :; }
  99. else
  100. if [ ! -f src/bash_profiler.so -o misc/tools-source/bash_profiler.c -nt src/bash_profiler.so ]; then
  101. echo "Building src/bash_profiler.so."
  102. gcc -shared -fPIC -Wall -o src/bash_profiler.so misc/tools-source/bash_profiler.c || exit 1
  103. fi
  104. enable -f src/bash_profiler.so bprof || exit 1
  105. bprof_print() {
  106. bprof all print >> config.profile
  107. awk '
  108. $4 == "profiled" { next; }
  109. $4 != "main" { count["profiled"]+=$1; time["profiled"]+=$2; }
  110. { count[$4]+=$1; time[$4]+=$2; }
  111. END {
  112. for (id in count)
  113. printf "%7d %7Ld %10.3f %s\n", count[id], time[id], time[id]/count[id], id;
  114. }
  115. ' < config.profile | sort -n -k2 > config.profile.new
  116. mv config.profile{.new,}
  117. }
  118. fi
  119. bprof main start
  120. echo "Running ROCK Linux $rockver configuration ..."
  121. if [ ! -e config/$config ] ; then
  122. mkdir -p config/$config
  123. echo "Creating new configuration $config ..."
  124. $0 -oldconfig $profile $nobashmod -cfg $config
  125. fi
  126. . scripts/config.func
  127. mkdir -p config/$config
  128. touch config/$config/{config{,_usr},packages}
  129. rm -rf $swpdir
  130. cp -r config/$config $swpdir
  131. . $swpdir/config
  132. . $swpdir/config_usr
  133. current=""
  134. menu_this=0 ; menu_current=0 ; menu_counter=0
  135. menu_stack=x
  136. spacer="" ; expert=0 ; tabspace="5" ; tabspace_list=""
  137. commentnr=0 ; editfilenr=0
  138. include ()
  139. {
  140. local x
  141. for x in $@ ; do
  142. [ -f "$x" ] && . "./$x"
  143. done
  144. }
  145. arch=none
  146. if expr "`uname -m`" : "x86_64" > /dev/null ; then arch=x86 ; fi
  147. if expr "`uname -m`" : "i.86" > /dev/null ; then arch=x86 ; fi
  148. if expr "`uname -m`" : "alpha" > /dev/null ; then arch=alpha ; fi
  149. if expr "`uname -m`" : "ppc" > /dev/null ; then arch=powerpc ; fi
  150. if expr "`uname -m`" : "powerpc" > /dev/null ; then arch=powerpc ; fi
  151. if expr "`uname -m`" : "sparc" > /dev/null ; then arch=sparc ; fi
  152. if expr "`uname -m`" : "mips" > /dev/null ; then arch=mips ; fi
  153. export CFGTEMP_ARCH="$arch"
  154. export CFGTEMP_ID="$rockver"
  155. export ROCKCFG_EXPERT=0
  156. include "architecture/*/preconfig.in"
  157. include "misc/*/preconfig.in"
  158. include "target/*/preconfig.in"
  159. old_pkg_cmd=""
  160. do_config_cycle=1
  161. recreate_packages=1
  162. while [ "$do_config_cycle" == 1 ] ; do
  163. pkg_cmd="$ROCKCFG_ARCH"
  164. [ "$ROCKCFG_DISABLE_BROKEN" = 1 ] && pkg_cmd="${pkg_cmd}-nobroken"
  165. if [ "$old_pkg_cmd" != "$pkg_cmd" ] ; then
  166. recreate_packages=1
  167. fi
  168. if [ "$recreate_packages" == 1 ] ; then
  169. recreate_packages=0
  170. if [ -f $swpdir/config.pcache.$pkg_cmd ] ; then
  171. cp -a $swpdir/config.pcache.$pkg_cmd $swpdir/packages
  172. pkgin
  173. else
  174. eval "./scripts/Create-PkgList $pkg_cmd" \
  175. > $swpdir/packages
  176. pkgin
  177. if [ ! -e "$swpdir/preconfig.in.tmp" ] ; then
  178. cat package/*/*/preconfig.in | grep -v "^#" \
  179. > "$swpdir/preconfig.in.tmp"
  180. fi
  181. include "$swpdir/preconfig.in.tmp"
  182. pkgout
  183. cp -a $swpdir/packages $swpdir/config.pcache.$pkg_cmd
  184. fi
  185. old_pkg_cmd="$pkg_cmd"
  186. else
  187. cp -a $swpdir/config.pcache.$pkg_cmd $swpdir/packages
  188. pkgin
  189. fi
  190. rm -f $swpdir/config.{dialog,data,help}{,.*}
  191. config_cycle
  192. bprof main stop
  193. bprof rockconfig start
  194. . scripts/config.in
  195. if [ ! -e "$swpdir/postconfig.in.tmp" ] ; then
  196. {
  197. ls misc/*/postconfig{,-*}.in 2>/dev/null \
  198. | LC_ALL=C sort -k3,3 -t"/" | tr '\n' ' ' | xargs cat
  199. cat package/*/*/postconfig.in
  200. } | grep -v "^#" > "$swpdir/postconfig.in.tmp"
  201. fi
  202. include "$swpdir/postconfig.in.tmp"
  203. include architecture/$ROCKCFG_ARCH/postconfig.in
  204. include target/$ROCKCFG_TARGET/postconfig.in
  205. bprof rockconfig stop
  206. bprof main start
  207. configtitle="$(printf ' %-50s %6s active packages ]' \
  208. "ROCK Linux $rockver Configuration - $config" \
  209. "[ $(echo `grep '^X' $swpdir/packages | wc -l`)" )"
  210. do_dialog_cycle=1
  211. while [ "$do_dialog_cycle" = 1 ] ; do
  212. if [ -z "$oldconfig" ] ; then
  213. bprof main stop
  214. bprof rockdialog start
  215. eval "./src/rockdialog.bin --title 'Build Config' \
  216. --backtitle '$configtitle' \
  217. --menu 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
  218. $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 )) \
  219. '$current' `tr '\n' ' ' \
  220. < $swpdir/config.dialog.$menu_current`" \
  221. 2> $swpdir/config.out
  222. returncode=$? ; item="`cat $swpdir/config.out`"
  223. bprof rockdialog stop
  224. bprof main start
  225. else
  226. returncode=1
  227. fi
  228. [ "$returncode" = 1 -a "$menu_current" -ne 0 ] && returncode="menu-back"
  229. case "$returncode" in
  230. 0|6)
  231. command="`grep "^$item " \
  232. $swpdir/config.data.$menu_current | cut -f2-`"
  233. if [[ "$command" != menu_current=* ]] ; then
  234. [ -n "$command" ] && do_dialog_cycle=0
  235. current="$item"
  236. fi
  237. eval "$command"
  238. ;;
  239. menu-back)
  240. command="`grep "^MENU_BACK " \
  241. $swpdir/config.data.$menu_current | cut -f2-`"
  242. eval "$command"
  243. ;;
  244. 1|255)
  245. do_dialog_cycle=0
  246. do_config_cycle=0
  247. rm -f $swpdir/config.{data,dialog,out,help}{,.*}
  248. rm -f $swpdir/config.pcache.*
  249. rm -f rockdialog.scrltmp # src/rockdialog.bin
  250. echo "New config written to config/$config/*."
  251. echo "Cleaning up. Configuration finished."
  252. ;;
  253. 2)
  254. item=$(echo $item | cut -f1 -d' ') # dialog(1) bug?
  255. current="$item"
  256. get_help $item > $swpdir/config.dialog
  257. bprof main stop
  258. ./src/rockdialog.bin --title 'ROCK Linux Config - Help' \
  259. --backtitle "ROCK Linux $rockver Configuration" \
  260. --textbox $swpdir/config.dialog \
  261. $(( $lines - 4 )) $(( $columns - 5 ))
  262. bprof main start
  263. ;;
  264. *)
  265. do_dialog_cycle=0
  266. do_config_cycle=0
  267. echo "unknown returncode: $returncode"
  268. ;;
  269. esac
  270. done
  271. bprof main stop
  272. bprof_print
  273. done
  274. pkgout
  275. rm -f $swpdir/*.tmp
  276. echo -e "#\n# ROCK Linux $rockver Config File\n#\n" \
  277. > $swpdir/config
  278. echo -e "#\n# ROCK Linux $rockver User Config File\n#" \
  279. > $swpdir/config_usr
  280. for x in ${!ROCKCFG_*}; do
  281. echo "export ${x}='${!x}'"
  282. done >> $swpdir/config
  283. for x in ${!ROCKCFGUSR_*}; do
  284. echo "${x}='${!x}'"
  285. done >> $swpdir/config_usr
  286. sort -k1,1r -k3,3 $swpdir/packages > $swpdir/packages.sorted
  287. mv -f $swpdir/packages{.sorted,}
  288. for x in $( ls $swpdir/ ); do
  289. cp $swpdir/{$x,__tmp}
  290. mv $swpdir/__tmp config/$config/$x
  291. done
  292. for x in $( ls config/$config ); do
  293. [ -e $swpdir/$x ] || rm -f config/$config/$x
  294. done
  295. rm -rf $swpdir