Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
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.

316 lines
5.5KB

  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2008 Jonathan Moore Liles
  4. # This file is licensed under version 2 of the GPL.
  5. . scripts/colors
  6. # support functions for 'configure' scripts.
  7. fatal ()
  8. {
  9. echo "$BOLD$RED$*$SGR0" > /dev/stderr
  10. exit 255
  11. }
  12. UPDATE=no
  13. HELP=no
  14. split ()
  15. {
  16. while [ $# -gt 0 ]
  17. do
  18. echo $1
  19. shift 1
  20. done
  21. }
  22. if [ $# -gt 0 ]
  23. then
  24. case "$1" in
  25. --update)
  26. UPDATE=yes
  27. shift 1
  28. ;;
  29. --help)
  30. HELP=yes
  31. shift 1
  32. ;;
  33. *)
  34. # fatal "This is not an autoconf script. Run it without any options and you will be prompted."
  35. ;;
  36. esac
  37. if [ $# -gt 0 ]
  38. then
  39. echo "## options" > .config
  40. split "$@" | sed '
  41. s/--\(enable\|disable\)-\([^ =]\+\)/--\1-\U\2/g;
  42. s/--enable-\([^ =]\+\)=\(.*\)/USE_\1=\2/g;
  43. s/--enable-\([^ =]\+\)/USE_\1=yes/g;
  44. s/--disable-\([^ =]\+\)/USE_\1=no/g;
  45. s/--\([^ =]\+\)/\1/g;
  46. ' | sed -n '/^[^ =]\+=./p' >> .config
  47. UPDATE=yes;
  48. fi
  49. fi
  50. if [ $HELP != yes ] && [ $UPDATE != yes ]
  51. then
  52. if ! ( [ -t 0 ] && [ -t 1 ] )
  53. then
  54. fatal "not a terminal!"
  55. fi
  56. fi
  57. ask ()
  58. {
  59. local A D O
  60. D="`eval echo \\$$2`"
  61. D=${D:-$3}
  62. if [ $HELP = yes ]
  63. then
  64. if [ "$3" = yes ] || [ "$3" = no ]
  65. then
  66. O=`echo -n "$2" | sed s/^USE_/--enable-/ | tr '[[:upper:]]' '[[:lower:]]'`
  67. else
  68. O=`echo -n "--$2" | tr '[[:upper:]]' '[[:lower:]]'`
  69. fi
  70. printf " ${BOLD}${GREEN}%-15s${SGR0}\t%-40s (currently: ${BOLD}%s${SGR0})\n" "$O" "$1" "$D"
  71. return
  72. fi
  73. echo -n "$BLACK$BOLD::$SGR0 ${1}? [$BOLD${D}$SGR0] "
  74. if [ $UPDATE = yes ]
  75. then
  76. A="$D"
  77. echo
  78. else
  79. read A
  80. A=${A:-$D}
  81. fi
  82. if [ "$3" = yes ] || [ "$3" = no ]
  83. then
  84. case "$A" in
  85. no | n | N) A=no ;;
  86. yes | y | Y) A=yes ;;
  87. * ) fatal "Invalid response. Must be 'yes' or 'no'" ;;
  88. esac
  89. fi
  90. append "${2}=${A:-$D}"
  91. }
  92. ok ()
  93. {
  94. echo -e '\r'`tput cuf 30`"$BOLD${GREEN}ok${SGR0} ${*:+${BOLD}${BLACK}($*)${SGR0}}"
  95. }
  96. failed ()
  97. {
  98. echo "$BOLD${RED}failed!${SGR0}" > /dev/stderr
  99. rm -f .config
  100. }
  101. using ()
  102. {
  103. [ "`eval echo \\$USE_$1`" = yes ]
  104. return $?
  105. }
  106. upcase ()
  107. {
  108. echo "$*" | tr '[[:lower:]]' '[[:upper:]]'
  109. }
  110. extract_options ()
  111. {
  112. local line name value
  113. if [ -f .config ]
  114. then
  115. {
  116. while read line
  117. do
  118. [ "$line" = "## options" ] && break
  119. done
  120. while read line
  121. do
  122. if [ "$line" = "## libs" ]
  123. then
  124. break
  125. else
  126. name=${line%=*}
  127. value=${line#*=}
  128. eval "$name='$value'"
  129. fi
  130. done
  131. } < .config
  132. fi
  133. }
  134. begin ()
  135. {
  136. echo -n "Checking sanity..."
  137. require_command pkg-config pkg-config > /dev/null
  138. require_command sed sed > /dev/null
  139. ok
  140. }
  141. warn ()
  142. {
  143. echo " ${BOLD}${YELLOW}* ${SGR0}$*"
  144. }
  145. info ()
  146. {
  147. echo "${BOLD}${CYAN}--- ${SGR0}$*"
  148. }
  149. begin_options ()
  150. {
  151. # get the old values
  152. extract_options
  153. if [ $HELP = yes ]
  154. then
  155. echo
  156. warn "This is a ${BOLD}non-configure${SGR0} script. Run without any arguments and you will be prompted"
  157. warn "with configuration choices. Alternatively, you may use the following autoconf style"
  158. warn "arguments for non-interactive configuration."
  159. echo
  160. echo " Available options:"
  161. echo
  162. else
  163. echo > .config
  164. append "# This file was automatically generated on `date`. Any changes may be lost!"
  165. append "## options"
  166. if [ $UPDATE = yes ]
  167. then
  168. info "Updating configuration"
  169. else
  170. info "Configuration required"
  171. fi
  172. fi
  173. }
  174. begin_tests ()
  175. {
  176. if [ $HELP = yes ]
  177. then
  178. echo
  179. exit 0;
  180. fi
  181. append "## libs"
  182. extract_options
  183. }
  184. append ()
  185. {
  186. echo "$1" >> .config
  187. }
  188. end ()
  189. {
  190. info "Configuration complete"
  191. touch .config
  192. }
  193. require_command ()
  194. {
  195. echo -n "Checking for ${BOLD}$1${SGR0}..."
  196. if ! [ -x "`which $2`" ]
  197. then
  198. failed
  199. fatal "Command $1 not found."
  200. else
  201. ok
  202. fi
  203. }
  204. require_package ()
  205. {
  206. local name
  207. echo -n "Checking for $BOLD$1$SGR0..."
  208. if ! pkg-config --exists $3
  209. then
  210. failed
  211. fatal "Required package $1 doesn't appear to be installed."
  212. elif ! pkg-config --atleast-version $2 $3
  213. then
  214. failed
  215. fatal "The installed version of $1 (`pkg-config --mod-version $3`) is too old."
  216. fi
  217. name="`upcase \"$1\"`"
  218. append "${name}_LIBS=`pkg-config --libs $3`"
  219. append "${name}_CFLAGS=-DHAVE_${1} `pkg-config --cflags $3`"
  220. ok `pkg-config --modversion "$3"`
  221. return 0
  222. }
  223. _test_version ()
  224. {
  225. [ $1 $4 $5 ] && [ $2 $4 $6 ] && [ $3 $4 $7 ]
  226. }
  227. test_version ()
  228. {
  229. local IFS
  230. IFS='.'
  231. if [ $2 != -ge ] && [ $2 != -le ]
  232. then
  233. fatal "Syntax error"
  234. fi
  235. _test_version $1 $2 $3
  236. }
  237. version_of ()
  238. {
  239. echo `pkg-config --modversion $1`
  240. }
  241. require_FLTK ()
  242. {
  243. local use
  244. echo -n "Checking for ${BOLD}FLTK${SGR0}..."
  245. FLTK_VERSION=`fltk-config --version`
  246. if ! test_version $FLTK_VERSION -ge $1
  247. then
  248. failed
  249. fatal "The installed FLTK version ($FLTK_VERSION) is too old."
  250. else
  251. ok $FLTK_VERSION
  252. fi
  253. use=
  254. while [ $# -gt 1 ]
  255. do
  256. shift 1
  257. use="$use --use-$1"
  258. done
  259. append "FLTK_LIBS=`fltk-config $use --ldflags`"
  260. append "FLTK_CFLAGS=`fltk-config $use --cflags`"
  261. }