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.

391 lines
8.3KB

  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 ' '`tput cuf 30`"$BOLD${GREEN}ok${SGR0} ${*:+${BOLD}${BLACK}($*)${SGR0}}"
  110. }
  111. failed ()
  112. {
  113. echo ' '`tput cuf 30`"$BOLD${RED}failed!${SGR0}" > /dev/stderr
  114. rm -f .config
  115. }
  116. missing ()
  117. {
  118. echo ' '`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. local name;
  217. if [ -x "$2" ]
  218. then
  219. name="$PWD/$2"
  220. ok "$name"
  221. elif [ -x "`which "$2"`" ]
  222. then
  223. name="`which "$2"`"
  224. ok "$name"
  225. else
  226. failed
  227. fatal "Command $1 not found."
  228. fi
  229. append "$1=$name"
  230. }
  231. require_package ()
  232. {
  233. local name
  234. echo -n "Checking for $BOLD$1$SGR0..."
  235. if ! pkg-config --exists $3
  236. then
  237. failed
  238. fatal "Required package $1 doesn't appear to be installed."
  239. elif ! pkg-config --atleast-version $2 $3
  240. then
  241. failed
  242. fatal "The installed version of $1 (`pkg-config --mod-version $3`) is too old."
  243. fi
  244. name="`upcase \"$1\"`"
  245. append "${name}_LIBS=`pkg-config --libs $3 | sed 's/,\\?--as-needed//g'`"
  246. append "${name}_CFLAGS=-DHAVE_${1} `pkg-config --cflags $3`"
  247. ok `pkg-config --modversion "$3"`
  248. return 0
  249. }
  250. suggest_package ()
  251. {
  252. local name
  253. echo -n "Checking for $BOLD$1$SGR0..."
  254. if ! pkg-config --exists $3
  255. then
  256. missing
  257. warn "Suggested package $1 doesn't appear to be installed. Some functionality may be missing from your build."
  258. warn "Continuing without $1...\n"
  259. return 1;
  260. elif ! pkg-config --atleast-version $2 $3
  261. then
  262. missing
  263. warn "The installed version of suggested package $1 (`pkg-config --mod-version $3`) is too old."
  264. warn "Continuing without $1..."
  265. return 1;
  266. fi
  267. name="`upcase \"$1\"`"
  268. append "${name}_LIBS=`pkg-config --libs $3 | sed 's/,\\?--as-needed//g'`"
  269. append "${name}_CFLAGS=-DHAVE_${1} `pkg-config --cflags $3`"
  270. ok `pkg-config --modversion "$3"`
  271. return 0
  272. }
  273. _test_version ()
  274. {
  275. if [ $# = 6 ]
  276. then
  277. [ $1 -gt $4 ] && return 0
  278. [ $1 -eq $4 ] && [ $2 -gt $5 ] && return 0
  279. [ $1 -eq $4 ] && [ $2 -eq $5 ] && [ $3 -gt $6 ] && return 0
  280. [ $1 -eq $4 ] && [ $2 -eq $5 ] && [ $3 -eq $6 ] && return 0
  281. return 1
  282. elif [ $# = 4 ]
  283. then
  284. [ $1 -gt $3 ] && return 0
  285. [ $1 -eq $3 ] && [ $2 -eq $4 ] && return 0
  286. return 1
  287. fi
  288. }
  289. # return true if #1 is greater than or equal to $2
  290. test_version ()
  291. {
  292. local IFS
  293. IFS='.'
  294. _test_version $1 $2
  295. }
  296. version_of ()
  297. {
  298. echo `pkg-config --modversion $1`
  299. }
  300. hostname_resolvable ()
  301. {
  302. ping -c1 `hostname` >/dev/null 2>/dev/null
  303. }
  304. require_FLTK ()
  305. {
  306. local use
  307. require_command fltk_config lib/fltk/fltk-config
  308. echo -n "Checking for ${BOLD}FLTK${SGR0}..."
  309. FLTK_VERSION=`lib/fltk/fltk-config --version`
  310. if ! test_version $FLTK_VERSION $1
  311. then
  312. failed
  313. fatal "The installed FLTK version ($FLTK_VERSION) is too old."
  314. else
  315. ok $FLTK_VERSION
  316. fi
  317. use=
  318. while [ $# -gt 1 ]
  319. do
  320. shift 1
  321. use="$use --use-$1"
  322. done
  323. append "FLTK_LIBS=`lib/fltk/fltk-config $use --libs | sed 's/,\\?--as-needed//g'`"
  324. append "FLTK_LDFLAGS=`lib/fltk/fltk-config $use --ldflags | sed 's/,\\?--as-needed//g'`"
  325. append "FLTK_CFLAGS=`lib/fltk/fltk-config $use --cflags`"
  326. }