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.

341 lines
7.0KB

  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. eval "${2}='${A:-$D}'"
  106. }
  107. ok ()
  108. {
  109. echo -e '\r'`tput cuf 30`"$BOLD${GREEN}ok${SGR0} ${*:+${BOLD}${BLACK}($*)${SGR0}}"
  110. }
  111. failed ()
  112. {
  113. echo "$BOLD${RED}failed!${SGR0}" > /dev/stderr
  114. rm -f .config
  115. }
  116. using ()
  117. {
  118. [ "`eval echo \\$USE_$1`" = yes ]
  119. return $?
  120. }
  121. upcase ()
  122. {
  123. echo "$*" | tr '[[:lower:]]' '[[:upper:]]'
  124. }
  125. extract_options ()
  126. {
  127. local line name value
  128. if [ -f .config ]
  129. then
  130. {
  131. while read line
  132. do
  133. [ "$line" = "## options" ] && break
  134. done
  135. while read line
  136. do
  137. if [ "$line" = "## libs" ]
  138. then
  139. break
  140. else
  141. name=${line%=*}
  142. value=${line#*=}
  143. eval "$name='$value'"
  144. fi
  145. done
  146. } < .config
  147. fi
  148. }
  149. begin ()
  150. {
  151. echo -n "Checking sanity..."
  152. require_command pkg-config pkg-config > /dev/null
  153. require_command sed sed > /dev/null
  154. ok
  155. }
  156. warn ()
  157. {
  158. echo " ${BOLD}${YELLOW}* ${SGR0}$*"
  159. }
  160. info ()
  161. {
  162. echo "${BOLD}${CYAN}--- ${SGR0}$*"
  163. }
  164. begin_options ()
  165. {
  166. # get the old values
  167. extract_options
  168. if [ $HELP = yes ]
  169. then
  170. echo
  171. warn "This is a ${BOLD}non-configure${SGR0} script. Run without any arguments and you will be prompted"
  172. warn "with configuration choices. Alternatively, you may use the following autoconf style"
  173. warn "arguments for non-interactive configuration."
  174. echo
  175. echo " Available options:"
  176. echo
  177. else
  178. echo > .config
  179. append "# This file was automatically generated on `date`. Any changes may be lost!"
  180. append "## options"
  181. if [ $UPDATE = yes ]
  182. then
  183. info "Updating configuration"
  184. else
  185. info "Configuration required"
  186. fi
  187. fi
  188. }
  189. begin_tests ()
  190. {
  191. if [ $HELP = yes ]
  192. then
  193. echo
  194. exit 0;
  195. fi
  196. append "## libs"
  197. extract_options
  198. }
  199. append ()
  200. {
  201. echo "$1" >> .config
  202. }
  203. end ()
  204. {
  205. info "Configuration complete"
  206. touch .config
  207. }
  208. require_command ()
  209. {
  210. echo -n "Checking for ${BOLD}$1${SGR0}..."
  211. if ! [ -x "`which $2`" ]
  212. then
  213. failed
  214. fatal "Command $1 not found."
  215. else
  216. ok
  217. fi
  218. }
  219. require_package ()
  220. {
  221. local name
  222. echo -n "Checking for $BOLD$1$SGR0..."
  223. if ! pkg-config --exists $3
  224. then
  225. failed
  226. fatal "Required package $1 doesn't appear to be installed."
  227. elif ! pkg-config --atleast-version $2 $3
  228. then
  229. failed
  230. fatal "The installed version of $1 (`pkg-config --mod-version $3`) is too old."
  231. fi
  232. name="`upcase \"$1\"`"
  233. append "${name}_LIBS=`pkg-config --libs $3 | sed 's/,\\?--as-needed//g'`"
  234. append "${name}_CFLAGS=-DHAVE_${1} `pkg-config --cflags $3`"
  235. ok `pkg-config --modversion "$3"`
  236. return 0
  237. }
  238. _test_version ()
  239. {
  240. if [ $# = 6 ]
  241. then
  242. [ $1 -gt $4 ] && return 0
  243. [ $1 -eq $4 ] && [ $2 -gt $5 ] && return 0
  244. [ $1 -eq $4 ] && [ $2 -eq $5 ] && [ $3 -gt $6 ] && return 0
  245. [ $1 -eq $4 ] && [ $2 -eq $5 ] && [ $3 -eq $6 ] && return 0
  246. return 1
  247. elif [ $# = 4 ]
  248. then
  249. [ $1 -gt $3 ] && return 0
  250. [ $1 -eq $3 ] && [ $2 -eq $4 ] && return 0
  251. return 1
  252. fi
  253. }
  254. # return true if #1 is greater than or equal to $2
  255. test_version ()
  256. {
  257. local IFS
  258. IFS='.'
  259. _test_version $1 $2
  260. }
  261. version_of ()
  262. {
  263. echo `pkg-config --modversion $1`
  264. }
  265. require_FLTK ()
  266. {
  267. local use
  268. echo -n "Checking for ${BOLD}FLTK${SGR0}..."
  269. FLTK_VERSION=`fltk-config --version`
  270. if ! test_version $FLTK_VERSION $1
  271. then
  272. failed
  273. fatal "The installed FLTK version ($FLTK_VERSION) is too old."
  274. else
  275. ok $FLTK_VERSION
  276. fi
  277. use=
  278. while [ $# -gt 1 ]
  279. do
  280. shift 1
  281. use="$use --use-$1"
  282. done
  283. append "FLTK_LIBS=`fltk-config $use --ldflags | sed 's/,\\?--as-needed//g'`"
  284. append "FLTK_CFLAGS=`fltk-config $use --cflags`"
  285. }