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.

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