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.

331 lines
6.7KB

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