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.

274 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 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="./scripts/Create-PkgList"
  152. cmd="$cmd $SDECFG_ARCH"
  153. if [ "$cmd" != "`cat $cfgtmpdir/config.pcache.cmd 2> /dev/null`" ] ; then
  154. eval "$cmd" | tee $cfgtmpdir/config.pcache.data > $cfgtmpdir/config/packages
  155. echo "$cmd" > $cfgtmpdir/config.pcache.cmd
  156. else
  157. cat $cfgtmpdir/config.pcache.data > $cfgtmpdir/config/packages
  158. fi
  159. bprof mkpkglist stop
  160. # Create lists of .in files
  161. create_dot_in_lists
  162. export SDECFG_ID="$sdever"; pkgin; . lib/sde-config/main.in; pkgout
  163. echo "export SDECFG_ID='$SDECFG_ID'" >> $cfgtmpdir/config/config
  164. rm -f $cfgtmpdir/*.tmp
  165. cut -f1,2,4,5,8- -d' ' $cfgtmpdir/config/packages | sed 's, [^ ]*$,,' | \
  166. tr ' ' '\t' | expand -t2,15,35, > $cfgtmpdir/packages.txt
  167. configtitle="$(printf ' %-50s %6s active packages ]' \
  168. "The OpenSDE ($sdever) Configuration - $config" \
  169. "[ $(echo `grep '^X' $cfgtmpdir/config/packages | wc -l`)" )"
  170. bprof main stop
  171. if [ -z "$oldconfig" ] ; then
  172. eval "./tmp/confdialog.bin --title 'Build Config' \
  173. --backtitle '$configtitle' \
  174. --menu 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
  175. $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 )) \
  176. '$current' `tr '\n' ' ' < $cfgtmpdir/config.dialog`" 2> $cfgtmpdir/config.out
  177. returncode=$? ; item="`cat $cfgtmpdir/config.out`"
  178. else
  179. returncode=1
  180. fi
  181. bprof main start
  182. [ "$returncode" = 1 -a "$menu_back" -ne -1 ] && returncode="menu-back"
  183. case "$returncode" in
  184. 0|6)
  185. command="`grep "^$item " $cfgtmpdir/config.data | cut -f2-`"
  186. { echo -e "\n# Remember menu position:\ncurrent='$item'"
  187. echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
  188. echo -e "\n# Execute this config command:\n$command"
  189. } >> $cfgtmpdir/config/config
  190. ;;
  191. menu-back)
  192. { echo -e "\n# New menu position:\ncurrent='$menu_backpos'"
  193. echo -e "\n# New sub-menu:\nmenu_current='$menu_back'"
  194. } >> $cfgtmpdir/config/config
  195. ;;
  196. 1|255)
  197. mkdir -p config/$config
  198. # sync
  199. for x in config/$config/*; do
  200. if [ ! -e "$cfgtmpdir/config/${x##*/}" ]; then
  201. rm -f "$x"
  202. fi
  203. done
  204. cp -a $cfgtmpdir/config/* config/$config/
  205. rm -rf $cfgtmpdir
  206. echo "New config written to config/$config/*."
  207. echo "Cleaning up. Configuration finished."
  208. bprof main stop
  209. bprof_print
  210. exit 1 ;;
  211. 2)
  212. tempitem=$item
  213. item=$(echo $item | cut -f1 -d' ') # dialog(1) bug?
  214. { echo -e "\n# Remember menu position:\ncurrent='$item'"
  215. echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
  216. } >> $cfgtmpdir/config/config
  217. get_help $item > $cfgtmpdir/config.dialog
  218. bprof main stop
  219. ./tmp/confdialog.bin --title 'The OpenSDE Config - Help' \
  220. --backtitle "The OpenSDE ($sdever) Configuration" \
  221. --textbox $cfgtmpdir/config.dialog \
  222. $(( $lines - 4 )) $(( $columns - 5 ))
  223. bprof main start
  224. ;;
  225. *)
  226. echo "unknown returncode: $returncode"
  227. bprof main stop
  228. bprof_print
  229. exit 1 ;;
  230. esac
  231. bprof main stop
  232. bprof_print
  233. exit 0