OpenSDE Framework (without history before r20070)
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.

273 lines
7.6 KiB

  1. #!/bin/bash
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: scripts/Config
  6. # Copyright (C) 2006 - 2008 The OpenSDE Project
  7. # Copyright (C) 2004 - 2006 The T2 SDE Project
  8. # Copyright (C) 1998 - 2003 Clifford Wolf
  9. #
  10. # More information can be found in the files COPYING and README.
  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; version 2 of the License. A copy of the
  15. # GNU General Public License can be found in the file COPYING.
  16. # --- SDE-COPYRIGHT-NOTE-END ---
  17. if [ -z "${lines:=$LINES}" -o -z "${columns:=$COLUMNS}" ] ; then
  18. if [ "$( type -p stty )" ] ; then
  19. lines="$( stty size 2> /dev/null | cut -d' ' -f1 )"
  20. columns="$( stty size 2> /dev/null | cut -d' ' -f2 )"
  21. fi
  22. [ -z "$lines" -o "$lines" -le 0 ] 2> /dev/null && lines=24
  23. [ -z "$columns" -o "$columns" -le 0 ] 2> /dev/null && columns=80
  24. fi
  25. eval "$(egrep '^sdever=' lib/parse-config)"
  26. config=default
  27. do_config_cycle=0
  28. delete_mode=0
  29. oldconfig=
  30. nobashmod=
  31. cfgtmpdir=
  32. profile=
  33. show_usage() {
  34. echo
  35. echo "Usage: $0 [ -delete | -oldconfig ] [ -cfg <config> ]"
  36. echo
  37. echo "Other options:"
  38. echo " -profile create a config.profile with profiling data"
  39. echo " -nobashmod don't use the bash config helper plugin"
  40. echo
  41. }
  42. while [ "$1" ] ; do
  43. case "$1" in
  44. -cycle) do_config_cycle=1 ; shift ;;
  45. -delete) delete_mode=1 ; shift ;;
  46. -profile) profile='-profile' ; shift ;;
  47. -oldconfig) oldconfig='-oldconfig' ; shift ;;
  48. -nobashmod) nobashmod='-nobashmod' ; shift ;;
  49. -cfg) config="$2" ; shift ; shift ;;
  50. *) show_usage
  51. exit 1 ;;
  52. esac
  53. done
  54. if [ -z "$config" ]; then
  55. show_usage
  56. exit 1
  57. fi
  58. if [ ! -d config/$config -a -n "$oldconfig" ]; then
  59. echo "Abort: -oldconfig is not supported for new configs"
  60. echo
  61. exit 1
  62. fi
  63. if [ $delete_mode = 1 ] ; then
  64. rm -rv config/$config
  65. exit $?
  66. fi
  67. cfgtmpdir=tmp/$config
  68. if [ $do_config_cycle = 0 ] ; then
  69. rm -rf $cfgtmpdir
  70. mkdir -p $cfgtmpdir # src
  71. if [ -z "$oldconfig" -a ! -f tmp/confdialog.bin ] ; then
  72. echo "Creating confdialog tool."
  73. command="gcc src/confdialog/*.c `
  74. `-Isrc/confdialog -lncurses -o tmp/confdialog.bin"
  75. set -e
  76. echo "$command" ; eval "$command.$$"
  77. mv tmp/confdialog.bin.$$ tmp/confdialog.bin
  78. set +e
  79. fi
  80. # don't accept Ctrl-C because it destroy the configurations
  81. trap '' INT
  82. if [ -d config/$config ]; then
  83. mkdir -p $cfgtmpdir/config/
  84. cp -a config/$config/* $cfgtmpdir/config/
  85. if [ $? -ne 0 ]; then
  86. echo "Copy of config failed, aborting."
  87. exit 1
  88. fi
  89. fi
  90. echo "Starting OpenSDE ($sdever) configuration ..."
  91. while "$0" -cfg $config $oldconfig $profile $nobashmod -cycle ; do : ; done
  92. trap INT
  93. exit 0
  94. fi
  95. if [ -z "$nobashmod" ]; then
  96. if [ ! -f tmp/config_helper.so -o src/tools-source/config_helper.c -nt tmp/config_helper.so ]; then
  97. echo "Building tmp/config_helper.so."
  98. gcc -shared -fPIC -Wall -o tmp/config_helper.so src/tools-source/config_helper.c || exit 1
  99. fi
  100. enable -f tmp/config_helper.so cfghlp || exit 1
  101. fi
  102. if [ -z "$profile" ]; then
  103. bprof() { :; }
  104. bprof_print() { :; }
  105. else
  106. if [ ! -f tmp/bash_profiler.so -o src/tools-source/bash_profiler.c -nt tmp/bash_profiler.so ]; then
  107. echo "Building tmp/bash_profiler.so."
  108. gcc -shared -fPIC -Wall -o tmp/bash_profiler.so src/tools-source/bash_profiler.c || exit 1
  109. fi
  110. enable -f tmp/bash_profiler.so bprof || exit 1
  111. bprof_print() {
  112. local cprof=$cfgtmpdir/config.profile
  113. bprof all print >> $cprof
  114. awk '
  115. $4 == "profiled" { next; }
  116. $4 != "main" { count["profiled"]+=$1; time["profiled"]+=$2; }
  117. { count[$4]+=$1; time[$4]+=$2; }
  118. END {
  119. for (id in count)
  120. printf "%7d %7Ld %10.3f %s\n", count[id], time[id], time[id]/count[id], id;
  121. }
  122. ' < $cprof | sort -n -k2 > $cprof.new
  123. mv $cprof.net $cprof
  124. }
  125. fi
  126. bprof main start
  127. . lib/sde-config/functions.in
  128. arch=`uname -m | uname2arch`
  129. current= ; export SDECFG_ARCH="$arch" ; export SDECFG_EXPERT=0
  130. menu_this=0 ; menu_current=0 ; menu_counter=0
  131. menu_stack=x ; menu_back=-1 ; menu_backpos=-1
  132. set -e
  133. mkdir -p $cfgtmpdir/config
  134. touch $cfgtmpdir/config/{config,packages}
  135. set +e
  136. configtitle="$(printf ' %-50s %6s active packages ]' \
  137. "The OpenSDE ($sdever) Configuration - $config" \
  138. "[ $(echo `grep '^X' $cfgtmpdir/config/packages | wc -l`)" )"
  139. bprof main stop
  140. # NOTE: ROCKCFG -> SDECFG automatized convertion
  141. grep -q 'ROCKCFG' $cfgtmpdir/config/config &&
  142. sed -i -e 's,ROCKCFG,SDECFG,g' $cfgtmpdir/config/config
  143. . $cfgtmpdir/config/config
  144. bprof main start
  145. rm -f $cfgtmpdir/config.{dialog,data,help}
  146. touch $cfgtmpdir/config.{dialog,data,help}
  147. echo -e "#\n# OpenSDE ($sdever) Config File\n#" > $cfgtmpdir/config/config
  148. spacer= ; expert=0 ; tabspace="5" ; tabspace_list=
  149. commentnr=0 ; editfilenr=0
  150. bprof mkpkglist start
  151. cmd="./bin/sde-list package --arch '$SDECFG_ARCH'"
  152. if [ "$cmd" != "`cat $cfgtmpdir/config.pcache.cmd 2> /dev/null`" ] ; then
  153. eval "$cmd" | tee $cfgtmpdir/config.pcache.data > $cfgtmpdir/config/packages
  154. echo "$cmd" > $cfgtmpdir/config.pcache.cmd
  155. else
  156. cat $cfgtmpdir/config.pcache.data > $cfgtmpdir/config/packages
  157. fi
  158. bprof mkpkglist stop
  159. # Create lists of .in files
  160. create_dot_in_lists
  161. export SDECFG_ID="$sdever"; pkgin; . lib/sde-config/main.in; pkgout
  162. echo "export SDECFG_ID='$SDECFG_ID'" >> $cfgtmpdir/config/config
  163. rm -f $cfgtmpdir/*.tmp
  164. cut -f1,2,4,5,8- -d' ' $cfgtmpdir/config/packages | sed 's, [^ ]*$,,' | \
  165. tr ' ' '\t' | expand -t2,15,35, > $cfgtmpdir/packages.txt
  166. configtitle="$(printf ' %-50s %6s active packages ]' \
  167. "The OpenSDE ($sdever) Configuration - $config" \
  168. "[ $(echo `grep '^X' $cfgtmpdir/config/packages | wc -l`)" )"
  169. bprof main stop
  170. if [ -z "$oldconfig" ] ; then
  171. eval "./tmp/confdialog.bin --title 'Build Config' \
  172. --backtitle '$configtitle' \
  173. --menu 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
  174. $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 )) \
  175. '$current' `tr '\n' ' ' < $cfgtmpdir/config.dialog`" 2> $cfgtmpdir/config.out
  176. returncode=$? ; item="`cat $cfgtmpdir/config.out`"
  177. else
  178. returncode=1
  179. fi
  180. bprof main start
  181. [ "$returncode" = 1 -a "$menu_back" -ne -1 ] && returncode="menu-back"
  182. case "$returncode" in
  183. 0|6)
  184. command="`grep "^$item " $cfgtmpdir/config.data | cut -f2-`"
  185. { echo -e "\n# Remember menu position:\ncurrent='$item'"
  186. echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
  187. echo -e "\n# Execute this config command:\n$command"
  188. } >> $cfgtmpdir/config/config
  189. ;;
  190. menu-back)
  191. { echo -e "\n# New menu position:\ncurrent='$menu_backpos'"
  192. echo -e "\n# New sub-menu:\nmenu_current='$menu_back'"
  193. } >> $cfgtmpdir/config/config
  194. ;;
  195. 1|255)
  196. mkdir -p config/$config
  197. # sync
  198. for x in config/$config/*; do
  199. if [ ! -e "$cfgtmpdir/config/${x##*/}" ]; then
  200. rm -f "$x"
  201. fi
  202. done
  203. cp -a $cfgtmpdir/config/* config/$config/
  204. rm -rf $cfgtmpdir
  205. echo "New config written to config/$config/*."
  206. echo "Cleaning up. Configuration finished."
  207. bprof main stop
  208. bprof_print
  209. exit 1 ;;
  210. 2)
  211. tempitem=$item
  212. item=$(echo $item | cut -f1 -d' ') # dialog(1) bug?
  213. { echo -e "\n# Remember menu position:\ncurrent='$item'"
  214. echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
  215. } >> $cfgtmpdir/config/config
  216. get_help $item > $cfgtmpdir/config.dialog
  217. bprof main stop
  218. ./tmp/confdialog.bin --title 'The OpenSDE Config - Help' \
  219. --backtitle "The OpenSDE ($sdever) Configuration" \
  220. --textbox $cfgtmpdir/config.dialog \
  221. $(( $lines - 4 )) $(( $columns - 5 ))
  222. bprof main start
  223. ;;
  224. *)
  225. echo "unknown returncode: $returncode"
  226. bprof main stop
  227. bprof_print
  228. exit 1 ;;
  229. esac
  230. bprof main stop
  231. bprof_print
  232. exit 0